Skip to content

Commit

Permalink
Use SDL_bool instead an int return code in the SDL API
Browse files Browse the repository at this point in the history
Most SDL functions used to indicate success or failure using an int return code. These functions have been changed to return SDL_bool.

Here is a coccinelle patch to change code that previously compared the return value to 0 and changes it to a boolean test:
@ bool_return_type @
identifier func =~ "^(Mix_FadeInMusic|Mix_FadeInMusicPos|Mix_GroupChannels|Mix_ModMusicJumpToOrder|Mix_OpenAudio|Mix_PlayMusic|Mix_SetMusicCMD|Mix_SetMusicPosition|Mix_SetSoundFonts|Mix_StartTrack)$";
@@
(
  func(
  ...
  )
- == 0
|
- func(
+ !func(
  ...
  )
- < 0
|
- func(
+ !func(
  ...
  )
- != 0
|
- func(
+ !func(
  ...
  )
- == -1
)
  • Loading branch information
slouken committed Aug 28, 2024
1 parent 46ad68a commit 49774b9
Show file tree
Hide file tree
Showing 29 changed files with 370 additions and 483 deletions.
2 changes: 1 addition & 1 deletion cmake/test/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ int main(int argc, char *argv[])
return 1;
}
if (Mix_Init(0) == 0) {
SDL_Log("Mix_Init: no sound/music loaders supported (%s)\n", Mix_GetError());
SDL_Log("Mix_Init: no sound/music loaders supported (%s)\n", SDL_GetError());
}
Mix_Quit();
SDL_Quit();
Expand Down
2 changes: 1 addition & 1 deletion examples/playmus.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ int main(int argc, char *argv[])
#endif

/* Open the audio device */
if (Mix_OpenAudio(0, &spec) < 0) {
if (!Mix_OpenAudio(0, &spec)) {
SDL_Log("Couldn't open audio: %s\n", SDL_GetError());
return 2;
} else {
Expand Down
10 changes: 5 additions & 5 deletions examples/playwave.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static void do_panning_update(void)
if (!panningok) {
SDL_Log("Mix_SetPanning(0, %d, %d) failed!\n",
(int) leftvol, (int) rightvol);
SDL_Log("Reason: [%s].\n", Mix_GetError());
SDL_Log("Reason: [%s].\n", SDL_GetError());
}

if ((leftvol == 255) || (leftvol == 0)) {
Expand Down Expand Up @@ -206,7 +206,7 @@ static void do_distance_update(void)
distanceok = Mix_SetDistance(0, distance);
if (!distanceok) {
SDL_Log("Mix_SetDistance(0, %d) failed!\n", (int) distance);
SDL_Log("Reason: [%s].\n", Mix_GetError());
SDL_Log("Reason: [%s].\n", SDL_GetError());
}

if (distance == 0) {
Expand Down Expand Up @@ -240,7 +240,7 @@ static void do_position_update(void)
if (!positionok) {
SDL_Log("Mix_SetPosition(0, %d, %d) failed!\n",
(int) angle, (int) distance);
SDL_Log("Reason: [%s].\n", Mix_GetError());
SDL_Log("Reason: [%s].\n", SDL_GetError());
}

if (angle == 0) {
Expand Down Expand Up @@ -424,7 +424,7 @@ int main(int argc, char *argv[])
#endif

/* Open the audio device */
if (Mix_OpenAudio(0, &spec) < 0) {
if (!Mix_OpenAudio(0, &spec)) {
SDL_Log("Couldn't open audio: %s\n", SDL_GetError());
CleanUp(2);
} else {
Expand Down Expand Up @@ -469,7 +469,7 @@ int main(int argc, char *argv[])
(reverse_stereo))
{
SDL_Log("Failed to set up reverse stereo effect!\n");
SDL_Log("Reason: [%s].\n", Mix_GetError());
SDL_Log("Reason: [%s].\n", SDL_GetError());
}

/* Play and then exit */
Expand Down
Loading

0 comments on commit 49774b9

Please sign in to comment.