sdl2-compat: Updated for latest SDL changes as of bc9780299c02e80eb0bfdb528367ed3a09fe948c

From cbc8bd0c4747920a62078c424fb03242422b2391 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Tue, 17 Sep 2024 20:10:00 +0300
Subject: [PATCH] Updated for latest SDL changes as of
 bc9780299c02e80eb0bfdb528367ed3a09fe948c

---
 src/sdl2_compat.c          | 16 ++++---
 src/sdl2_compat.h          |  2 +
 src/sdl3_include_wrapper.h | 85 ++++++++++++++++++++++----------------
 src/sdl3_syms.h            | 14 +++----
 4 files changed, 66 insertions(+), 51 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 5fec75a..78cc99e 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -157,8 +157,8 @@ extern "C" {
 
 
 /* these are macros (etc) in the SDL headers, so make our own. */
-#define SDL3_AtomicIncRef(a)  SDL3_AtomicAdd(a, 1)
-#define SDL3_AtomicDecRef(a) (SDL3_AtomicAdd(a,-1) == 1)
+#define SDL3_AtomicIncRef(a)  SDL3_AddAtomicInt(a, 1)
+#define SDL3_AtomicDecRef(a) (SDL3_AddAtomicInt(a,-1) == 1)
 #define SDL3_Unsupported()            SDL3_SetError("That operation is not supported")
 #define SDL3_InvalidParamError(param) SDL3_SetError("Parameter '%s' is invalid", (param))
 #define SDL3_zero(x) SDL3_memset(&(x), 0, sizeof((x)))
@@ -9516,32 +9516,30 @@ SDL_AndroidGetExternalStorageState(void)
     return (int)SDL3_GetAndroidExternalStorageState();
 }
 
-static void SDLCALL AndroidRequestPermissionBlockingCallback(void *userdata, const char *permission, SDL2_bool granted)
+static void SDLCALL AndroidRequestPermissionBlockingCallback(void *userdata, const char *permission, SDL_bool granted)
 {
-    SDL3_AtomicSet((SDL_AtomicInt *) userdata, granted ? 1 : -1);
+    SDL3_SetAtomicInt((SDL_AtomicInt *) userdata, granted ? 1 : -1);
 }
 
 SDL_DECLSPEC SDL2_bool SDLCALL
 SDL_AndroidRequestPermission(const char *permission)
 {
     SDL_AtomicInt response;
-    SDL3_AtomicSet(&response, 0);
+    SDL3_SetAtomicInt(&response, 0);
 
     if (!SDL3_RequestAndroidPermission(permission, AndroidRequestPermissionBlockingCallback, &response)) {
         return SDL2_FALSE;
     }
 
     /* Wait for the request to complete */
-    while (SDL3_AtomicGet(&response) == 0) {
+    while (SDL3_GetAtomicInt(&response) == 0) {
         SDL3_Delay(10);
     }
 
-    return (SDL3_AtomicGet(&response) < 0) ? SDL2_FALSE : SDL2_TRUE;
+    return (SDL3_GetAtomicInt(&response) < 0) ? SDL2_FALSE : SDL2_TRUE;
 }
 #endif
 
 #ifdef __cplusplus
 }
 #endif
-
-/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/sdl2_compat.h b/src/sdl2_compat.h
index 9094f9d..3263432 100644
--- a/src/sdl2_compat.h
+++ b/src/sdl2_compat.h
@@ -24,6 +24,8 @@
 
 #include <SDL3/SDL_begin_code.h> /* for correct structure alignment, just in case */
 
+/* #define SDL_INIT_TIMER 0x00000001u */ /* removed in SDL3. not used here. */
+
 #ifdef __CC_ARM
 /* ARM's compiler throws warnings if we use an enum: like "SDL2_bool x = a < b;" */
 #define SDL2_FALSE 0
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index b14f06c..11bb400 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -37,6 +37,7 @@
 #define SDL_AcquireCameraFrame IGNORE_THIS_VERSION_OF_SDL_AcquireCameraFrame
 #define SDL_AcquireGPUCommandBuffer IGNORE_THIS_VERSION_OF_SDL_AcquireGPUCommandBuffer
 #define SDL_AcquireGPUSwapchainTexture IGNORE_THIS_VERSION_OF_SDL_AcquireGPUSwapchainTexture
+#define SDL_AddAtomicInt IGNORE_THIS_VERSION_OF_SDL_AddAtomicInt
 #define SDL_AddEventWatch IGNORE_THIS_VERSION_OF_SDL_AddEventWatch
 #define SDL_AddGamepadMapping IGNORE_THIS_VERSION_OF_SDL_AddGamepadMapping
 #define SDL_AddGamepadMappingsFromFile IGNORE_THIS_VERSION_OF_SDL_AddGamepadMappingsFromFile
@@ -46,13 +47,6 @@
 #define SDL_AddTimer IGNORE_THIS_VERSION_OF_SDL_AddTimer
 #define SDL_AddTimerNS IGNORE_THIS_VERSION_OF_SDL_AddTimerNS
 #define SDL_AddVulkanRenderSemaphores IGNORE_THIS_VERSION_OF_SDL_AddVulkanRenderSemaphores
-#define SDL_AtomicAdd IGNORE_THIS_VERSION_OF_SDL_AtomicAdd
-#define SDL_AtomicCompareAndSwap IGNORE_THIS_VERSION_OF_SDL_AtomicCompareAndSwap
-#define SDL_AtomicCompareAndSwapPointer IGNORE_THIS_VERSION_OF_SDL_AtomicCompareAndSwapPointer
-#define SDL_AtomicGet IGNORE_THIS_VERSION_OF_SDL_AtomicGet
-#define SDL_AtomicGetPointer IGNORE_THIS_VERSION_OF_SDL_AtomicGetPointer
-#define SDL_AtomicSet IGNORE_THIS_VERSION_OF_SDL_AtomicSet
-#define SDL_AtomicSetPointer IGNORE_THIS_VERSION_OF_SDL_AtomicSetPointer
 #define SDL_AttachVirtualJoystick IGNORE_THIS_VERSION_OF_SDL_AttachVirtualJoystick
 #define SDL_AudioDevicePaused IGNORE_THIS_VERSION_OF_SDL_AudioDevicePaused
 #define SDL_BeginGPUComputePass IGNORE_THIS_VERSION_OF_SDL_BeginGPUComputePass
@@ -99,6 +93,9 @@
 #define SDL_CloseJoystick IGNORE_THIS_VERSION_OF_SDL_CloseJoystick
 #define SDL_CloseSensor IGNORE_THIS_VERSION_OF_SDL_CloseSensor
 #define SDL_CloseStorage IGNORE_THIS_VERSION_OF_SDL_CloseStorage
+#define SDL_CompareAndSwapAtomicInt IGNORE_THIS_VERSION_OF_SDL_CompareAndSwapAtomicInt
+#define SDL_CompareAndSwapAtomicPointer IGNORE_THIS_VERSION_OF_SDL_CompareAndSwapAtomicPointer
+#define SDL_CompareAndSwapAtomicU32 IGNORE_THIS_VERSION_OF_SDL_CompareAndSwapAtomicU32
 #define SDL_ComposeCustomBlendMode IGNORE_THIS_VERSION_OF_SDL_ComposeCustomBlendMode
 #define SDL_ConvertAudioSamples IGNORE_THIS_VERSION_OF_SDL_ConvertAudioSamples
 #define SDL_ConvertEventToRenderCoordinates IGNORE_THIS_VERSION_OF_SDL_ConvertEventToRenderCoordinates
@@ -249,6 +246,9 @@
 #define SDL_GetAppMetadataProperty IGNORE_THIS_VERSION_OF_SDL_GetAppMetadataProperty
 #define SDL_GetAssertionHandler IGNORE_THIS_VERSION_OF_SDL_GetAssertionHandler
 #define SDL_GetAssertionReport IGNORE_THIS_VERSION_OF_SDL_GetAssertionReport
+#define SDL_GetAtomicInt IGNORE_THIS_VERSION_OF_SDL_GetAtomicInt
+#define SDL_GetAtomicPointer IGNORE_THIS_VERSION_OF_SDL_GetAtomicPointer
+#define SDL_GetAtomicU32 IGNORE_THIS_VERSION_OF_SDL_GetAtomicU32
 #define SDL_GetAudioDeviceChannelMap IGNORE_THIS_VERSION_OF_SDL_GetAudioDeviceChannelMap
 #define SDL_GetAudioDeviceFormat IGNORE_THIS_VERSION_OF_SDL_GetAudioDeviceFormat
 #define SDL_GetAudioDeviceGain IGNORE_THIS_VERSION_OF_SDL_GetAudioDeviceGain
@@ -812,6 +812,9 @@
 #define SDL_SetAppMetadata IGNORE_THIS_VERSION_OF_SDL_SetAppMetadata
 #define SDL_SetAppMetadataProperty IGNORE_THIS_VERSION_OF_SDL_SetAppMetadataProperty
 #define SDL_SetAssertionHandler IGNORE_THIS_VERSION_OF_SDL_SetAssertionHandler
+#define SDL_SetAtomicInt IGNORE_THIS_VERSION_OF_SDL_SetAtomicInt
+#define SDL_SetAtomicPointer IGNORE_THIS_VERSION_OF_SDL_SetAtomicPointer
+#define SDL_SetAtomicU32 IGNORE_THIS_VERSION_OF_SDL_SetAtomicU32
 #define SDL_SetAudioDeviceGain IGNORE_THIS_VERSION_OF_SDL_SetAudioDeviceGain
 #define SDL_SetAudioPostmixCallback IGNORE_THIS_VERSION_OF_SDL_SetAudioPostmixCallback
 #define SDL_SetAudioStreamFormat IGNORE_THIS_VERSION_OF_SDL_SetAudioStreamFormat
@@ -1240,6 +1243,10 @@
 #undef SDL_AcquireGPUSwapchainTexture
 #endif
 
+#ifdef SDL_AddAtomicInt
+#undef SDL_AddAtomicInt
+#endif
+
 #ifdef SDL_AddEventWatch
 #undef SDL_AddEventWatch
 #endif
@@ -1276,34 +1283,6 @@
 #undef SDL_AddVulkanRenderSemaphores
 #endif
 
-#ifdef SDL_AtomicAdd
-#undef SDL_AtomicAdd
-#endif
-
-#ifdef SDL_AtomicCompareAndSwap
-#undef SDL_AtomicCompareAndSwap
-#endif
-
-#ifdef SDL_AtomicCompareAndSwapPointer
-#undef SDL_AtomicCompareAndSwapPointer
-#endif
-
-#ifdef SDL_AtomicGet
-#undef SDL_AtomicGet
-#endif
-
-#ifdef SDL_AtomicGetPointer
-#undef SDL_AtomicGetPointer
-#endif
-
-#ifdef SDL_AtomicSet
-#undef SDL_AtomicSet
-#endif
-
-#ifdef SDL_AtomicSetPointer
-#undef SDL_AtomicSetPointer
-#endif
-
 #ifdef SDL_AttachVirtualJoystick
 #undef SDL_AttachVirtualJoystick
 #endif
@@ -1488,6 +1467,18 @@
 #undef SDL_CloseStorage
 #endif
 
+#ifdef SDL_CompareAndSwapAtomicInt
+#undef SDL_CompareAndSwapAtomicInt
+#endif
+
+#ifdef SDL_CompareAndSwapAtomicPointer
+#undef SDL_CompareAndSwapAtomicPointer
+#endif
+
+#ifdef SDL_CompareAndSwapAtomicU32
+#undef SDL_CompareAndSwapAtomicU32
+#endif
+
 #ifdef SDL_ComposeCustomBlendMode
 #undef SDL_ComposeCustomBlendMode
 #endif
@@ -2088,6 +2079,18 @@
 #undef SDL_GetAssertionReport
 #endif
 
+#ifdef SDL_GetAtomicInt
+#undef SDL_GetAtomicInt
+#endif
+
+#ifdef SDL_GetAtomicPointer
+#undef SDL_GetAtomicPointer
+#endif
+
+#ifdef SDL_GetAtomicU32
+#undef SDL_GetAtomicU32
+#endif
+
 #ifdef SDL_GetAudioDeviceChannelMap
 #undef SDL_GetAudioDeviceChannelMap
 #endif
@@ -4340,6 +4343,18 @@
 #undef SDL_SetAssertionHandler
 #endif
 
+#ifdef SDL_SetAtomicInt
+#undef SDL_SetAtomicInt
+#endif
+
+#ifdef SDL_SetAtomicPointer
+#undef SDL_SetAtomicPointer
+#endif
+
+#ifdef SDL_SetAtomicU32
+#undef SDL_SetAtomicU32
+#endif
+
 #ifdef SDL_SetAudioDeviceGain
 #undef SDL_SetAudioDeviceGain
 #endif
diff --git a/src/sdl3_syms.h b/src/sdl3_syms.h
index ae18086..5bea371 100644
--- a/src/sdl3_syms.h
+++ b/src/sdl3_syms.h
@@ -106,14 +106,14 @@ SDL3_SYM(int,AddGamepadMappingsFromIO,(SDL_IOStream *a, SDL_bool b),(a,b),return
 SDL3_SYM(SDL_bool,AddHintCallback,(const char *a, SDL_HintCallback b, void *c),(a,b,c),)
 SDL3_SYM(SDL_TimerID,AddTimer,(Uint32 a, SDL_TimerCallback b, void *c),(a,b,c),return)
 SDL3_SYM_RENAMED(SDL_Palette*,AllocPalette,CreatePalette,(int a),(a),return)
-SDL3_SYM_PASSTHROUGH(int,AtomicAdd,(SDL_atomic_t *a, int b),(a,b),return)
-SDL3_SYM_RENAMED_BOOL(SDL_bool,AtomicCAS,AtomicCompareAndSwap,(SDL_atomic_t *a, int b, int c),(a,b,c),return)
-SDL3_SYM_RENAMED_BOOL(SDL_bool,AtomicCASPtr,AtomicCompareAndSwapPointer,(void **a, void *b, void *c),(a,b,c),return)
-SDL3_SYM_PASSTHROUGH(int,AtomicGet,(SDL_atomic_t *a),(a),return)
-SDL3_SYM_RENAMED(void*,AtomicGetPtr,AtomicGetPointer,(void **a),(a),return)
+SDL3_SYM_RENAMED(int,AtomicAdd,AddAtomicInt,(SDL_atomic_t *a, int b),(a,b),return)
+SDL3_SYM_RENAMED_BOOL(SDL_bool,AtomicCAS,CompareAndSwapAtomicInt,(SDL_atomic_t *a, int b, int c),(a,b,c),return)
+SDL3_SYM_RENAMED_BOOL(SDL_bool,AtomicCASPtr,CompareAndSwapAtomicPointer,(void **a, void *b, void *c),(a,b,c),return)
+SDL3_SYM_RENAMED(int,AtomicGet,GetAtomicInt,(SDL_atomic_t *a),(a),return)
+SDL3_SYM_RENAMED(void*,AtomicGetPtr,GetAtomicPointer,(void **a),(a),return)
 SDL3_SYM_RENAMED(void,AtomicLock,LockSpinlock,(SDL_SpinLock *a),(a),)
-SDL3_SYM_PASSTHROUGH(int,AtomicSet,(SDL_atomic_t *a, int b),(a,b),return)
-SDL3_SYM_RENAMED(void*,AtomicSetPtr,AtomicSetPointer,(void **a, void *b),(a,b),return)
+SDL3_SYM_RENAMED(int,AtomicSet,SetAtomicInt,(SDL_atomic_t *a, int b),(a,b),return)
+SDL3_SYM_RENAMED(void*,AtomicSetPtr,SetAtomicPointer,(void **a, void *b),(a,b),return)
 SDL3_SYM_RENAMED_BOOL(SDL_bool,AtomicTryLock,TryLockSpinlock,(SDL_SpinLock *a),(a),return)
 SDL3_SYM_RENAMED(void,AtomicUnlock,UnlockSpinlock,(SDL_SpinLock *a),(a),)
 SDL3_SYM(SDL_JoystickID,AttachVirtualJoystick,(const SDL_VirtualJoystickDesc *a),(a),return)