From 2d39bf227e319a128d933aec92d19047dfb800fc Mon Sep 17 00:00:00 2001
From: pionere <[EMAIL REDACTED]>
Date: Tue, 21 Dec 2021 11:09:29 +0100
Subject: [PATCH] more consistent error reporting
---
include/SDL_mixer.h | 1 +
src/codecs/load_aiff.c | 18 +++++++++---------
src/codecs/music_cmd.c | 2 +-
src/codecs/music_wav.c | 10 +++++-----
src/codecs/native_midi/native_midi_common.c | 6 +++---
src/effect_position.c | 6 +++---
src/mixer.c | 20 ++++++++++----------
src/music.c | 8 ++++----
8 files changed, 36 insertions(+), 35 deletions(-)
diff --git a/include/SDL_mixer.h b/include/SDL_mixer.h
index fefc8168..3832245f 100644
--- a/include/SDL_mixer.h
+++ b/include/SDL_mixer.h
@@ -690,6 +690,7 @@ extern DECLSPEC void SDLCALL Mix_CloseAudio(void);
#define Mix_SetError SDL_SetError
#define Mix_GetError SDL_GetError
#define Mix_ClearError SDL_ClearError
+#define Mix_OutOfMemory SDL_OutOfMemory
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
diff --git a/src/codecs/load_aiff.c b/src/codecs/load_aiff.c
index 5d88a110..38993dab 100644
--- a/src/codecs/load_aiff.c
+++ b/src/codecs/load_aiff.c
@@ -108,7 +108,7 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc,
AIFFmagic = SDL_ReadLE32(src);
}
if ((FORMchunk != FORM) || ((AIFFmagic != AIFF) && (AIFFmagic != _8SVX))) {
- SDL_SetError("Unrecognized file type (not AIFF nor 8SVX)");
+ Mix_SetError("Unrecognized file type (not AIFF nor 8SVX)");
was_error = 1;
goto done;
}
@@ -145,7 +145,7 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc,
SDL_RWread(src, sane_freq, sizeof(sane_freq), 1);
frequency = SANE_to_Uint32(sane_freq);
if (frequency == 0) {
- SDL_SetError("Bad AIFF sample frequency");
+ Mix_SetError("Bad AIFF sample frequency");
was_error = 1;
goto done;
}
@@ -178,25 +178,25 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc,
&& SDL_RWseek(src, next_chunk, RW_SEEK_SET) != 1);
if ((AIFFmagic == AIFF) && !found_SSND) {
- SDL_SetError("Bad AIFF (no SSND chunk)");
+ Mix_SetError("Bad AIFF (no SSND chunk)");
was_error = 1;
goto done;
}
if ((AIFFmagic == AIFF) && !found_COMM) {
- SDL_SetError("Bad AIFF (no COMM chunk)");
+ Mix_SetError("Bad AIFF (no COMM chunk)");
was_error = 1;
goto done;
}
if ((AIFFmagic == _8SVX) && !found_VHDR) {
- SDL_SetError("Bad 8SVX (no VHDR chunk)");
+ Mix_SetError("Bad 8SVX (no VHDR chunk)");
was_error = 1;
goto done;
}
if ((AIFFmagic == _8SVX) && !found_BODY) {
- SDL_SetError("Bad 8SVX (no BODY chunk)");
+ Mix_SetError("Bad 8SVX (no BODY chunk)");
was_error = 1;
goto done;
}
@@ -212,7 +212,7 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc,
spec->format = AUDIO_S16MSB;
break;
default:
- SDL_SetError("Unsupported AIFF samplesize");
+ Mix_SetError("Unsupported AIFF samplesize");
was_error = 1;
goto done;
}
@@ -222,12 +222,12 @@ SDL_AudioSpec *Mix_LoadAIFF_RW (SDL_RWops *src, int freesrc,
*audio_len = channels * numsamples * (samplesize / 8);
*audio_buf = (Uint8 *)SDL_malloc(*audio_len);
if (*audio_buf == NULL) {
- SDL_SetError("Out of memory");
+ Mix_OutOfMemory();
return(NULL);
}
SDL_RWseek(src, start, RW_SEEK_SET);
if (SDL_RWread(src, *audio_buf, *audio_len, 1) != 1) {
- SDL_SetError("Unable to read audio data");
+ Mix_SetError("Unable to read audio data");
return(NULL);
}
diff --git a/src/codecs/music_cmd.c b/src/codecs/music_cmd.c
index 7a9156c8..1188e7d0 100644
--- a/src/codecs/music_cmd.c
+++ b/src/codecs/music_cmd.c
@@ -65,7 +65,7 @@ static void *MusicCMD_CreateFromFile(const char *file)
/* Allocate and fill the music structure */
music = (MusicCMD *)SDL_calloc(1, sizeof *music);
if (music == NULL) {
- Mix_SetError("Out of memory");
+ Mix_OutOfMemory();
return NULL;
}
music->file = SDL_strdup(file);
diff --git a/src/codecs/music_wav.c b/src/codecs/music_wav.c
index b4f49bc7..4b9b7220 100644
--- a/src/codecs/music_wav.c
+++ b/src/codecs/music_wav.c
@@ -181,7 +181,7 @@ static void *WAV_CreateFromRW(SDL_RWops *src, int freesrc)
music = (WAV_Music *)SDL_calloc(1, sizeof(*music));
if (!music) {
- SDL_OutOfMemory();
+ Mix_OutOfMemory();
return NULL;
}
music->src = src;
@@ -204,7 +204,7 @@ static void *WAV_CreateFromRW(SDL_RWops *src, int freesrc)
}
music->buffer = (Uint8*)SDL_malloc(music->spec.size);
if (!music->buffer) {
- SDL_OutOfMemory();
+ Mix_OutOfMemory();
WAV_Delete(music);
return NULL;
}
@@ -757,7 +757,7 @@ static SDL_bool AddLoopPoint(WAV_Music *wave, Uint32 play_count, Uint32 start, U
WAVLoopPoint *loop;
WAVLoopPoint *loops = SDL_realloc(wave->loops, (wave->numloops + 1) * sizeof(*wave->loops));
if (!loops) {
- Mix_SetError("Out of memory");
+ Mix_OutOfMemory();
return SDL_FALSE;
}
@@ -781,7 +781,7 @@ static SDL_bool ParseSMPL(WAV_Music *wave, Uint32 chunk_length)
data = (Uint8 *)SDL_malloc(chunk_length);
if (!data) {
- Mix_SetError("Out of memory");
+ Mix_OutOfMemory();
return SDL_FALSE;
}
if (!SDL_RWread(wave->src, data, chunk_length, 1)) {
@@ -831,7 +831,7 @@ static SDL_bool ParseLIST(WAV_Music *wave, Uint32 chunk_length)
data = (Uint8 *)SDL_malloc(chunk_length);
if (!data) {
- Mix_SetError("Out of memory");
+ Mix_OutOfMemory();
return SDL_FALSE;
}
diff --git a/src/codecs/native_midi/native_midi_common.c b/src/codecs/native_midi/native_midi_common.c
index 88244865..cfc014ba 100644
--- a/src/codecs/native_midi/native_midi_common.c
+++ b/src/codecs/native_midi/native_midi_common.c
@@ -90,7 +90,7 @@ static MIDIEvent *CreateEvent(Uint32 time, Uint8 event, Uint8 a, Uint8 b)
newEvent->data[1] = b;
}
else
- Mix_SetError("Out of memory");
+ Mix_OutOfMemory();
return newEvent;
}
@@ -318,7 +318,7 @@ static int ReadMIDIFile(MIDIFile *mididata, SDL_RWops *src)
mididata->track = (MIDITrack*) SDL_calloc(1, sizeof(MIDITrack) * mididata->nTracks);
if (NULL == mididata->track)
{
- Mix_SetError("Out of memory");
+ Mix_OutOfMemory();
goto bail;
}
@@ -336,7 +336,7 @@ static int ReadMIDIFile(MIDIFile *mididata, SDL_RWops *src)
mididata->track[i].data = SDL_malloc(size);
if (NULL == mididata->track[i].data)
{
- Mix_SetError("Out of memory");
+ Mix_OutOfMemory();
goto bail;
}
SDL_RWread(src, mididata->track[i].data, 1, size);
diff --git a/src/effect_position.c b/src/effect_position.c
index 0819ded6..a6accf18 100644
--- a/src/effect_position.c
+++ b/src/effect_position.c
@@ -1589,7 +1589,7 @@ static position_args *get_position_arg(int channel)
if (pos_args_global == NULL) {
pos_args_global = SDL_malloc(sizeof (position_args));
if (pos_args_global == NULL) {
- Mix_SetError("Out of memory");
+ Mix_OutOfMemory();
return(NULL);
}
init_position_args(pos_args_global);
@@ -1601,7 +1601,7 @@ static position_args *get_position_arg(int channel)
if (channel >= position_channels) {
rc = SDL_realloc(pos_args_array, (size_t)(channel + 1) * sizeof(position_args *));
if (rc == NULL) {
- Mix_SetError("Out of memory");
+ Mix_OutOfMemory();
return(NULL);
}
pos_args_array = (position_args **) rc;
@@ -1614,7 +1614,7 @@ static position_args *get_position_arg(int channel)
if (pos_args_array[channel] == NULL) {
pos_args_array[channel] = (position_args *)SDL_malloc(sizeof(position_args));
if (pos_args_array[channel] == NULL) {
- Mix_SetError("Out of memory");
+ Mix_OutOfMemory();
return(NULL);
}
init_position_args(pos_args_array[channel]);
diff --git a/src/mixer.c b/src/mixer.c
index 59c22d7b..4eff625e 100644
--- a/src/mixer.c
+++ b/src/mixer.c
@@ -645,7 +645,7 @@ static SDL_AudioSpec *Mix_LoadMusic_RW(SDL_RWops *src, int freesrc, SDL_AudioSpe
dst += fragment->size;
}
} else {
- SDL_OutOfMemory();
+ Mix_OutOfMemory();
spec = NULL;
}
} else {
@@ -677,13 +677,13 @@ Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, int freesrc)
/* rcg06012001 Make sure src is valid */
if (!src) {
- SDL_SetError("Mix_LoadWAV_RW with NULL src");
+ Mix_SetError("Mix_LoadWAV_RW with NULL src");
return(NULL);
}
/* Make sure audio has been opened */
if (!audio_opened) {
- SDL_SetError("Audio device hasn't been opened");
+ Mix_SetError("Audio device hasn't been opened");
if (freesrc) {
SDL_RWclose(src);
}
@@ -693,7 +693,7 @@ Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, int freesrc)
/* Allocate the chunk memory */
chunk = (Mix_Chunk *)SDL_malloc(sizeof(Mix_Chunk));
if (chunk == NULL) {
- SDL_SetError("Out of memory");
+ Mix_OutOfMemory();
if (freesrc) {
SDL_RWclose(src);
}
@@ -747,7 +747,7 @@ Mix_Chunk *Mix_LoadWAV_RW(SDL_RWops *src, int freesrc)
wavecvt.len = chunk->alen & ~(samplesize-1);
wavecvt.buf = (Uint8 *)SDL_calloc(1, wavecvt.len*wavecvt.len_mult);
if (wavecvt.buf == NULL) {
- SDL_SetError("Out of memory");
+ Mix_OutOfMemory();
SDL_free(chunk->abuf);
SDL_free(chunk);
return(NULL);
@@ -780,14 +780,14 @@ Mix_Chunk *Mix_QuickLoad_WAV(Uint8 *mem)
/* Make sure audio has been opened */
if (! audio_opened) {
- SDL_SetError("Audio device hasn't been opened");
+ Mix_SetError("Audio device hasn't been opened");
return(NULL);
}
/* Allocate the chunk memory */
chunk = (Mix_Chunk *)SDL_calloc(1,sizeof(Mix_Chunk));
if (chunk == NULL) {
- SDL_SetError("Out of memory");
+ Mix_OutOfMemory();
return(NULL);
}
@@ -814,14 +814,14 @@ Mix_Chunk *Mix_QuickLoad_RAW(Uint8 *mem, Uint32 len)
/* Make sure audio has been opened */
if (! audio_opened) {
- SDL_SetError("Audio device hasn't been opened");
+ Mix_SetError("Audio device hasn't been opened");
return(NULL);
}
/* Allocate the chunk memory */
chunk = (Mix_Chunk *)SDL_malloc(sizeof(Mix_Chunk));
if (chunk == NULL) {
- SDL_SetError("Out of memory");
+ Mix_OutOfMemory();
return(NULL);
}
@@ -1432,7 +1432,7 @@ static int _Mix_register_effect(effect_info **e, Mix_EffectFunc_t f,
new_e = SDL_malloc(sizeof (effect_info));
if (new_e == NULL) {
- Mix_SetError("Out of memory");
+ Mix_OutOfMemory();
return(0);
}
diff --git a/src/music.c b/src/music.c
index b6e8063d..95022860 100644
--- a/src/music.c
+++ b/src/music.c
@@ -577,7 +577,7 @@ Mix_Music *Mix_LoadMUS(const char *file)
/* Allocate memory for the music structure */
Mix_Music *music = (Mix_Music *)SDL_calloc(1, sizeof(Mix_Music));
if (music == NULL) {
- Mix_SetError("Out of memory");
+ Mix_OutOfMemory();
return NULL;
}
music->interface = interface;
@@ -688,7 +688,7 @@ Mix_Music *Mix_LoadMUSType_RW(SDL_RWops *src, Mix_MusicType type, int freesrc)
Mix_Music *music = (Mix_Music *)SDL_calloc(1, sizeof(Mix_Music));
if (music == NULL) {
interface->Delete(context);
- Mix_SetError("Out of memory");
+ Mix_OutOfMemory();
return NULL;
}
music->interface = interface;
@@ -866,7 +866,7 @@ int Mix_FadeInMusicPos(Mix_Music *music, int loops, int ms, double position)
int retval;
if (ms_per_step == 0) {
- SDL_SetError("Audio device hasn't been opened");
+ Mix_SetError("Audio device hasn't been opened");
return(-1);
}
@@ -1174,7 +1174,7 @@ int Mix_FadeOutMusic(int ms)
int retval = 0;
if (ms_per_step == 0) {
- SDL_SetError("Audio device hasn't been opened");
+ Mix_SetError("Audio device hasn't been opened");
return 0;
}