SDL: SDL_AddHintCallback() now returns a standard int result instead of void

From 5feebcdce0252f6af7c21c2aa7525134c09b5002 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Mon, 9 Jan 2023 12:09:30 -0800
Subject: [PATCH] SDL_AddHintCallback() now returns a standard int result
 instead of void

Fixes https://github.com/libsdl-org/SDL/issues/7035
---
 docs/README-migration.md      |  2 ++
 include/SDL3/SDL_hints.h      |  8 +++++---
 src/SDL_hints.c               | 18 +++++++-----------
 src/dynapi/SDL_dynapi_procs.h |  2 +-
 4 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/docs/README-migration.md b/docs/README-migration.md
index 955d2f77896e..9205ebed80ad 100644
--- a/docs/README-migration.md
+++ b/docs/README-migration.md
@@ -272,6 +272,8 @@ functionality to your app and aid migration. That is located in the
 
 ## SDL_hints.h
 
+SDL_AddHintCallback() now returns a standard int result instead of void, returning 0 if the function succeeds or a negative error code if there was an error.
+
 The following hints have been removed:
 * SDL_HINT_IDLE_TIMER_DISABLED (use SDL_DisableScreenSaver instead)
 * SDL_HINT_VIDEO_X11_FORCE_EGL (use SDL_HINT_VIDEO_FORCE_EGL instead)
diff --git a/include/SDL3/SDL_hints.h b/include/SDL3/SDL_hints.h
index 2942a0976c5f..d2675bfd09d4 100644
--- a/include/SDL3/SDL_hints.h
+++ b/include/SDL3/SDL_hints.h
@@ -2525,14 +2525,16 @@ typedef void (SDLCALL *SDL_HintCallback)(void *userdata, const char *name, const
  * \param callback An SDL_HintCallback function that will be called when the
  *                 hint value changes
  * \param userdata a pointer to pass to the callback function
+ * \returns 0 on success or a negative error code on failure; call
+ *          SDL_GetError() for more information.
  *
  * \since This function is available since SDL 3.0.0.
  *
  * \sa SDL_DelHintCallback
  */
-extern DECLSPEC void SDLCALL SDL_AddHintCallback(const char *name,
-                                                 SDL_HintCallback callback,
-                                                 void *userdata);
+extern DECLSPEC int SDLCALL SDL_AddHintCallback(const char *name,
+                                                SDL_HintCallback callback,
+                                                void *userdata);
 
 /**
  * Remove a function watching a particular hint.
diff --git a/src/SDL_hints.c b/src/SDL_hints.c
index ac57fdf3dc6f..85eda0a68c70 100644
--- a/src/SDL_hints.c
+++ b/src/SDL_hints.c
@@ -195,27 +195,24 @@ SDL_GetHintBoolean(const char *name, SDL_bool default_value)
     return SDL_GetStringBoolean(hint, default_value);
 }
 
-void SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
+int SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
 {
     SDL_Hint *hint;
     SDL_HintWatch *entry;
     const char *value;
 
     if (name == NULL || !*name) {
-        SDL_InvalidParamError("name");
-        return;
+        return SDL_InvalidParamError("name");
     }
     if (!callback) {
-        SDL_InvalidParamError("callback");
-        return;
+        return SDL_InvalidParamError("callback");
     }
 
     SDL_DelHintCallback(name, callback, userdata);
 
     entry = (SDL_HintWatch *)SDL_malloc(sizeof(*entry));
     if (entry == NULL) {
-        SDL_OutOfMemory();
-        return;
+        return SDL_OutOfMemory();
     }
     entry->callback = callback;
     entry->userdata = userdata;
@@ -229,16 +226,14 @@ void SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *user
         /* Need to add a hint entry for this watcher */
         hint = (SDL_Hint *)SDL_malloc(sizeof(*hint));
         if (hint == NULL) {
-            SDL_OutOfMemory();
             SDL_free(entry);
-            return;
+            return SDL_OutOfMemory();
         }
         hint->name = SDL_strdup(name);
         if (!hint->name) {
             SDL_free(entry);
             SDL_free(hint);
-            SDL_OutOfMemory();
-            return;
+            return SDL_OutOfMemory();
         }
         hint->value = NULL;
         hint->priority = SDL_HINT_DEFAULT;
@@ -254,6 +249,7 @@ void SDL_AddHintCallback(const char *name, SDL_HintCallback callback, void *user
     /* Now call it with the current value */
     value = SDL_GetHint(name);
     callback(userdata, name, value, value);
+    return 0;
 }
 
 void SDL_DelHintCallback(const char *name, SDL_HintCallback callback, void *userdata)
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index 914d97eea88b..781c8873927a 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -119,7 +119,7 @@ SDL_DYNAPI_PROC(SDL_bool,SDL_IsDeXMode,(void),(),return)
 SDL_DYNAPI_PROC(void,SDL_AddEventWatch,(SDL_EventFilter a, void *b),(a,b),)
 SDL_DYNAPI_PROC(int,SDL_AddGamepadMapping,(const char *a),(a),return)
 SDL_DYNAPI_PROC(int,SDL_AddGamepadMappingsFromRW,(SDL_RWops *a, int b),(a,b),return)
-SDL_DYNAPI_PROC(void,SDL_AddHintCallback,(const char *a, SDL_HintCallback b, void *c),(a,b,c),)
+SDL_DYNAPI_PROC(int,SDL_AddHintCallback,(const char *a, SDL_HintCallback b, void *c),(a,b,c),return)
 SDL_DYNAPI_PROC(SDL_TimerID,SDL_AddTimer,(Uint32 a, SDL_TimerCallback b, void *c),(a,b,c),return)
 SDL_DYNAPI_PROC(SDL_RWops*,SDL_CreateRW,(void),(),return)
 SDL_DYNAPI_PROC(int,SDL_AtomicAdd,(SDL_atomic_t *a, int b),(a,b),return)