sdl2-compat: undefine more 'function macros' from SDL3 headers.

From 4a2564b1668246aa8b585c5f68c6bc5c8ff9cf8e Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Thu, 9 Mar 2023 18:50:00 +0300
Subject: [PATCH] undefine more 'function macros' from SDL3 headers.

---
 src/sdl2_compat.c          | 24 ++++++++--
 src/sdl3_include_wrapper.h | 97 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 118 insertions(+), 3 deletions(-)

diff --git a/src/sdl2_compat.c b/src/sdl2_compat.c
index 72629a3..cb220e3 100644
--- a/src/sdl2_compat.c
+++ b/src/sdl2_compat.c
@@ -136,6 +136,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_OutOfMemory() SDL3_Error(SDL_ENOMEM)
 #define SDL3_Unsupported() SDL3_Error(SDL_UNSUPPORTED)
 #define SDL3_InvalidParamError(param) SDL3_SetError("Parameter '%s' is invalid", (param))
@@ -146,6 +148,21 @@ extern "C" {
     { SDL_COMPILE_TIME_ASSERT(SDL3_copyp, sizeof(*(dst)) == sizeof(*(src))); }  \
     SDL3_memcpy((dst), (src), sizeof(*(src)))
 
+/* for SDL_assert() : */
+#define SDL_enabled_assert(condition) \
+do { \
+    while ( !(condition) ) { \
+        static struct SDL_AssertData sdl_assert_data = { 0, 0, #condition, 0, 0, 0, 0 }; \
+        const SDL_AssertState sdl_assert_state = SDL3_ReportAssertion(&sdl_assert_data, SDL_FUNCTION, SDL_FILE, SDL_LINE); \
+        if (sdl_assert_state == SDL_ASSERTION_RETRY) { \
+            continue; /* go again. */ \
+        } else if (sdl_assert_state == SDL_ASSERTION_BREAK) { \
+            SDL_AssertBreakpoint(); \
+        } \
+        break; /* not retrying. */ \
+    } \
+} while (SDL_NULL_WHILE_LOOP_CONDITION)
+
 
 static SDL_bool WantDebugLogging = SDL_FALSE;
 static Uint32 LinkedSDL3VersionInt = 0;
@@ -3995,7 +4012,7 @@ SDL_GetClosestDisplayMode(int displayIndex, const SDL2_DisplayMode *mode, SDL2_D
     SDL_DisplayMode *ret3;
 
     if (mode == NULL || closest == NULL) {
-        SDL_InvalidParamError("mode/closest");
+        SDL3_InvalidParamError("mode/closest");
         return NULL;
     }
 
@@ -4196,6 +4213,7 @@ SDL_RenderFillRects(SDL_Renderer *renderer, const SDL_Rect *rects, int count)
     if (frects == NULL) {
         return SDL3_OutOfMemory();
     }
+
     for (i = 0; i < count; ++i) {
         frects[i].x = (float)rects[i].x;
         frects[i].y = (float)rects[i].y;
@@ -5208,7 +5226,7 @@ SDL_BuildAudioCVT(SDL_AudioCVT *cvt,
 {
     /* Sanity check target pointer */
     if (cvt == NULL) {
-        return SDL_InvalidParamError("cvt");
+        return SDL3_InvalidParamError("cvt");
     }
 
     /* Make sure we zero out the audio conversion before error checking */
@@ -5305,7 +5323,7 @@ SDL_ConvertAudio(SDL_AudioCVT *cvt)
 
     /* Sanity check target pointer */
     if (cvt == NULL) {
-        return SDL_InvalidParamError("cvt");
+        return SDL3_InvalidParamError("cvt");
     }
 
     { /* Fetch from the end of filters[], aligned */
diff --git a/src/sdl3_include_wrapper.h b/src/sdl3_include_wrapper.h
index 64d154d..d8c5898 100644
--- a/src/sdl3_include_wrapper.h
+++ b/src/sdl3_include_wrapper.h
@@ -4277,6 +4277,95 @@ typedef void (__cdecl *pfnSDL_CurrentEndThread) (unsigned);
 #endif
 
 /* undefine these macros too: */
+/* if needed, redefine using SDL3_xxx instead. */
+
+#ifdef SDL_enabled_assert
+#undef SDL_enabled_assert
+#endif
+
+#ifdef SDL_OutOfMemory
+#undef SDL_OutOfMemory
+#endif
+
+#ifdef SDL_Unsupported
+#undef SDL_Unsupported
+#endif
+
+#ifdef SDL_InvalidParamError
+#undef SDL_InvalidParamError
+#endif
+
+#ifdef AtomicIncRef
+#undef AtomicIncRef
+#endif
+
+#ifdef SDL_AtomicDecRef
+#undef SDL_AtomicDecRef
+#endif
+
+#ifdef SDL_mutexP
+#undef SDL_mutexP
+#endif
+
+#ifdef SDL_mutexV
+#undef SDL_mutexV
+#endif
+
+#ifdef SDL_copyp
+#undef SDL_copyp
+#endif
+
+#ifdef SDL_zero
+#undef SDL_zero
+#endif
+
+#ifdef SDL_zeroa
+#undef SDL_zeroa
+#endif
+
+#ifdef SDL_zerop
+#undef SDL_zerop
+#endif
+
+#ifdef SDL_stack_alloc
+#undef SDL_stack_alloc
+#endif
+
+#ifdef SDL_stack_free
+#undef SDL_stack_free
+#endif
+
+#ifdef SDL_iconv_utf8_locale
+#undef SDL_iconv_utf8_locale
+#endif
+
+#ifdef SDL_iconv_utf8_ucs2
+#undef SDL_iconv_utf8_ucs2
+#endif
+
+#ifdef SDL_iconv_utf8_ucs4
+#undef SDL_iconv_utf8_ucs4
+#endif
+
+#ifdef SDL_iconv_wchar_utf8
+#undef SDL_iconv_wchar_utf8
+#endif
+
+#ifdef SDL_LoadWAV
+#undef SDL_LoadWAV
+#endif
+
+#ifdef SDL_LoadBMP
+#undef SDL_LoadBMP
+#endif
+
+#ifdef SDL_SaveBMP
+#undef SDL_SaveBMP
+#endif
+
+#ifdef SDL_AddGamepadMappingsFromFile
+#undef SDL_AddGamepadMappingsFromFile
+#endif
 
 #ifdef SDL_GDKRunApp
 #undef SDL_GDKRunApp
@@ -4290,6 +4379,14 @@ typedef void (__cdecl *pfnSDL_CurrentEndThread) (unsigned);
 #undef SDL_UIKitRunApp
 #endif
 
+#ifdef SDL_iOSSetAnimationCallback
+#undef SDL_iOSSetAnimationCallback
+#endif
+
+#ifdef SDL_iOSSetEventPump
+#undef SDL_iOSSetEventPump
+#endif
+
 #endif
 
 /* vi: set ts=4 sw=4 expandtab: */