From eb22fcce358e93e8c8dafb17d24c1fed56dcf5ff Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 18 Jul 2024 22:15:11 -0700 Subject: [PATCH] SDL_GetTouchDevices() follows the SDL_GetStringRule --- include/SDL3/SDL_touch.h | 9 +++++---- src/dynapi/SDL_dynapi_procs.h | 2 +- src/events/SDL_touch.c | 4 ++-- src/video/x11/SDL_x11xinput2.c | 3 +-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/SDL3/SDL_touch.h b/include/SDL3/SDL_touch.h index 4e258fca97..808a69ea43 100644 --- a/include/SDL3/SDL_touch.h +++ b/include/SDL3/SDL_touch.h @@ -83,15 +83,16 @@ typedef struct SDL_Finger * Therefore the returned list might be empty, although devices are available. * After using all devices at least once the number will be correct. * - * \param count a pointer filled in with the number of devices returned, can + * The returned array follows the SDL_GetStringRule, and will be automatically freed later. + * + * \param count a pointer filled in with the number of devices returned, may * be NULL. - * \returns a 0 terminated array of touch device IDs which should be freed - * with SDL_free(), or NULL on failure; call SDL_GetError() for more + * \returns a 0 terminated array of touch device IDs or NULL on failure; call SDL_GetError() for more * information. * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC SDL_TouchID * SDLCALL SDL_GetTouchDevices(int *count); +extern SDL_DECLSPEC const SDL_TouchID * SDLCALL SDL_GetTouchDevices(int *count); /** * Get the touch device name as reported from the driver. diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 64b0d0a4a5..769d1e9bb6 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -502,7 +502,7 @@ SDL_DYNAPI_PROC(Uint64,SDL_GetTicks,(void),(),return) SDL_DYNAPI_PROC(Uint64,SDL_GetTicksNS,(void),(),return) SDL_DYNAPI_PROC(const char*,SDL_GetTouchDeviceName,(SDL_TouchID a),(a),return) SDL_DYNAPI_PROC(SDL_TouchDeviceType,SDL_GetTouchDeviceType,(SDL_TouchID a),(a),return) -SDL_DYNAPI_PROC(SDL_TouchID*,SDL_GetTouchDevices,(int *a),(a),return) +SDL_DYNAPI_PROC(const SDL_TouchID*,SDL_GetTouchDevices,(int *a),(a),return) SDL_DYNAPI_PROC(SDL_Finger**,SDL_GetTouchFingers,(SDL_TouchID a, int *b),(a,b),return) SDL_DYNAPI_PROC(const char*,SDL_GetUserFolder,(SDL_Folder a),(a),return) SDL_DYNAPI_PROC(int,SDL_GetVersion,(void),(),return) diff --git a/src/events/SDL_touch.c b/src/events/SDL_touch.c index 7d4e4ff19b..c2cada0567 100644 --- a/src/events/SDL_touch.c +++ b/src/events/SDL_touch.c @@ -49,7 +49,7 @@ SDL_bool SDL_TouchDevicesAvailable(void) return SDL_num_touch > 0; } -SDL_TouchID *SDL_GetTouchDevices(int *count) +const SDL_TouchID *SDL_GetTouchDevices(int *count) { if (count) { *count = 0; @@ -67,7 +67,7 @@ SDL_TouchID *SDL_GetTouchDevices(int *count) } } - return retval; + return SDL_FreeLater(retval); } static int SDL_GetTouchIndex(SDL_TouchID id) diff --git a/src/video/x11/SDL_x11xinput2.c b/src/video/x11/SDL_x11xinput2.c index 8ef4197cf4..9ab979f0f1 100644 --- a/src/video/x11/SDL_x11xinput2.c +++ b/src/video/x11/SDL_x11xinput2.c @@ -742,7 +742,7 @@ void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, SDL_bool initial_check) int new_mouse_count = 0; SDL_MouseID *new_mice = NULL; int old_touch_count = 0; - SDL_TouchID *old_touch_devices64 = NULL; + const SDL_TouchID *old_touch_devices64 = NULL; Uint32 *old_touch_devices = NULL; int new_touch_count = 0; Uint32 *new_touch_devices = NULL; @@ -765,7 +765,6 @@ void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, SDL_bool initial_check) } } } - SDL_free(old_touch_devices64); for (int i = 0; i < ndevices; i++) { XIDeviceInfo *dev = &info[i];