SDL_mixer: Changed 'freesrc' parameter from int to SDL_bool

From 6c4e80c09d820c0dabb082e0bd14cf447dc05f16 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sun, 9 Jul 2023 16:32:24 -0700
Subject: [PATCH] Changed 'freesrc' parameter from int to SDL_bool

---
 include/SDL3/SDL_mixer.h                     | 20 ++++----
 src/codecs/load_aiff.c                       | 51 +++++++++++++-------
 src/codecs/load_aiff.h                       |  2 +-
 src/codecs/load_sndfile.c                    | 50 ++++++++++++-------
 src/codecs/load_sndfile.h                    |  2 +-
 src/codecs/load_voc.c                        | 47 ++++++++++++------
 src/codecs/load_voc.h                        |  2 +-
 src/codecs/music_drflac.c                    |  4 +-
 src/codecs/music_drmp3.c                     |  4 +-
 src/codecs/music_flac.c                      |  4 +-
 src/codecs/music_fluidsynth.c                |  2 +-
 src/codecs/music_gme.c                       |  4 +-
 src/codecs/music_modplug.c                   |  2 +-
 src/codecs/music_mpg123.c                    |  4 +-
 src/codecs/music_nativemidi.c                |  2 +-
 src/codecs/music_ogg.c                       |  4 +-
 src/codecs/music_ogg_stb.c                   |  4 +-
 src/codecs/music_opus.c                      |  4 +-
 src/codecs/music_timidity.c                  |  2 +-
 src/codecs/music_wav.c                       |  4 +-
 src/codecs/music_wavpack.c                   | 10 ++--
 src/codecs/music_xmp.c                       |  2 +-
 src/codecs/native_midi/native_midi.h         |  2 +-
 src/codecs/native_midi/native_midi_haiku.cpp |  2 +-
 src/codecs/native_midi/native_midi_macosx.c  |  2 +-
 src/codecs/native_midi/native_midi_win32.c   |  2 +-
 src/mixer.c                                  |  4 +-
 src/music.c                                  |  4 +-
 src/music.h                                  |  2 +-
 29 files changed, 149 insertions(+), 99 deletions(-)

diff --git a/include/SDL3/SDL_mixer.h b/include/SDL3/SDL_mixer.h
index 8bc0816a..60b72f1c 100644
--- a/include/SDL3/SDL_mixer.h
+++ b/include/SDL3/SDL_mixer.h
@@ -553,7 +553,7 @@ extern DECLSPEC int SDLCALL Mix_AllocateChannels(int numchans);
  * fly. Also, crucially, there are as many channels for chunks as the app can
  * allocate, but SDL_mixer only offers a single "music" channel.
  *
- * If `freesrc` is non-zero, the RWops will be closed before returning,
+ * If `freesrc` is SDL_TRUE, the RWops will be closed before returning,
  * whether this function succeeds or not. SDL_mixer reads everything it needs
  * from the RWops during this call in any case.
  *
@@ -566,7 +566,7 @@ extern DECLSPEC int SDLCALL Mix_AllocateChannels(int numchans);
  * Mix_FreeChunk().
  *
  * \param src an SDL_RWops that data will be read from.
- * \param freesrc non-zero to close/free the SDL_RWops before returning, zero
+ * \param freesrc SDL_TRUE to close/free the SDL_RWops before returning, SDL_FALSE
  *                to leave it open.
  * \returns a new chunk, or NULL on error.
  *
@@ -576,7 +576,7 @@ extern DECLSPEC int SDLCALL Mix_AllocateChannels(int numchans);
  * \sa Mix_LoadWAV
  * \sa Mix_FreeChunk
  */
-extern DECLSPEC Mix_Chunk * SDLCALL Mix_LoadWAV_RW(SDL_RWops *src, int freesrc);
+extern DECLSPEC Mix_Chunk * SDLCALL Mix_LoadWAV_RW(SDL_RWops *src, SDL_bool freesrc);
 
 /**
  * Load a supported audio format into a chunk.
@@ -603,7 +603,7 @@ extern DECLSPEC Mix_Chunk * SDLCALL Mix_LoadWAV_RW(SDL_RWops *src, int freesrc);
  * Mix_FreeChunk().
  *
  * Note that before SDL_mixer 2.6.0, this function was a macro that called
- * Mix_LoadWAV_RW(), creating a RWops and setting `freesrc` to 1. This macro
+ * Mix_LoadWAV_RW(), creating a RWops and setting `freesrc` to SDL_TRUE. This macro
  * has since been promoted to a proper API function. Older binaries linked
  * against a newer SDL_mixer will still call Mix_LoadWAV_RW directly, as they
  * are using the macro, which was available since the dawn of time.
@@ -668,7 +668,7 @@ extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS(const char *file);
  * fly. Also, crucially, there are as many channels for chunks as the app can
  * allocate, but SDL_mixer only offers a single "music" channel.
  *
- * If `freesrc` is non-zero, the RWops will be closed before returning,
+ * If `freesrc` is SDL_TRUE, the RWops will be closed before returning,
  * whether this function succeeds or not. SDL_mixer reads everything it needs
  * from the RWops during this call in any case.
  *
@@ -684,7 +684,7 @@ extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS(const char *file);
  * Mix_FreeMusic().
  *
  * \param src an SDL_RWops that data will be read from.
- * \param freesrc non-zero to close/free the SDL_RWops before returning, zero
+ * \param freesrc SDL_TRUE to close/free the SDL_RWops before returning, SDL_FALSE
  *                to leave it open.
  * \returns a new music object, or NULL on error.
  *
@@ -692,7 +692,7 @@ extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS(const char *file);
  *
  * \sa Mix_FreeMusic
  */
-extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS_RW(SDL_RWops *src, int freesrc);
+extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS_RW(SDL_RWops *src, SDL_bool freesrc);
 
 /**
  * Load an audio format into a music object, assuming a specific format.
@@ -728,7 +728,7 @@ extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS_RW(SDL_RWops *src, int freesrc);
  * - `MUS_OPUS` (Opus files)
  * - `MUS_WAVPACK` (WavPack files)
  *
- * If `freesrc` is non-zero, the RWops will be closed before returning,
+ * If `freesrc` is SDL_TRUE, the RWops will be closed before returning,
  * whether this function succeeds or not. SDL_mixer reads everything it needs
  * from the RWops during this call in any case.
  *
@@ -741,7 +741,7 @@ extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS_RW(SDL_RWops *src, int freesrc);
  *
  * \param src an SDL_RWops that data will be read from.
  * \param type the type of audio data provided by `src`.
- * \param freesrc non-zero to close/free the SDL_RWops before returning, zero
+ * \param freesrc SDL_TRUE to close/free the SDL_RWops before returning, SDL_FALSE
  *                to leave it open.
  * \returns a new music object, or NULL on error.
  *
@@ -749,7 +749,7 @@ extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUS_RW(SDL_RWops *src, int freesrc);
  *
  * \sa Mix_FreeMusic
  */
-extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUSType_RW(SDL_RWops *src, Mix_MusicType type, int freesrc);
+extern DECLSPEC Mix_Music * SDLCALL Mix_LoadMUSType_RW(SDL_RWops *src, Mix_MusicType type, SDL_bool freesrc);
 
 /**
  * Load a WAV file from memory as quickly as possible.
diff --git a/src/codecs/load_aiff.c b/src/codecs/load_aiff.c
index 415e890c..85584f0d 100644
--- a/src/codecs/load_aiff.c
+++ b/src/codecs/load_aiff.c
@@ -62,10 +62,10 @@ static Uint32 SANE_to_Uint32 (Uint8 *sanebuf)
 
 /* This function is based on SDL_LoadWAV_RW(). */
 
-SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc,
+SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, SDL_bool freesrc,
     SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
 {
-    int was_error;
+    SDL_bool was_error = SDL_TRUE;
     int found_SSND;
     int found_COMM;
     int found_VHDR;
@@ -91,10 +91,24 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc,
     Uint8 sane_freq[10];
     Uint32 frequency = 0;
 
-    /* Make sure we are passed a valid data source */
-    was_error = 0;
-    if (src == NULL) {
-        was_error = 1;
+    /* Sanity checks */
+    if (audio_buf) {
+        *audio_buf = NULL;
+    }
+    if (!src) {
+        SDL_InvalidParamError("src");
+        goto done;
+    }
+    if (!spec) {
+        SDL_InvalidParamError("spec");
+        goto done;
+    }
+    if (!audio_buf) {
+        SDL_InvalidParamError("audio_buf");
+        goto done;
+    }
+    if (!audio_len) {
+        SDL_InvalidParamError("audio_len");
         goto done;
     }
 
@@ -109,7 +123,6 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc,
     }
     if ((FORMchunk != FORM) || ((AIFFmagic != AIFF) && (AIFFmagic != _8SVX))) {
         Mix_SetError("Unrecognized file type (not AIFF nor 8SVX)");
-        was_error = 1;
         goto done;
     }
 
@@ -144,13 +157,11 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc,
                 samplesize  = SDL_ReadBE16(src);
                 if (SDL_RWread(src, sane_freq, sizeof(sane_freq)) != sizeof(sane_freq)) {
                     Mix_SetError("Bad AIFF sample frequency");
-                    was_error = 1;
                     goto done;
                 }
                 frequency   = SANE_to_Uint32(sane_freq);
                 if (frequency == 0) {
                     Mix_SetError("Bad AIFF sample frequency");
-                    was_error = 1;
                     goto done;
                 }
                 break;
@@ -183,30 +194,26 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc,
 
     if ((AIFFmagic == AIFF) && !found_SSND) {
         Mix_SetError("Bad AIFF (no SSND chunk)");
-        was_error = 1;
         goto done;
     }
 
     if ((AIFFmagic == AIFF) && !found_COMM) {
         Mix_SetError("Bad AIFF (no COMM chunk)");
-        was_error = 1;
         goto done;
     }
 
     if ((AIFFmagic == _8SVX) && !found_VHDR) {
         Mix_SetError("Bad 8SVX (no VHDR chunk)");
-        was_error = 1;
         goto done;
     }
 
     if ((AIFFmagic == _8SVX) && !found_BODY) {
         Mix_SetError("Bad 8SVX (no BODY chunk)");
-        was_error = 1;
         goto done;
     }
 
     /* Decode the audio data format */
-    SDL_memset(spec, 0, sizeof(*spec));
+    SDL_zerop(spec);
     spec->freq = frequency;
     switch (samplesize) {
         case 8:
@@ -217,7 +224,6 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc,
             break;
         default:
             Mix_SetError("Unsupported AIFF samplesize");
-            was_error = 1;
             goto done;
     }
     spec->channels = (Uint8) channels;
@@ -227,25 +233,34 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc,
     *audio_buf = (Uint8 *)SDL_malloc(*audio_len);
     if (*audio_buf == NULL) {
         Mix_OutOfMemory();
-        return(NULL);
+        goto done;
     }
     SDL_RWseek(src, start, SDL_RW_SEEK_SET);
     if (SDL_RWread(src, *audio_buf, *audio_len) != *audio_len) {
         Mix_SetError("Unable to read audio data");
-        return(NULL);
+        goto done;
     }
 
     /* Don't return a buffer that isn't a multiple of samplesize */
     *audio_len &= ~((samplesize / 8) - 1);
 
+    was_error = SDL_FALSE;
+
 done:
     if (freesrc && src) {
         SDL_RWclose(src);
     }
     if (was_error) {
+        if (audio_buf && *audio_buf) {
+            SDL_free(*audio_buf);
+            *audio_buf = NULL;
+        }
+        if (audio_len) {
+            *audio_len = 0;
+        }
         spec = NULL;
     }
-    return(spec);
+    return spec;
 }
 
 /* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/codecs/load_aiff.h b/src/codecs/load_aiff.h
index a5f327a0..61278871 100644
--- a/src/codecs/load_aiff.h
+++ b/src/codecs/load_aiff.h
@@ -27,7 +27,7 @@
 */
 
 /* Don't call this directly; use Mix_LoadWAV_RW() for now. */
-SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc,
+SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, SDL_bool freesrc,
     SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len);
 
 /* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/codecs/load_sndfile.c b/src/codecs/load_sndfile.c
index d0a4beb2..038867a5 100644
--- a/src/codecs/load_sndfile.c
+++ b/src/codecs/load_sndfile.c
@@ -117,9 +117,10 @@ static sf_count_t sfvio_tell(void *user_data)
     return SDL_RWtell(RWops);
 }
 
-SDL_AudioSpec *Mix_LoadSndFile_RW (SDL_RWops *src, int freesrc,
+SDL_AudioSpec *Mix_LoadSndFile_RW (SDL_RWops *src, SDL_bool freesrc,
         SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
 {
+    SDL_bool was_error = SDL_TRUE;
     SNDFILE *sndfile = NULL;
     SF_INFO sfinfo;
     SF_VIRTUAL_IO sfvio = {
@@ -132,16 +133,26 @@ SDL_AudioSpec *Mix_LoadSndFile_RW (SDL_RWops *src, int freesrc,
     Uint32 len;
     short *buf = NULL;
 
-    int was_error = 1;
-
-    if (src == NULL || spec == NULL ||
-        audio_buf == NULL || audio_len == NULL) {
+    /* Sanity checks */
+    if (audio_buf) {
+        *audio_buf = NULL;
+    }
+    if (!src) {
+        SDL_InvalidParamError("src");
+        goto done;
+    }
+    if (!spec) {
+        SDL_InvalidParamError("spec");
+        goto done;
+    }
+    if (!audio_buf) {
+        SDL_InvalidParamError("audio_buf");
+        goto done;
+    }
+    if (!audio_len) {
+        SDL_InvalidParamError("audio_len");
         goto done;
     }
-
-    *audio_buf = NULL;
-    *audio_len = 0;
-    SDL_memset(spec, 0, sizeof(*spec));
 
     if (SNDFILE_loaded == 0) {
         if (SNDFILE_init() != 0) {
@@ -182,8 +193,7 @@ SDL_AudioSpec *Mix_LoadSndFile_RW (SDL_RWops *src, int freesrc,
         goto done;
     }
 
-    was_error = 0;
-
+    SDL_zerop(spec);
     spec->channels = sfinfo.channels;
     spec->freq = sfinfo.samplerate;
     spec->format = SDL_AUDIO_S16;
@@ -191,25 +201,31 @@ SDL_AudioSpec *Mix_LoadSndFile_RW (SDL_RWops *src, int freesrc,
     *audio_buf = (Uint8 *)buf;
     *audio_len = len;
 
-    if (freesrc && src) {
-        SDL_RWclose(src);
-    }
+    was_error = SDL_FALSE;
 
 done:
     if (sndfile) {
         SF_sf_close(sndfile);
     }
-
+    if (freesrc && src) {
+        SDL_RWclose(src);
+    }
     if (was_error) {
+        if (audio_buf && *audio_buf) {
+            SDL_free(*audio_buf);
+            *audio_buf = NULL;
+        }
+        if (audio_len) {
+            *audio_len = 0;
+        }
         spec = NULL;
     }
-
     return spec;
 }
 
 #else
 
-SDL_AudioSpec *Mix_LoadSndFile_RW (SDL_RWops *src, int freesrc,
+SDL_AudioSpec *Mix_LoadSndFile_RW (SDL_RWops *src, SDL_bool freesrc,
         SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
 {
     (void) src;
diff --git a/src/codecs/load_sndfile.h b/src/codecs/load_sndfile.h
index 2f12e53e..2d88935e 100644
--- a/src/codecs/load_sndfile.h
+++ b/src/codecs/load_sndfile.h
@@ -31,7 +31,7 @@
 #include <SDL3/SDL_mixer.h>
 
 /* Don't call this directly; use Mix_LoadWAV_RW() for now. */
-SDL_AudioSpec *Mix_LoadSndFile_RW (SDL_RWops *src, int freesrc,
+SDL_AudioSpec *Mix_LoadSndFile_RW (SDL_RWops *src, SDL_bool freesrc,
         SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len);
 
 void SNDFILE_uninit (void);
diff --git a/src/codecs/load_voc.c b/src/codecs/load_voc.c
index 956b2cae..8ccd8229 100644
--- a/src/codecs/load_voc.c
+++ b/src/codecs/load_voc.c
@@ -371,28 +371,43 @@ static Uint32 voc_read(SDL_RWops *src, vs_t *v, Uint8 *buf, SDL_AudioSpec *spec)
 
 
 /* don't call this directly; use Mix_LoadWAV_RW() for now. */
-SDL_AudioSpec *Mix_LoadVOC_RW (SDL_RWops *src, int freesrc,
+SDL_AudioSpec *Mix_LoadVOC_RW (SDL_RWops *src, SDL_bool freesrc,
         SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
 {
+    SDL_bool was_error = SDL_TRUE;
     vs_t v;
-    int was_error = 1;
     int samplesize;
     Uint8 *fillptr;
     void *ptr;
 
-    if ((!src) || (!audio_buf) || (!audio_len))   /* sanity checks. */
+    /* Sanity checks */
+    if (audio_buf) {
+        *audio_buf = NULL;
+    }
+    if (!src) {
+        SDL_InvalidParamError("src");
+        goto done;
+    }
+    if (!spec) {
+        SDL_InvalidParamError("spec");
+        goto done;
+    }
+    if (!audio_buf) {
+        SDL_InvalidParamError("audio_buf");
         goto done;
+    }
+    if (!audio_len) {
+        SDL_InvalidParamError("audio_len");
+        goto done;
+    }
 
     if (!voc_check_header(src))
         goto done;
 
-    SDL_memset(&v, 0, sizeof(vs_t));
+    SDL_zero(v);
     v.rate = VOC_BAD_RATE;
     v.rest = 0;
     v.has_extended = 0;
-    *audio_buf = NULL;
-    *audio_len = 0;
-    SDL_memset(spec, '\0', sizeof(SDL_AudioSpec));
 
     if (!voc_get_block(src, &v, spec))
         goto done;
@@ -407,6 +422,7 @@ SDL_AudioSpec *Mix_LoadVOC_RW (SDL_RWops *src, int freesrc,
         goto done;
     }
 
+    SDL_zerop(spec);
     spec->format = ((v.size == ST_SIZE_WORD) ? SDL_AUDIO_S16 : SDL_AUDIO_U8);
     if (spec->channels == 0)
         spec->channels = v.channels;
@@ -427,9 +443,6 @@ SDL_AudioSpec *Mix_LoadVOC_RW (SDL_RWops *src, int freesrc,
         ptr = SDL_realloc(*audio_buf, *audio_len);
         if (ptr == NULL)
         {
-            SDL_free(*audio_buf);
-            *audio_buf = NULL;
-            *audio_len = 0;
             goto done;
         }
 
@@ -439,22 +452,28 @@ SDL_AudioSpec *Mix_LoadVOC_RW (SDL_RWops *src, int freesrc,
 
     spec->samples = (Uint16)(*audio_len / v.size);
 
-    was_error = 0;  /* success, baby! */
-
     /* Don't return a buffer that isn't a multiple of samplesize */
     samplesize = ((spec->format & 0xFF)/8)*spec->channels;
     *audio_len &= (Uint32) ~(samplesize-1);
 
+    was_error = SDL_FALSE;
+
 done:
     if (freesrc && src) {
         SDL_RWclose(src);
     }
-
     if (was_error) {
+        if (audio_buf && *audio_buf) {
+            SDL_free(*audio_buf);
+            *audio_buf = NULL;
+        }
+        if (audio_len) {
+            *audio_len = 0;
+        }
         spec = NULL;
     }
+    return spec;
 
-    return(spec);
 } /* Mix_LoadVOC_RW */
 
 /* end of load_voc.c ... */
diff --git a/src/codecs/load_voc.h b/src/codecs/load_voc.h
index c650653d..eeb83d8b 100644
--- a/src/codecs/load_voc.h
+++ b/src/codecs/load_voc.h
@@ -30,7 +30,7 @@
 */
 
 /* Don't call this directly; use Mix_LoadWAV_RW() for now. */
-SDL_AudioSpec *Mix_LoadVOC_RW (SDL_RWops *src, int freesrc,
+SDL_AudioSpec *Mix_LoadVOC_RW (SDL_RWops *src, SDL_bool freesrc,
         SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len);
 
 /* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/codecs/music_drflac.c b/src/codecs/music_drflac.c
index 4a5b54dc..841373dc 100644
--- a/src/codecs/music_drflac.c
+++ b/src/codecs/music_drflac.c
@@ -51,7 +51,7 @@ typedef struct {
     struct mp3file_t file;
     drflac *dec;
     int play_count;
-    int freesrc;
+    SDL_bool freesrc;
     int volume;
     int status;
     int sample_rate;
@@ -158,7 +158,7 @@ static void DRFLAC_MetaCB(void *context, drflac_metadata *metadata)
 
 static int DRFLAC_Seek(void *context, double position);
 
-static void *DRFLAC_CreateFromRW(SDL_RWops *src, int freesrc)
+static void *DRFLAC_CreateFromRW(SDL_RWops *src, SDL_bool freesrc)
 {
     DRFLAC_Music *music;
 
diff --git a/src/codecs/music_drmp3.c b/src/codecs/music_drmp3.c
index 6cdc0499..f6ba73f2 100644
--- a/src/codecs/music_drmp3.c
+++ b/src/codecs/music_drmp3.c
@@ -49,7 +49,7 @@ typedef struct {
     struct mp3file_t file;
     drmp3 dec;
     int play_count;
-    int freesrc;
+    SDL_bool freesrc;
     int volume;
     int status;
     SDL_AudioStream *stream;
@@ -79,7 +79,7 @@ static drmp3_bool32 DRMP3_SeekCB(void *context, int offset, drmp3_seek_origin or
 
 static int DRMP3_Seek(void *context, double position);
 
-static void *DRMP3_CreateFromRW(SDL_RWops *src, int freesrc)
+static void *DRMP3_CreateFromRW(SDL_RWops *src, SDL_bool freesrc)
 {
     DRMP3_Music *music;
 
diff --git a/src/codecs/music_flac.c b/src/codecs/music_flac.c
index a5427a85..089dd763 100644
--- a/src/codecs/music_flac.c
+++ b/src/codecs/music_flac.c
@@ -144,7 +144,7 @@ typedef struct {
     unsigned channels;
     unsigned bits_per_sample;
     SDL_RWops *src;
-    int freesrc;
+    SDL_bool freesrc;
     SDL_AudioStream *stream;
     int loop;
     FLAC__int64 pcm_pos;
@@ -481,7 +481,7 @@ static void flac_error_music_cb(
 }
 
 /* Load an FLAC stream from an SDL_RWops object */
-static void *FLAC_CreateFromRW(SDL_RWops *src, int freesrc)
+static void *FLAC_CreateFromRW(SDL_RWops *src, SDL_bool freesrc)
 {
     FLAC_Music *music;
     int init_stage = 0;
diff --git a/src/codecs/music_fluidsynth.c b/src/codecs/music_fluidsynth.c
index 856ccc1f..9cbbadfd 100644
--- a/src/codecs/music_fluidsynth.c
+++ b/src/codecs/music_fluidsynth.c
@@ -245,7 +245,7 @@ static FLUIDSYNTH_Music *FLUIDSYNTH_LoadMusic(void *data)
     return NULL;
 }
 
-static void *FLUIDSYNTH_CreateFromRW(SDL_RWops *src, int freesrc)
+static void *FLUIDSYNTH_CreateFromRW(SDL_RWops *src, SDL_bool freesrc)
 {
     FLUIDSYNTH_Music *music;
 
diff --git a/src/codecs/music_gme.c b/src/codecs/music_gme.c
index fa3db80d..d724bda3 100644
--- a/src/codecs/music_gme.c
+++ b/src/codecs/music_gme.c
@@ -125,7 +125,7 @@ typedef struct
 {
     int play_count;
     Music_Emu* game_emu;
-    int freesrc;
+    SDL_bool freesrc;
     SDL_bool has_track_length;
     int track_length;
     int intro_length;
@@ -205,7 +205,7 @@ static int initialize_from_track_info(GME_Music *music, int track)
     return 0;
 }
 
-static void *GME_CreateFromRW(struct SDL_RWops *src, int freesrc)
+static void *GME_CreateFromRW(struct SDL_RWops *src, SDL_bool freesrc)
 {
     void *mem = 0;
     size_t size;
diff --git a/src/codecs/music_modplug.c b/src/codecs/music_modplug.c
index 486b60eb..ef8be2ea 100644
--- a/src/codecs/music_modplug.c
+++ b/src/codecs/music_modplug.c
@@ -161,7 +161,7 @@ static int MODPLUG_Open(const SDL_AudioSpec *spec)
 }
 
 /* Load a modplug stream from an SDL_RWops object */
-void *MODPLUG_CreateFromRW(SDL_RWops *src, int freesrc)
+void *MODPLUG_CreateFromRW(SDL_RWops *src, SDL_bool freesrc)
 {
     MODPLUG_Music *music;
     void *buffer;
diff --git a/src/codecs/music_mpg123.c b/src/codecs/music_mpg123.c
index a95c91ab..7b06312b 100644
--- a/src/codecs/music_mpg123.c
+++ b/src/codecs/music_mpg123.c
@@ -136,7 +136,7 @@ typedef struct
 {
     struct mp3file_t mp3file;
     int play_count;
-    int freesrc;
+    SDL_bool freesrc;
     int volume;
 
     mpg123_handle* handle;
@@ -222,7 +222,7 @@ static int MPG123_Open(const SDL_AudioSpec *spec)
     return 0;
 }
 
-static void *MPG123_CreateFromRW(SDL_RWops *src, int freesrc)
+static void *MPG123_CreateFromRW(SDL_RWops *src, SDL_bool freesrc)
 {
     MPG123_Music *music;
     int result, format, channels, encoding;
diff --git a/src/codecs/music_nativemidi.c b/src/codecs/music_nativemidi.c
index 5616508f..ba8fe7a8 100644
--- a/src/codecs/music_nativemidi.c
+++ b/src/codecs/music_nativemidi.c
@@ -27,7 +27,7 @@
 #include "native_midi/native_midi.h"
 
 
-static void *NATIVEMIDI_CreateFromRW(SDL_RWops *src, int freesrc)
+static void *NATIVEMIDI_CreateFromRW(SDL_RWops *src, SDL_bool freesrc)
 {
     NativeMidiSong *music = native_midi_loadsong_RW(src, freesrc);
     if (!music) {
diff --git a/src/codecs/music_ogg.c b/src/codecs/music_ogg.c
index 952955c4..a2c45a33 100644
--- a/src/codecs/music_ogg.c
+++ b/src/codecs/music_ogg.c
@@ -122,7 +122,7 @@ static void OGG_Unload(void)
 
 typedef struct {
     SDL_RWops *src;
-    int freesrc;
+    SDL_bool freesrc;
     int play_count;
     int volume;
     OggVorbis_File vf;
@@ -229,7 +229,7 @@ static int OGG_UpdateSection(OGG_music *music)
 }
 
 /* Load an OGG stream from an SDL_RWops object */
-static void *OGG_CreateFromRW(SDL_RWops *src, int freesrc)
+static void *OGG_CreateFromRW(SDL_RWops *src, SDL_bool freesrc)
 {
     OGG_music *music;
     ov_callbacks callbacks;
diff --git a/src/codecs/music_ogg_stb.c b/src/codecs/music_ogg_stb.c
index 715c4fd5..8f8aa0a5 100644
--- a/src/codecs/music_ogg_stb.c
+++ b/src/codecs/music_ogg_stb.c
@@ -69,7 +69,7 @@
 
 typedef struct {
     SDL_RWops *src;
-    int freesrc;
+    SDL_bool freesrc;
     int play_count;
     int volume;
     stb_vorbis *vf;
@@ -164,7 +164,7 @@ static int OGG_UpdateSection(OGG_music *music)
 }
 
 /* Load an OGG stream from an SDL_RWops object */
-static void *OGG_CreateFromRW(SDL_RWops *src, int freesrc)
+static void *OGG_CreateFromRW(SDL_RWops *src, SDL_bool freesrc)
 {
     OGG_music *music;
     stb_vorbis_comment vc;
diff --git a/src/codecs/music_opus.c b/src/codecs/music_opus.c
index ee936ae1..8fa42cdb 100644
--- a/src/codecs/music_opus.c
+++ b/src/codecs/music_opus.c
@@ -100,7 +100,7 @@ static void OPUS_Unload(void)
 
 typedef struct {
     SDL_RWops *src;
-    int freesrc;
+    SDL_bool freesrc;
     int play_count;
     int volume;
     OggOpusFile *of;
@@ -210,7 +210,7 @@ static int OPUS_UpdateSection(OPUS_music *music)
 }
 
 /* Load an Opus stream from an SDL_RWops object */
-static void *OPUS_CreateFromRW(SDL_RWops *src, int freesrc)
+static void *OPUS_CreateFromRW(SDL_RWops *src, SDL_bool freesrc)
 {
     OPUS_music *music;
     OpusFileCallbacks callbacks;
diff --git a/src/codecs/music_timidity.c b/src/codecs/music_timidity.c
index 2c7a6964..281e6316 100644
--- a/src/codecs/music_timidity.c
+++ b/src/codecs/music_timidity.c
@@ -86,7 +86,7 @@ static void TIMIDITY_Close(void)
     Timidity_Exit();
 }
 
-void *TIMIDITY_CreateFromRW(SDL_RWops *src, int freesrc)
+void *TIMIDITY_CreateFromRW(SDL_RWops *src, SDL_bool freesrc)
 {
     TIMIDITY_Music *music;
     SDL_AudioSpec spec;
diff --git a/src/codecs/music_wav.c b/src/codecs/music_wav.c
index 4f6582bd..a7e934db 100644
--- a/src/codecs/music_wav.c
+++ b/src/codecs/music_wav.c
@@ -78,7 +78,7 @@ typedef struct {
 
 typedef struct {
     SDL_RWops *src;
-    int freesrc;
+    SDL_bool freesrc;
     SDL_AudioSpec spec;
     int volume;
     int play_count;
@@ -221,7 +221,7 @@ static void WAV_Delete(void *context);
 static int fetch_pcm(void *context, int length);
 
 /* Load a WAV stream from the given RWops object */
-static void *WAV_CreateFromRW(SDL_RWops *src, int freesrc)
+static void *WAV_CreateFromRW(SDL_RWops *src, SDL_bool freesrc)
 {
     WAV_Music *music;
     Uint32 magic;
diff --git a/src/codecs/music_wavpack.c b/src/codecs/music_wavpack.c
index 205d376e..1961a3cc 100644
--- a/src/codecs/music_wavpack.c
+++ b/src/codecs/music_wavpack.c
@@ -178,7 +178,7 @@ static void WAVPACK_Unload(void)
 typedef struct {
     SDL_RWops *src1; /* wavpack file    */
     SDL_RWops *src2; /* correction file */
-    int freesrc;
+    SDL_bool freesrc;
     int play_count;
     int volume;
 
@@ -289,13 +289,13 @@ static WavpackStreamReader64 sdl_reader64 = {
 
 static int WAVPACK_Seek(void *context, double time);
 static void WAVPACK_Delete(void *context);
-static void *WAVPACK_CreateFromRW_internal(SDL_RWops *src1, SDL_RWops *src2, int freesrc, int *freesrc2);
+static void *WAVPACK_CreateFromRW_internal(SDL_RWops *src1, SDL_RWops *src2, SDL_bool freesrc, int *freesrc2);
 
 static void *decimation_init(int num_channels, int ratio);
 static int decimation_run(void *context, int32_t *samples, int num_samples);
 static void decimation_reset(void *context);
 
-static void *WAVPACK_CreateFromRW(SDL_RWops *src, int freesrc)
+static void *WAVPACK_CreateFromRW(SDL_RWops *src, SDL_bool freesrc)
 {
     return WAVPACK_CreateFromRW_internal(src, NULL, freesrc, NULL);
 }
@@ -304,7 +304,7 @@ static void *WAVPACK_CreateFromFile(const char *file)
 {
     SDL_RWops *src1, *src2;
     WAVPACK_music *music;
-    int freesrc2 = 1;
+    SDL_bool freesrc2 = 1;
     size_t len;
     char *file2;
 
@@ -341,7 +341,7 @@ static void *WAVPACK_CreateFromFile(const char *file)
 }
 
 /* Load a WavPack stream from an SDL_RWops object */
-static void *WAVPACK_CreateFromRW_internal(SDL_RWops *src1, SDL_RWops *src2, int freesrc, int *freesrc2)
+static void *WAVPACK_CreateFromRW_internal(SDL_RWops *src1, SDL_RWops *src2, SDL_bool freesrc, int *freesrc2)
 {
     WAVPACK_music *music;
     SDL_AudioFormat format;
diff --git a/src/codecs/music_xmp.c b/src/codecs/music_xmp.c
index cc3d48e3..69b94afe 100644
--- a/src/codecs/music_xmp.c
+++ b/src/codecs/music_xmp.c
@@ -191,7 +191,7 @@ static long xmp_ftell(void *src) {
 }
 
 /* Load a libxmp stream from an SDL_RWops object */
-void *XMP_CreateFromRW(SDL_RWops *src, int freesrc)
+void *XMP_CreateFromRW(SDL_RWops *src, SDL_bool freesrc)
 {
     XMP_Music *music;
     struct xmp_callbacks file_callbacks = {
diff --git a/src/codecs/native_midi/native_midi.h b/src/codecs/native_midi/native_midi.h
index ffafd555..c01dcf43 100644
--- a/src/codecs/native_midi/native_midi.h
+++ b/src/codecs/native_midi/native_midi.h
@@ -27,7 +27,7 @@
 typedef struct _NativeMidiSong NativeMidiSong;
 
 int native_midi_detect(void);
-NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *src, int freesrc);
+NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *src, SDL_bool freesrc);
 void native_midi_freesong(NativeMidiSong *song);
 void native_midi_start(NativeMidiSong *song, int loops);
 void native_midi_pause(void);
diff --git a/src/codecs/native_midi/native_midi_haiku.cpp b/src/codecs/native_midi/native_midi_haiku.cpp
index bd64cfe4..d26130d4 100644
--- a/src/codecs/native_midi/native_midi_haiku.cpp
+++ b/src/codecs/native_midi/native_midi_haiku.cpp
@@ -219,7 +219,7 @@ void native_midi_setvolume(int volume)
   synth.SetVolume(volume / 128.0);
 }
 
-NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *src, int freesrc)
+NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *src, SDL_bool freesrc)
 {
   NativeMidiSong *song = new NativeMidiSong;
   song->store = new MidiEventsStore;
diff --git a/src/codecs/native_midi/native_midi_macosx.c b/src/codecs/native_midi/native_midi_macosx.c
index 4661c62b..cd826151 100644
--- a/src/codecs/native_midi/native_midi_macosx.c
+++ b/src/codecs/native_midi/native_midi_macosx.c
@@ -196,7 +196,7 @@ int native_midi_detect(void)
     return 1;  /* always available. */
 }
 
-NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *src, int freesrc)
+NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *src, SDL_bool freesrc)
 {
     NativeMidiSong *retval = NULL;
     void *buf = NULL;
diff --git a/src/codecs/native_midi/native_midi_win32.c b/src/codecs/native_midi/native_midi_win32.c
index 241226f6..914e32ae 100644
--- a/src/codecs/native_midi/native_midi_win32.c
+++ b/src/codecs/native_midi/native_midi_win32.c
@@ -213,7 +213,7 @@ int native_midi_detect(void)
   return 1;
 }
 
-NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *src, int freesrc)
+NativeMidiSong *native_midi_loadsong_RW(SDL_RWops *src, SDL_bool freesrc)
 {
     NativeMidiSong *newsong;
     MIDIEvent       *evntlist = NULL;
diff --git a/src/mixer.c b/src/mixer.c
index a6cd9d68..d2171526 100644
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -625,7 +625,7 @@ typedef struct _MusicFragment
     struct _MusicFragment *next;
 } MusicFragment;
 
-static SDL_AudioSpec *Mix_LoadMusic_RW(SDL_RWops *src, int freesrc, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
+static SDL_AudioSpec *Mix_LoadMusic_RW(SDL_RWops *src, SDL_bool freesrc, SDL_AudioSpec *spec, Uint8 **audio_buf, Uint32 *audio_len)
 {
     int i;
     Mix_MusicType music_type;
@@ -768,7 +768,7 @@ static SDL_AudioSpec *Mix_LoadMusic_RW(SDL_RWops *src, int freesrc, SDL_AudioSpe
 }
 
 /* Load a wave file */
-Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, int freesrc)
+Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, SDL_bool freesrc)
 {
     Uint8 magic[4];
     Mix_Chunk *chunk;
diff --git a/src/music.c b/src/music.c
index ad95bb27..e4b33866 100644
--- a/src/music.c
+++ b/src/music.c
@@ -733,12 +733,12 @@ Mix_Music *Mix_LoadMUS(const char *file)
     return Mix_LoadMUSType_RW(src, type, SDL_TRUE);
 }
 
-Mix_Music *Mix_LoadMUS_RW(SDL_RWops *src, int freesrc)
+Mix_Music *Mix_LoadMUS_RW(SDL_RWops *src, SDL_bool freesrc)
 {
     return Mix_LoadMUSType_RW(src, MUS_NONE, freesrc);
 }
 
-Mix_Music *Mix_LoadMUSType_RW(SDL_RWops *src, Mix_MusicType type, int freesrc)
+Mix_Music *Mix_LoadMUSType_RW(SDL_RWops *src, Mix_MusicType type, SDL_bool freesrc)
 {
     int i;
     void *context;
diff --git a/src/music.h b/src/music.h
index 3e4c462e..172c0f54 100644
--- a/src/music.h
+++ b/src/music.h
@@ -90,7 +90,7 @@ typedef struct
     /* Create a music object from an SDL_RWops stream
      * If the function returns NULL, 'src' will be freed if needed by the caller.
      */
-    void *(*CreateFromRW)(SDL_RWops *src, int

(Patch may be truncated, please check the link at the top of this post.)