From ed1f93cd11fe7812719553a19a18230d3685439c Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Mon, 15 Jul 2024 20:36:33 -0400 Subject: [PATCH] filesystem: `SDL_Glob*Directory()` functions now follow the SDL_GetStringRule. Reference Issue #10229. --- include/SDL3/SDL_filesystem.h | 4 ++-- include/SDL3/SDL_storage.h | 4 ++-- src/dynapi/SDL_dynapi_procs.h | 4 ++-- src/filesystem/SDL_filesystem.c | 7 ++++--- src/filesystem/SDL_sysfilesystem.h | 2 +- src/storage/SDL_storage.c | 2 +- test/testfilesystem.c | 3 +-- 7 files changed, 13 insertions(+), 13 deletions(-) diff --git a/include/SDL3/SDL_filesystem.h b/include/SDL3/SDL_filesystem.h index 3520e0aea..0650dbdeb 100644 --- a/include/SDL3/SDL_filesystem.h +++ b/include/SDL3/SDL_filesystem.h @@ -354,7 +354,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetPathInfo(const char *path, SDL_PathInfo * * convenience, but if `count` is non-NULL, on return it will contain the * number of items in the array, not counting the NULL terminator. * - * You must free the returned pointer with SDL_free() when done with it. + * The returned pointer follows the SDL_GetStringRule. * * \param path the path of the directory to enumerate. * \param pattern the pattern that files in the directory must match. Can be @@ -370,7 +370,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetPathInfo(const char *path, SDL_PathInfo * * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC char **SDLCALL SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count); +extern SDL_DECLSPEC const char * const *SDLCALL SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count); /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/include/SDL3/SDL_storage.h b/include/SDL3/SDL_storage.h index c98c5201a..743174894 100644 --- a/include/SDL3/SDL_storage.h +++ b/include/SDL3/SDL_storage.h @@ -383,7 +383,7 @@ extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetStorageSpaceRemaining(SDL_Storage *sto * convenience, but if `count` is non-NULL, on return it will contain the * number of items in the array, not counting the NULL terminator. * - * You must free the returned pointer with SDL_free() when done with it. + * The returned pointer follows the SDL_GetStringRule. * * \param storage a storage container. * \param path the path of the directory to enumerate. @@ -401,7 +401,7 @@ extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetStorageSpaceRemaining(SDL_Storage *sto * * \since This function is available since SDL 3.0.0. */ -extern SDL_DECLSPEC char **SDLCALL SDL_GlobStorageDirectory(SDL_Storage *storage, const char *path, const char *pattern, SDL_GlobFlags flags, int *count); +extern SDL_DECLSPEC const char * const *SDLCALL SDL_GlobStorageDirectory(SDL_Storage *storage, const char *path, const char *pattern, SDL_GlobFlags flags, int *count); /* Ends C function definitions when using C++ */ #ifdef __cplusplus diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h index 345bb35d3..ac14f04df 100644 --- a/src/dynapi/SDL_dynapi_procs.h +++ b/src/dynapi/SDL_dynapi_procs.h @@ -532,8 +532,8 @@ 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(char**,SDL_GlobDirectory,(const char *a, const char *b, SDL_GlobFlags c, int *d),(a,b,c,d),return) -SDL_DYNAPI_PROC(char**,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(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) SDL_DYNAPI_PROC(SDL_bool,SDL_HapticRumbleSupported,(SDL_Haptic *a),(a),return) SDL_DYNAPI_PROC(SDL_bool,SDL_HasARMSIMD,(void),(),return) diff --git a/src/filesystem/SDL_filesystem.c b/src/filesystem/SDL_filesystem.c index 324d31c0d..bc3222a64 100644 --- a/src/filesystem/SDL_filesystem.c +++ b/src/filesystem/SDL_filesystem.c @@ -286,7 +286,7 @@ static int SDLCALL GlobDirectoryCallback(void *userdata, const char *dirname, co return retval; } -char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata) +const char * const *SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata) { int dummycount; if (!count) { @@ -381,7 +381,8 @@ char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_Glob SDL_free(folded); SDL_free(pathcpy); - return retval; + SDL_FreeLater(retval); + return (const char * const *) retval; } static int GlobDirectoryGetPathInfo(const char *path, SDL_PathInfo *info, void *userdata) @@ -394,7 +395,7 @@ static int GlobDirectoryEnumerator(const char *path, SDL_EnumerateDirectoryCallb return SDL_EnumerateDirectory(path, cb, cbuserdata); } -char **SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count) +const char * const *SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count) { //SDL_Log("SDL_GlobDirectory('%s', '%s') ...", path, pattern); return SDL_InternalGlobDirectory(path, pattern, flags, count, GlobDirectoryEnumerator, GlobDirectoryGetPathInfo, NULL); diff --git a/src/filesystem/SDL_sysfilesystem.h b/src/filesystem/SDL_sysfilesystem.h index bd010cac8..9f02a1e8d 100644 --- a/src/filesystem/SDL_sysfilesystem.h +++ b/src/filesystem/SDL_sysfilesystem.h @@ -35,7 +35,7 @@ int SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info); typedef int (*SDL_GlobEnumeratorFunc)(const char *path, SDL_EnumerateDirectoryCallback cb, void *cbuserdata, void *userdata); typedef int (*SDL_GlobGetPathInfoFunc)(const char *path, SDL_PathInfo *info, void *userdata); -char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata); +const char * const *SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata); #endif diff --git a/src/storage/SDL_storage.c b/src/storage/SDL_storage.c index 431110f95..b61f1a1ee 100644 --- a/src/storage/SDL_storage.c +++ b/src/storage/SDL_storage.c @@ -335,7 +335,7 @@ static int GlobStorageDirectoryEnumerator(const char *path, SDL_EnumerateDirecto return SDL_EnumerateStorageDirectory((SDL_Storage *) userdata, path, cb, cbuserdata); } -char **SDL_GlobStorageDirectory(SDL_Storage *storage, const char *path, const char *pattern, SDL_GlobFlags flags, int *count) +const char * const *SDL_GlobStorageDirectory(SDL_Storage *storage, const char *path, const char *pattern, SDL_GlobFlags flags, int *count) { CHECK_STORAGE_MAGIC_RET(NULL) return SDL_InternalGlobDirectory(path, pattern, flags, count, GlobStorageDirectoryEnumerator, GlobStorageDirectoryGetPathInfo, storage); diff --git a/test/testfilesystem.c b/test/testfilesystem.c index 39c5177ff..286de004a 100644 --- a/test/testfilesystem.c +++ b/test/testfilesystem.c @@ -108,7 +108,7 @@ int main(int argc, char *argv[]) } if (base_path) { - char **globlist; + const char * const *globlist; if (SDL_EnumerateDirectory(base_path, enum_callback, NULL) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Base path enumeration failed!"); @@ -122,7 +122,6 @@ int main(int argc, char *argv[]) for (i = 0; globlist[i]; i++) { SDL_Log("GLOB[%d]: '%s'", i, globlist[i]); } - SDL_free(globlist); } /* !!! FIXME: put this in a subroutine and make it test more thoroughly (and put it in testautomation). */