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

Fixes https://github.com/libsdl-org/SDL/issues/7035
This commit is contained in:
Sam Lantinga 2023-01-09 12:09:30 -08:00
parent fde78d12f2
commit 5feebcdce0
4 changed files with 15 additions and 15 deletions

View file

@ -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)

View file

@ -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.

View file

@ -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)

View file

@ -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)