sdl2-compat: several type / prototype fixes for SDL3 functions,

From ae4b84a76b1ca651f5213c2591740eb496926fda Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Fri, 3 Feb 2023 20:56:28 +0300
Subject: [PATCH] several type / prototype fixes for SDL3 functions,

along with a few minor style clean-ups.
---
 src/sdl2_compat.c          | 53 ++++++++++++++++++++------------------
 src/sdl3_include_wrapper.h |  1 +
 src/sdl3_syms.h            | 17 +++++++-----
 3 files changed, 39 insertions(+), 32 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index f24d100..5ef7c67 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -3348,9 +3348,9 @@ SDL_GetNumDisplayModes(int displayIndex)
 {
     SDL_DisplayID displayID = Display_IndexToID(displayIndex);
     int count = 0;
-    SDL_DisplayMode **list;
+    const SDL_DisplayMode **list;
     list = SDL3_GetFullscreenDisplayModes(displayID, &count);
-    SDL_free(list);
+    SDL_free((void *)list);
     return count;
 }
 
@@ -3379,7 +3379,7 @@ DECLSPEC int SDLCALL
 SDL_GetDisplayMode(int displayIndex, int modeIndex, SDL2_DisplayMode *mode)
 {
     SDL_DisplayID displayID = Display_IndexToID(displayIndex);
-    SDL_DisplayMode **list;
+    const SDL_DisplayMode **list;
     int count = 0;
     int ret = -1;
     list = SDL3_GetFullscreenDisplayModes(displayID, &count);
@@ -3389,14 +3389,14 @@ SDL_GetDisplayMode(int displayIndex, int modeIndex, SDL2_DisplayMode *mode)
         }
         ret = 0;
     }
-    SDL_free(list);
+    SDL_free((void *)list);
     return ret;
 }
 
 DECLSPEC int SDLCALL
 SDL_GetCurrentDisplayMode(int displayIndex, SDL2_DisplayMode *mode)
 {
-    SDL_DisplayMode *dp = SDL3_GetCurrentDisplayMode(Display_IndexToID(displayIndex));
+    const SDL_DisplayMode *dp = SDL3_GetCurrentDisplayMode(Display_IndexToID(displayIndex));
     if (dp == NULL) {
         return -1;
     }
@@ -3409,7 +3409,7 @@ SDL_GetCurrentDisplayMode(int displayIndex, SDL2_DisplayMode *mode)
 DECLSPEC int SDLCALL
 SDL_GetDesktopDisplayMode(int displayIndex, SDL2_DisplayMode *mode)
 {
-    SDL_DisplayMode *dp = SDL3_GetDesktopDisplayMode(Display_IndexToID(displayIndex));
+    const SDL_DisplayMode *dp = SDL3_GetDesktopDisplayMode(Display_IndexToID(displayIndex));
     if (dp == NULL) {
         return -1;
     }
@@ -3423,10 +3423,10 @@ DECLSPEC int SDLCALL
 SDL_GetWindowDisplayMode(SDL_Window *window, SDL2_DisplayMode *mode)
 {
     /* returns a pointer to the fullscreen mode to use or NULL for desktop mode */
-    SDL_DisplayMode *dp = SDL3_GetWindowFullscreenMode(window);
+    const SDL_DisplayMode *dp = SDL3_GetWindowFullscreenMode(window);
     if (dp == NULL) {
         /* Desktop mode */
-        // FIXME: is this correct ?
+        /* FIXME: is this correct ? */
         dp = SDL3_GetDesktopDisplayMode(SDL3_GetPrimaryDisplay());
         if (dp == NULL) {
             return -1;
@@ -3438,7 +3438,8 @@ SDL_GetWindowDisplayMode(SDL_Window *window, SDL2_DisplayMode *mode)
     return 0;
 }
 
-static void SDL_FinalizeDisplayMode(SDL_DisplayMode *mode)
+static void
+SDL_FinalizeDisplayMode(SDL_DisplayMode *mode)
 {
     /* Make sure all the fields are set up correctly */
     if (mode->display_scale <= 0.0f) {
@@ -3472,17 +3473,17 @@ static void SDL_FinalizeDisplayMode(SDL_DisplayMode *mode)
     }
 }
 
-static SDL_DisplayMode *SDL_GetClosestDisplayModeForDisplay(/* SDL_VideoDisplay *display, */
-                                                            SDL_DisplayID displayID,
-                                                            const SDL_DisplayMode *mode,
-                                                            SDL_DisplayMode *closest)
+static SDL_DisplayMode *
+SDL_GetClosestDisplayModeForDisplay(SDL_DisplayID displayID,
+                                    const SDL_DisplayMode *mode,
+                                    SDL_DisplayMode *closest)
 {
     Uint32 target_format;
     float target_refresh_rate;
     int i;
     SDL_DisplayMode requested_mode;
-    SDL_DisplayMode *current, *match;
-    SDL_DisplayMode **list;
+    const SDL_DisplayMode *current, *match;
+    const SDL_DisplayMode **list;
     int count = 0;
 
     /* Make sure all the fields are filled out in the requested mode */
@@ -3494,8 +3495,8 @@ static SDL_DisplayMode *SDL_GetClosestDisplayModeForDisplay(/* SDL_VideoDisplay
     if (mode->format) {
         target_format = mode->format;
     } else {
-// FIXME: Desktop mode ?
-//        target_format = display->desktop_mode.format;
+/* FIXME: Desktop mode ?
+        target_format = display->desktop_mode.format;*/
         target_format = mode->format;
     }
 
@@ -3503,8 +3504,8 @@ static SDL_DisplayMode *SDL_GetClosestDisplayModeForDisplay(/* SDL_VideoDisplay
     if (mode->refresh_rate > 0.0f) {
         target_refresh_rate = mode->refresh_rate;
     } else {
-// FIXME: Desktop mode ?
-//        target_refresh_rate = display->desktop_mode.refresh_rate;
+/* FIXME: Desktop mode ?
+        target_refresh_rate = display->desktop_mode.refresh_rate;*/
         target_refresh_rate = mode->refresh_rate;
     }
 
@@ -3593,7 +3594,7 @@ static SDL_DisplayMode *SDL_GetClosestDisplayModeForDisplay(/* SDL_VideoDisplay
         SDL_free(list);
         return closest;
     }
-    SDL_free(list);
+    SDL_free((void *)list);
     return NULL;
 }
 
@@ -3633,15 +3634,15 @@ SDL_SetWindowDisplayMode(SDL_Window *window, const SDL2_DisplayMode *mode)
         return 0;
     } else {
         int count = 0;
-        SDL_DisplayMode **list;
+        const SDL_DisplayMode **list;
         int ret = -1;
 
-        // FIXME: at least set a valid fullscreen mode
+        /* FIXME: at least set a valid fullscreen mode */
         list = SDL3_GetFullscreenDisplayModes(SDL3_GetPrimaryDisplay(), &count);
         if (list && count) {
             ret = SDL3_SetWindowFullscreenMode(window, list[0]);
         }
-        SDL_free(list);
+        SDL_free((void *)list);
         return ret;
     }
 }
@@ -3941,8 +3942,10 @@ SDL_FreeWAV(Uint8 *audio_buf)
     SDL3_free(audio_buf);
 }
 
-/* SDL_WINDOW_FULLSCREEN_DESKTOP has been removed, and you can call SDL_GetWindowFullscreenMode() to see whether an exclusive fullscreen mode will be used or the fullscreen desktop mode will be used when the window is fullscreen.
-*/
+/* SDL_WINDOW_FULLSCREEN_DESKTOP has been removed, and you can call
+ * SDL_GetWindowFullscreenMode() to see whether an exclusive fullscreen
+ * mode will be used or the fullscreen desktop mode will be used when
+ * the window is fullscreen. */
 /* SDL3 removed SDL_WINDOW_SHOWN as redundant to SDL_WINDOW_HIDDEN. */
 DECLSPEC Uint32 SDLCALL
 SDL_GetWindowFlags(SDL_Window *window)
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index e2b7571..d45c89d 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -875,6 +875,7 @@
 #define SDL_PASSED_BEGINTHREAD_ENDTHREAD
 #endif
 
+#define SDL_FUNCTION_POINTER_IS_VOID_POINTER 1
 #define SDL_DISABLE_OLD_NAMES 1
 #define __BUILDING_SDL2_COMPAT__ 1
 #include <SDL3/SDL.h>
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index 61b4464..e7a8cbd 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -455,7 +455,7 @@ SDL3_SYM_RENAMED(int,LowerBlit,BlitSurfaceUnchecked,(SDL_Surface *a, SDL_Rect *b
 SDL3_SYM_PASSTHROUGH(int,SoftStretch,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, const SDL_Rect *d),(a,b,c,d),return)
 SDL3_SYM_RENAMED(int,UpperBlitScaled,BlitSurfaceScaled,(SDL_Surface *a, const SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
 SDL3_SYM_RENAMED(int,LowerBlitScaled,BlitSurfaceUncheckedScaled,(SDL_Surface *a, SDL_Rect *b, SDL_Surface *c, SDL_Rect *d),(a,b,c,d),return)
-SDL3_SYM(SDL_bool,GetWindowWMInfo,(SDL_Window *a, SDL_SysWMinfo *b),(a,b),return)
+SDL3_SYM(int,GetWindowWMInfo,(SDL_Window *a, SDL_SysWMinfo *b, Uint32 c),(a,b,c),return)
 SDL3_SYM_PASSTHROUGH(const char*,GetThreadName,(SDL_Thread *a),(a),return)
 SDL3_SYM_PASSTHROUGH(SDL_threadID,ThreadID,(void),(),return)
 SDL3_SYM_PASSTHROUGH(SDL_threadID,GetThreadID,(SDL_Thread *a),(a),return)
@@ -482,8 +482,8 @@ SDL3_SYM_PASSTHROUGH(const char*,GetVideoDriver,(int a),(a),return)
 SDL3_SYM_PASSTHROUGH(const char*,GetCurrentVideoDriver,(void),(),return)
 SDL3_SYM(const char*,GetDisplayName,(SDL_DisplayID a),(a),return)
 SDL3_SYM(int,GetDisplayBounds,(SDL_DisplayID a, SDL_Rect *b),(a,b),return)
-SDL3_SYM(SDL_DisplayMode*,GetDesktopDisplayMode,(SDL_DisplayID a),(a),return)
-SDL3_SYM(SDL_DisplayMode*,GetCurrentDisplayMode,(SDL_DisplayID a),(a),return)
+SDL3_SYM(const SDL_DisplayMode*,GetDesktopDisplayMode,(SDL_DisplayID a),(a),return)
+SDL3_SYM(const SDL_DisplayMode*,GetCurrentDisplayMode,(SDL_DisplayID a),(a),return)
 SDL3_SYM(int,SetWindowFullscreenMode,(SDL_Window *a, const SDL_DisplayMode *b),(a,b),return)
 SDL3_SYM_PASSTHROUGH(Uint32,GetWindowPixelFormat,(SDL_Window *a),(a),return)
 SDL3_SYM(SDL_Window*,CreateWindow,(const char *a, int b, int c, int d, int e, Uint32 f),(a,b,c,d,e,f),return)
@@ -722,8 +722,12 @@ SDL3_SYM_PASSTHROUGH(int,GetAndroidSDKVersion,(void),(),return)
 #endif
 SDL3_SYM_PASSTHROUGH(int,isupper,(int a),(a),return)
 SDL3_SYM_PASSTHROUGH(int,islower,(int a),(a),return)
+
+/* FIXME: the following three are wrong and can't be passthrough. */
 SDL3_SYM_RENAMED(int,JoystickAttachVirtual,AttachVirtualJoystick,(SDL_JoystickType a, int b, int c, int d),(a,b,c,d),return)
 SDL3_SYM_RENAMED(int,JoystickDetachVirtual,DetachVirtualJoystick,(int a),(a),return)
+SDL3_SYM_RENAMED(int,JoystickAttachVirtualEx,AttachVirtualJoystickEx,(const SDL_VirtualJoystickDesc *a),(a),return)
+
 SDL3_SYM_RENAMED(int,JoystickSetVirtualAxis,SetJoystickVirtualAxis,(SDL_Joystick *a, int b, Sint16 c),(a,b,c),return)
 SDL3_SYM_RENAMED(int,JoystickSetVirtualButton,SetJoystickVirtualButton,(SDL_Joystick *a, int b, Uint8 c),(a,b,c),return)
 SDL3_SYM_RENAMED(int,JoystickSetVirtualHat,SetJoystickVirtualHat,(SDL_Joystick *a, int b, Uint8 c),(a,b,c),return)
@@ -844,7 +848,6 @@ SDL3_SYM_RENAMED(SDL_Window*,RenderGetWindow,GetRenderWindow,(SDL_Renderer *a),(
 SDL3_SYM_PASSTHROUGH(void*,bsearch,(const void *a, const void *b, size_t c, size_t d, int (SDLCALL *e)(const void *, const void *)),(a,b,c,d,e),return)
 SDL3_SYM_RENAMED(const char*,GameControllerPath,GetGamepadPath,(SDL_GameController *a),(a),return)
 SDL3_SYM_RENAMED(const char*,JoystickPath,GetJoystickPath,(SDL_Joystick *a),(a),return)
-SDL3_SYM_RENAMED(int,JoystickAttachVirtualEx,AttachVirtualJoystickEx,(const SDL_VirtualJoystickDesc *a),(a),return)
 SDL3_SYM_RENAMED(Uint16,GameControllerGetFirmwareVersion,GetGamepadFirmwareVersion,(SDL_GameController *a),(a),return)
 SDL3_SYM_RENAMED(Uint16,JoystickGetFirmwareVersion,GetJoystickFirmwareVersion,(SDL_Joystick *a),(a),return)
 SDL3_SYM_PASSTHROUGH(void,GUIDToString,(SDL_GUID a, char *b, int c),(a,b,c),)
@@ -910,9 +913,9 @@ SDL3_SYM(SDL_DisplayID,GetDisplayForWindow,(SDL_Window *a),(a),return)
 SDL3_SYM(SDL_DisplayID,GetDisplayForPoint,(const SDL_Point *a),(a),return)
 SDL3_SYM(SDL_DisplayID,GetDisplayForRect,(const SDL_Rect *a),(a),return)
 SDL3_SYM(SDL_DisplayID,GetPrimaryDisplay,(),(),return)
-SDL3_SYM(int,RunApp,(int a, char *b, SDL_main_func c, void *d),(a,b,c,d),return)
-SDL3_SYM(SDL_DisplayMode *,GetWindowFullscreenMode,(SDL_Window *a),(a),return)
-SDL3_SYM(SDL_DisplayMode **,GetFullscreenDisplayModes,(SDL_DisplayID a, int *b),(a,b),return)
+SDL3_SYM(int,RunApp,(int a, char **b, SDL_main_func c, void *d),(a,b,c,d),return)
+SDL3_SYM(const SDL_DisplayMode *,GetWindowFullscreenMode,(SDL_Window *a),(a),return)
+SDL3_SYM(const SDL_DisplayMode **,GetFullscreenDisplayModes,(SDL_DisplayID a, int *b),(a,b),return)
 
 #undef SDL3_SYM
 #undef SDL3_SYM_PASSTHROUGH