SDL_LoadMUS_RW() now takes an argument telling whether or not the data source should be freed when done.
authorSam Lantinga <slouken@libsdl.org>
Sat, 01 Jun 2013 19:52:15 -0700
changeset 6251d489d8ec2e0
parent 624 449c261f8480
child 626 1da1d92ffa9c
SDL_LoadMUS_RW() now takes an argument telling whether or not the data source should be freed when done.
Fixes crashes cleaning up the data source for music when loading fails.
CHANGES.txt
SDL_mixer.h
VisualC/external/include/smpeg.h
VisualC/external/lib/x64/smpeg2.dll
VisualC/external/lib/x86/smpeg2.dll
Xcode/Frameworks/smpeg2.framework/Versions/A/Headers/smpeg.h
Xcode/Frameworks/smpeg2.framework/Versions/A/smpeg2
dynamic_mp3.c
dynamic_mp3.h
external/smpeg2-2.0.0/MPEG.cpp
external/smpeg2-2.0.0/MPEG.h
external/smpeg2-2.0.0/g++-fat.sh
external/smpeg2-2.0.0/smpeg.cpp
external/smpeg2-2.0.0/smpeg.h
fluidsynth.c
load_aiff.c
load_flac.c
load_ogg.c
load_voc.c
mixer.c
music.c
music_flac.c
music_flac.h
music_mad.c
music_modplug.c
music_ogg.c
music_ogg.h
native_midi/native_midi.h
native_midi/native_midi_common.c
native_midi/native_midi_haiku.cpp
native_midi/native_midi_mac.c
native_midi/native_midi_macosx.c
native_midi/native_midi_win32.c
playmus.c
timidity/playmidi.c
wavestream.c
wavestream.h
     1.1 --- a/CHANGES.txt	Sat Jun 01 15:49:18 2013 -0700
     1.2 +++ b/CHANGES.txt	Sat Jun 01 19:52:15 2013 -0700
     1.3 @@ -1,3 +1,8 @@
     1.4 +2.0.0:
     1.5 +Sam Lantinga - Sat Jun  1 19:11:08 PDT 2013
     1.6 + * Updated for SDL 2.0 release
     1.7 + * SDL_LoadMUS_RW() now takes an argument telling whether or not the data source should be freed when done.
     1.8 +
     1.9  1.2.13:
    1.10  Paul P Komkoff Jr - Sun Jul 22 16:12:28 PDT 2012
    1.11   * Fixed malloc/free mismatch in the MikMod driver
     2.1 --- a/SDL_mixer.h	Sat Jun 01 15:49:18 2013 -0700
     2.2 +++ b/SDL_mixer.h	Sat Jun 01 19:52:15 2013 -0700
     2.3 @@ -151,10 +151,10 @@
     2.4  
     2.5  /* Load a music file from an SDL_RWop object (Ogg and MikMod specific currently)
     2.6     Matt Campbell (matt@campbellhome.dhs.org) April 2000 */
     2.7 -extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS_RW(SDL_RWops *rw);
     2.8 +extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS_RW(SDL_RWops *src, int freesrc);
     2.9  
    2.10  /* Load a music file from an SDL_RWop object assuming a specific format */
    2.11 -extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUSType_RW(SDL_RWops *rw, Mix_MusicType type, int freesrc);
    2.12 +extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUSType_RW(SDL_RWops *src, Mix_MusicType type, int freesrc);
    2.13  
    2.14  /* Load a wave file of the mixer format from a memory buffer */
    2.15  extern DECLSPEC Mix_Chunk * SDLCALL Mix_QuickLoad_WAV(Uint8 *mem);
     3.1 --- a/VisualC/external/include/smpeg.h	Sat Jun 01 15:49:18 2013 -0700
     3.2 +++ b/VisualC/external/include/smpeg.h	Sat Jun 01 19:52:15 2013 -0700
     3.3 @@ -102,8 +102,10 @@
     3.4   */
     3.5  extern DECLSPEC SMPEG* SMPEG_new_data(void *data, int size, SMPEG_Info* info, int sdl_audio);
     3.6  
     3.7 -/* The same for a generic SDL_RWops structure. */
     3.8 -extern DECLSPEC SMPEG* SMPEG_new_rwops(SDL_RWops *src, SMPEG_Info* info, int sdl_audio);
     3.9 +/* The same for a generic SDL_RWops structure.
    3.10 +   'freesrc' should be non-zero if SMPEG should close the source when it's done.
    3.11 + */
    3.12 +extern DECLSPEC SMPEG* SMPEG_new_rwops(SDL_RWops *src, SMPEG_Info* info, int freesrc, int sdl_audio);
    3.13  
    3.14  /* Get current information about an SMPEG object */
    3.15  extern DECLSPEC void SMPEG_getinfo( SMPEG* mpeg, SMPEG_Info* info );
     4.1 Binary file VisualC/external/lib/x64/smpeg2.dll has changed
     5.1 Binary file VisualC/external/lib/x86/smpeg2.dll has changed
     6.1 --- a/Xcode/Frameworks/smpeg2.framework/Versions/A/Headers/smpeg.h	Sat Jun 01 15:49:18 2013 -0700
     6.2 +++ b/Xcode/Frameworks/smpeg2.framework/Versions/A/Headers/smpeg.h	Sat Jun 01 19:52:15 2013 -0700
     6.3 @@ -102,8 +102,10 @@
     6.4   */
     6.5  extern DECLSPEC SMPEG* SMPEG_new_data(void *data, int size, SMPEG_Info* info, int sdl_audio);
     6.6  
     6.7 -/* The same for a generic SDL_RWops structure. */
     6.8 -extern DECLSPEC SMPEG* SMPEG_new_rwops(SDL_RWops *src, SMPEG_Info* info, int sdl_audio);
     6.9 +/* The same for a generic SDL_RWops structure.
    6.10 +   'freesrc' should be non-zero if SMPEG should close the source when it's done.
    6.11 + */
    6.12 +extern DECLSPEC SMPEG* SMPEG_new_rwops(SDL_RWops *src, SMPEG_Info* info, int freesrc, int sdl_audio);
    6.13  
    6.14  /* Get current information about an SMPEG object */
    6.15  extern DECLSPEC void SMPEG_getinfo( SMPEG* mpeg, SMPEG_Info* info );
     7.1 Binary file Xcode/Frameworks/smpeg2.framework/Versions/A/smpeg2 has changed
     8.1 --- a/dynamic_mp3.c	Sat Jun 01 15:49:18 2013 -0700
     8.2 +++ b/dynamic_mp3.c	Sat Jun 01 19:52:15 2013 -0700
     8.3 @@ -66,7 +66,7 @@
     8.4              return -1;
     8.5          }
     8.6          smpeg.SMPEG_new_rwops =
     8.7 -            (SMPEG* (*)(SDL_RWops *, SMPEG_Info*, int))
     8.8 +            (SMPEG* (*)(SDL_RWops *, SMPEG_Info*, int, int))
     8.9              SDL_LoadFunction(smpeg.handle, "SMPEG_new_rwops");
    8.10          if ( smpeg.SMPEG_new_rwops == NULL ) {
    8.11              SDL_UnloadObject(smpeg.handle);
     9.1 --- a/dynamic_mp3.h	Sat Jun 01 15:49:18 2013 -0700
     9.2 +++ b/dynamic_mp3.h	Sat Jun 01 19:52:15 2013 -0700
     9.3 @@ -29,7 +29,7 @@
     9.4      void (*SMPEG_delete)( SMPEG* mpeg );
     9.5      void (*SMPEG_enableaudio)( SMPEG* mpeg, int enable );
     9.6      void (*SMPEG_enablevideo)( SMPEG* mpeg, int enable );
     9.7 -    SMPEG* (*SMPEG_new_rwops)(SDL_RWops *src, SMPEG_Info* info, int sdl_audio);
     9.8 +    SMPEG* (*SMPEG_new_rwops)(SDL_RWops *src, SMPEG_Info* info, int freesrc, int sdl_audio);
     9.9      void (*SMPEG_play)( SMPEG* mpeg );
    9.10      int (*SMPEG_playAudio)( SMPEG *mpeg, Uint8 *stream, int len );
    9.11      void (*SMPEG_rewind)( SMPEG* mpeg );
    10.1 --- a/external/smpeg2-2.0.0/MPEG.cpp	Sat Jun 01 15:49:18 2013 -0700
    10.2 +++ b/external/smpeg2-2.0.0/MPEG.cpp	Sat Jun 01 19:52:15 2013 -0700
    10.3 @@ -28,7 +28,7 @@
    10.4      SetError(SDL_GetError());
    10.5      return;
    10.6    }
    10.7 -  Init(source, SDLaudio);
    10.8 +  Init(source, SDL_TRUE, SDLaudio);
    10.9  }
   10.10  
   10.11  MPEG::MPEG(int Mpeg_FD, bool SDLaudio) :
   10.12 @@ -47,13 +47,13 @@
   10.13      return;
   10.14    }
   10.15  
   10.16 -  source = SDL_RWFromFP(file,(SDL_bool) false);
   10.17 +  source = SDL_RWFromFP(file, SDL_FALSE);
   10.18    if (!source) {
   10.19      InitErrorState();
   10.20      SetError(SDL_GetError());
   10.21      return;
   10.22    }
   10.23 -  Init(source, SDLaudio);
   10.24 +  Init(source, SDL_TRUE, SDLaudio);
   10.25  }
   10.26  
   10.27  MPEG::MPEG(void *data, int size, bool SDLaudio) :
   10.28 @@ -72,19 +72,20 @@
   10.29      SetError(SDL_GetError());
   10.30      return;
   10.31    }
   10.32 -  Init(source, SDLaudio);
   10.33 +  Init(source, SDL_TRUE, SDLaudio);
   10.34  }
   10.35  
   10.36 -MPEG::MPEG(SDL_RWops *mpeg_source, bool SDLaudio) :
   10.37 +MPEG::MPEG(SDL_RWops *mpeg_source, int mpeg_freesrc, bool SDLaudio) :
   10.38    MPEGerror()
   10.39  {
   10.40    mpeg_mem = 0;
   10.41 -  Init(mpeg_source, SDLaudio);
   10.42 +  Init(mpeg_source, mpeg_freesrc, SDLaudio);
   10.43  }
   10.44  
   10.45 -void MPEG::Init(SDL_RWops *mpeg_source, bool SDLaudio)
   10.46 +void MPEG::Init(SDL_RWops *mpeg_source, int mpeg_freesrc, bool SDLaudio)
   10.47  {
   10.48      source = mpeg_source;
   10.49 +    freesrc = mpeg_freesrc;
   10.50      sdlaudio = SDLaudio;
   10.51  
   10.52      /* Create the system that will parse the MPEG stream */
   10.53 @@ -135,6 +136,7 @@
   10.54      system = NULL;
   10.55      error = NULL;
   10.56      source = NULL;
   10.57 +    freesrc = 0;
   10.58  
   10.59      audiostream = videostream = NULL;
   10.60      audioaction = NULL;
   10.61 @@ -152,10 +154,8 @@
   10.62    if(video) delete video;
   10.63    if(audio) delete audio;
   10.64    if(system) delete system;
   10.65 -  
   10.66 -  if(source) SDL_RWclose(source);
   10.67 -  if ( mpeg_mem )
   10.68 -    delete[] mpeg_mem;
   10.69 +  if(source && freesrc) SDL_RWclose(source);
   10.70 +  if (mpeg_mem) delete[] mpeg_mem;
   10.71  }
   10.72  
   10.73  bool MPEG::AudioEnabled(void) {
    11.1 --- a/external/smpeg2-2.0.0/MPEG.h	Sat Jun 01 15:49:18 2013 -0700
    11.2 +++ b/external/smpeg2-2.0.0/MPEG.h	Sat Jun 01 19:52:15 2013 -0700
    11.3 @@ -58,11 +58,11 @@
    11.4      MPEG(const char * name, bool SDLaudio = true);
    11.5      MPEG(int Mpeg_FD, bool SDLaudio = true);
    11.6      MPEG(void *data, int size, bool SDLaudio = true);
    11.7 -    MPEG(SDL_RWops *mpeg_source,bool SDLaudio = true);
    11.8 +    MPEG(SDL_RWops *mpeg_source, int mpeg_freesrc, bool SDLaudio = true);
    11.9      virtual ~MPEG();
   11.10  
   11.11      /* Initialize the MPEG */
   11.12 -    void Init(SDL_RWops *mpeg_source, bool SDLaudio);
   11.13 +    void Init(SDL_RWops *mpeg_source, int mpeg_freesrc, bool SDLaudio);
   11.14      void InitErrorState();
   11.15  
   11.16      /* Enable/Disable audio and video */
   11.17 @@ -108,6 +108,7 @@
   11.18  protected:
   11.19      char *mpeg_mem;       // Used to copy MPEG passed in as memory
   11.20      SDL_RWops *source;
   11.21 +    int freesrc;
   11.22      MPEGaudioaction *audioaction;
   11.23      MPEGvideoaction *videoaction;
   11.24  
    12.1 --- a/external/smpeg2-2.0.0/g++-fat.sh	Sat Jun 01 15:49:18 2013 -0700
    12.2 +++ b/external/smpeg2-2.0.0/g++-fat.sh	Sat Jun 01 19:52:15 2013 -0700
    12.3 @@ -2,7 +2,7 @@
    12.4  #
    12.5  # Build Universal binaries on Mac OS X, thanks Ryan!
    12.6  #
    12.7 -# Usage: ./configure CC="sh g++-fat.sh" && make && rm -rf x86 x64
    12.8 +# Usage: ./configure CXX="sh g++-fat.sh" && make && rm -rf x86 x64
    12.9  
   12.10  DEVELOPER="`xcode-select -print-path`/Platforms/MacOSX.platform/Developer"
   12.11  
    13.1 --- a/external/smpeg2-2.0.0/smpeg.cpp	Sat Jun 01 15:49:18 2013 -0700
    13.2 +++ b/external/smpeg2-2.0.0/smpeg.cpp	Sat Jun 01 19:52:15 2013 -0700
    13.3 @@ -131,7 +131,7 @@
    13.4      return(mpeg);
    13.5  }
    13.6  
    13.7 -SMPEG* SMPEG_new_rwops(SDL_RWops *src, SMPEG_Info* info, int sdl_audio)
    13.8 +SMPEG* SMPEG_new_rwops(SDL_RWops *src, SMPEG_Info* info, int freesrc, int sdl_audio)
    13.9  {
   13.10      SMPEG *mpeg;
   13.11  
   13.12 @@ -140,7 +140,7 @@
   13.13  
   13.14      /* Create a new SMPEG object! */
   13.15      mpeg = new SMPEG;
   13.16 -    mpeg->obj = new MPEG(src, sdl_audio ? true : false);
   13.17 +    mpeg->obj = new MPEG(src, freesrc, sdl_audio ? true : false);
   13.18  
   13.19      /* Find out the details of the stream, if requested */
   13.20      SMPEG_getinfo(mpeg, info);
    14.1 --- a/external/smpeg2-2.0.0/smpeg.h	Sat Jun 01 15:49:18 2013 -0700
    14.2 +++ b/external/smpeg2-2.0.0/smpeg.h	Sat Jun 01 19:52:15 2013 -0700
    14.3 @@ -102,8 +102,10 @@
    14.4   */
    14.5  extern DECLSPEC SMPEG* SMPEG_new_data(void *data, int size, SMPEG_Info* info, int sdl_audio);
    14.6  
    14.7 -/* The same for a generic SDL_RWops structure. */
    14.8 -extern DECLSPEC SMPEG* SMPEG_new_rwops(SDL_RWops *src, SMPEG_Info* info, int sdl_audio);
    14.9 +/* The same for a generic SDL_RWops structure.
   14.10 +   'freesrc' should be non-zero if SMPEG should close the source when it's done.
   14.11 + */
   14.12 +extern DECLSPEC SMPEG* SMPEG_new_rwops(SDL_RWops *src, SMPEG_Info* info, int freesrc, int sdl_audio);
   14.13  
   14.14  /* Get current information about an SMPEG object */
   14.15  extern DECLSPEC void SMPEG_getinfo( SMPEG* mpeg, SMPEG_Info* info );
    15.1 --- a/fluidsynth.c	Sat Jun 01 15:49:18 2013 -0700
    15.2 +++ b/fluidsynth.c	Sat Jun 01 19:52:15 2013 -0700
    15.3 @@ -111,18 +111,18 @@
    15.4  
    15.5  static int fluidsynth_loadsong_RW_internal(FluidSynthMidiSong *song, void *data)
    15.6  {
    15.7 -    off_t offset;
    15.8 +    Sint64 offset;
    15.9      size_t size;
   15.10      char *buffer;
   15.11 -    SDL_RWops *rw = (SDL_RWops*) data;
   15.12 +    SDL_RWops *src = (SDL_RWops*) data;
   15.13  
   15.14 -    offset = SDL_RWtell(rw);
   15.15 -    SDL_RWseek(rw, 0, RW_SEEK_END);
   15.16 -    size = SDL_RWtell(rw) - offset;
   15.17 -    SDL_RWseek(rw, offset, RW_SEEK_SET);
   15.18 +    offset = SDL_RWtell(src);
   15.19 +    SDL_RWseek(src, 0, RW_SEEK_END);
   15.20 +    size = (size_t)(SDL_RWtell(src) - offset);
   15.21 +    SDL_RWseek(src, offset, RW_SEEK_SET);
   15.22  
   15.23      if ((buffer = (char*) SDL_malloc(size))) {
   15.24 -        if(SDL_RWread(rw, buffer, size, 1) == 1) {
   15.25 +        if(SDL_RWread(src, buffer, size, 1) == 1) {
   15.26              if (fluidsynth.fluid_player_add_mem(song->player, buffer, size) == FLUID_OK) {
   15.27                  return 1;
   15.28              } else {
   15.29 @@ -138,13 +138,13 @@
   15.30      return 0;
   15.31  }
   15.32  
   15.33 -FluidSynthMidiSong *fluidsynth_loadsong_RW(SDL_RWops *rw, int freerw)
   15.34 +FluidSynthMidiSong *fluidsynth_loadsong_RW(SDL_RWops *src, int freesrc)
   15.35  {
   15.36      FluidSynthMidiSong *song;
   15.37  
   15.38 -    song = fluidsynth_loadsong_common(fluidsynth_loadsong_RW_internal, (void*) rw);
   15.39 -    if (freerw) {
   15.40 -        SDL_RWclose(rw);
   15.41 +    song = fluidsynth_loadsong_common(fluidsynth_loadsong_RW_internal, (void*) src);
   15.42 +    if (song && freesrc) {
   15.43 +        SDL_RWclose(src);
   15.44      }
   15.45      return song;
   15.46  }
    16.1 --- a/load_aiff.c	Sat Jun 01 15:49:18 2013 -0700
    16.2 +++ b/load_aiff.c	Sat Jun 01 19:52:15 2013 -0700
    16.3 @@ -239,10 +239,10 @@
    16.4      *audio_len &= ~((samplesize / 8) - 1);
    16.5  
    16.6  done:
    16.7 -    if ( freesrc && src ) {
    16.8 +    if (freesrc && src) {
    16.9          SDL_RWclose(src);
   16.10      }
   16.11 -    if ( was_error ) {
   16.12 +    if (was_error) {
   16.13          spec = NULL;
   16.14      }
   16.15      return(spec);
    17.1 --- a/load_flac.c	Sat Jun 01 15:49:18 2013 -0700
    17.2 +++ b/load_flac.c	Sat Jun 01 19:52:15 2013 -0700
    17.3 @@ -315,15 +315,13 @@
    17.4          flac.FLAC__stream_decoder_delete (decoder);
    17.5      }
    17.6  
    17.7 -    if (src) {
    17.8 -        if (freesrc)
    17.9 -            SDL_RWclose (src);
   17.10 -        else
   17.11 -            SDL_RWseek (src, 0, RW_SEEK_SET);
   17.12 +    if (freesrc && src) {
   17.13 +        SDL_RWclose (src);
   17.14      }
   17.15  
   17.16 -    if (was_error)
   17.17 +    if (was_error) {
   17.18          spec = NULL;
   17.19 +    }
   17.20  
   17.21      return spec;
   17.22  }
    18.1 --- a/load_ogg.c	Sat Jun 01 15:49:18 2013 -0700
    18.2 +++ b/load_ogg.c	Sat Jun 01 19:52:15 2013 -0700
    18.3 @@ -144,16 +144,13 @@
    18.4      *audio_len &= ~(samplesize-1);
    18.5  
    18.6  done:
    18.7 -    if (src && must_close)
    18.8 -    {
    18.9 -        if (freesrc)
   18.10 -            SDL_RWclose(src);
   18.11 -        else
   18.12 -            SDL_RWseek(src, 0, RW_SEEK_SET);
   18.13 +    if (freesrc && src && must_close) {
   18.14 +        SDL_RWclose(src);
   18.15      }
   18.16  
   18.17 -    if ( was_error )
   18.18 +    if (was_error) {
   18.19          spec = NULL;
   18.20 +    }
   18.21  
   18.22      return(spec);
   18.23  } /* Mix_LoadOGG_RW */
    19.1 --- a/load_voc.c	Sat Jun 01 15:49:18 2013 -0700
    19.2 +++ b/load_voc.c	Sat Jun 01 19:52:15 2013 -0700
    19.3 @@ -445,16 +445,13 @@
    19.4      *audio_len &= ~(samplesize-1);
    19.5  
    19.6  done:
    19.7 -    if (src)
    19.8 -    {
    19.9 -        if (freesrc)
   19.10 -            SDL_RWclose(src);
   19.11 -        else
   19.12 -            SDL_RWseek(src, 0, RW_SEEK_SET);
   19.13 +    if (freesrc && src) {
   19.14 +        SDL_RWclose(src);
   19.15      }
   19.16  
   19.17 -    if ( was_error )
   19.18 +    if (was_error) {
   19.19          spec = NULL;
   19.20 +    }
   19.21  
   19.22      return(spec);
   19.23  } /* Mix_LoadVOC_RW */
    20.1 --- a/mixer.c	Sat Jun 01 15:49:18 2013 -0700
    20.2 +++ b/mixer.c	Sat Jun 01 19:52:15 2013 -0700
    20.3 @@ -561,7 +561,7 @@
    20.4      /* Make sure audio has been opened */
    20.5      if ( ! audio_opened ) {
    20.6          SDL_SetError("Audio device hasn't been opened");
    20.7 -        if ( freesrc && src ) {
    20.8 +        if ( freesrc ) {
    20.9              SDL_RWclose(src);
   20.10          }
   20.11          return(NULL);
    21.1 --- a/music.c	Sat Jun 01 15:49:18 2013 -0700
    21.2 +++ b/music.c	Sat Jun 01 19:52:15 2013 -0700
    21.3 @@ -192,7 +192,7 @@
    21.4  
    21.5  
    21.6  /* If music isn't playing, halt it if no looping is required, restart it */
    21.7 -/* otherwhise. NOP if the music is playing */
    21.8 +/* othesrchise. NOP if the music is playing */
    21.9  static int music_halt_or_loop (void)
   21.10  {
   21.11      /* Restart music if it has to loop */
   21.12 @@ -461,17 +461,17 @@
   21.13   * actually be MOD-based.
   21.14   *
   21.15   * Returns MUS_NONE in case of errors. */
   21.16 -static Mix_MusicType detect_music_type(SDL_RWops *rw)
   21.17 +static Mix_MusicType detect_music_type(SDL_RWops *src)
   21.18  {
   21.19      Uint8 magic[5];
   21.20      Uint8 moremagic[9];
   21.21  
   21.22 -    Sint64 start = SDL_RWtell(rw);
   21.23 -    if (SDL_RWread(rw, magic, 1, 4) != 4 || SDL_RWread(rw, moremagic, 1, 8) != 8 ) {
   21.24 +    Sint64 start = SDL_RWtell(src);
   21.25 +    if (SDL_RWread(src, magic, 1, 4) != 4 || SDL_RWread(src, moremagic, 1, 8) != 8 ) {
   21.26          Mix_SetError("Couldn't read from RWops");
   21.27          return MUS_NONE;
   21.28      }
   21.29 -    SDL_RWseek(rw, start, RW_SEEK_SET);
   21.30 +    SDL_RWseek(src, start, RW_SEEK_SET);
   21.31      magic[4]='\0';
   21.32      moremagic[8] = '\0';
   21.33  
   21.34 @@ -512,7 +512,7 @@
   21.35  /* Load a music file */
   21.36  Mix_Music *Mix_LoadMUS(const char *file)
   21.37  {
   21.38 -    SDL_RWops *rw;
   21.39 +    SDL_RWops *src;
   21.40      Mix_Music *music;
   21.41      Mix_MusicType type;
   21.42      char *ext = strrchr(file, '.');
   21.43 @@ -536,8 +536,8 @@
   21.44      }
   21.45  #endif
   21.46  
   21.47 -    rw = SDL_RWFromFile(file, "rb");
   21.48 -    if ( rw == NULL ) {
   21.49 +    src = SDL_RWFromFile(file, "rb");
   21.50 +    if ( src == NULL ) {
   21.51          Mix_SetError("Couldn't open '%s'", file);
   21.52          return NULL;
   21.53      }
   21.54 @@ -567,40 +567,44 @@
   21.55          }
   21.56      }
   21.57      if ( type == MUS_NONE ) {
   21.58 -        type = detect_music_type(rw);
   21.59 +        type = detect_music_type(src);
   21.60      }
   21.61  
   21.62      /* We need to know if a specific error occurs; if not, we'll set a
   21.63       * generic one, so we clear the current one. */
   21.64      Mix_SetError("");
   21.65 -    music = Mix_LoadMUSType_RW(rw, type, SDL_TRUE);
   21.66 +    music = Mix_LoadMUSType_RW(src, type, SDL_TRUE);
   21.67      if ( music == NULL && Mix_GetError()[0] == '\0' ) {
   21.68 -        SDL_FreeRW(rw);
   21.69          Mix_SetError("Couldn't open '%s'", file);
   21.70      }
   21.71      return music;
   21.72  }
   21.73  
   21.74 -Mix_Music *Mix_LoadMUS_RW(SDL_RWops *rw)
   21.75 +Mix_Music *Mix_LoadMUS_RW(SDL_RWops *src, int freesrc)
   21.76  {
   21.77 -    return Mix_LoadMUSType_RW(rw, MUS_NONE, SDL_FALSE);
   21.78 +    return Mix_LoadMUSType_RW(src, MUS_NONE, freesrc);
   21.79  }
   21.80  
   21.81 -Mix_Music *Mix_LoadMUSType_RW(SDL_RWops *rw, Mix_MusicType type, int freesrc)
   21.82 +Mix_Music *Mix_LoadMUSType_RW(SDL_RWops *src, Mix_MusicType type, int freesrc)
   21.83  {
   21.84      Mix_Music *music;
   21.85 +    Sint64 start;
   21.86  
   21.87 -    if (!rw) {
   21.88 +    if (!src) {
   21.89          Mix_SetError("RWops pointer is NULL");
   21.90          return NULL;
   21.91      }
   21.92 +    start = SDL_RWtell(src);
   21.93  
   21.94      /* If the caller wants auto-detection, figure out what kind of file
   21.95       * this is. */
   21.96      if (type == MUS_NONE) {
   21.97 -        if ((type = detect_music_type(rw)) == MUS_NONE) {
   21.98 +        if ((type = detect_music_type(src)) == MUS_NONE) {
   21.99              /* Don't call Mix_SetError() here since detect_music_type()
  21.100               * does that. */
  21.101 +            if (freesrc) {
  21.102 +                SDL_RWclose(src);
  21.103 +            }
  21.104              return NULL;
  21.105          }
  21.106      }
  21.107 @@ -609,73 +613,66 @@
  21.108      music = (Mix_Music *)SDL_malloc(sizeof(Mix_Music));
  21.109      if (music == NULL ) {
  21.110          Mix_SetError("Out of memory");
  21.111 +        if (freesrc) {
  21.112 +            SDL_RWclose(src);
  21.113 +        }
  21.114          return NULL;
  21.115      }
  21.116 -    music->error = 0;
  21.117 +    music->error = 1;
  21.118  
  21.119      switch (type) {
  21.120  #ifdef WAV_MUSIC
  21.121      case MUS_WAV:
  21.122 -        /* The WAVE loader needs the first 4 bytes of the header */
  21.123 -        {
  21.124 -            Uint8 magic[5];
  21.125 -            Sint64 start = SDL_RWtell(rw);
  21.126 -            if (SDL_RWread(rw, magic, 1, 4) != 4) {
  21.127 -                Mix_SetError("Couldn't read from RWops");
  21.128 -                SDL_free(music);
  21.129 -                return NULL;
  21.130 -            }
  21.131 -            SDL_RWseek(rw, start, RW_SEEK_SET);
  21.132 -            magic[4] = '\0';
  21.133 -            music->type = MUS_WAV;
  21.134 -            music->data.wave = WAVStream_LoadSong_RW(rw, (char *)magic, freesrc);
  21.135 -        }
  21.136 -        if (music->data.wave == NULL) {
  21.137 -            music->error = 1;
  21.138 +        music->type = MUS_WAV;
  21.139 +        music->data.wave = WAVStream_LoadSong_RW(src, freesrc);
  21.140 +        if (music->data.wave) {
  21.141 +            music->error = 0;
  21.142          }
  21.143          break;
  21.144  #endif
  21.145  #ifdef OGG_MUSIC
  21.146      case MUS_OGG:
  21.147          music->type = MUS_OGG;
  21.148 -        music->data.ogg = OGG_new_RW(rw, freesrc);
  21.149 -        if ( music->data.ogg == NULL ) {
  21.150 -            music->error = 1;
  21.151 +        music->data.ogg = OGG_new_RW(src, freesrc);
  21.152 +        if (music->data.ogg) {
  21.153 +            music->error = 0;
  21.154          }
  21.155          break;
  21.156  #endif
  21.157  #ifdef FLAC_MUSIC
  21.158      case MUS_FLAC:
  21.159          music->type = MUS_FLAC;
  21.160 -        music->data.flac = FLAC_new_RW(rw, freesrc);
  21.161 -        if ( music->data.flac == NULL ) {
  21.162 -            music->error = 1;
  21.163 +        music->data.flac = FLAC_new_RW(src, freesrc);
  21.164 +        if (music->data.flac) {
  21.165 +            music->error = 0;
  21.166          }
  21.167          break;
  21.168  #endif
  21.169  #ifdef MP3_MUSIC
  21.170      case MUS_MP3:
  21.171 -        if ( Mix_Init(MIX_INIT_MP3) ) {
  21.172 +        if (Mix_Init(MIX_INIT_MP3)) {
  21.173              SMPEG_Info info;
  21.174              music->type = MUS_MP3;
  21.175 -            music->data.mp3 = smpeg.SMPEG_new_rwops(rw, &info, 0);
  21.176 -            if ( !info.has_audio ) {
  21.177 +            music->data.mp3 = smpeg.SMPEG_new_rwops(src, &info, freesrc, 0);
  21.178 +            if (!info.has_audio) {
  21.179                  Mix_SetError("MPEG file does not have any audio stream.");
  21.180 -                music->error = 1;
  21.181 +                smpeg.SMPEG_delete(music->data.mp3);
  21.182 +                /* Deleting the MP3 closed the source if desired */
  21.183 +                freesrc = SDL_FALSE;
  21.184              } else {
  21.185                  smpeg.SMPEG_actualSpec(music->data.mp3, &used_mixer);
  21.186 +                music->error = 0;
  21.187              }
  21.188 -        } else {
  21.189 -            music->error = 1;
  21.190          }
  21.191          break;
  21.192  #elif defined(MP3_MAD_MUSIC)
  21.193      case MUS_MP3:
  21.194          music->type = MUS_MP3_MAD;
  21.195 -        music->data.mp3_mad = mad_openFileRW(rw, &used_mixer, freesrc);
  21.196 -        if (music->data.mp3_mad == 0) {
  21.197 +        music->data.mp3_mad = mad_openFileRW(src, &used_mixer, freesrc);
  21.198 +        if (music->data.mp3_mad) {
  21.199 +            music->error = 0;
  21.200 +        } else {
  21.201              Mix_SetError("Could not initialize MPEG stream.");
  21.202 -            music->error = 1;
  21.203          }
  21.204          break;
  21.205  #endif
  21.206 @@ -683,55 +680,60 @@
  21.207      case MUS_MID:
  21.208          music->type = MUS_MID;
  21.209  #ifdef USE_NATIVE_MIDI
  21.210 -        if ( native_midi_ok ) {
  21.211 -            music->data.nativemidi = native_midi_loadsong_RW(rw, freesrc);
  21.212 -            if ( music->data.nativemidi == NULL ) {
  21.213 +        if (native_midi_ok) {
  21.214 +            SDL_RWseek(src, start, RW_SEEK_SET);
  21.215 +            music->data.nativemidi = native_midi_loadsong_RW(src, freesrc);
  21.216 +            if (music->data.nativemidi) {
  21.217 +                music->error = 0;
  21.218 +            } else {
  21.219                  Mix_SetError("%s", native_midi_error());
  21.220 -                music->error = 1;
  21.221              }
  21.222              break;
  21.223          }
  21.224  #endif
  21.225  #ifdef USE_FLUIDSYNTH_MIDI
  21.226 -        if ( fluidsynth_ok ) {
  21.227 -            music->data.fluidsynthmidi = fluidsynth_loadsong_RW(rw, freesrc);
  21.228 -            if ( music->data.fluidsynthmidi == NULL ) {
  21.229 -                music->error = 1;
  21.230 +        if (fluidsynth_ok) {
  21.231 +            SDL_RWseek(src, start, RW_SEEK_SET);
  21.232 +            music->data.fluidsynthmidi = fluidsynth_loadsong_RW(src, freesrc);
  21.233 +            if (music->data.fluidsynthmidi) {
  21.234 +                music->error = 0;
  21.235              }
  21.236              break;
  21.237          }
  21.238  #endif
  21.239  #ifdef USE_TIMIDITY_MIDI
  21.240 -        if ( timidity_ok ) {
  21.241 -            music->data.midi = Timidity_LoadSong_RW(rw, freesrc);
  21.242 -            if ( music->data.midi == NULL ) {
  21.243 +        if (timidity_ok) {
  21.244 +            SDL_RWseek(src, start, RW_SEEK_SET);
  21.245 +            music->data.midi = Timidity_LoadSong_RW(src, freesrc);
  21.246 +            if (music->data.midi) {
  21.247 +                music->error = 0;
  21.248 +            } else {
  21.249                  Mix_SetError("%s", Timidity_Error());
  21.250 -                music->error = 1;
  21.251              }
  21.252          } else {
  21.253              Mix_SetError("%s", Timidity_Error());
  21.254 -            music->error = 1;
  21.255          }
  21.256  #endif
  21.257          break;
  21.258  #endif
  21.259  #if defined(MODPLUG_MUSIC) || defined(MOD_MUSIC)
  21.260      case MUS_MOD:
  21.261 -        music->error = 1;
  21.262  #ifdef MODPLUG_MUSIC
  21.263 -        if ( music->error ) {
  21.264 +        if (music->error) {
  21.265 +            SDL_RWseek(src, start, RW_SEEK_SET);
  21.266              music->type = MUS_MODPLUG;
  21.267 -            music->data.modplug = modplug_new_RW(rw, freesrc);
  21.268 -            if ( music->data.modplug ) {
  21.269 +            music->data.modplug = modplug_new_RW(src, freesrc);
  21.270 +            if (music->data.modplug) {
  21.271                  music->error = 0;
  21.272              }
  21.273          }
  21.274  #endif
  21.275  #ifdef MOD_MUSIC
  21.276 -        if ( music->error ) {
  21.277 +        if (music->error) {
  21.278 +            SDL_RWseek(src, start, RW_SEEK_SET);
  21.279              music->type = MUS_MOD;
  21.280 -            music->data.module = MOD_new_RW(rw, freesrc);
  21.281 -            if ( music->data.module ) {
  21.282 +            music->data.module = MOD_new_RW(src, freesrc);
  21.283 +            if (music->data.module) {
  21.284                  music->error = 0;
  21.285              }
  21.286          }
  21.287 @@ -741,15 +743,19 @@
  21.288  
  21.289      default:
  21.290          Mix_SetError("Unrecognized music format");
  21.291 -        music->error=1;
  21.292 +        break;
  21.293      } /* switch (want) */
  21.294  
  21.295 -
  21.296      if (music->error) {
  21.297          SDL_free(music);
  21.298 -        music=NULL;
  21.299 +        if (freesrc) {
  21.300 +            SDL_RWclose(src);
  21.301 +        } else {
  21.302 +            SDL_RWseek(src, start, RW_SEEK_SET);
  21.303 +        }
  21.304 +        music = NULL;
  21.305      }
  21.306 -    return(music);
  21.307 +    return music;
  21.308  }
  21.309  
  21.310  /* Free a music chunk previously loaded */
    22.1 --- a/music_flac.c	Sat Jun 01 15:49:18 2013 -0700
    22.2 +++ b/music_flac.c	Sat Jun 01 19:52:15 2013 -0700
    22.3 @@ -60,7 +60,7 @@
    22.4  
    22.5      // make sure there is something to be reading
    22.6      if (*bytes > 0) {
    22.7 -        *bytes = SDL_RWread (data->rwops, buffer, sizeof (FLAC__byte), *bytes);
    22.8 +        *bytes = SDL_RWread (data->src, buffer, sizeof (FLAC__byte), *bytes);
    22.9  
   22.10          if (*bytes == 0 ) { // error or no data was read (EOF)
   22.11              return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
   22.12 @@ -79,7 +79,7 @@
   22.13  {
   22.14      FLAC_music *data = (FLAC_music*)client_data;
   22.15  
   22.16 -    if (SDL_RWseek (data->rwops, absolute_byte_offset, RW_SEEK_SET) < 0) {
   22.17 +    if (SDL_RWseek (data->src, absolute_byte_offset, RW_SEEK_SET) < 0) {
   22.18          return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
   22.19      } else {
   22.20          return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
   22.21 @@ -93,7 +93,7 @@
   22.22  {
   22.23      FLAC_music *data = (FLAC_music*)client_data;
   22.24  
   22.25 -    Sint64 pos = SDL_RWtell (data->rwops);
   22.26 +    Sint64 pos = SDL_RWtell (data->src);
   22.27  
   22.28      if (pos < 0) {
   22.29          return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
   22.30 @@ -110,10 +110,10 @@
   22.31  {
   22.32      FLAC_music *data = (FLAC_music*)client_data;
   22.33  
   22.34 -    Sint64 pos = SDL_RWtell (data->rwops);
   22.35 -    Sint64 length = SDL_RWseek (data->rwops, 0, RW_SEEK_END);
   22.36 +    Sint64 pos = SDL_RWtell (data->src);
   22.37 +    Sint64 length = SDL_RWseek (data->src, 0, RW_SEEK_END);
   22.38  
   22.39 -    if (SDL_RWseek (data->rwops, pos, RW_SEEK_SET) != pos || length < 0) {
   22.40 +    if (SDL_RWseek (data->src, pos, RW_SEEK_SET) != pos || length < 0) {
   22.41          /* there was an error attempting to return the stream to the original
   22.42           * position, or the length was invalid. */
   22.43          return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
   22.44 @@ -129,8 +129,8 @@
   22.45  {
   22.46      FLAC_music *data = (FLAC_music*)client_data;
   22.47  
   22.48 -    Sint64 pos = SDL_RWtell (data->rwops);
   22.49 -    Sint64 end = SDL_RWseek (data->rwops, 0, RW_SEEK_END);
   22.50 +    Sint64 pos = SDL_RWtell (data->src);
   22.51 +    Sint64 end = SDL_RWseek (data->src, 0, RW_SEEK_END);
   22.52  
   22.53      // was the original position equal to the end (a.k.a. the seek didn't move)?
   22.54      if (pos == end) {
   22.55 @@ -138,7 +138,7 @@
   22.56          return true;
   22.57      } else {
   22.58          // not EOF, return to the original position
   22.59 -        SDL_RWseek (data->rwops, pos, RW_SEEK_SET);
   22.60 +        SDL_RWseek (data->src, pos, RW_SEEK_SET);
   22.61          return false;
   22.62      }
   22.63  }
   22.64 @@ -290,16 +290,13 @@
   22.65  }
   22.66  
   22.67  /* Load an FLAC stream from an SDL_RWops object */
   22.68 -FLAC_music *FLAC_new_RW(SDL_RWops *rw, int freerw)
   22.69 +FLAC_music *FLAC_new_RW(SDL_RWops *src, int freesrc)
   22.70  {
   22.71      FLAC_music *music;
   22.72      int init_stage = 0;
   22.73      int was_error = 1;
   22.74  
   22.75      if (!Mix_Init(MIX_INIT_FLAC)) {
   22.76 -        if (freerw) {
   22.77 -            SDL_RWclose(rw);
   22.78 -        }
   22.79          return NULL;
   22.80      }
   22.81  
   22.82 @@ -310,8 +307,8 @@
   22.83          FLAC_stop (music);
   22.84          FLAC_setvolume (music, MIX_MAX_VOLUME);
   22.85          music->section = -1;
   22.86 -        music->rwops = rw;
   22.87 -        music->freerw = freerw;
   22.88 +        music->src = src;
   22.89 +        music->freesrc = freesrc;
   22.90          music->flac_data.max_to_read = 0;
   22.91          music->flac_data.overflow = NULL;
   22.92          music->flac_data.overflow_len = 0;
   22.93 @@ -358,18 +355,12 @@
   22.94                  case 1:
   22.95                  case 0:
   22.96                      SDL_free(music);
   22.97 -                    if (freerw) {
   22.98 -                        SDL_RWclose(rw);
   22.99 -                    }
  22.100                      break;
  22.101              }
  22.102              return NULL;
  22.103          }
  22.104      } else {
  22.105          SDL_OutOfMemory();
  22.106 -        if (freerw) {
  22.107 -            SDL_RWclose(rw);
  22.108 -        }
  22.109          return NULL;
  22.110      }
  22.111  
  22.112 @@ -535,8 +526,8 @@
  22.113              SDL_free (music->cvt.buf);
  22.114          }
  22.115  
  22.116 -        if (music->freerw) {
  22.117 -            SDL_RWclose(music->rwops);
  22.118 +        if (music->freesrc) {
  22.119 +            SDL_RWclose(music->src);
  22.120          }
  22.121          SDL_free (music);
  22.122      }
    23.1 --- a/music_flac.h	Sat Jun 01 15:49:18 2013 -0700
    23.2 +++ b/music_flac.h	Sat Jun 01 19:52:15 2013 -0700
    23.3 @@ -51,8 +51,8 @@
    23.4      int section;
    23.5      FLAC__StreamDecoder *flac_decoder;
    23.6      FLAC_Data flac_data;
    23.7 -    SDL_RWops *rwops;
    23.8 -    int freerw;
    23.9 +    SDL_RWops *src;
   23.10 +    int freesrc;
   23.11      SDL_AudioCVT cvt;
   23.12      int len_available;
   23.13      Uint8 *snd_available;
   23.14 @@ -67,7 +67,7 @@
   23.15  extern void FLAC_setvolume(FLAC_music *music, int volume);
   23.16  
   23.17  /* Load an FLAC stream from an SDL_RWops object */
   23.18 -extern FLAC_music *FLAC_new_RW(SDL_RWops *rw, int freerw);
   23.19 +extern FLAC_music *FLAC_new_RW(SDL_RWops *src, int freesrc);
   23.20  
   23.21  /* Start playback of a given FLAC stream */
   23.22  extern void FLAC_play(FLAC_music *music);
    24.1 --- a/music_mad.c	Sat Jun 01 15:49:18 2013 -0700
    24.2 +++ b/music_mad.c	Sat Jun 01 19:52:15 2013 -0700
    24.3 @@ -26,14 +26,14 @@
    24.4  #include "music_mad.h"
    24.5  
    24.6  mad_data *
    24.7 -mad_openFileRW(SDL_RWops *rw, SDL_AudioSpec *mixer, int freerw)
    24.8 +mad_openFileRW(SDL_RWops *src, SDL_AudioSpec *mixer, int freesrc)
    24.9  {
   24.10    mad_data *mp3_mad;
   24.11  
   24.12    mp3_mad = (mad_data *)SDL_malloc(sizeof(mad_data));
   24.13    if (mp3_mad) {
   24.14 -    mp3_mad->rw = rw;
   24.15 -    mp3_mad->freerw = freerw;
   24.16 +    mp3_mad->src = src;
   24.17 +    mp3_mad->freesrc = freesrc;
   24.18      mad_stream_init(&mp3_mad->stream);
   24.19      mad_frame_init(&mp3_mad->frame);
   24.20      mad_synth_init(&mp3_mad->synth);
   24.21 @@ -55,8 +55,8 @@
   24.22    mad_frame_finish(&mp3_mad->frame);
   24.23    mad_synth_finish(&mp3_mad->synth);
   24.24  
   24.25 -  if (mp3_mad->freerw) {
   24.26 -    SDL_RWclose(mp3_mad->rw);
   24.27 +  if (mp3_mad->freesrc) {
   24.28 +    SDL_RWclose(mp3_mad->src);
   24.29    }
   24.30    SDL_free(mp3_mad);
   24.31  }
    25.1 --- a/music_modplug.c	Sat Jun 01 15:49:18 2013 -0700
    25.2 +++ b/music_modplug.c	Sat Jun 01 19:52:15 2013 -0700
    25.3 @@ -75,45 +75,38 @@
    25.4  }
    25.5  
    25.6  /* Load a modplug stream from an SDL_RWops object */
    25.7 -modplug_data *modplug_new_RW(SDL_RWops *rw, int freerw)
    25.8 +modplug_data *modplug_new_RW(SDL_RWops *src, int freesrc)
    25.9  {
   25.10 -    modplug_data *music=NULL;
   25.11 -    long offset,sz;
   25.12 -    char *buf=NULL;
   25.13 +    modplug_data *music = NULL;
   25.14 +    Sint64 offset;
   25.15 +    size_t sz;
   25.16 +    char *buf;
   25.17  
   25.18 -    offset = SDL_RWtell(rw);
   25.19 -    SDL_RWseek(rw, 0, RW_SEEK_END);
   25.20 -    sz = SDL_RWtell(rw)-offset;
   25.21 -    SDL_RWseek(rw, offset, RW_SEEK_SET);
   25.22 -    buf=(char*)SDL_malloc(sz);
   25.23 -    if(buf)
   25.24 -    {
   25.25 -        if(SDL_RWread(rw, buf, sz, 1)==1)
   25.26 -        {
   25.27 -            music=(modplug_data*)SDL_malloc(sizeof(modplug_data));
   25.28 -            if (music)
   25.29 -            {
   25.30 -                music->playing=0;
   25.31 -                music->file=ModPlug_Load(buf,sz);
   25.32 -                if(!music->file)
   25.33 -                {
   25.34 +    offset = SDL_RWtell(src);
   25.35 +    SDL_RWseek(src, 0, RW_SEEK_END);
   25.36 +    sz = (size_t)(SDL_RWtell(src) - offset);
   25.37 +    SDL_RWseek(src, offset, RW_SEEK_SET);
   25.38 +    buf = (char*)SDL_malloc(sz);
   25.39 +    if (buf) {
   25.40 +        if (SDL_RWread(src, buf, sz, 1) == 1) {
   25.41 +            music = (modplug_data*)SDL_malloc(sizeof(modplug_data));
   25.42 +            if (music) {
   25.43 +                music->playing = 0;
   25.44 +                music->file = ModPlug_Load(buf, sz);
   25.45 +                if (!music->file) {
   25.46                      SDL_free(music);
   25.47 -                    music=NULL;
   25.48 +                    music = NULL;
   25.49                  }
   25.50 -            }
   25.51 -            else
   25.52 -            {
   25.53 +            } else {
   25.54                  SDL_OutOfMemory();
   25.55              }
   25.56          }
   25.57          SDL_free(buf);
   25.58 -    }
   25.59 -    else
   25.60 -    {
   25.61 +    } else {
   25.62          SDL_OutOfMemory();
   25.63      }
   25.64 -    if (freerw) {
   25.65 -        SDL_RWclose(rw);
   25.66 +    if (music && freesrc) {
   25.67 +        SDL_RWclose(src);
   25.68      }
   25.69      return music;
   25.70  }
    26.1 --- a/music_ogg.c	Sat Jun 01 15:49:18 2013 -0700
    26.2 +++ b/music_ogg.c	Sat Jun 01 19:52:15 2013 -0700
    26.3 @@ -67,15 +67,12 @@
    26.4  }
    26.5  
    26.6  /* Load an OGG stream from an SDL_RWops object */
    26.7 -OGG_music *OGG_new_RW(SDL_RWops *rw, int freerw)
    26.8 +OGG_music *OGG_new_RW(SDL_RWops *src, int freesrc)
    26.9  {
   26.10      OGG_music *music;
   26.11      ov_callbacks callbacks;
   26.12  
   26.13      if ( !Mix_Init(MIX_INIT_OGG) ) {
   26.14 -        if ( freerw ) {
   26.15 -            SDL_RWclose(rw);
   26.16 -        }
   26.17          return(NULL);
   26.18      }
   26.19  
   26.20 @@ -88,24 +85,18 @@
   26.21      if ( music ) {
   26.22          /* Initialize the music structure */
   26.23          SDL_memset(music, 0, (sizeof *music));
   26.24 -        music->rw = rw;
   26.25 -        music->freerw = freerw;
   26.26 +        music->src = src;
   26.27 +        music->freesrc = freesrc;
   26.28          OGG_stop(music);
   26.29          OGG_setvolume(music, MIX_MAX_VOLUME);
   26.30          music->section = -1;
   26.31  
   26.32 -        if ( vorbis.ov_open_callbacks(rw, &music->vf, NULL, 0, callbacks) < 0 ) {
   26.33 +        if ( vorbis.ov_open_callbacks(src, &music->vf, NULL, 0, callbacks) < 0 ) {
   26.34 +            SDL_SetError("Not an Ogg Vorbis audio stream");
   26.35              SDL_free(music);
   26.36 -            if ( freerw ) {
   26.37 -                SDL_RWclose(rw);
   26.38 -            }
   26.39 -            SDL_SetError("Not an Ogg Vorbis audio stream");
   26.40              return(NULL);
   26.41          }
   26.42      } else {
   26.43 -        if ( freerw ) {
   26.44 -            SDL_RWclose(rw);
   26.45 -        }
   26.46          SDL_OutOfMemory();
   26.47          return(NULL);
   26.48      }
   26.49 @@ -213,8 +204,8 @@
   26.50          if ( music->cvt.buf ) {
   26.51              SDL_free(music->cvt.buf);
   26.52          }
   26.53 -        if ( music->freerw ) {
   26.54 -            SDL_RWclose(music->rw);
   26.55 +        if ( music->freesrc ) {
   26.56 +            SDL_RWclose(music->src);
   26.57          }
   26.58          vorbis.ov_clear(&music->vf);
   26.59          SDL_free(music);
    27.1 --- a/music_ogg.h	Sat Jun 01 15:49:18 2013 -0700
    27.2 +++ b/music_ogg.h	Sat Jun 01 19:52:15 2013 -0700
    27.3 @@ -32,8 +32,8 @@
    27.4  #endif
    27.5  
    27.6  typedef struct {
    27.7 -    SDL_RWops *rw;
    27.8 -    int freerw;
    27.9 +    SDL_RWops *src;
   27.10 +    int freesrc;
   27.11      int playing;
   27.12      int volume;
   27.13      OggVorbis_File vf;
   27.14 @@ -52,7 +52,7 @@
   27.15  extern void OGG_setvolume(OGG_music *music, int volume);
   27.16  
   27.17  /* Load an OGG stream from an SDL_RWops object */
   27.18 -extern OGG_music *OGG_new_RW(SDL_RWops *rw, int freerw);
   27.19 +extern OGG_music *OGG_new_RW(SDL_RWops *src, int freesrc);
   27.20  
   27.21  /* Start playback of a given OGG stream */
   27.22  extern void OGG_play(OGG_music *music);
    28.1 --- a/native_midi/native_midi.h	Sat Jun 01 15:49:18 2013 -0700
    28.2 +++ b/native_midi/native_midi.h	Sat Jun 01 19:52:15 2013 -0700
    28.3 @@ -27,7 +27,7 @@
    28.4  typedef struct _NativeMidiSong NativeMidiSong;
    28.5  
    28.6  int native_midi_detect();
    28.7 -NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw, int freerw);
    28.8 +NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *src, int freesrc);
    28.9  void native_midi_freesong(NativeMidiSong *song);
   28.10  void native_midi_start(NativeMidiSong *song, int loops);
   28.11  void native_midi_stop();
    29.1 --- a/native_midi/native_midi_common.c	Sat Jun 01 15:49:18 2013 -0700
    29.2 +++ b/native_midi/native_midi_common.c	Sat Jun 01 19:52:15 2013 -0700
    29.3 @@ -276,7 +276,7 @@
    29.4      return currentEvent;
    29.5  }
    29.6  
    29.7 -static int ReadMIDIFile(MIDIFile *mididata, SDL_RWops *rw)
    29.8 +static int ReadMIDIFile(MIDIFile *mididata, SDL_RWops *src)
    29.9  {
   29.10      int i = 0;
   29.11      Uint32  ID;
   29.12 @@ -287,27 +287,27 @@
   29.13  
   29.14      if (!mididata)
   29.15          return 0;
   29.16 -    if (!rw)
   29.17 +    if (!src)
   29.18          return 0;
   29.19  
   29.20      /* Make sure this is really a MIDI file */
   29.21 -    SDL_RWread(rw, &ID, 1, 4);
   29.22 +    SDL_RWread(src, &ID, 1, 4);
   29.23      if (BE_LONG(ID) != 'MThd')
   29.24          return 0;
   29.25  
   29.26      /* Header size must be 6 */
   29.27 -    SDL_RWread(rw, &size, 1, 4);
   29.28 +    SDL_RWread(src, &size, 1, 4);
   29.29      size = BE_LONG(size);
   29.30      if (size != 6)
   29.31          return 0;
   29.32  
   29.33      /* We only support format 0 and 1, but not 2 */
   29.34 -    SDL_RWread(rw, &format, 1, 2);
   29.35 +    SDL_RWread(src, &format, 1, 2);
   29.36      format = BE_SHORT(format);
   29.37      if (format != 0 && format != 1)
   29.38          return 0;
   29.39  
   29.40 -    SDL_RWread(rw, &tracks, 1, 2);
   29.41 +    SDL_RWread(src, &tracks, 1, 2);
   29.42      tracks = BE_SHORT(tracks);
   29.43      mididata->nTracks = tracks;
   29.44  
   29.45 @@ -320,14 +320,14 @@
   29.46      }
   29.47  
   29.48      /* Retrieve the PPQN value, needed for playback */
   29.49 -    SDL_RWread(rw, &division, 1, 2);
   29.50 +    SDL_RWread(src, &division, 1, 2);
   29.51      mididata->division = BE_SHORT(division);
   29.52  
   29.53  
   29.54      for (i=0; i<tracks; i++)
   29.55      {
   29.56 -        SDL_RWread(rw, &ID, 1, 4);  /* We might want to verify this is MTrk... */
   29.57 -        SDL_RWread(rw, &size, 1, 4);
   29.58 +        SDL_RWread(src, &ID, 1, 4);  /* We might want to verify this is MTrk... */
   29.59 +        SDL_RWread(src, &size, 1, 4);
   29.60          size = BE_LONG(size);
   29.61          mididata->track[i].len = size;
   29.62          mididata->track[i].data = malloc(size);
   29.63 @@ -336,7 +336,7 @@
   29.64              Mix_SetError("Out of memory");
   29.65              goto bail;
   29.66          }
   29.67 -        SDL_RWread(rw, mididata->track[i].data, 1, size);
   29.68 +        SDL_RWread(src, mididata->track[i].data, 1, size);
   29.69      }
   29.70      return 1;
   29.71  
   29.72 @@ -350,7 +350,7 @@
   29.73      return 0;
   29.74  }
   29.75  
   29.76 -MIDIEvent *CreateMIDIEventList(SDL_RWops *rw, Uint16 *division)
   29.77 +MIDIEvent *CreateMIDIEventList(SDL_RWops *src, Uint16 *division)
   29.78  {
   29.79      MIDIFile *mididata = NULL;
   29.80      MIDIEvent *eventList;
   29.81 @@ -361,10 +361,10 @@
   29.82          return NULL;
   29.83  
   29.84      /* Open the file */
   29.85 -    if ( rw != NULL )
   29.86 +    if ( src != NULL )
   29.87      {
   29.88          /* Read in the data */
   29.89 -        if ( ! ReadMIDIFile(mididata, rw))
   29.90 +        if ( ! ReadMIDIFile(mididata, src))
   29.91          {
   29.92              free(mididata);
   29.93              return NULL;
    30.1 --- a/native_midi/native_midi_haiku.cpp	Sat Jun 01 15:49:18 2013 -0700
    30.2 +++ b/native_midi/native_midi_haiku.cpp	Sat Jun 01 19:52:15 2013 -0700
    30.3 @@ -47,9 +47,9 @@
    30.4      fPlaying = false;
    30.5      fLoops = 0;
    30.6    }
    30.7 -  virtual status_t Import(SDL_RWops *rw)
    30.8 +  virtual status_t Import(SDL_RWops *src)
    30.9    {
   30.10 -    fEvs = CreateMIDIEventList(rw, &fDivision);
   30.11 +    fEvs = CreateMIDIEventList(src, &fDivision);
   30.12      if (!fEvs) {
   30.13        return B_BAD_MIDI_DATA;
   30.14      }
   30.15 @@ -219,15 +219,12 @@
   30.16    synth.SetVolume(volume / 128.0);
   30.17  }
   30.18  
   30.19 -NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw, int freerw)
   30.20 +NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *src, int freesrc)
   30.21  {
   30.22    NativeMidiSong *song = new NativeMidiSong;
   30.23    song->store = new MidiEventsStore;
   30.24 -  status_t res = song->store->Import(rw);
   30.25 +  status_t res = song->store->Import(src);
   30.26  
   30.27 -  if (freerw) {
   30.28 -    SDL_RWclose(rw);
   30.29 -  }
   30.30    if (res != B_OK)
   30.31    {
   30.32      snprintf(lasterr, sizeof lasterr, "Cannot Import() midi file: status_t=%d", res);
   30.33 @@ -235,6 +232,12 @@
   30.34      delete song;
   30.35      return NULL;
   30.36    }
   30.37 +  else
   30.38 +  {
   30.39 +    if (freesrc) {
   30.40 +      SDL_RWclose(src);
   30.41 +    }
   30.42 +  }
   30.43    return song;
   30.44  }
   30.45  
    31.1 --- a/native_midi/native_midi_mac.c	Sat Jun 01 15:49:18 2013 -0700
    31.2 +++ b/native_midi/native_midi_mac.c	Sat Jun 01 19:52:15 2013 -0700
    31.3 @@ -88,7 +88,7 @@
    31.4      return 1;
    31.5  }
    31.6  
    31.7 -NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw, int freerw)
    31.8 +NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *src, int freesrc)
    31.9  {
   31.10      NativeMidiSong  *song = NULL;
   31.11      MIDIEvent       *evntlist = NULL;
   31.12 @@ -102,7 +102,7 @@
   31.13      memset(part_to_inst,-1,sizeof(part_to_inst));
   31.14  
   31.15      /* Attempt to load the midi file */
   31.16 -    evntlist = CreateMIDIEventList(rw, &ppqn);
   31.17 +    evntlist = CreateMIDIEventList(src, &ppqn);
   31.18      if (!evntlist)
   31.19          goto bail;
   31.20  
   31.21 @@ -150,10 +150,6 @@
   31.22  
   31.23          free(song);
   31.24      }
   31.25 -
   31.26 -    if (freerw) {
   31.27 -        SDL_RWclose(rw);
   31.28 -    }
   31.29      return NULL;
   31.30  }
   31.31  
    32.1 --- a/native_midi/native_midi_macosx.c	Sat Jun 01 15:49:18 2013 -0700
    32.2 +++ b/native_midi/native_midi_macosx.c	Sat Jun 01 19:52:15 2013 -0700
    32.3 @@ -154,26 +154,26 @@
    32.4      return 1;  /* always available. */
    32.5  }
    32.6  
    32.7 -NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw, int freerw)
    32.8 +NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *src, int freesrc)
    32.9  {
   32.10      NativeMidiSong *retval = NULL;
   32.11      void *buf = NULL;
   32.12 -    int len = 0;
   32.13 +    Sint64 len = 0;
   32.14      CFDataRef data = NULL;
   32.15  
   32.16 -    if (SDL_RWseek(rw, 0, RW_SEEK_END) < 0)
   32.17 +    if (SDL_RWseek(src, 0, RW_SEEK_END) < 0)
   32.18          goto fail;
   32.19 -    len = SDL_RWtell(rw);
   32.20 +    len = SDL_RWtell(src);
   32.21      if (len < 0)
   32.22          goto fail;
   32.23 -    if (SDL_RWseek(rw, 0, RW_SEEK_SET) < 0)
   32.24 +    if (SDL_RWseek(src, 0, RW_SEEK_SET) < 0)
   32.25          goto fail;
   32.26  
   32.27      buf = malloc(len);
   32.28      if (buf == NULL)
   32.29          goto fail;
   32.30  
   32.31 -    if (SDL_RWread(rw, buf, len, 1) != 1)
   32.32 +    if (SDL_RWread(src, buf, len, 1) != 1)
   32.33          goto fail;
   32.34  
   32.35      retval = malloc(sizeof(NativeMidiSong));
   32.36 @@ -221,8 +221,8 @@
   32.37      if (MusicPlayerSetSequence(retval->player, retval->sequence) != noErr)
   32.38          goto fail;
   32.39  
   32.40 -    if (freerw)
   32.41 -        SDL_RWclose(rw);
   32.42 +    if (freesrc)
   32.43 +        SDL_RWclose(src);
   32.44  
   32.45      return retval;
   32.46  
   32.47 @@ -241,9 +241,6 @@
   32.48      if (buf)
   32.49          free(buf);
   32.50  
   32.51 -    if (freerw)
   32.52 -        SDL_RWclose(rw);
   32.53 -
   32.54      return NULL;
   32.55  }
   32.56  
    33.1 --- a/native_midi/native_midi_win32.c	Sat Jun 01 15:49:18 2013 -0700
    33.2 +++ b/native_midi/native_midi_win32.c	Sat Jun 01 19:52:15 2013 -0700
    33.3 @@ -200,28 +200,22 @@
    33.4    return 1;
    33.5  }
    33.6  
    33.7 -NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *rw, int freerw)
    33.8 +NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *src, int freesrc)
    33.9  {
   33.10      NativeMidiSong *newsong;
   33.11      MIDIEvent       *evntlist = NULL;
   33.12  
   33.13      newsong=malloc(sizeof(NativeMidiSong));
   33.14      if (!newsong) {
   33.15 -        if (freerw) {
   33.16 -            SDL_RWclose(rw);
   33.17 -        }
   33.18          return NULL;
   33.19      }
   33.20      memset(newsong,0,sizeof(NativeMidiSong));
   33.21  
   33.22      /* Attempt to load the midi file */
   33.23 -    evntlist = CreateMIDIEventList(rw, &newsong->ppqn);
   33.24 +    evntlist = CreateMIDIEventList(src, &newsong->ppqn);
   33.25      if (!evntlist)
   33.26      {
   33.27          free(newsong);
   33.28 -        if (freerw) {
   33.29 -            SDL_RWclose(rw);
   33.30 -        }
   33.31          return NULL;
   33.32      }
   33.33  
   33.34 @@ -229,8 +223,8 @@
   33.35  
   33.36      FreeMIDIEventList(evntlist);
   33.37  
   33.38 -    if (freerw) {
   33.39 -        SDL_RWclose(rw);
   33.40 +    if (freesrc) {
   33.41 +        SDL_RWclose(src);
   33.42      }
   33.43      return newsong;
   33.44  }
    34.1 --- a/playmus.c	Sat Jun 01 15:49:18 2013 -0700
    34.2 +++ b/playmus.c	Sat Jun 01 19:52:15 2013 -0700
    34.3 @@ -105,7 +105,6 @@
    34.4  
    34.5  int main(int argc, char *argv[])
    34.6  {
    34.7 -    SDL_RWops *rwfp = NULL;
    34.8      int audio_rate;
    34.9      Uint16 audio_format;
   34.10      int audio_channels;
   34.11 @@ -200,8 +199,7 @@
   34.12  
   34.13          /* Load the requested music file */
   34.14          if ( rwops ) {
   34.15 -            rwfp = SDL_RWFromFile(argv[i], "rb");
   34.16 -            music = Mix_LoadMUS_RW(rwfp);
   34.17 +            music = Mix_LoadMUS_RW(SDL_RWFromFile(argv[i], "rb"), SDL_TRUE);
   34.18          } else {
   34.19              music = Mix_LoadMUS(argv[i]);
   34.20          }
   34.21 @@ -221,9 +219,6 @@
   34.22                  SDL_Delay(100);
   34.23          }
   34.24          Mix_FreeMusic(music);
   34.25 -        if ( rwops ) {
   34.26 -            SDL_RWclose(rwfp);
   34.27 -        }
   34.28          music = NULL;
   34.29  
   34.30          /* If the user presses Ctrl-C more than once, exit. */
    35.1 --- a/timidity/playmidi.c	Sat Jun 01 15:49:18 2013 -0700
    35.2 +++ b/timidity/playmidi.c	Sat Jun 01 19:52:15 2013 -0700
    35.3 @@ -1676,7 +1676,7 @@
    35.4    ctl->master_volume(amplification);
    35.5  }
    35.6  
    35.7 -MidiSong *Timidity_LoadSong_RW(SDL_RWops *rw, int freerw)
    35.8 +MidiSong *Timidity_LoadSong_RW(SDL_RWops *src, int freesrc)
    35.9  {
   35.10    MidiSong *song;
   35.11    int32 events;
   35.12 @@ -1687,13 +1687,12 @@
   35.13  
   35.14    strcpy(midi_name, "SDLrwops source");
   35.15  
   35.16 -  song->events = read_midi_file(rw, &events, &song->samples);
   35.17 -  if (freerw) {
   35.18 -    SDL_RWclose(rw);
   35.19 -  }
   35.20 -
   35.21 -  /* Make sure everything is okay */
   35.22 -  if (!song->events) {
   35.23 +  song->events = read_midi_file(src, &events, &song->samples);
   35.24 +  if (song->events) {
   35.25 +    if (freesrc) {
   35.26 +      SDL_RWclose(src);
   35.27 +    }
   35.28 +  } else {
   35.29      free(song);
   35.30      song = NULL;
   35.31    }
    36.1 --- a/wavestream.c	Sat Jun 01 15:49:18 2013 -0700
    36.2 +++ b/wavestream.c	Sat Jun 01 19:52:15 2013 -0700
    36.3 @@ -114,37 +114,32 @@
    36.4  }
    36.5  
    36.6  /* Load a WAV stream from the given RWops object */
    36.7 -WAVStream *WAVStream_LoadSong_RW(SDL_RWops *rw, const char *magic, int freerw)
    36.8 +WAVStream *WAVStream_LoadSong_RW(SDL_RWops *src, int freesrc)
    36.9  {
   36.10      WAVStream *wave;
   36.11      SDL_AudioSpec wavespec;
   36.12  
   36.13      if ( ! mixer.format ) {
   36.14          Mix_SetError("WAV music output not started");
   36.15 -        if ( freerw ) {
   36.16 -            SDL_RWclose(rw);
   36.17 -        }
   36.18          return(NULL);
   36.19      }
   36.20      wave = (WAVStream *)SDL_malloc(sizeof *wave);
   36.21      if ( wave ) {
   36.22 -        SDL_memset(wave, 0, (sizeof *wave));
   36.23 -        wave->freerw = freerw;
   36.24 -        if ( strcmp(magic, "RIFF") == 0 ) {
   36.25 -            wave->rw = LoadWAVStream(rw, &wavespec,
   36.26 -                    &wave->start, &wave->stop);
   36.27 -        } else
   36.28 -        if ( strcmp(magic, "FORM") == 0 ) {
   36.29 -            wave->rw = LoadAIFFStream(rw, &wavespec,
   36.30 -                    &wave->start, &wave->stop);
   36.31 +        Uint32 magic;
   36.32 +
   36.33 +        SDL_zerop(wave);
   36.34 +        wave->freesrc = freesrc;
   36.35 +
   36.36 +        magic = SDL_ReadLE32(src);
   36.37 +        if ( magic == RIFF || magic == WAVE ) {
   36.38 +            wave->src = LoadWAVStream(src, &wavespec, &wave->start, &wave->stop);
   36.39 +        } else if ( magic == FORM ) {
   36.40 +            wave->src = LoadAIFFStream(src, &wavespec, &wave->start, &wave->stop);
   36.41          } else {
   36.42              Mix_SetError("Unknown WAVE format");
   36.43          }
   36.44 -        if ( wave->rw == NULL ) {
   36.45 +        if ( wave->src == NULL ) {
   36.46              SDL_free(wave);
   36.47 -            if ( freerw ) {
   36.48 -                SDL_RWclose(rw);
   36.49 -            }
   36.50              return(NULL);
   36.51          }
   36.52          SDL_BuildAudioCVT(&wave->cvt,
   36.53 @@ -152,9 +147,6 @@
   36.54              mixer.format, mixer.channels, mixer.freq);
   36.55      } else {
   36.56          SDL_OutOfMemory();
   36.57 -        if ( freerw ) {
   36.58 -            SDL_RWclose(rw);
   36.59 -        }
   36.60          return(NULL);
   36.61      }
   36.62      return(wave);
   36.63 @@ -163,7 +155,7 @@
   36.64  /* Start playback of a given WAV stream */
   36.65  void WAVStream_Start(WAVStream *wave)
   36.66  {
   36.67 -    SDL_RWseek (wave->rw, wave->start, RW_SEEK_SET);
   36.68 +    SDL_RWseek (wave->src, wave->start, RW_SEEK_SET);
   36.69      music = wave;
   36.70  }
   36.71  
   36.72 @@ -173,7 +165,7 @@
   36.73      Sint64 pos;
   36.74      Sint64 left = 0;
   36.75  
   36.76 -    if ( music && ((pos=SDL_RWtell(music->rw)) < music->stop) ) {
   36.77 +    if ( music && ((pos=SDL_RWtell(music->src)) < music->stop) ) {
   36.78          if ( music->cvt.needed ) {
   36.79              int original_len;
   36.80  
   36.81 @@ -195,7 +187,7 @@
   36.82                  original_len -= left;
   36.83                  left = (int)((double)left*music->cvt.len_ratio);
   36.84              }
   36.85 -            original_len = SDL_RWread(music->rw, music->cvt.buf,1,original_len);
   36.86 +            original_len = SDL_RWread(music->src, music->cvt.buf,1,original_len);
   36.87              /* At least at the time of writing, SDL_ConvertAudio()
   36.88                 does byte-order swapping starting at the end of the
   36.89                 buffer. Thus, if we are reading 16-bit samples, we
   36.90 @@ -217,7 +209,7 @@
   36.91              data = SDL_stack_alloc(Uint8, len);
   36.92              if (data)
   36.93              {
   36.94 -                SDL_RWread(music->rw, data, len, 1);
   36.95 +                SDL_RWread(music->src, data, len, 1);
   36.96                  SDL_MixAudio(stream, data, len, wavestream_volume);
   36.97                  SDL_stack_free(data);
   36.98              }
   36.99 @@ -240,8 +232,8 @@
  36.100          if ( wave->cvt.buf ) {
  36.101              SDL_free(wave->cvt.buf);
  36.102          }
  36.103 -        if ( wave->freerw ) {
  36.104 -            SDL_RWclose(wave->rw);
  36.105 +        if ( wave->freesrc ) {
  36.106 +            SDL_RWclose(wave->src);
  36.107          }
  36.108          SDL_free(wave);
  36.109      }
  36.110 @@ -253,7 +245,7 @@
  36.111      int active;
  36.112  
  36.113      active = 0;
  36.114 -    if ( music && (SDL_RWtell(music->rw) < music->stop) ) {
  36.115 +    if ( music && (SDL_RWtell(music->src) < music->stop) ) {
  36.116          active = 1;
  36.117      }
  36.118      return(active);
  36.119 @@ -288,7 +280,6 @@
  36.120      int lenread;
  36.121  
  36.122      /* WAV magic header */
  36.123 -    Uint32 RIFFchunk;
  36.124      Uint32 wavelen;
  36.125      Uint32 WAVEmagic;
  36.126  
  36.127 @@ -298,14 +289,8 @@
  36.128      was_error = 0;
  36.129  
  36.130      /* Check the magic header */
  36.131 -    RIFFchunk   = SDL_ReadLE32(src);
  36.132      wavelen     = SDL_ReadLE32(src);
  36.133      WAVEmagic   = SDL_ReadLE32(src);
  36.134 -    if ( (RIFFchunk != RIFF) || (WAVEmagic != WAVE) ) {
  36.135 -        Mix_SetError("Unrecognized file type (not WAVE)");
  36.136 -        was_error = 1;
  36.137 -        goto done;
  36.138 -    }
  36.139  
  36.140      /* Read the audio data format chunk */
  36.141      chunk.data = NULL;
  36.142 @@ -415,7 +400,6 @@
  36.143      Sint64 next_chunk;
  36.144  
  36.145      /* AIFF magic header */
  36.146 -    Uint32 FORMchunk;
  36.147      Uint32 AIFFmagic;
  36.148      /* SSND chunk        */
  36.149      Uint32 offset;
  36.150 @@ -430,10 +414,9 @@
  36.151      was_error = 0;
  36.152  
  36.153      /* Check the magic header */
  36.154 -    FORMchunk   = SDL_ReadLE32(src);
  36.155      chunk_length    = SDL_ReadBE32(src);
  36.156      AIFFmagic   = SDL_ReadLE32(src);
  36.157 -    if ( (FORMchunk != FORM) || (AIFFmagic != AIFF) ) {
  36.158 +    if ( AIFFmagic != AIFF ) {
  36.159          Mix_SetError("Unrecognized file type (not AIFF)");
  36.160          was_error = 1;
  36.161          goto done;
  36.162 @@ -444,7 +427,7 @@
  36.163       *
  36.164       * TODO: Better sanity-checking. E.g. what happens if the AIFF file
  36.165       *       contains compressed sound data?
  36.166 -         */
  36.167 +     */
  36.168  
  36.169      found_SSND = 0;
  36.170      found_COMM = 0;
  36.171 @@ -458,7 +441,7 @@
  36.172          if (chunk_length == 0)
  36.173          break;
  36.174  
  36.175 -            switch (chunk_type) {
  36.176 +        switch (chunk_type) {
  36.177          case SSND:
  36.178              found_SSND      = 1;
  36.179              offset      = SDL_ReadBE32(src);
    37.1 --- a/wavestream.h	Sat Jun 01 15:49:18 2013 -0700
    37.2 +++ b/wavestream.h	Sat Jun 01 19:52:15 2013 -0700
    37.3 @@ -26,8 +26,8 @@
    37.4  #include <stdio.h>
    37.5  
    37.6  typedef struct {
    37.7 -    SDL_RWops *rw;
    37.8 -    SDL_bool freerw;
    37.9 +    SDL_RWops *src;
   37.10 +    SDL_bool freesrc;
   37.11      long  start;
   37.12      long  stop;
   37.13      SDL_AudioCVT cvt;
   37.14 @@ -42,7 +42,7 @@
   37.15  extern void WAVStream_SetVolume(int volume);
   37.16  
   37.17  /* Load a WAV stream from an SDL_RWops object */
   37.18 -extern WAVStream *WAVStream_LoadSong_RW(SDL_RWops *rw, const char *magic, int freerw);
   37.19 +extern WAVStream *WAVStream_LoadSong_RW(SDL_RWops *src, int freesrc);
   37.20  
   37.21  /* Start playback of a given WAV stream */
   37.22  extern void WAVStream_Start(WAVStream *wave);