sdl2-compat: Updated for SDL3 change to use SDL_bool instead of int return code

From 6dbcdcd7683b5de35788fb8b036f441a7aca1834 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 26 Aug 2024 20:20:34 -0700
Subject: [PATCH] Updated for SDL3 change to use SDL_bool instead of int return
 code

---
 src/sdl2_compat.c |  588 +++++++++++++------
 src/sdl2_compat.h |    2 +
 src/sdl3_syms.h   | 1408 +++++++++++++++++++++++----------------------
 3 files changed, 1108 insertions(+), 890 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 83d3f0f..c7678fa 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -140,11 +140,15 @@ extern "C" {
 /* Things that _should_ be binary compatible pass right through... */
 #define SDL3_SYM_PASSTHROUGH(rc,fn,params,args,ret) \
     SDL_DECLSPEC rc SDLCALL SDL_##fn params { ret SDL3_##fn args; }
+#define SDL3_SYM_PASSTHROUGH_RETCODE(rc,fn,params,args,ret) \
+    SDL_DECLSPEC int SDLCALL SDL_##fn params { ret (SDL3_##fn args) ? 0 : -1; }
 #include "sdl3_syms.h"
 
 /* Things that were renamed and _should_ be binary compatible pass right through with the correct names... */
 #define SDL3_SYM_RENAMED(rc,oldfn,newfn,params,args,ret) \
     SDL_DECLSPEC rc SDLCALL SDL_##oldfn params { ret SDL3_##newfn args; }
+#define SDL3_SYM_RENAMED_RETCODE(rc,oldfn,newfn,params,args,ret) \
+    SDL_DECLSPEC int SDLCALL SDL_##oldfn params { ret (SDL3_##newfn args) ? 0 : -1; }
 #include "sdl3_syms.h"
 
 
@@ -466,13 +470,13 @@ SDL2_to_SDL3_hint(const char *name)
 SDL_DECLSPEC SDL_bool SDLCALL
 SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPriority priority)
 {
-    return SDL3_SetHintWithPriority(SDL2_to_SDL3_hint(name), value, priority) == 0;
+    return SDL3_SetHintWithPriority(SDL2_to_SDL3_hint(name), value, priority);
 }
 
 SDL_DECLSPEC SDL_bool SDLCALL
 SDL_SetHint(const char *name, const char *value)
 {
-    return SDL3_SetHint(SDL2_to_SDL3_hint(name), value) == 0;
+    return SDL3_SetHint(SDL2_to_SDL3_hint(name), value);
 }
 
 SDL_DECLSPEC const char * SDLCALL
@@ -484,7 +488,7 @@ SDL_GetHint(const char *name)
 SDL_DECLSPEC SDL_bool SDLCALL
 SDL_ResetHint(const char *name)
 {
-    return SDL3_ResetHint(SDL2_to_SDL3_hint(name)) == 0;
+    return SDL3_ResetHint(SDL2_to_SDL3_hint(name));
 }
 
 SDL_DECLSPEC SDL_bool SDLCALL
@@ -943,18 +947,25 @@ SDL_Error(SDL_errorcode code)
 {
     switch (code) {
     case SDL_ENOMEM:
-        return SDL3_OutOfMemory();
+        SDL3_OutOfMemory();
+        break;
     case SDL_EFREAD:
-        return SDL3_SetError("Error reading from datastream");
+        SDL3_SetError("Error reading from datastream");
+        break;
     case SDL_EFWRITE:
-        return SDL3_SetError("Error writing to datastream");
+        SDL3_SetError("Error writing to datastream");
+        break;
     case SDL_EFSEEK:
-        return SDL3_SetError("Error seeking in datastream");
+        SDL3_SetError("Error seeking in datastream");
+        break;
     case SDL_UNSUPPORTED:
-        return SDL3_Unsupported();
+        SDL3_Unsupported();
+        break;
     default:
-        return SDL3_SetError("Unknown SDL error");
+        SDL3_SetError("Unknown SDL error");
+        break;
     }
+    return -1;
 }
 
 SDL_DECLSPEC int SDLCALL
@@ -1391,7 +1402,13 @@ SDL_DECLSPEC int SDLCALL
 SDL_PushEvent(SDL2_Event *event2)
 {
     SDL_Event event3;
-    return SDL3_PushEvent(Event2to3(event2, &event3));
+    if (SDL3_PushEvent(Event2to3(event2, &event3))) {
+        return 1;
+    } else if (*SDL_GetError() == '\0') {
+        return 0;
+    } else {
+        return -1;
+    }
 }
 
 static int Display_IDToIndex(SDL_DisplayID displayID);
@@ -1439,7 +1456,7 @@ WindowEventType3To2(Uint32 event_type3)
     }
 }
 
-static int SDLCALL
+static SDL_bool SDLCALL
 EventFilter3to2(void *userdata, SDL_Event *event3)
 {
     SDL2_Event event2;  /* note that event filters do not receive events as const! So we have to convert or copy it for each one! */
@@ -1657,7 +1674,7 @@ SDL_DelEventWatch(SDL2_EventFilter filter2, void *userdata)
     SDL3_UnlockMutex(EventWatchListMutex);
 }
 
-static int SDLCALL
+static SDL_bool SDLCALL
 EventFilterWrapper3to2(void *userdata, SDL_Event *event)
 {
     const EventFilterWrapperData *wrapperdata = (const EventFilterWrapperData *) userdata;
@@ -1926,7 +1943,7 @@ SDL_WarpMouseInWindow(SDL_Window *window, int x, int y)
 SDL_DECLSPEC int SDLCALL
 SDL_WarpMouseGlobal(int x, int y)
 {
-    return SDL3_WarpMouseGlobal((float)x, (float)y);
+    return SDL3_WarpMouseGlobal((float)x, (float)y) ? 0 : -1;
 }
 
 SDL_DECLSPEC int SDLCALL
@@ -1938,7 +1955,7 @@ SDL_SetRelativeMouseMode(SDL_bool enabled)
         int i;
 
         for (i = 0; windows[i]; ++i) {
-            if (SDL3_SetWindowRelativeMouseMode(windows[i], enabled) < 0) {
+            if (!SDL3_SetWindowRelativeMouseMode(windows[i], enabled)) {
                 retval = -1;
             }
         }
@@ -2008,7 +2025,7 @@ RWops3to2_write(SDL2_RWops *rwops2, const void *ptr, size_t size, size_t maxnum)
 static int SDLCALL
 RWops3to2_close(SDL2_RWops *rwops2)
 {
-    const int retval = SDL3_CloseIO(rwops2->hidden.sdl3.iostrm);
+    const int retval = SDL3_CloseIO(rwops2->hidden.sdl3.iostrm) ? 0 : -1;
     SDL_FreeRW(rwops2);
     return retval;
 }
@@ -2233,19 +2250,22 @@ stdio_seek(SDL2_RWops *rwops2, Sint64 offset, int whence)
         stdiowhence = SEEK_END;
         break;
     default:
-        return SDL3_SetError("Unknown value for 'whence'");
+        SDL3_SetError("Unknown value for 'whence'");
+        return -1;
     }
 
 #if defined(FSEEK_OFF_MIN) && defined(FSEEK_OFF_MAX)
     if (offset < (Sint64)(FSEEK_OFF_MIN) || offset > (Sint64)(FSEEK_OFF_MAX)) {
-        return SDL3_SetError("Seek offset out of range");
+        SDL3_SetError("Seek offset out of range");
+        return -1;
     }
 #endif
 
     if (fseek(fp, (long)offset, stdiowhence) == 0) {
         Sint64 pos = ftell(fp);
         if (pos < 0) {
-            return SDL3_SetError("Couldn't get stream offset");
+            SDL3_SetError("Couldn't get stream offset");
+            return -1;
         }
         return pos;
     }
@@ -2331,12 +2351,12 @@ RWops2to3_write(void *userdata, const void *ptr, size_t size, SDL_IOStatus *stat
     return SDL_RWwrite((SDL2_RWops *) userdata, ptr, 1, size);
 }
 
-static int SDLCALL
+static SDL_bool SDLCALL
 RWops2to3_close(void *userdata)
 {
     /* Never close the SDL2_RWops here! This is just a wrapper to talk to SDL3 APIs. We will manually close the rwops2 if appropriate. */
-    /*return SDL_CloseIO((SDL2_RWops *) userdata);*/
-    return 0;
+    /*return SDL_CloseIO((SDL2_RWops *) userdata) ? 0 : -1;*/
+    return SDL_TRUE;
 }
 
 static SDL_IOStream *
@@ -2388,9 +2408,9 @@ SDL_LoadWAV_RW(SDL2_RWops *rwops2, int freesrc, SDL2_AudioSpec *spec2, Uint8 **a
         SDL_IOStream *iostrm3 = RWops2to3(rwops2);
         if (iostrm3) {
             SDL_AudioSpec spec3;
-            const int rc = SDL3_LoadWAV_IO(iostrm3, SDL_TRUE, &spec3, audio_buf, audio_len);   /* always close the iostrm3 bridge object. */
+            const SDL_bool rc = SDL3_LoadWAV_IO(iostrm3, SDL_TRUE, &spec3, audio_buf, audio_len);   /* always close the iostrm3 bridge object. */
             SDL3_zerop(spec2);
-            if (rc == 0) {
+            if (rc) {
                 spec2->format = spec3.format;
                 spec2->channels = spec3.channels;
                 spec2->freq = spec3.freq;
@@ -2521,7 +2541,7 @@ SDL_SaveBMP_RW(SDL2_Surface *surface, SDL2_RWops *rwops, int freedst)
     int retval = -1;
     SDL_IOStream *iostream = RWops2to3(rwops);
     if (iostream) {
-        retval = SDL3_SaveBMP_IO(Surface2to3(surface), iostream, SDL_TRUE);    /* always close the iostrm3 bridge object. */
+        retval = SDL3_SaveBMP_IO(Surface2to3(surface), iostream, SDL_TRUE) ? 0 : -1;    /* always close the iostrm3 bridge object. */
     }
     if (rwops && freedst) {
         SDL_RWclose(rwops);
@@ -2551,14 +2571,15 @@ SDL_GameControllerAddMappingsFromRW(SDL2_RWops *rwops2, int freerw)
 SDL_DECLSPEC int SDLCALL
 SDL_SetWindowBrightness(SDL_Window *window, float brightness)
 {
-    return SDL3_Unsupported();
+    SDL3_Unsupported();
+    return -1;
 }
 
 SDL_DECLSPEC float SDLCALL
 SDL_GetWindowBrightness(SDL_Window *window)
 {
     if (!window) {
-        SDL_SetError("Invalid window");
+        SDL3_SetError("Invalid window");
     }
     return 1.0f;
 }
@@ -2566,7 +2587,8 @@ SDL_GetWindowBrightness(SDL_Window *window)
 SDL_DECLSPEC int SDLCALL
 SDL_SetWindowGammaRamp(SDL_Window *window, const Uint16 *r, const Uint16 *g, const Uint16 *b)
 {
-    return SDL3_Unsupported();
+    SDL3_Unsupported();
+    return -1;
 }
 
 SDL_DECLSPEC void SDLCALL
@@ -2616,7 +2638,8 @@ SDL_GetWindowGammaRamp(SDL_Window *window, Uint16 *red, Uint16 *blue, Uint16 *gr
     Uint16 *buf;
 
     if (!window) {
-        return SDL_SetError("Invalid window");
+        SDL3_SetError("Invalid window");
+        return -1;
     }
 
     buf = red ? red : (green ? green : blue);
@@ -2730,13 +2753,13 @@ SDL_ConvertPixels(int width, int height, Uint32 src_format, const void *src, int
 {
     SDL_Colorspace src_colorspace = GetColorspaceForFormatAndSize(src_format, width, height);
     SDL_Colorspace dst_colorspace = GetColorspaceForFormatAndSize(dst_format, width, height);
-    return SDL3_ConvertPixelsAndColorspace(width, height, (SDL_PixelFormat)src_format, src_colorspace, 0, src, src_pitch, (SDL_PixelFormat)dst_format, dst_colorspace, 0, dst, dst_pitch);
+    return SDL3_ConvertPixelsAndColorspace(width, height, (SDL_PixelFormat)src_format, src_colorspace, 0, src, src_pitch, (SDL_PixelFormat)dst_format, dst_colorspace, 0, dst, dst_pitch) ? 0 : -1;
 }
 
 SDL_DECLSPEC int SDLCALL
 SDL_PremultiplyAlpha(int width, int height, Uint32 src_format, const void * src, int src_pitch, Uint32 dst_format, void * dst, int dst_pitch)
 {
-    return SDL3_PremultiplyAlpha(width, height, (SDL_PixelFormat)src_format, src, src_pitch, (SDL_PixelFormat)dst_format, dst, dst_pitch, SDL_FALSE);
+    return SDL3_PremultiplyAlpha(width, height, (SDL_PixelFormat)src_format, src, src_pitch, (SDL_PixelFormat)dst_format, dst, dst_pitch, SDL_FALSE) ? 0 : -1;
 }
 
 SDL_DECLSPEC SDL2_Surface * SDLCALL
@@ -2780,13 +2803,13 @@ SDL_FreeSurface(SDL2_Surface *surface)
 SDL_DECLSPEC int SDLCALL
 SDL_FillRect(SDL2_Surface *dst, const SDL_Rect *rect, Uint32 color)
 {
-    return SDL3_FillSurfaceRect(Surface2to3(dst), rect, color);
+    return SDL3_FillSurfaceRect(Surface2to3(dst), rect, color) ? 0 : -1;
 }
 
 SDL_DECLSPEC int SDLCALL
 SDL_FillRects(SDL2_Surface *dst, const SDL_Rect *rects, int count, Uint32 color)
 {
-    return SDL3_FillSurfaceRects(Surface2to3(dst), rects, count, color);
+    return SDL3_FillSurfaceRects(Surface2to3(dst), rects, count, color) ? 0 : -1;
 }
 
 SDL_DECLSPEC int SDLCALL
@@ -2796,11 +2819,14 @@ SDL_UpperBlit(SDL2_Surface *src, const SDL_Rect *srcrect, SDL2_Surface *dst, SDL
 
     /* Make sure the surfaces aren't locked */
     if (!src) {
-        return SDL3_InvalidParamError("src");
+        SDL3_InvalidParamError("src");
+        return -1;
     } else if (!dst) {
-        return SDL3_InvalidParamError("dst");
+        SDL3_InvalidParamError("dst");
+        return -1;
     } else if (src->locked || dst->locked) {
-        return SDL3_SetError("Surfaces must not be locked during blit");
+        SDL3_SetError("Surfaces must not be locked during blit");
+        return -1;
     }
 
     /* Full src surface */
@@ -2870,7 +2896,7 @@ SDL_UpperBlit(SDL2_Surface *src, const SDL_Rect *srcrect, SDL2_Surface *dst, SDL
 SDL_DECLSPEC int SDLCALL
 SDL_LowerBlit(SDL2_Surface *src, SDL_Rect *srcrect, SDL2_Surface *dst, SDL_Rect *dstrect)
 {
-    return SDL3_BlitSurfaceUnchecked(Surface2to3(src), srcrect, Surface2to3(dst), dstrect);
+    return SDL3_BlitSurfaceUnchecked(Surface2to3(src), srcrect, Surface2to3(dst), dstrect) ? 0 : -1;
 }
 
 SDL_DECLSPEC int SDLCALL
@@ -2885,10 +2911,12 @@ SDL_UpperBlitScaled(SDL2_Surface *src, const SDL_Rect *srcrect, SDL2_Surface *ds
 
     /* Make sure the surfaces aren't locked */
     if (!src || !dst) {
-        return SDL3_InvalidParamError("SDL_UpperBlitScaled(): src/dst");
+        SDL3_InvalidParamError("SDL_UpperBlitScaled(): src/dst");
+        return -1;
     }
     if (src->locked || dst->locked) {
-        return SDL3_SetError("Surfaces must not be locked during blit");
+        SDL3_SetError("Surfaces must not be locked during blit");
+        return -1;
     }
 
     if (!srcrect) {
@@ -3034,19 +3062,19 @@ SDL_UpperBlitScaled(SDL2_Surface *src, const SDL_Rect *srcrect, SDL2_Surface *ds
 SDL_DECLSPEC int SDLCALL
 SDL_LowerBlitScaled(SDL2_Surface *src, SDL_Rect *srcrect, SDL2_Surface *dst, SDL_Rect *dstrect)
 {
-    return SDL3_BlitSurfaceUncheckedScaled(Surface2to3(src), srcrect, Surface2to3(dst), dstrect, SDL_SCALEMODE_NEAREST);
+    return SDL3_BlitSurfaceUncheckedScaled(Surface2to3(src), srcrect, Surface2to3(dst), dstrect, SDL_SCALEMODE_NEAREST) ? 0 : -1;
 }
 
 SDL_DECLSPEC int SDLCALL
 SDL_SoftStretch(SDL2_Surface *src, const SDL_Rect *srcrect, SDL2_Surface *dst, const SDL_Rect *dstrect)
 {
-    return SDL3_BlitSurfaceScaled(Surface2to3(src), srcrect, Surface2to3(dst), dstrect, SDL_SCALEMODE_NEAREST);
+    return SDL3_BlitSurfaceScaled(Surface2to3(src), srcrect, Surface2to3(dst), dstrect, SDL_SCALEMODE_NEAREST) ? 0 : -1;
 }
 
 SDL_DECLSPEC int SDLCALL
 SDL_SoftStretchLinear(SDL2_Surface *src, const SDL_Rect *srcrect, SDL2_Surface *dst, const SDL_Rect *dstrect)
 {
-    return SDL3_BlitSurfaceScaled(Surface2to3(src), srcrect, Surface2to3(dst), dstrect, SDL_SCALEMODE_LINEAR);
+    return SDL3_BlitSurfaceScaled(Surface2to3(src), srcrect, Surface2to3(dst), dstrect, SDL_SCALEMODE_LINEAR) ? 0 : -1;
 }
 
 /* SDL_GetTicks is 64-bit in SDL3. Clamp it for SDL2. */
@@ -3168,14 +3196,16 @@ SDL_DECLSPEC SDL_bool SDLCALL SDL_GetWindowWMInfo(SDL_Window *window, SDL_SysWMi
 SDL_DECLSPEC int SDLCALL
 SDL_GameControllerGetSensorDataWithTimestamp(SDL_GameController *gamecontroller, SDL_SensorType type, Uint64 *timestamp, float *data, int num_values)
 {
-    return SDL3_Unsupported();  /* !!! FIXME: maybe try to track this from SDL3 events if something needs this? I can't imagine this was widely used. */
+    SDL3_Unsupported();  /* !!! FIXME: maybe try to track this from SDL3 events if something needs this? I can't imagine this was widely used. */
+    return -1;
 }
 
 /* this API was removed in SDL3; use sensor event timestamps instead! */
 SDL_DECLSPEC int SDLCALL
 SDL_SensorGetDataWithTimestamp(SDL_Sensor *sensor, Uint64 *timestamp, float *data, int num_values)
 {
-    return SDL3_Unsupported();  /* !!! FIXME: maybe try to track this from SDL3 events if something needs this? I can't imagine this was widely used. */
+    SDL3_Unsupported();  /* !!! FIXME: maybe try to track this from SDL3 events if something needs this? I can't imagine this was widely used. */
+    return -1;
 }
 
 SDL_DECLSPEC int SDLCALL
@@ -3404,7 +3434,8 @@ SDL_SaveDollarTemplate(SDL2_GestureID gestureId, SDL2_RWops *dst)
             }
         }
     }
-    return SDL3_SetError("Unknown gestureId");
+    SDL3_SetError("Unknown gestureId");
+    return -1;
 }
 
 /* path is an already sampled set of points
@@ -3437,7 +3468,8 @@ GestureAddDollar(GestureTouch *inTouch, SDL_FPoint *path)
     if (inTouch == NULL) {
         int i, idx;
         if (GestureNumTouches == 0) {
-            return SDL3_SetError("no gesture touch devices registered");
+            SDL3_SetError("no gesture touch devices registered");
+            return -1;
         }
         for (i = 0, idx = -1; i < GestureNumTouches; i++) {
             inTouch = &GestureTouches[i];
@@ -3467,7 +3499,8 @@ SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL2_RWops *src)
             }
         }
         if (touch == NULL) {
-            return SDL3_SetError("given touch id not found");
+            SDL3_SetError("given touch id not found");
+            return -1;
         }
     }
 
@@ -3476,7 +3509,8 @@ SDL_LoadDollarTemplates(SDL_TouchID touchId, SDL2_RWops *src)
 
         if (SDL_RWread(src, templ.path, sizeof(templ.path[0]), GESTURE_DOLLARNPOINTS) < GESTURE_DOLLARNPOINTS) {
             if (loaded == 0) {
-                return SDL3_SetError("could not read any dollar gesture from rwops");
+                SDL3_SetError("could not read any dollar gesture from rwops");
+                return -1;
             }
             break;
         }
@@ -3987,12 +4021,12 @@ SDL_SetWindowShape(SDL_Window *window, SDL2_Surface *shape, SDL_WindowShapeMode
 
     SDL_CalculateShapeBitmap(*shape_mode, shape, (Uint32 *)surface->pixels, surface->pitch);
 
-    result = SDL3_SetWindowShape(window, surface);
+    result = SDL3_SetWindowShape(window, surface) ? 0 : -1;
     if (result == 0) {
         SDL_WindowShapeMode *property = (SDL_WindowShapeMode *)SDL3_malloc(sizeof(*property));
         if (property) {
             SDL3_copyp(property, shape_mode);
-            result = SDL3_SetPointerPropertyWithCleanup(SDL3_GetWindowProperties(window), PROP_WINDOW_SHAPE_MODE_POINTER, property, CleanupFreeableProperty, NULL);
+            result = SDL3_SetPointerPropertyWithCleanup(SDL3_GetWindowProperties(window), PROP_WINDOW_SHAPE_MODE_POINTER, property, CleanupFreeableProperty, NULL) ? 0 : -1;
         } else {
             result = -1;
         }
@@ -4249,9 +4283,9 @@ SDL_RenderSetLogicalSize(SDL_Renderer *renderer, int w, int h)
 {
     int retval;
     if (w == 0 && h == 0) {
-        retval = SDL3_SetRenderLogicalPresentation(renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED, SDL_SCALEMODE_NEAREST);
+        retval = SDL3_SetRenderLogicalPresentation(renderer, 0, 0, SDL_LOGICAL_PRESENTATION_DISABLED, SDL_SCALEMODE_NEAREST) ? 0 : -1;
     } else {
-        retval = SDL3_SetRenderLogicalPresentation(renderer, w, h, SDL_LOGICAL_PRESENTATION_LETTERBOX, SDL_SCALEMODE_LINEAR);
+        retval = SDL3_SetRenderLogicalPresentation(renderer, w, h, SDL_LOGICAL_PRESENTATION_LETTERBOX, SDL_SCALEMODE_LINEAR) ? 0 : -1;
     }
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
@@ -4270,7 +4304,7 @@ SDL_RenderSetIntegerScale(SDL_Renderer *renderer, SDL_bool enable)
     int w, h;
     int retval;
 
-    retval = SDL3_GetRenderLogicalPresentation(renderer, &w, &h, &mode, &scale_mode);
+    retval = SDL3_GetRenderLogicalPresentation(renderer, &w, &h, &mode, &scale_mode) ? 0 : -1;
     if (retval < 0) {
         return retval;
     }
@@ -4284,9 +4318,9 @@ SDL_RenderSetIntegerScale(SDL_Renderer *renderer, SDL_bool enable)
     }
 
     if (enable) {
-        retval = SDL3_SetRenderLogicalPresentation(renderer, w, h, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE, scale_mode);
+        retval = SDL3_SetRenderLogicalPresentation(renderer, w, h, SDL_LOGICAL_PRESENTATION_INTEGER_SCALE, scale_mode) ? 0 : -1;
     } else {
-        retval = SDL3_SetRenderLogicalPresentation(renderer, w, h, SDL_LOGICAL_PRESENTATION_DISABLED, scale_mode);
+        retval = SDL3_SetRenderLogicalPresentation(renderer, w, h, SDL_LOGICAL_PRESENTATION_DISABLED, scale_mode) ? 0 : -1;
     }
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
@@ -4295,7 +4329,7 @@ SDL_DECLSPEC SDL_bool SDLCALL
 SDL_RenderGetIntegerScale(SDL_Renderer *renderer)
 {
     SDL_RendererLogicalPresentation mode;
-    if (SDL3_GetRenderLogicalPresentation(renderer, NULL, NULL, &mode, NULL) == 0) {
+    if (SDL3_GetRenderLogicalPresentation(renderer, NULL, NULL, &mode, NULL)) {
         if (mode == SDL_LOGICAL_PRESENTATION_INTEGER_SCALE) {
             return SDL_TRUE;
         }
@@ -4306,21 +4340,21 @@ SDL_RenderGetIntegerScale(SDL_Renderer *renderer)
 SDL_DECLSPEC int SDLCALL
 SDL_RenderSetViewport(SDL_Renderer *renderer, const SDL_Rect *rect)
 {
-    const int retval = SDL3_SetRenderViewport(renderer, rect);
+    const int retval = SDL3_SetRenderViewport(renderer, rect) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
 SDL_DECLSPEC int SDLCALL
 SDL_RenderSetClipRect(SDL_Renderer *renderer, const SDL_Rect *rect)
 {
-    const int retval = SDL3_SetRenderClipRect(renderer, rect);
+    const int retval = SDL3_SetRenderClipRect(renderer, rect) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
 SDL_DECLSPEC int SDLCALL
 SDL_RenderClear(SDL_Renderer *renderer)
 {
-    const int retval = SDL3_RenderClear(renderer);
+    const int retval = SDL3_RenderClear(renderer) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
@@ -4331,14 +4365,14 @@ SDL_RenderDrawPointF(SDL_Renderer *renderer, float x, float y)
     SDL_FPoint fpoint;
     fpoint.x = x;
     fpoint.y = y;
-    retval = SDL3_RenderPoints(renderer, &fpoint, 1);
+    retval = SDL3_RenderPoints(renderer, &fpoint, 1) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
 SDL_DECLSPEC int SDLCALL
 SDL_RenderDrawPoint(SDL_Renderer *renderer, int x, int y)
 {
-    return SDL_RenderDrawPointF(renderer, (float) x, (float) y);
+    return SDL_RenderDrawPointF(renderer, (float) x, (float) y) ? 0 : -1;
 }
 
 SDL_DECLSPEC int SDLCALL
@@ -4350,7 +4384,8 @@ SDL_RenderDrawPoints(SDL_Renderer *renderer,
     int retval;
 
     if (points == NULL) {
-        return SDL3_InvalidParamError("points");
+        SDL3_InvalidParamError("points");
+        return -1;
     }
 
     fpoints = (SDL_FPoint *) SDL3_malloc(sizeof (SDL_FPoint) * count);
@@ -4363,7 +4398,7 @@ SDL_RenderDrawPoints(SDL_Renderer *renderer,
         fpoints[i].y = (float)points[i].y;
     }
 
-    retval = SDL3_RenderPoints(renderer, fpoints, count);
+    retval = SDL3_RenderPoints(renderer, fpoints, count) ? 0 : -1;
 
     SDL3_free(fpoints);
 
@@ -4373,7 +4408,7 @@ SDL_RenderDrawPoints(SDL_Renderer *renderer,
 SDL_DECLSPEC int SDLCALL
 SDL_RenderDrawPointsF(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
 {
-    const int retval = SDL3_RenderPoints(renderer, points, count);
+    const int retval = SDL3_RenderPoints(renderer, points, count) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
@@ -4386,7 +4421,7 @@ SDL_RenderDrawLineF(SDL_Renderer *renderer, float x1, float y1, float x2, float
     points[0].y = (float)y1;
     points[1].x = (float)x2;
     points[1].y = (float)y2;
-    retval = SDL3_RenderLines(renderer, points, 2);
+    retval = SDL3_RenderLines(renderer, points, 2) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
@@ -4404,7 +4439,8 @@ SDL_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count)
     int retval;
 
     if (points == NULL) {
-        return SDL3_InvalidParamError("points");
+        SDL3_InvalidParamError("points");
+        return -1;
     }
     if (count < 2) {
         return 0;
@@ -4420,7 +4456,7 @@ SDL_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count)
         fpoints[i].y = (float)points[i].y;
     }
 
-    retval = SDL3_RenderLines(renderer, fpoints, count);
+    retval = SDL3_RenderLines(renderer, fpoints, count) ? 0 : -1;
 
     SDL3_free(fpoints);
 
@@ -4430,7 +4466,7 @@ SDL_RenderDrawLines(SDL_Renderer *renderer, const SDL_Point *points, int count)
 SDL_DECLSPEC int SDLCALL
 SDL_RenderDrawLinesF(SDL_Renderer *renderer, const SDL_FPoint *points, int count)
 {
-    const int retval = SDL3_RenderLines(renderer, points, count);
+    const int retval = SDL3_RenderLines(renderer, points, count) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
@@ -4449,7 +4485,7 @@ SDL_RenderDrawRect(SDL_Renderer *renderer, const SDL_Rect *rect)
         prect = &frect;
     }
 
-    retval = SDL3_RenderRect(renderer, prect);
+    retval = SDL3_RenderRect(renderer, prect) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
@@ -4459,7 +4495,8 @@ SDL_RenderDrawRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count)
     int i;
 
     if (rects == NULL) {
-        return SDL3_InvalidParamError("rects");
+        SDL3_InvalidParamError("rects");
+        return -1;
     }
     if (count < 1) {
         return 0;
@@ -4476,14 +4513,14 @@ SDL_RenderDrawRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count)
 SDL_DECLSPEC int SDLCALL
 SDL_RenderDrawRectF(SDL_Renderer *renderer, const SDL_FRect *rect)
 {
-    const int retval = SDL3_RenderRect(renderer, rect);
+    const int retval = SDL3_RenderRect(renderer, rect) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
 SDL_DECLSPEC int SDLCALL
 SDL_RenderDrawRectsF(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
 {
-    const int retval = SDL3_RenderRects(renderer, rects, count);
+    const int retval = SDL3_RenderRects(renderer, rects, count) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
@@ -4497,9 +4534,9 @@ SDL_RenderFillRect(SDL_Renderer *renderer, const SDL_Rect *rect)
         frect.y = (float)rect->y;
         frect.w = (float)rect->w;
         frect.h = (float)rect->h;
-        return SDL3_RenderFillRect(renderer, &frect);
+        return SDL3_RenderFillRect(renderer, &frect) ? 0 : -1;
     }
-    retval = SDL3_RenderFillRect(renderer, NULL);
+    retval = SDL3_RenderFillRect(renderer, NULL) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
@@ -4511,7 +4548,8 @@ SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count)
     int retval;
 
     if (rects == NULL) {
-        return SDL3_InvalidParamError("rects");
+        SDL3_InvalidParamError("rects");
+        return -1;
     }
     if (count < 1) {
         return 0;
@@ -4529,7 +4567,7 @@ SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count)
         frects[i].h = (float)rects[i].h;
     }
 
-    retval = SDL3_RenderFillRects(renderer, frects, count);
+    retval = SDL3_RenderFillRects(renderer, frects, count) ? 0 : -1;
 
     SDL3_free(frects);
 
@@ -4539,14 +4577,14 @@ SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count)
 SDL_DECLSPEC int SDLCALL
 SDL_RenderFillRectF(SDL_Renderer *renderer, const SDL_FRect *rect)
 {
-    const int retval = SDL3_RenderFillRect(renderer, rect);
+    const int retval = SDL3_RenderFillRect(renderer, rect) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
 SDL_DECLSPEC int SDLCALL
 SDL_RenderFillRectsF(SDL_Renderer *renderer, const SDL_FRect *rects, int count)
 {
-    const int retval = SDL3_RenderFillRects(renderer, rects, count);
+    const int retval = SDL3_RenderFillRects(renderer, rects, count) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
@@ -4572,7 +4610,7 @@ SDL_RenderCopy(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *src
         dstfrect.h = (float)dstrect->h;
         pdstfrect = &dstfrect;
     }
-    retval = SDL3_RenderTexture(renderer, texture, psrcfrect, pdstfrect);
+    retval = SDL3_RenderTexture(renderer, texture, psrcfrect, pdstfrect) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
@@ -4589,7 +4627,7 @@ SDL_RenderCopyF(SDL_Renderer *renderer, SDL_Texture *texture, const SDL_Rect *sr
         srcfrect.h = (float)srcrect->h;
         psrcfrect = &srcfrect;
     }
-    retval = SDL3_RenderTexture(renderer, texture, psrcfrect, dstrect);
+    retval = SDL3_RenderTexture(renderer, texture, psrcfrect, dstrect) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
@@ -4628,7 +4666,7 @@ SDL_RenderCopyEx(SDL_Renderer *renderer, SDL_Texture *texture,
         pfcenter = &fcenter;
     }
 
-    retval = SDL3_RenderTextureRotated(renderer, texture, psrcfrect, pdstfrect, angle, pfcenter, flip);
+    retval = SDL3_RenderTextureRotated(renderer, texture, psrcfrect, pdstfrect, angle, pfcenter, flip) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
@@ -4649,7 +4687,7 @@ SDL_RenderCopyExF(SDL_Renderer *renderer, SDL_Texture *texture,
         psrcfrect = &srcfrect;
     }
 
-    retval = SDL3_RenderTextureRotated(renderer, texture, psrcfrect, dstrect, angle, center, flip);
+    retval = SDL3_RenderTextureRotated(renderer, texture, psrcfrect, dstrect, angle, center, flip) ? 0 : -1;
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
 
@@ -4666,7 +4704,8 @@ SDL_RenderGeometry(SDL_Renderer *renderer, SDL_Texture *texture, const SDL2_Vert
         int size_indices = 4;
         return SDL_RenderGeometryRaw(renderer, texture, xy, xy_stride, color, color_stride, uv, uv_stride, num_vertices, indices, num_indices, size_indices);
     }
-    return SDL3_InvalidParamError("vertices");
+    SDL3_InvalidParamError("vertices");
+    return -1;
 }
 
 SDL_DECLSPEC int SDLCALL
@@ -4677,15 +4716,18 @@ SDL_RenderGeometryRaw(SDL_Renderer *renderer, SDL_Texture *texture, const float
     SDL_FColor *color3;
 
     if (num_vertices <= 0) {
-        return SDL3_InvalidParamError("num_vertices");
+        SDL3_InvalidParamError("num_vertices");
+        return -1;
     }
     if (!color) {
-        return SDL3_InvalidParamError("color");
+        SDL3_InvalidParamError("color");
+        return -1;
     }
 
     color3 = (SDL_FColor *) SDL3_small_alloc(SDL_FColor, num_vertices, &isstack);
     if (!color3) {
-        return SDL3_OutOfMemory();
+        SDL3_OutOfMemory();
+        return -1;
     }
     for (i = 0; i < num_vertices; ++i) {
         color3[i].r = color->r / 255.0f;
@@ -4697,7 +4739,7 @@ SDL_RenderGeometryRaw(SDL_Renderer *renderer, SDL_Texture *texture, const float
     }
 
     color_stride = sizeof(SDL_FColor);
-    retval = SDL3_RenderGeometryRaw(renderer, texture, xy, xy_stride, color3, color_stride, uv, uv_stride, num_vertices, indices, num_indices, size_indices);
+    retval = SDL3_RenderGeometryRaw(renderer, texture, xy, xy_stride, color3, color_stride, uv, uv_stride, num_vertices, indices, num_indices, size_indices) ? 0 : -1;
     SDL3_small_free(color3, isstack);
     return retval < 0 ? retval : FlushRendererIfNotBatching(renderer);
 }
@@ -4712,7 +4754,7 @@ SDL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 form
         return -1;
     }
 
-    if (SDL3_ConvertPixelsAndColorspace(surface->w, surface->h, surface->format, SDL3_GetSurfaceColorspace(surface), SDL3_GetSurfaceProperties(surface), surface->pixels, surface->pitch, (SDL_PixelFormat)format, SDL_COLORSPACE_SRGB, 0, pixels, pitch) == 0) {
+    if (SDL3_ConvertPixelsAndColorspace(surface->w, surface->h, surface->format, SDL3_GetSurfaceColorspace(surface), SDL3_GetSurfaceProperties(surface), surface->pixels, surface->pitch, (SDL_PixelFormat)format, SDL_COLORSPACE_SRGB, 0, pixels, pitch)) {
         result = 0;
     }
 
@@ -4793,6 +4835,16 @@ SDL_LockMutex(SDL_Mutex *a)
     return 0;
 }
 
+SDL_DECLSPEC int SDLCALL
+SDL_TryLockMutex(SDL_Mutex *a)
+{
+    if (SDL3_TryLockMutex(a)) {
+        return 0;
+    } else {
+        return SDL2_MUTEX_TIMEDOUT;
+    }
+}
+
 SDL_DECLSPEC int SDLCALL
 SDL_UnlockMutex(SDL_Mutex *a)
 {
@@ -4860,11 +4912,7 @@ SDL_RemoveTimer(SDL2_TimerID id)
     SDL3_snprintf(name, sizeof(name), "%" SDL_PRIu32, id);
     SDL3_ClearProperty(timers, name);
 
-    if (SDL3_RemoveTimer((SDL_TimerID)id) == 0) {
-        return SDL_TRUE;
-    } else {
-        return SDL_FALSE;
-    }
+    return SDL3_RemoveTimer((SDL_TimerID)id);
 }
 
 
@@ -4874,7 +4922,7 @@ SDL_AudioInit(const char *driver_name)
     if (driver_name) {
         SDL3_SetHint("SDL_AUDIO_DRIVER", driver_name);
     }
-    return SDL3_InitSubSystem(SDL_INIT_AUDIO);
+    return SDL3_InitSubSystem(SDL_INIT_AUDIO) ? 0 : -1;
 }
 
 SDL_DECLSPEC void SDLCAL

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