From 375bde8a4fc6a5ca413dea13c3e47de1bae974a8 Mon Sep 17 00:00:00 2001 From: Linus Probert Date: Mon, 6 Feb 2023 17:53:52 +0100 Subject: [PATCH] [SDL3] Cleanup void functions (#7253) Some functions that do call SDL_SetError but return void changed to instead return non-zero in case of errors. --- include/SDL3/SDL_video.h | 20 +++++++++--- src/dynapi/SDL_dynapi_procs.h | 10 +++--- src/video/SDL_video.c | 59 +++++++++++++++++------------------ 3 files changed, 48 insertions(+), 41 deletions(-) diff --git a/include/SDL3/SDL_video.h b/include/SDL3/SDL_video.h index 15c1cf48f3..d35d61951b 100644 --- a/include/SDL3/SDL_video.h +++ b/include/SDL3/SDL_video.h @@ -750,12 +750,14 @@ extern DECLSPEC Uint32 SDLCALL SDL_GetWindowFlags(SDL_Window *window); * * \param window the window to change * \param title the desired window title in UTF-8 format + * \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_GetWindowTitle */ -extern DECLSPEC void SDLCALL SDL_SetWindowTitle(SDL_Window *window, const char *title); +extern DECLSPEC int SDLCALL SDL_SetWindowTitle(SDL_Window *window, const char *title); /** * Get the title of a window. @@ -775,10 +777,12 @@ extern DECLSPEC const char *SDLCALL SDL_GetWindowTitle(SDL_Window *window); * * \param window the window to change * \param icon an SDL_Surface structure containing the icon for the window + * \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. */ -extern DECLSPEC void SDLCALL SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon); +extern DECLSPEC int SDLCALL SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon); /** * Associate an arbitrary named pointer with a window. @@ -852,13 +856,15 @@ extern DECLSPEC void SDLCALL SDL_GetWindowPosition(SDL_Window *window, int *x, i * \param window the window to change * \param w the width of the window, must be > 0 * \param h the height of the window, must be > 0 + * \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_GetWindowSize * \sa SDL_SetWindowFullscreenMode */ -extern DECLSPEC void SDLCALL SDL_SetWindowSize(SDL_Window *window, int w, int h); +extern DECLSPEC int SDLCALL SDL_SetWindowSize(SDL_Window *window, int w, int h); /** * Get the size of a window's client area, in screen coordinates. @@ -942,13 +948,15 @@ extern DECLSPEC void SDLCALL SDL_GetWindowSizeInPixels(SDL_Window *window, int * * \param window the window to change * \param min_w the minimum width of the window * \param min_h the minimum height of the window + * \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_GetWindowMinimumSize * \sa SDL_SetWindowMaximumSize */ -extern DECLSPEC void SDLCALL SDL_SetWindowMinimumSize(SDL_Window *window, int min_w, int min_h); +extern DECLSPEC int SDLCALL SDL_SetWindowMinimumSize(SDL_Window *window, int min_w, int min_h); /** * Get the minimum size of a window's client area, in screen coordinates. @@ -972,13 +980,15 @@ extern DECLSPEC void SDLCALL SDL_GetWindowMinimumSize(SDL_Window *window, int *w * \param window the window to change * \param max_w the maximum width of the window * \param max_h the maximum height of the window + * \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_GetWindowMaximumSize * \sa SDL_SetWindowMinimumSize */ -extern DECLSPEC void SDLCALL SDL_SetWindowMaximumSize(SDL_Window *window, int max_w, int max_h); +extern DECLSPEC int SDLCALL SDL_SetWindowMaximumSize(SDL_Window *window, int max_w, int max_h); /** * Get the maximum size of a window's client area, in screen coordinates. diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 0cc19e3707..44a0014534 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -689,11 +689,11 @@ SDL_DYNAPI_PROC(int,SDL_SetWindowFullscreenMode,(SDL_Window *a, const SDL_Displa SDL_DYNAPI_PROC(int,SDL_SetWindowFullscreen,(SDL_Window *a, SDL_bool b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_SetWindowGrab,(SDL_Window *a, SDL_bool b),(a,b),) SDL_DYNAPI_PROC(int,SDL_SetWindowHitTest,(SDL_Window *a, SDL_HitTest b, void *c),(a,b,c),return) -SDL_DYNAPI_PROC(void,SDL_SetWindowIcon,(SDL_Window *a, SDL_Surface *b),(a,b),) +SDL_DYNAPI_PROC(int,SDL_SetWindowIcon,(SDL_Window *a, SDL_Surface *b),(a,b),return) SDL_DYNAPI_PROC(int,SDL_SetWindowInputFocus,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(void,SDL_SetWindowKeyboardGrab,(SDL_Window *a, SDL_bool b),(a,b),) -SDL_DYNAPI_PROC(void,SDL_SetWindowMaximumSize,(SDL_Window *a, int b, int c),(a,b,c),) -SDL_DYNAPI_PROC(void,SDL_SetWindowMinimumSize,(SDL_Window *a, int b, int c),(a,b,c),) +SDL_DYNAPI_PROC(int,SDL_SetWindowMaximumSize,(SDL_Window *a, int b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(int,SDL_SetWindowMinimumSize,(SDL_Window *a, int b, int c),(a,b,c),return) SDL_DYNAPI_PROC(int,SDL_SetWindowModalFor,(SDL_Window *a, SDL_Window *b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_SetWindowMouseGrab,(SDL_Window *a, SDL_bool b),(a,b),) SDL_DYNAPI_PROC(int,SDL_SetWindowMouseRect,(SDL_Window *a, const SDL_Rect *b),(a,b),return) @@ -701,8 +701,8 @@ SDL_DYNAPI_PROC(int,SDL_SetWindowOpacity,(SDL_Window *a, float b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_SetWindowPosition,(SDL_Window *a, int b, int c),(a,b,c),) SDL_DYNAPI_PROC(void,SDL_SetWindowResizable,(SDL_Window *a, SDL_bool b),(a,b),) SDL_DYNAPI_PROC(int,SDL_SetWindowShape,(SDL_Window *a, SDL_Surface *b, SDL_WindowShapeMode *c),(a,b,c),return) -SDL_DYNAPI_PROC(void,SDL_SetWindowSize,(SDL_Window *a, int b, int c),(a,b,c),) -SDL_DYNAPI_PROC(void,SDL_SetWindowTitle,(SDL_Window *a, const char *b),(a,b),) +SDL_DYNAPI_PROC(int,SDL_SetWindowSize,(SDL_Window *a, int b, int c),(a,b,c),return) +SDL_DYNAPI_PROC(int,SDL_SetWindowTitle,(SDL_Window *a, const char *b),(a,b),return) SDL_DYNAPI_PROC(void,SDL_SetYUVConversionMode,(SDL_YUV_CONVERSION_MODE a),(a),) SDL_DYNAPI_PROC(int,SDL_ShowCursor,(void),(),return) SDL_DYNAPI_PROC(int,SDL_ShowMessageBox,(const SDL_MessageBoxData *a, int *b),(a,b),return) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 7610c4121c..32baa6efd0 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -2036,12 +2036,12 @@ Uint32 SDL_GetWindowFlags(SDL_Window *window) return window->flags; } -void SDL_SetWindowTitle(SDL_Window *window, const char *title) +int SDL_SetWindowTitle(SDL_Window *window, const char *title) { - CHECK_WINDOW_MAGIC(window, ); + CHECK_WINDOW_MAGIC(window, -1); if (title == window->title) { - return; + return 0; } SDL_free(window->title); @@ -2050,6 +2050,7 @@ void SDL_SetWindowTitle(SDL_Window *window, const char *title) if (_this->SetWindowTitle) { _this->SetWindowTitle(_this, window); } + return 0; } const char *SDL_GetWindowTitle(SDL_Window *window) @@ -2059,12 +2060,12 @@ const char *SDL_GetWindowTitle(SDL_Window *window) return window->title ? window->title : ""; } -void SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon) +int SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon) { - CHECK_WINDOW_MAGIC(window, ); + CHECK_WINDOW_MAGIC(window, -1); if (icon == NULL) { - return; + return 0; } SDL_DestroySurface(window->icon); @@ -2072,12 +2073,13 @@ void SDL_SetWindowIcon(SDL_Window *window, SDL_Surface *icon) /* Convert the icon into ARGB8888 */ window->icon = SDL_ConvertSurfaceFormat(icon, SDL_PIXELFORMAT_ARGB8888); if (!window->icon) { - return; + return -1; } if (_this->SetWindowIcon) { _this->SetWindowIcon(_this, window, window->icon); } + return 0; } void *SDL_SetWindowData(SDL_Window *window, const char *name, void *userdata) @@ -2284,16 +2286,14 @@ void SDL_SetWindowAlwaysOnTop(SDL_Window *window, SDL_bool on_top) } } -void SDL_SetWindowSize(SDL_Window *window, int w, int h) +int SDL_SetWindowSize(SDL_Window *window, int w, int h) { - CHECK_WINDOW_MAGIC(window, ); + CHECK_WINDOW_MAGIC(window, -1); if (w <= 0) { - SDL_InvalidParamError("w"); - return; + return SDL_InvalidParamError("w"); } if (h <= 0) { - SDL_InvalidParamError("h"); - return; + return SDL_InvalidParamError("h"); } /* Make sure we don't exceed any window size limits */ @@ -2318,6 +2318,7 @@ void SDL_SetWindowSize(SDL_Window *window, int w, int h) _this->SetWindowSize(_this, window); } } + return 0; } void SDL_GetWindowSize(SDL_Window *window, int *w, int *h) @@ -2402,22 +2403,19 @@ void SDL_GetWindowSizeInPixels(SDL_Window *window, int *w, int *h) } } -void SDL_SetWindowMinimumSize(SDL_Window *window, int min_w, int min_h) +int SDL_SetWindowMinimumSize(SDL_Window *window, int min_w, int min_h) { - CHECK_WINDOW_MAGIC(window, ); + CHECK_WINDOW_MAGIC(window, -1); if (min_w <= 0) { - SDL_InvalidParamError("min_w"); - return; + return SDL_InvalidParamError("min_w"); } if (min_h <= 0) { - SDL_InvalidParamError("min_h"); - return; + return SDL_InvalidParamError("min_h"); } if ((window->max_w && min_w > window->max_w) || (window->max_h && min_h > window->max_h)) { - SDL_SetError("SDL_SetWindowMinimumSize(): Tried to set minimum size larger than maximum size"); - return; + return SDL_SetError("SDL_SetWindowMinimumSize(): Tried to set minimum size larger than maximum size"); } window->min_w = min_w; @@ -2428,8 +2426,9 @@ void SDL_SetWindowMinimumSize(SDL_Window *window, int min_w, int min_h) _this->SetWindowMinimumSize(_this, window); } /* Ensure that window is not smaller than minimal size */ - SDL_SetWindowSize(window, SDL_max(window->w, window->min_w), SDL_max(window->h, window->min_h)); + return SDL_SetWindowSize(window, SDL_max(window->w, window->min_w), SDL_max(window->h, window->min_h)); } + return 0; } void SDL_GetWindowMinimumSize(SDL_Window *window, int *min_w, int *min_h) @@ -2443,21 +2442,18 @@ void SDL_GetWindowMinimumSize(SDL_Window *window, int *min_w, int *min_h) } } -void SDL_SetWindowMaximumSize(SDL_Window *window, int max_w, int max_h) +int SDL_SetWindowMaximumSize(SDL_Window *window, int max_w, int max_h) { - CHECK_WINDOW_MAGIC(window, ); + CHECK_WINDOW_MAGIC(window, -1); if (max_w <= 0) { - SDL_InvalidParamError("max_w"); - return; + return SDL_InvalidParamError("max_w"); } if (max_h <= 0) { - SDL_InvalidParamError("max_h"); - return; + return SDL_InvalidParamError("max_h"); } if (max_w < window->min_w || max_h < window->min_h) { - SDL_SetError("SDL_SetWindowMaximumSize(): Tried to set maximum size smaller than minimum size"); - return; + return SDL_SetError("SDL_SetWindowMaximumSize(): Tried to set maximum size smaller than minimum size"); } window->max_w = max_w; @@ -2468,8 +2464,9 @@ void SDL_SetWindowMaximumSize(SDL_Window *window, int max_w, int max_h) _this->SetWindowMaximumSize(_this, window); } /* Ensure that window is not larger than maximal size */ - SDL_SetWindowSize(window, SDL_min(window->w, window->max_w), SDL_min(window->h, window->max_h)); + return SDL_SetWindowSize(window, SDL_min(window->w, window->max_w), SDL_min(window->h, window->max_h)); } + return 0; } void SDL_GetWindowMaximumSize(SDL_Window *window, int *max_w, int *max_h)