From bdafc8e21211abaa5f6e981d78ed183ca8e5f15e Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 18 Jul 2024 08:30:50 -0700 Subject: [PATCH] SDL_GetWindows() follows the SDL_GetStringRule --- include/SDL3/SDL_video.h | 8 ++++---- src/dynapi/SDL_dynapi_procs.h | 2 +- src/video/SDL_video.c | 4 ++-- test/testautomation_video.c | 3 +-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/include/SDL3/SDL_video.h b/include/SDL3/SDL_video.h index 3819bfbfea..4572a73455 100644 --- a/include/SDL3/SDL_video.h +++ b/include/SDL3/SDL_video.h @@ -791,15 +791,15 @@ extern SDL_DECLSPEC SDL_PixelFormat SDLCALL SDL_GetWindowPixelFormat(SDL_Window /** * Get a list of valid windows. * + * The returned array follows the SDL_GetStringRule, and will be automatically freed later. + * * \param count a pointer filled in with the number of windows returned, may * be NULL. - * \returns a 0 terminated array of window pointers which should be freed with - * SDL_free(), or NULL on error; call SDL_GetError() for more - * details. + * \returns a NULL terminated array of SDL_Window pointers or NULL on failure; call SDL_GetError() for more information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC SDL_Window **SDLCALL SDL_GetWindows(int *count); +extern SDL_DECLSPEC SDL_Window * const *SDLCALL SDL_GetWindows(int *count); /** * Create a window with the specified dimensions and flags. diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 4a633a3c0e..6380957353 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -533,7 +533,7 @@ SDL_DYNAPI_PROC(int,SDL_GetWindowSizeInPixels,(SDL_Window *a, int *b, int *c),(a SDL_DYNAPI_PROC(SDL_Surface*,SDL_GetWindowSurface,(SDL_Window *a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetWindowSurfaceVSync,(SDL_Window *a, int *b),(a,b),return) SDL_DYNAPI_PROC(const char*,SDL_GetWindowTitle,(SDL_Window *a),(a),return) -SDL_DYNAPI_PROC(SDL_Window**,SDL_GetWindows,(int *a),(a),return) +SDL_DYNAPI_PROC(SDL_Window* const*,SDL_GetWindows,(int *a),(a),return) SDL_DYNAPI_PROC(const char * const *,SDL_GlobDirectory,(const char *a, const char *b, SDL_GlobFlags c, int *d),(a,b,c,d),return) SDL_DYNAPI_PROC(const char * const *,SDL_GlobStorageDirectory,(SDL_Storage *a, const char *b, const char *c, SDL_GlobFlags d, int *e),(a,b,c,d,e),return) SDL_DYNAPI_PROC(SDL_bool,SDL_HapticEffectSupported,(SDL_Haptic *a, const SDL_HapticEffect *b),(a,b),return) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 1270ee90cb..0fe87785ed 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -2056,7 +2056,7 @@ void SDL_ToggleDragAndDropSupport(void) } } -SDL_Window **SDLCALL SDL_GetWindows(int *count) +SDL_Window * const *SDLCALL SDL_GetWindows(int *count) { if (count) { *count = 0; @@ -2091,7 +2091,7 @@ SDL_Window **SDLCALL SDL_GetWindows(int *count) if (count) { *count = num_added; } - return windows; + return SDL_FreeLater(windows); } static void ApplyWindowFlags(SDL_Window *window, SDL_WindowFlags flags) diff --git a/test/testautomation_video.c b/test/testautomation_video.c index 5a4c32b3e1..c044fd5df3 100644 --- a/test/testautomation_video.c +++ b/test/testautomation_video.c @@ -13,7 +13,7 @@ static SDL_Window *createVideoSuiteTestWindow(const char *title) { SDL_Window *window; - SDL_Window **windows; + SDL_Window * const *windows; SDL_Event event; int w, h; int count; @@ -34,7 +34,6 @@ static SDL_Window *createVideoSuiteTestWindow(const char *title) windows = SDL_GetWindows(&count); SDLTest_AssertCheck(windows != NULL, "Validate that returned window list is not NULL"); SDLTest_AssertCheck(windows[0] == window, "Validate that the window is first in the window list"); - SDL_free(windows); /* Wayland and XWayland windows require that a frame be presented before they are fully mapped and visible onscreen. * This is required for the mouse/keyboard grab tests to pass.