diff --git a/include/SDL3/SDL_pixels.h b/include/SDL3/SDL_pixels.h index b87b6f733..851d5950f 100644 --- a/include/SDL3/SDL_pixels.h +++ b/include/SDL3/SDL_pixels.h @@ -723,8 +723,6 @@ typedef struct SDL_PixelFormatDetails /** * Get the human readable name of a pixel format. * - * The returned string follows the SDL_GetStringRule, and will be automatically freed later. - * * \param format the pixel format to query. * \returns the human readable name of the specified pixel format or * "SDL_PIXELFORMAT_UNKNOWN" if the format isn't recognized. diff --git a/include/SDL3/SDL_platform.h b/include/SDL3/SDL_platform.h index a811a6561..bfdfa3a41 100644 --- a/include/SDL3/SDL_platform.h +++ b/include/SDL3/SDL_platform.h @@ -48,8 +48,6 @@ extern "C" { * - "iOS" * - "Android" * - * The returned string follows the SDL_GetStringRule, and will be automatically freed later. - * * \returns the name of the platform. If the correct platform name is not * available, returns a string beginning with the text "Unknown". * diff --git a/include/SDL3/SDL_version.h b/include/SDL3/SDL_version.h index 516b66ade..c0f518d4a 100644 --- a/include/SDL3/SDL_version.h +++ b/include/SDL3/SDL_version.h @@ -163,8 +163,6 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetVersion(void); * You shouldn't use this function for anything but logging it for debugging * purposes. The string is not intended to be reliable in any way. * - * The returned string follows the SDL_GetStringRule, and will be automatically freed later. - * * \returns an arbitrary string, uniquely identifying the exact revision of * the SDL library in use. * diff --git a/src/SDL.c b/src/SDL.c index 8b76ef274..43bd2c576 100644 --- a/src/SDL.c +++ b/src/SDL.c @@ -601,11 +601,10 @@ int SDL_GetVersion(void) /* Get the library source revision */ const char *SDL_GetRevision(void) { - return SDL_REVISION; // a string literal, no need to SDL_FreeLater it. + return SDL_REVISION; } // Get the name of the platform -// (a string literal, no need to SDL_FreeLater it.) const char *SDL_GetPlatform(void) { #if defined(SDL_PLATFORM_AIX) diff --git a/src/audio/SDL_audio.c b/src/audio/SDL_audio.c index dd6037d27..3253956c1 100644 --- a/src/audio/SDL_audio.c +++ b/src/audio/SDL_audio.c @@ -131,19 +131,17 @@ int SDL_GetNumAudioDrivers(void) return num_drivers; } -// this returns string literals, so there's no need to use SDL_FreeLater. const char *SDL_GetAudioDriver(int index) { if (index >= 0 && index < SDL_GetNumAudioDrivers()) { - return deduped_bootstrap[index]->name; + return SDL_CreateTemporaryString(deduped_bootstrap[index]->name); } return NULL; } -// this returns string literals, so there's no need to use SDL_FreeLater. const char *SDL_GetCurrentAudioDriver(void) { - return current_audio.name; + return SDL_CreateTemporaryString(current_audio.name); } static int GetDefaultSampleFramesFromFreq(const int freq) diff --git a/src/camera/SDL_camera.c b/src/camera/SDL_camera.c index ae1b1f928..0247e660f 100644 --- a/src/camera/SDL_camera.c +++ b/src/camera/SDL_camera.c @@ -63,19 +63,17 @@ int SDL_GetNumCameraDrivers(void) return SDL_arraysize(bootstrap) - 1; } -// this returns string literals, so there's no need to use SDL_FreeLater. const char *SDL_GetCameraDriver(int index) { if (index >= 0 && index < SDL_GetNumCameraDrivers()) { - return bootstrap[index]->name; + return SDL_CreateTemporaryString(bootstrap[index]->name); } return NULL; } -// this returns string literals, so there's no need to use SDL_FreeLater. const char *SDL_GetCurrentCameraDriver(void) { - return camera_driver.name; + return SDL_CreateTemporaryString(camera_driver.name); } char *SDL_GetCameraThreadName(SDL_Camera *device, char *buf, size_t buflen) diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c index b97c8c4a9..6f5e5ec6a 100644 --- a/src/core/android/SDL_android.c +++ b/src/core/android/SDL_android.c @@ -2452,7 +2452,6 @@ void SDL_SendAndroidBackButton(void) (*env)->CallStaticVoidMethod(env, mActivityClass, midManualBackButton); } -// this caches a string until the process ends, so there's no need to use SDL_FreeLater. const char *SDL_GetAndroidInternalStoragePath(void) { static char *s_AndroidInternalFilesPath = NULL; @@ -2504,7 +2503,7 @@ const char *SDL_GetAndroidInternalStoragePath(void) LocalReferenceHolder_Cleanup(&refs); } - return s_AndroidInternalFilesPath; + return SDL_CreateTemporaryString(s_AndroidInternalFilesPath); } Uint32 SDL_GetAndroidExternalStorageState(void) @@ -2547,7 +2546,6 @@ Uint32 SDL_GetAndroidExternalStorageState(void) return stateFlags; } -// this caches a string until the process ends, so there's no need to use SDL_FreeLater. const char *SDL_GetAndroidExternalStoragePath(void) { static char *s_AndroidExternalFilesPath = NULL; @@ -2590,10 +2588,9 @@ const char *SDL_GetAndroidExternalStoragePath(void) LocalReferenceHolder_Cleanup(&refs); } - return s_AndroidExternalFilesPath; + return SDL_CreateTemporaryString(s_AndroidExternalFilesPath); } -// this caches a string until the process ends, so there's no need to use SDL_FreeLater. const char *SDL_GetAndroidCachePath(void) { // !!! FIXME: lots of duplication with SDL_GetAndroidExternalStoragePath and SDL_GetAndroidInternalStoragePath; consolidate these functions! @@ -2637,7 +2634,7 @@ const char *SDL_GetAndroidCachePath(void) LocalReferenceHolder_Cleanup(&refs); } - return s_AndroidCachePath; + return SDL_CreateTemporaryString(s_AndroidCachePath); } int SDL_ShowAndroidToast(const char *message, int duration, int gravity, int xOffset, int yOffset) diff --git a/src/events/SDL_keymap.c b/src/events/SDL_keymap.c index c0ab8a16a..cfa5b213e 100644 --- a/src/events/SDL_keymap.c +++ b/src/events/SDL_keymap.c @@ -945,7 +945,6 @@ int SDL_SetScancodeName(SDL_Scancode scancode, const char *name) return 0; } -// these are static memory, so we don't use SDL_FreeLater on them. const char *SDL_GetScancodeName(SDL_Scancode scancode) { const char *name; @@ -955,11 +954,10 @@ const char *SDL_GetScancodeName(SDL_Scancode scancode) } name = SDL_scancode_names[scancode]; - if (name) { - return name; + if (!name) { + name = ""; } - - return ""; + return SDL_CreateTemporaryString(name); } SDL_Scancode SDL_GetScancodeFromName(const char *name) diff --git a/src/filesystem/winrt/SDL_sysfilesystem.cpp b/src/filesystem/winrt/SDL_sysfilesystem.cpp index fce365048..04dacd55f 100644 --- a/src/filesystem/winrt/SDL_sysfilesystem.cpp +++ b/src/filesystem/winrt/SDL_sysfilesystem.cpp @@ -97,7 +97,6 @@ static const wchar_t *SDL_GetWinRTFSPathUNICODE(SDL_WinRT_Path pathType) return NULL; } -// this caches a string until the process ends, so there's no need to use SDL_FreeLater. extern "C" const char *SDL_GetWinRTFSPath(SDL_WinRT_Path pathType) { typedef unordered_map UTF8PathMap; @@ -116,7 +115,7 @@ extern "C" const char *SDL_GetWinRTFSPath(SDL_WinRT_Path pathType) char *utf8Path = WIN_StringToUTF8W(ucs2Path); utf8Paths[pathType] = utf8Path; SDL_free(utf8Path); - return utf8Paths[pathType].c_str(); + return SDL_CreateTemporaryString(utf8Paths[pathType].c_str()); } extern "C" char *SDL_SYS_GetBasePath(void) diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c index ed6d6ad0a..1f44e833a 100644 --- a/src/render/SDL_render.c +++ b/src/render/SDL_render.c @@ -799,7 +799,6 @@ int SDL_GetNumRenderDrivers(void) #endif } -// this returns string literals, so there's no need to use SDL_FreeLater. const char *SDL_GetRenderDriver(int index) { #ifndef SDL_RENDER_DISABLED @@ -808,7 +807,7 @@ const char *SDL_GetRenderDriver(int index) SDL_GetNumRenderDrivers() - 1); return NULL; } - return render_drivers[index]->name; + return SDL_CreateTemporaryString(render_drivers[index]->name); #else SDL_SetError("SDL not built with rendering support"); return NULL; diff --git a/src/video/SDL_pixels.c b/src/video/SDL_pixels.c index 903a62be9..34c0f35f7 100644 --- a/src/video/SDL_pixels.c +++ b/src/video/SDL_pixels.c @@ -88,7 +88,6 @@ SDL_COMPILE_TIME_ASSERT(SDL_expand_byte_10_size, SDL_arraysize(SDL_expand_byte_1 /* Helper functions */ -// This doesn't need SDL_FreeLater since it returns string literals. #define CASE(X) \ case X: \ return #X; diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 8f4ea4910..70c366053 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -515,11 +515,10 @@ int SDL_GetNumVideoDrivers(void) return SDL_arraysize(bootstrap) - 1; } -// this returns string literals, so there's no need to use SDL_FreeLater. const char *SDL_GetVideoDriver(int index) { if (index >= 0 && index < SDL_GetNumVideoDrivers()) { - return bootstrap[index]->name; + return SDL_CreateTemporaryString(bootstrap[index]->name); } return NULL; } @@ -657,14 +656,13 @@ pre_driver_error: return -1; } -// this returns string literals, so there's no need to use SDL_FreeLater. const char *SDL_GetCurrentVideoDriver(void) { if (!_this) { SDL_UninitializedVideo(); return NULL; } - return _this->name; + return SDL_CreateTemporaryString(_this->name); } SDL_VideoDevice *SDL_GetVideoDevice(void)