Simple Directmedia Layer
fork

Configure Feed

Select the types of activity you want to include in your feed.

Removed temporary memory from the API

It was intended to make the API easier to use, but various automatic garbage collection all had flaws, and making the application periodically clean up temporary memory added cognitive load to using the API, and in many cases was it was difficult to restructure threaded code to handle this.

So, we're largely going back to the original system, where the API returns allocated results and you free them.

In addition, to solve the problems we originally wanted temporary memory for:
* Short strings with a finite count, like device names, get stored in a per-thread string pool.
* Events continue to use temporary memory internally, which is cleaned up on the next event processing cycle.

+721 -837
+13 -25
docs/README-migration.md
··· 158 158 if (devices) { 159 159 for (i = 0; i < num_devices; ++i) { 160 160 SDL_AudioDeviceID instance_id = devices[i]; 161 - const char *name = SDL_GetAudioDeviceName(instance_id); 162 - SDL_Log("AudioDevice %" SDL_PRIu32 ": %s\n", instance_id, name); 161 + SDL_Log("AudioDevice %" SDL_PRIu32 ": %s\n", instance_id, SDL_GetAudioDeviceName(instance_id)); 163 162 } 163 + SDL_free(devices); 164 164 } 165 165 SDL_QuitSubSystem(SDL_INIT_AUDIO); 166 166 } ··· 297 297 298 298 The following symbols have been removed: 299 299 * SDL_MIX_MAXVOLUME - mixer volume is now a float between 0.0 and 1.0 300 - 301 - ## SDL_clipboard.h 302 - 303 - SDL_GetClipboardText() and SDL_GetPrimarySelectionText() return a const pointer to temporary memory, which does not need to be freed. You can use SDL_ClaimTemporaryMemory() to convert it to a non-const pointer that should be freed when you're done with it. 304 300 305 301 ## SDL_cpuinfo.h 306 302 ··· 458 454 The following enums have been renamed: 459 455 * SDL_eventaction => SDL_EventAction 460 456 461 - ## SDL_filesystem.h 462 - 463 - SDL_GetBasePath() and SDL_GetPrefPath() return a const pointer to temporary memory, which does not need to be freed. You can use SDL_ClaimTemporaryMemory() to convert it to a non-const pointer that should be freed when you're done with it. 464 - 465 457 ## SDL_gamecontroller.h 466 458 467 459 SDL_gamecontroller.h has been renamed SDL_gamepad.h, and all APIs have been renamed to match. ··· 710 702 { 711 703 if (SDL_InitSubSystem(SDL_INIT_HAPTIC) == 0) { 712 704 int i, num_haptics; 713 - const SDL_HapticID *haptics = SDL_GetHaptics(&num_haptics); 705 + SDL_HapticID *haptics = SDL_GetHaptics(&num_haptics); 714 706 if (haptics) { 715 707 for (i = 0; i < num_haptics; ++i) { 716 708 SDL_HapticID instance_id = haptics[i]; 717 - const char *name = SDL_GetHapticNameForID(instance_id); 718 - 719 - SDL_Log("Haptic %" SDL_PRIu32 ": %s\n", 720 - instance_id, name ? name : "Unknown"); 709 + SDL_Log("Haptic %" SDL_PRIu32 ": %s\n", instance_id, SDL_GetHapticNameForID(instance_id)); 721 710 } 711 + SDL_free(haptics); 722 712 } 723 713 SDL_QuitSubSystem(SDL_INIT_HAPTIC); 724 714 } ··· 840 830 { 841 831 if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0) { 842 832 int i, num_joysticks; 843 - const SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks); 833 + SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks); 844 834 if (joysticks) { 845 835 for (i = 0; i < num_joysticks; ++i) { 846 836 SDL_JoystickID instance_id = joysticks[i]; ··· 850 840 SDL_Log("Joystick %" SDL_PRIu32 ": %s%s%s VID 0x%.4x, PID 0x%.4x\n", 851 841 instance_id, name ? name : "Unknown", path ? ", " : "", path ? path : "", SDL_GetJoystickVendorForID(instance_id), SDL_GetJoystickProductForID(instance_id)); 852 842 } 843 + SDL_free(joysticks); 853 844 } 854 845 SDL_QuitSubSystem(SDL_INIT_JOYSTICK); 855 846 } ··· 1033 1024 ## SDL_loadso.h 1034 1025 1035 1026 SDL_LoadFunction() now returns `SDL_FunctionPointer` instead of `void *`, and should be cast to the appropriate function type. You can define SDL_FUNCTION_POINTER_IS_VOID_POINTER in your project to restore the previous behavior. 1036 - 1037 - ## SDL_locale.h 1038 - 1039 - SDL_GetPreferredLocales() returns a const array of locale pointers, which does not need to be freed. You can use SDL_ClaimTemporaryMemory() to convert it to a non-const pointer that should be freed when you're done with it. 1040 1027 1041 1028 ## SDL_log.h 1042 1029 ··· 1588 1575 { 1589 1576 if (SDL_InitSubSystem(SDL_INIT_SENSOR) == 0) { 1590 1577 int i, num_sensors; 1591 - const SDL_SensorID *sensors = SDL_GetSensors(&num_sensors); 1578 + SDL_SensorID *sensors = SDL_GetSensors(&num_sensors); 1592 1579 if (sensors) { 1593 1580 for (i = 0; i < num_sensors; ++i) { 1594 1581 SDL_Log("Sensor %" SDL_PRIu32 ": %s, type %d, platform type %d\n", ··· 1597 1584 SDL_GetSensorTypeForID(sensors[i]), 1598 1585 SDL_GetSensorNonPortableTypeForID(sensors[i])); 1599 1586 } 1587 + SDL_free(sensors); 1600 1588 } 1601 1589 SDL_QuitSubSystem(SDL_INIT_SENSOR); 1602 1590 } ··· 1996 1984 { 1997 1985 if (SDL_InitSubSystem(SDL_INIT_VIDEO) == 0) { 1998 1986 int i, num_displays = 0; 1999 - const SDL_DisplayID *displays = SDL_GetDisplays(&num_displays); 1987 + SDL_DisplayID *displays = SDL_GetDisplays(&num_displays); 2000 1988 if (displays) { 2001 1989 for (i = 0; i < num_displays; ++i) { 2002 1990 SDL_DisplayID instance_id = displays[i]; ··· 2004 1992 2005 1993 SDL_Log("Display %" SDL_PRIu32 ": %s\n", instance_id, name ? name : "Unknown"); 2006 1994 } 1995 + SDL_free(displays); 2007 1996 } 2008 1997 SDL_QuitSubSystem(SDL_INIT_VIDEO); 2009 1998 } ··· 2041 2030 { 2042 2031 SDL_DisplayID display = SDL_GetPrimaryDisplay(); 2043 2032 int num_modes = 0; 2044 - const SDL_DisplayMode * const *modes = SDL_GetFullscreenDisplayModes(display, &num_modes); 2033 + SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes); 2045 2034 if (modes) { 2046 2035 for (i = 0; i < num_modes; ++i) { 2047 2036 SDL_DisplayMode *mode = modes[i]; 2048 2037 SDL_Log("Display %" SDL_PRIu32 " mode %d: %dx%d@%gx %gHz\n", 2049 2038 display, i, mode->w, mode->h, mode->pixel_density, mode->refresh_rate); 2050 2039 } 2040 + SDL_free(modes); 2051 2041 } 2052 2042 } 2053 2043 ``` ··· 2079 2069 SDL_WindowFlags is used instead of Uint32 for API functions that refer to window flags, and has been extended to 64 bits. 2080 2070 2081 2071 SDL_GetWindowOpacity() directly returns the opacity instead of using an out parameter. 2082 - 2083 - SDL_GetWindowICCProfile() returns a const pointer to temporary memory, which does not need to be freed. You can use SDL_ClaimTemporaryMemory() to convert it to a non-const pointer that should be freed when you're done with it. 2084 2072 2085 2073 The following functions have been renamed: 2086 2074 * SDL_GL_DeleteContext() => SDL_GL_DestroyContext()
-52
docs/README-strings.md
··· 5 5 Unless otherwise specified, all strings in SDL, across all platforms, are 6 6 UTF-8 encoded and can represent the full range of [Unicode](https://unicode.org). 7 7 8 - 9 - ## The SDL Get String Rule. 10 - 11 - Did you see 'SDL_GetStringRule' in the wiki or headers? Here are the details 12 - that aren't worth copying across dozens of functions' documentation. 13 - 14 - tl;dr: If an SDL function returns a `const char *` string, do not modify or 15 - free it, and if you need to save it, make a copy right away. 16 - 17 - In several cases, SDL wants to return a string to the app, and the question 18 - in any library that does this is: _who owns this thing?_ 19 - 20 - The answer in almost all cases, is that SDL does, but not for long. 21 - 22 - The pointer is only guaranteed to be valid until the next time the event 23 - queue is updated, or SDL_Quit is called. 24 - 25 - The reason for this is memory safety. 26 - 27 - There are several strings that SDL provides that could be freed at 28 - any moment. For example, an app calls SDL_GetAudioDeviceName(), which returns 29 - a string that is part of the internal audio device structure. But, while this 30 - function is returning, the user yanks the USB audio device out of the 31 - computer, and SDL decides to deallocate the structure...and the string! 32 - Now the app is holding a pointer that didn't live long enough to be useful, 33 - and could crash if accessed. 34 - 35 - To avoid this, instead of calling SDL_free on a string as soon as it's done 36 - with it, SDL adds the pointer to a list. This list is freed at specific 37 - points: when the event queue is run (for ongoing cleanup) and when SDL_Quit 38 - is called (to catch things that are just hanging around). This allows the 39 - app to use a string without worrying about it becoming bogus in the middle 40 - of a printf() call. If the app needs it for longer, it should copy it. 41 - 42 - When does "the event queue run"? There are several points: 43 - 44 - - If the app calls SDL_PumpEvents() _from any thread_. 45 - - SDL_PumpEvents is also called by several other APIs internally: 46 - SDL_PollEvent(), SDL_PeepEvents(), SDL_WaitEvent(), 47 - SDL_WaitEventTimeout(), and maybe others. 48 - - If you are using [the main callbacks](main-functions#main-callbacks-in-sdl3), 49 - the event queue can run immediately after any of the callback functions 50 - return. 51 - 52 - Note that these are just guaranteed minimum lifespans; any given string 53 - might live much longer--some might even be static memory that is _never_ 54 - deallocated--but this rule promises that the app has a safe window. 55 - 56 - Note that none of this applies if the return value is `char *` instead of 57 - `const char *`. Please see the specific function's documentation for how 58 - to handle those pointers. 59 -
-39
docs/README-winrt.md
··· 95 95 96 96 97 97 98 - Upgrade Notes 99 - ------------- 100 - 101 - #### SDL_GetPrefPath() usage when upgrading WinRT apps from SDL 2.0.3 102 - 103 - SDL 2.0.4 fixes two bugs found in the WinRT version of SDL_GetPrefPath(). 104 - The fixes may affect older, SDL 2.0.3-based apps' save data. Please note 105 - that these changes only apply to SDL-based WinRT apps, and not to apps for 106 - any other platform. 107 - 108 - 1. SDL_GetPrefPath() would return an invalid path, one in which the path's 109 - directory had not been created. Attempts to create files there 110 - (via fopen(), for example), would fail, unless that directory was 111 - explicitly created beforehand. 112 - 113 - 2. SDL_GetPrefPath(), for non-WinPhone-based apps, would return a path inside 114 - a WinRT 'Roaming' folder, the contents of which get automatically 115 - synchronized across multiple devices. This process can occur while an 116 - application runs, and can cause existing save-data to be overwritten 117 - at unexpected times, with data from other devices. (Windows Phone apps 118 - written with SDL 2.0.3 did not utilize a Roaming folder, due to API 119 - restrictions in Windows Phone 8.0). 120 - 121 - 122 - SDL_GetPrefPath(), starting with SDL 2.0.4, addresses these by: 123 - 124 - 1. making sure that SDL_GetPrefPath() returns a directory in which data 125 - can be written to immediately, without first needing to create directories. 126 - 127 - 2. basing SDL_GetPrefPath() off of a different, non-Roaming folder, the 128 - contents of which do not automatically get synchronized across devices 129 - (and which require less work to use safely, in terms of data integrity). 130 - 131 - Apps that wish to get their Roaming folder's path can do so either by using 132 - SDL_GetWinRTFSPath(), or directly through the WinRT class, 133 - Windows.Storage.ApplicationData. 134 - 135 - 136 - 137 98 Setup, High-Level Steps 138 99 ----------------------- 139 100
+13 -13
include/SDL3/SDL_audio.h
··· 411 411 * 412 412 * \sa SDL_GetNumAudioDrivers 413 413 */ 414 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetAudioDriver(int index); 414 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetAudioDriver(int index); 415 415 /* @} */ 416 416 417 417 /** ··· 428 428 * 429 429 * \since This function is available since SDL 3.0.0. 430 430 */ 431 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetCurrentAudioDriver(void); 431 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentAudioDriver(void); 432 432 433 433 /** 434 434 * Get a list of currently-connected audio playback devices. ··· 447 447 * \param count a pointer filled in with the number of devices returned, may 448 448 * be NULL. 449 449 * \returns a 0 terminated array of device instance IDs or NULL on error; call 450 - * SDL_GetError() for more information. 450 + * SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed. 451 451 * 452 452 * \threadsafety It is safe to call this function from any thread. 453 453 * ··· 456 456 * \sa SDL_OpenAudioDevice 457 457 * \sa SDL_GetAudioRecordingDevices 458 458 */ 459 - extern SDL_DECLSPEC_TEMP const SDL_AudioDeviceID * SDLCALL SDL_GetAudioPlaybackDevices(int *count); 459 + extern SDL_DECLSPEC_FREE SDL_AudioDeviceID * SDLCALL SDL_GetAudioPlaybackDevices(int *count); 460 460 461 461 /** 462 462 * Get a list of currently-connected audio recording devices. ··· 475 475 * \param count a pointer filled in with the number of devices returned, may 476 476 * be NULL. 477 477 * \returns a 0 terminated array of device instance IDs, or NULL on failure; 478 - * call SDL_GetError() for more information. 478 + * call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed. 479 479 * 480 480 * \threadsafety It is safe to call this function from any thread. 481 481 * ··· 484 484 * \sa SDL_OpenAudioDevice 485 485 * \sa SDL_GetAudioPlaybackDevices 486 486 */ 487 - extern SDL_DECLSPEC_TEMP const SDL_AudioDeviceID * SDLCALL SDL_GetAudioRecordingDevices(int *count); 487 + extern SDL_DECLSPEC_FREE SDL_AudioDeviceID * SDLCALL SDL_GetAudioRecordingDevices(int *count); 488 488 489 489 /** 490 490 * Get the human-readable name of a specific audio device. ··· 501 501 * \sa SDL_GetAudioRecordingDevices 502 502 * \sa SDL_GetDefaultAudioInfo 503 503 */ 504 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetAudioDeviceName(SDL_AudioDeviceID devid); 504 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetAudioDeviceName(SDL_AudioDeviceID devid); 505 505 506 506 /** 507 507 * Get the current audio format of a specific audio device. ··· 550 550 * \param devid the instance ID of the device to query. 551 551 * \param count On output, set to number of channels in the map. Can be NULL. 552 552 * \returns an array of the current channel mapping, with as many elements as 553 - * the current output spec's channels, or NULL if default. 553 + * the current output spec's channels, or NULL if default. This should be freed with SDL_free() when it is no longer needed. 554 554 * 555 555 * \threadsafety It is safe to call this function from any thread. 556 556 * ··· 558 558 * 559 559 * \sa SDL_SetAudioStreamInputChannelMap 560 560 */ 561 - extern SDL_DECLSPEC_TEMP const int * SDLCALL SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int *count); 561 + extern SDL_DECLSPEC_FREE int * SDLCALL SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int *count); 562 562 563 563 /** 564 564 * Open a specific audio device. ··· 1098 1098 * \param stream the SDL_AudioStream to query. 1099 1099 * \param count On output, set to number of channels in the map. Can be NULL. 1100 1100 * \returns an array of the current channel mapping, with as many elements as 1101 - * the current output spec's channels, or NULL if default. 1101 + * the current output spec's channels, or NULL if default. This should be freed with SDL_free() when it is no longer needed. 1102 1102 * 1103 1103 * \threadsafety It is safe to call this function from any thread, as it holds 1104 1104 * a stream-specific mutex while running. ··· 1107 1107 * 1108 1108 * \sa SDL_SetAudioStreamInputChannelMap 1109 1109 */ 1110 - extern SDL_DECLSPEC_TEMP const int * SDLCALL SDL_GetAudioStreamInputChannelMap(SDL_AudioStream *stream, int *count); 1110 + extern SDL_DECLSPEC_FREE int * SDLCALL SDL_GetAudioStreamInputChannelMap(SDL_AudioStream *stream, int *count); 1111 1111 1112 1112 /** 1113 1113 * Get the current output channel map of an audio stream. ··· 1121 1121 * \param stream the SDL_AudioStream to query. 1122 1122 * \param count On output, set to number of channels in the map. Can be NULL. 1123 1123 * \returns an array of the current channel mapping, with as many elements as 1124 - * the current output spec's channels, or NULL if default. 1124 + * the current output spec's channels, or NULL if default. This should be freed with SDL_free() when it is no longer needed. 1125 1125 * 1126 1126 * \threadsafety It is safe to call this function from any thread, as it holds 1127 1127 * a stream-specific mutex while running. ··· 1130 1130 * 1131 1131 * \sa SDL_SetAudioStreamInputChannelMap 1132 1132 */ 1133 - extern SDL_DECLSPEC_TEMP const int * SDLCALL SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream *stream, int *count); 1133 + extern SDL_DECLSPEC_FREE int * SDLCALL SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream *stream, int *count); 1134 1134 1135 1135 /** 1136 1136 * Set the current input channel map of an audio stream.
+5 -2
include/SDL3/SDL_begin_code.h
··· 67 67 # endif 68 68 # endif 69 69 #endif 70 - /* This is used to mark functions that return temporary memory */ 71 - #define SDL_DECLSPEC_TEMP SDL_DECLSPEC 70 + 71 + /* This is used to mark functions that return memory that need to be freed with SDL_free() */ 72 + #ifndef SDL_DECLSPEC_FREE 73 + #define SDL_DECLSPEC_FREE SDL_DECLSPEC 74 + #endif 72 75 73 76 /* By default SDL uses the C calling convention */ 74 77 #ifndef SDLCALL
+7 -7
include/SDL3/SDL_camera.h
··· 145 145 * 146 146 * \sa SDL_GetNumCameraDrivers 147 147 */ 148 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetCameraDriver(int index); 148 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetCameraDriver(int index); 149 149 150 150 /** 151 151 * Get the name of the current camera driver. ··· 161 161 * 162 162 * \since This function is available since SDL 3.0.0. 163 163 */ 164 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetCurrentCameraDriver(void); 164 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentCameraDriver(void); 165 165 166 166 /** 167 167 * Get a list of currently connected camera devices. ··· 169 169 * \param count a pointer filled in with the number of cameras returned, may 170 170 * be NULL. 171 171 * \returns a 0 terminated array of camera instance IDs or NULL on failure; 172 - * call SDL_GetError() for more information. 172 + * call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed. 173 173 * 174 174 * \threadsafety It is safe to call this function from any thread. 175 175 * ··· 177 177 * 178 178 * \sa SDL_OpenCamera 179 179 */ 180 - extern SDL_DECLSPEC_TEMP const SDL_CameraID * SDLCALL SDL_GetCameras(int *count); 180 + extern SDL_DECLSPEC_FREE SDL_CameraID * SDLCALL SDL_GetCameras(int *count); 181 181 182 182 /** 183 183 * Get the list of native formats/sizes a camera supports. ··· 205 205 * \param count a pointer filled in with the number of elements in the list, 206 206 * may be NULL. 207 207 * \returns a NULL terminated array of pointers to SDL_CameraSpec or NULL on 208 - * failure; call SDL_GetError() for more information. 208 + * failure; call SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed. 209 209 * 210 210 * \threadsafety It is safe to call this function from any thread. 211 211 * ··· 214 214 * \sa SDL_GetCameras 215 215 * \sa SDL_OpenCamera 216 216 */ 217 - extern SDL_DECLSPEC_TEMP const SDL_CameraSpec * const * SDLCALL SDL_GetCameraSupportedFormats(SDL_CameraID devid, int *count); 217 + extern SDL_DECLSPEC_FREE SDL_CameraSpec ** SDLCALL SDL_GetCameraSupportedFormats(SDL_CameraID devid, int *count); 218 218 219 219 /** 220 220 * Get the human-readable device name for a camera. ··· 229 229 * 230 230 * \sa SDL_GetCameras 231 231 */ 232 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetCameraName(SDL_CameraID instance_id); 232 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetCameraName(SDL_CameraID instance_id); 233 233 234 234 /** 235 235 * Get the position of the camera in relation to the system.
+6 -6
include/SDL3/SDL_clipboard.h
··· 63 63 * a copy of the clipboard's content. 64 64 * 65 65 * \returns the clipboard text on success or an empty string on failure; call 66 - * SDL_GetError() for more information. 66 + * SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed. 67 67 * 68 68 * \since This function is available since SDL 3.0.0. 69 69 * 70 70 * \sa SDL_HasClipboardText 71 71 * \sa SDL_SetClipboardText 72 72 */ 73 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetClipboardText(void); 73 + extern SDL_DECLSPEC_FREE char * SDLCALL SDL_GetClipboardText(void); 74 74 75 75 /** 76 76 * Query whether the clipboard exists and contains a non-empty text string. ··· 105 105 * a copy of the primary selection's content. 106 106 * 107 107 * \returns the primary selection text on success or an empty string on 108 - * failure; call SDL_GetError() for more information. 108 + * failure; call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed. 109 109 * 110 110 * \since This function is available since SDL 3.0.0. 111 111 * 112 112 * \sa SDL_HasPrimarySelectionText 113 113 * \sa SDL_SetPrimarySelectionText 114 114 */ 115 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetPrimarySelectionText(void); 115 + extern SDL_DECLSPEC_FREE char * SDLCALL SDL_GetPrimarySelectionText(void); 116 116 117 117 /** 118 118 * Query whether the primary selection exists and contains a non-empty text ··· 215 215 * \param mime_type the mime type to read from the clipboard. 216 216 * \param size a pointer filled in with the length of the returned data. 217 217 * \returns the retrieved data buffer or NULL on failure; call SDL_GetError() 218 - * for more information. 218 + * for more information. This should be freed with SDL_free() when it is no longer needed. 219 219 * 220 220 * \since This function is available since SDL 3.0.0. 221 221 * 222 222 * \sa SDL_HasClipboardData 223 223 * \sa SDL_SetClipboardData 224 224 */ 225 - extern SDL_DECLSPEC_TEMP const void * SDLCALL SDL_GetClipboardData(const char *mime_type, size_t *size); 225 + extern SDL_DECLSPEC_FREE void * SDLCALL SDL_GetClipboardData(const char *mime_type, size_t *size); 226 226 227 227 /** 228 228 * Query whether there is data in the clipboard for the provided mime type.
-79
include/SDL3/SDL_events.h
··· 352 352 * will be inserted into the editing text. The length is the number of UTF-8 353 353 * characters that will be replaced by new typing. 354 354 * 355 - * The text string is temporary memory which will be freed in 356 - * SDL_FreeTemporaryMemory() and can be claimed with 357 - * SDL_ClaimTemporaryMemory(). 358 - * 359 355 * \since This struct is available since SDL 3.0.0. 360 356 */ 361 357 typedef struct SDL_TextEditingEvent ··· 372 368 /** 373 369 * Keyboard IME candidates event structure (event.edit_candidates.*) 374 370 * 375 - * The candidates are a single allocation of temporary memory which will be 376 - * freed in SDL_FreeTemporaryMemory() and can be claimed with 377 - * SDL_ClaimTemporaryMemory(). 378 - * 379 371 * \since This struct is available since SDL 3.0.0. 380 372 */ 381 373 typedef struct SDL_TextEditingCandidatesEvent ··· 392 384 393 385 /** 394 386 * Keyboard text input event structure (event.text.*) 395 - * 396 - * The text string is temporary memory which will be freed in 397 - * SDL_FreeTemporaryMemory() and can be claimed with 398 - * SDL_ClaimTemporaryMemory(). 399 387 * 400 388 * This event will never be delivered unless text input is enabled by calling 401 389 * SDL_StartTextInput(). Text input is disabled by default! ··· 792 780 * An event used to drop text or request a file open by the system 793 781 * (event.drop.*) 794 782 * 795 - * The source and data strings are temporary memory which will be freed in 796 - * SDL_FreeTemporaryMemory() and can be claimed with 797 - * SDL_ClaimTemporaryMemory(). 798 - * 799 783 * \since This struct is available since SDL 3.0.0. 800 784 */ 801 785 typedef struct SDL_DropEvent ··· 858 842 * SDL_PushEvent(). The contents of the structure members are completely up to 859 843 * the programmer; the only requirement is that '''type''' is a value obtained 860 844 * from SDL_RegisterEvents(). 861 - * 862 - * If the data pointers are temporary memory, they will be automatically 863 - * transfered to the thread that pulls the event from the queue, or freed if 864 - * the event is flushed. 865 845 * 866 846 * \since This struct is available since SDL 3.0.0. 867 847 */ ··· 1420 1400 */ 1421 1401 extern SDL_DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents); 1422 1402 1423 - /** 1424 - * Allocate temporary memory. 1425 - * 1426 - * You can use this to allocate memory from the temporary memory pool for the 1427 - * current thread. 1428 - * 1429 - * \param size the amount of memory to allocate. 1430 - * \returns a pointer to the memory allocated or NULL on failure; call 1431 - * SDL_GetError() for more information. 1432 - * 1433 - * \threadsafety It is safe to call this function from any thread. 1434 - * 1435 - * \since This function is available since SDL 3.0.0. 1436 - * 1437 - * \sa SDL_ClaimTemporaryMemory 1438 - * \sa SDL_FreeTemporaryMemory 1439 - */ 1440 - extern SDL_DECLSPEC void * SDLCALL SDL_AllocateTemporaryMemory(size_t size); 1441 - 1442 - /** 1443 - * Claim ownership of temporary memory. 1444 - * 1445 - * This function removes memory from the temporary memory pool for the current 1446 - * thread and gives ownership to the application. The application should use 1447 - * SDL_free() to free it when it is done using it. 1448 - * 1449 - * \param mem a pointer allocated with SDL_AllocateTemporaryMemory(). 1450 - * \returns a pointer to the memory now owned by the application, which must 1451 - * be freed using SDL_free(), or NULL if the memory is not in the 1452 - * temporary memory pool for the current thread. 1453 - * 1454 - * \threadsafety It is safe to call this function from any thread. 1455 - * 1456 - * \since This function is available since SDL 3.0.0. 1457 - * 1458 - * \sa SDL_AllocateTemporaryMemory 1459 - * \sa SDL_free 1460 - */ 1461 - extern SDL_DECLSPEC void * SDLCALL SDL_ClaimTemporaryMemory(const void *mem); 1462 - 1463 - /** 1464 - * Free temporary memory for the current thread. 1465 - * 1466 - * This function frees all temporary memory for the current thread. If you 1467 - * would like to hold onto a specific pointer beyond this call, you should 1468 - * call SDL_ClaimTemporaryMemory() to move it out of the temporary memory 1469 - * pool. 1470 - * 1471 - * This function is automatically called in SDL_Quit() on the main thread and 1472 - * in SDL_CleanupTLS() when other threads complete. 1473 - * 1474 - * \threadsafety It is safe to call this function from any thread. 1475 - * 1476 - * \since This function is available since SDL 3.0.0. 1477 - * 1478 - * \sa SDL_AllocateTemporaryMemory 1479 - * \sa SDL_ClaimTemporaryMemory 1480 - */ 1481 - extern SDL_DECLSPEC void SDLCALL SDL_FreeTemporaryMemory(void); 1482 1403 1483 1404 /* Ends C function definitions when using C++ */ 1484 1405 #ifdef __cplusplus
+6 -6
include/SDL3/SDL_filesystem.h
··· 77 77 * 78 78 * \sa SDL_GetPrefPath 79 79 */ 80 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetBasePath(void); 80 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetBasePath(void); 81 81 82 82 /** 83 83 * Get the user-and-app-specific path where files can be written. ··· 125 125 * \param app the name of your application. 126 126 * \returns a UTF-8 string of the user directory in platform-dependent 127 127 * notation. NULL if there's a problem (creating directory failed, 128 - * etc.). 128 + * etc.). This should be freed with SDL_free() when it is no longer needed. 129 129 * 130 130 * \since This function is available since SDL 3.0.0. 131 131 * 132 132 * \sa SDL_GetBasePath 133 133 */ 134 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetPrefPath(const char *org, const char *app); 134 + extern SDL_DECLSPEC_FREE char * SDLCALL SDL_GetPrefPath(const char *org, const char *app); 135 135 136 136 /** 137 137 * The type of the OS-provided default folder for a specific purpose. ··· 227 227 * 228 228 * \since This function is available since SDL 3.0.0. 229 229 */ 230 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetUserFolder(SDL_Folder folder); 230 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetUserFolder(SDL_Folder folder); 231 231 232 232 233 233 /* Abstract filesystem interface */ ··· 367 367 * \param count on return, will be set to the number of items in the returned 368 368 * array. Can be NULL. 369 369 * \returns an array of strings on success or NULL on failure; call 370 - * SDL_GetError() for more information. 370 + * SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed. 371 371 * 372 372 * \threadsafety It is safe to call this function from any thread. 373 373 * 374 374 * \since This function is available since SDL 3.0.0. 375 375 */ 376 - extern SDL_DECLSPEC_TEMP const char * const * SDLCALL SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count); 376 + extern SDL_DECLSPEC_FREE char ** SDLCALL SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count); 377 377 378 378 /* Ends C function definitions when using C++ */ 379 379 #ifdef __cplusplus
+22 -22
include/SDL3/SDL_gamepad.h
··· 392 392 * \param count a pointer filled in with the number of mappings returned, can 393 393 * be NULL. 394 394 * \returns an array of the mapping strings, NULL-terminated, or NULL on 395 - * failure; call SDL_GetError() for more information. 395 + * failure; call SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed. 396 396 * 397 397 * \since This function is available since SDL 3.0.0. 398 398 */ 399 - extern SDL_DECLSPEC_TEMP const char * const * SDLCALL SDL_GetGamepadMappings(int *count); 399 + extern SDL_DECLSPEC_FREE char ** SDLCALL SDL_GetGamepadMappings(int *count); 400 400 401 401 /** 402 402 * Get the gamepad mapping string for a given GUID. 403 403 * 404 404 * \param guid a structure containing the GUID for which a mapping is desired. 405 405 * \returns a mapping string or NULL on failure; call SDL_GetError() for more 406 - * information. 406 + * information. This should be freed with SDL_free() when it is no longer needed. 407 407 * 408 408 * \since This function is available since SDL 3.0.0. 409 409 * 410 410 * \sa SDL_GetJoystickGUIDForID 411 411 * \sa SDL_GetJoystickGUID 412 412 */ 413 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_GUID guid); 413 + extern SDL_DECLSPEC_FREE char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_GUID guid); 414 414 415 415 /** 416 416 * Get the current mapping of a gamepad. ··· 419 419 * 420 420 * \param gamepad the gamepad you want to get the current mapping for. 421 421 * \returns a string that has the gamepad's mapping or NULL if no mapping is 422 - * available; call SDL_GetError() for more information. 422 + * available; call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed. 423 423 * 424 424 * \since This function is available since SDL 3.0.0. 425 425 * ··· 428 428 * \sa SDL_GetGamepadMappingForGUID 429 429 * \sa SDL_SetGamepadMapping 430 430 */ 431 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad); 431 + extern SDL_DECLSPEC_FREE char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad); 432 432 433 433 /** 434 434 * Set the current mapping of a joystick or gamepad. ··· 465 465 * \param count a pointer filled in with the number of gamepads returned, may 466 466 * be NULL. 467 467 * \returns a 0 terminated array of joystick instance IDs or NULL on failure; 468 - * call SDL_GetError() for more information. 468 + * call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed. 469 469 * 470 470 * \since This function is available since SDL 3.0.0. 471 471 * 472 472 * \sa SDL_HasGamepad 473 473 * \sa SDL_OpenGamepad 474 474 */ 475 - extern SDL_DECLSPEC_TEMP const SDL_JoystickID * SDLCALL SDL_GetGamepads(int *count); 475 + extern SDL_DECLSPEC_FREE SDL_JoystickID * SDLCALL SDL_GetGamepads(int *count); 476 476 477 477 /** 478 478 * Check if the given joystick is supported by the gamepad interface. ··· 502 502 * \sa SDL_GetGamepadName 503 503 * \sa SDL_GetGamepads 504 504 */ 505 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadNameForID(SDL_JoystickID instance_id); 505 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadNameForID(SDL_JoystickID instance_id); 506 506 507 507 /** 508 508 * Get the implementation dependent path of a gamepad. ··· 518 518 * \sa SDL_GetGamepadPath 519 519 * \sa SDL_GetGamepads 520 520 */ 521 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadPathForID(SDL_JoystickID instance_id); 521 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadPathForID(SDL_JoystickID instance_id); 522 522 523 523 /** 524 524 * Get the player index of a gamepad. ··· 640 640 * This can be called before any gamepads are opened. 641 641 * 642 642 * \param instance_id the joystick instance ID. 643 - * \returns the mapping string. Returns NULL if no mapping is available. 643 + * \returns the mapping string. Returns NULL if no mapping is available. This should be freed with SDL_free() when it is no longer needed. 644 644 * 645 645 * \since This function is available since SDL 3.0.0. 646 646 * 647 647 * \sa SDL_GetGamepads 648 648 * \sa SDL_GetGamepadMapping 649 649 */ 650 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadMappingForID(SDL_JoystickID instance_id); 650 + extern SDL_DECLSPEC_FREE char * SDLCALL SDL_GetGamepadMappingForID(SDL_JoystickID instance_id); 651 651 652 652 /** 653 653 * Open a gamepad for use. ··· 745 745 * 746 746 * \sa SDL_GetGamepadNameForID 747 747 */ 748 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadName(SDL_Gamepad *gamepad); 748 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadName(SDL_Gamepad *gamepad); 749 749 750 750 /** 751 751 * Get the implementation-dependent path for an opened gamepad. ··· 759 759 * 760 760 * \sa SDL_GetGamepadPathForID 761 761 */ 762 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadPath(SDL_Gamepad *gamepad); 762 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadPath(SDL_Gamepad *gamepad); 763 763 764 764 /** 765 765 * Get the type of an opened gamepad. ··· 880 880 * 881 881 * \since This function is available since SDL 3.0.0. 882 882 */ 883 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad); 883 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad); 884 884 885 885 /** 886 886 * Get the Steam Input handle of an opened gamepad, if available. ··· 995 995 * \param gamepad a gamepad. 996 996 * \param count a pointer filled in with the number of bindings returned. 997 997 * \returns a NULL terminated array of pointers to bindings or NULL on 998 - * failure; call SDL_GetError() for more information. 998 + * failure; call SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed. 999 999 * 1000 1000 * \since This function is available since SDL 3.0.0. 1001 1001 */ 1002 - extern SDL_DECLSPEC_TEMP const SDL_GamepadBinding * const * SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count); 1002 + extern SDL_DECLSPEC_FREE SDL_GamepadBinding ** SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count); 1003 1003 1004 1004 /** 1005 1005 * Manually pump gamepad updates if not using the loop. ··· 1042 1042 * 1043 1043 * \sa SDL_GetGamepadTypeFromString 1044 1044 */ 1045 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadStringForType(SDL_GamepadType type); 1045 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForType(SDL_GamepadType type); 1046 1046 1047 1047 /** 1048 1048 * Convert a string into SDL_GamepadAxis enum. ··· 1078 1078 * 1079 1079 * \sa SDL_GetGamepadAxisFromString 1080 1080 */ 1081 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis); 1081 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis); 1082 1082 1083 1083 /** 1084 1084 * Query whether a gamepad has a given axis. ··· 1151 1151 * 1152 1152 * \sa SDL_GetGamepadButtonFromString 1153 1153 */ 1154 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadStringForButton(SDL_GamepadButton button); 1154 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForButton(SDL_GamepadButton button); 1155 1155 1156 1156 /** 1157 1157 * Query whether a gamepad has a given button. ··· 1436 1436 * 1437 1437 * \sa SDL_GetGamepadAppleSFSymbolsNameForAxis 1438 1438 */ 1439 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button); 1439 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button); 1440 1440 1441 1441 /** 1442 1442 * Return the sfSymbolsName for a given axis on a gamepad on Apple platforms. ··· 1449 1449 * 1450 1450 * \sa SDL_GetGamepadAppleSFSymbolsNameForButton 1451 1451 */ 1452 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis); 1452 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis); 1453 1453 1454 1454 1455 1455 /* Ends C function definitions when using C++ */
+3 -3
include/SDL3/SDL_guid.h
··· 67 67 * Get an ASCII string representation for a given SDL_GUID. 68 68 * 69 69 * \param guid the SDL_GUID you wish to convert to string. 70 - * \returns the string representation of the GUID or NULL on failure; call 71 - * SDL_GetError() for more information. 70 + * \param pszGUID buffer in which to write the ASCII string. 71 + * \param cbGUID the size of pszGUID, should be at least 33 bytes. 72 72 * 73 73 * \since This function is available since SDL 3.0.0. 74 74 * 75 75 * \sa SDL_StringToGUID 76 76 */ 77 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GUIDToString(SDL_GUID guid); 77 + extern SDL_DECLSPEC void SDLCALL SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID); 78 78 79 79 /** 80 80 * Convert a GUID string into a SDL_GUID structure.
+5 -4
include/SDL3/SDL_haptic.h
··· 45 45 * SDL_HapticID *haptics = SDL_GetHaptics(NULL); 46 46 * if (haptics) { 47 47 * haptic = SDL_OpenHaptic(haptics[0]); 48 + * SDL_free(haptics); 48 49 * } 49 50 * if (haptic == NULL) 50 51 * return -1; ··· 934 935 * \param count a pointer filled in with the number of haptic devices 935 936 * returned, may be NULL. 936 937 * \returns a 0 terminated array of haptic device instance IDs or NULL on 937 - * failure; call SDL_GetError() for more information. 938 + * failure; call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed. 938 939 * 939 940 * \since This function is available since SDL 3.0.0. 940 941 * 941 942 * \sa SDL_OpenHaptic 942 943 */ 943 - extern SDL_DECLSPEC_TEMP const SDL_HapticID * SDLCALL SDL_GetHaptics(int *count); 944 + extern SDL_DECLSPEC_FREE SDL_HapticID * SDLCALL SDL_GetHaptics(int *count); 944 945 945 946 /** 946 947 * Get the implementation dependent name of a haptic device. ··· 957 958 * \sa SDL_GetHapticName 958 959 * \sa SDL_OpenHaptic 959 960 */ 960 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetHapticNameForID(SDL_HapticID instance_id); 961 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetHapticNameForID(SDL_HapticID instance_id); 961 962 962 963 /** 963 964 * Open a haptic device for use. ··· 1019 1020 * 1020 1021 * \sa SDL_GetHapticNameForID 1021 1022 */ 1022 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetHapticName(SDL_Haptic *haptic); 1023 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetHapticName(SDL_Haptic *haptic); 1023 1024 1024 1025 /** 1025 1026 * Query whether or not the current mouse has haptic capabilities.
+1 -1
include/SDL3/SDL_hints.h
··· 3880 3880 * \sa SDL_SetHint 3881 3881 * \sa SDL_SetHintWithPriority 3882 3882 */ 3883 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetHint(const char *name); 3883 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetHint(const char *name); 3884 3884 3885 3885 /** 3886 3886 * Get the boolean value of a hint variable.
+7 -7
include/SDL3/SDL_joystick.h
··· 204 204 * \param count a pointer filled in with the number of joysticks returned, may 205 205 * be NULL. 206 206 * \returns a 0 terminated array of joystick instance IDs or NULL on failure; 207 - * call SDL_GetError() for more information. 207 + * call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed. 208 208 * 209 209 * \since This function is available since SDL 3.0.0. 210 210 * 211 211 * \sa SDL_HasJoystick 212 212 * \sa SDL_OpenJoystick 213 213 */ 214 - extern SDL_DECLSPEC_TEMP const SDL_JoystickID * SDLCALL SDL_GetJoysticks(int *count); 214 + extern SDL_DECLSPEC_FREE SDL_JoystickID * SDLCALL SDL_GetJoysticks(int *count); 215 215 216 216 /** 217 217 * Get the implementation dependent name of a joystick. ··· 227 227 * \sa SDL_GetJoystickName 228 228 * \sa SDL_GetJoysticks 229 229 */ 230 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetJoystickNameForID(SDL_JoystickID instance_id); 230 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickNameForID(SDL_JoystickID instance_id); 231 231 232 232 /** 233 233 * Get the implementation dependent path of a joystick. ··· 243 243 * \sa SDL_GetJoystickPath 244 244 * \sa SDL_GetJoysticks 245 245 */ 246 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetJoystickPathForID(SDL_JoystickID instance_id); 246 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPathForID(SDL_JoystickID instance_id); 247 247 248 248 /** 249 249 * Get the player index of a joystick. ··· 661 661 * 662 662 * \sa SDL_GetJoystickNameForID 663 663 */ 664 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetJoystickName(SDL_Joystick *joystick); 664 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickName(SDL_Joystick *joystick); 665 665 666 666 /** 667 667 * Get the implementation dependent path of a joystick. ··· 674 674 * 675 675 * \sa SDL_GetJoystickPathForID 676 676 */ 677 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetJoystickPath(SDL_Joystick *joystick); 677 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPath(SDL_Joystick *joystick); 678 678 679 679 /** 680 680 * Get the player index of an opened joystick. ··· 789 789 * 790 790 * \since This function is available since SDL 3.0.0. 791 791 */ 792 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joystick); 792 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joystick); 793 793 794 794 /** 795 795 * Get the type of an opened joystick.
+5 -5
include/SDL3/SDL_keyboard.h
··· 76 76 * \param count a pointer filled in with the number of keyboards returned, may 77 77 * be NULL. 78 78 * \returns a 0 terminated array of keyboards instance IDs or NULL on failure; 79 - * call SDL_GetError() for more information. 79 + * call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed. 80 80 * 81 81 * \since This function is available since SDL 3.0.0. 82 82 * 83 83 * \sa SDL_GetKeyboardNameForID 84 84 * \sa SDL_HasKeyboard 85 85 */ 86 - extern SDL_DECLSPEC_TEMP const SDL_KeyboardID * SDLCALL SDL_GetKeyboards(int *count); 86 + extern SDL_DECLSPEC_FREE SDL_KeyboardID * SDLCALL SDL_GetKeyboards(int *count); 87 87 88 88 /** 89 89 * Get the name of a keyboard. ··· 98 98 * 99 99 * \sa SDL_GetKeyboards 100 100 */ 101 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetKeyboardNameForID(SDL_KeyboardID instance_id); 101 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetKeyboardNameForID(SDL_KeyboardID instance_id); 102 102 103 103 /** 104 104 * Query the window which currently has keyboard focus. ··· 297 297 * \sa SDL_GetScancodeFromName 298 298 * \sa SDL_SetScancodeName 299 299 */ 300 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetScancodeName(SDL_Scancode scancode); 300 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetScancodeName(SDL_Scancode scancode); 301 301 302 302 /** 303 303 * Get a scancode from a human-readable name. ··· 331 331 * \sa SDL_GetKeyFromScancode 332 332 * \sa SDL_GetScancodeFromKey 333 333 */ 334 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetKeyName(SDL_Keycode key); 334 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetKeyName(SDL_Keycode key); 335 335 336 336 /** 337 337 * Get a key code from a human-readable name.
+2 -2
include/SDL3/SDL_locale.h
··· 92 92 * \param count a pointer filled in with the number of locales returned, may 93 93 * be NULL. 94 94 * \returns a NULL terminated array of locale pointers, or NULL on failure; 95 - * call SDL_GetError() for more information. 95 + * call SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed. 96 96 * 97 97 * \since This function is available since SDL 3.0.0. 98 98 */ 99 - extern SDL_DECLSPEC_TEMP const SDL_Locale * const * SDLCALL SDL_GetPreferredLocales(int *count); 99 + extern SDL_DECLSPEC_FREE SDL_Locale ** SDLCALL SDL_GetPreferredLocales(int *count); 100 100 101 101 /* Ends C function definitions when using C++ */ 102 102 #ifdef __cplusplus
+3 -3
include/SDL3/SDL_mouse.h
··· 138 138 * \param count a pointer filled in with the number of mice returned, may be 139 139 * NULL. 140 140 * \returns a 0 terminated array of mouse instance IDs or NULL on failure; 141 - * call SDL_GetError() for more information. 141 + * call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed. 142 142 * 143 143 * \since This function is available since SDL 3.0.0. 144 144 * 145 145 * \sa SDL_GetMouseNameForID 146 146 * \sa SDL_HasMouse 147 147 */ 148 - extern SDL_DECLSPEC_TEMP const SDL_MouseID * SDLCALL SDL_GetMice(int *count); 148 + extern SDL_DECLSPEC_FREE SDL_MouseID * SDLCALL SDL_GetMice(int *count); 149 149 150 150 /** 151 151 * Get the name of a mouse. ··· 160 160 * 161 161 * \sa SDL_GetMice 162 162 */ 163 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetMouseNameForID(SDL_MouseID instance_id); 163 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetMouseNameForID(SDL_MouseID instance_id); 164 164 165 165 /** 166 166 * Get the window which currently has mouse focus.
+1 -1
include/SDL3/SDL_pen.h
··· 235 235 * 236 236 * \since This function is available since SDL 3.0.0. 237 237 */ 238 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetPenName(SDL_PenID instance_id); 238 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetPenName(SDL_PenID instance_id); 239 239 240 240 /** 241 241 * Pen capabilities, as reported by SDL_GetPenCapabilities()
+7 -2
include/SDL3/SDL_properties.h
··· 384 384 * \returns the value of the property, or `default_value` if it is not set or 385 385 * not a string property. 386 386 * 387 - * \threadsafety It is safe to call this function from any thread. 387 + * \threadsafety It is safe to call this function from any thread, although 388 + * the data returned is not protected and could potentially be 389 + * freed if you call SDL_SetStringProperty() or 390 + * SDL_ClearProperty() on these properties from another thread. 391 + * If you need to avoid this, use SDL_LockProperties() and 392 + * SDL_UnlockProperties(). 388 393 * 389 394 * \since This function is available since SDL 3.0.0. 390 395 * ··· 392 397 * \sa SDL_HasProperty 393 398 * \sa SDL_SetStringProperty 394 399 */ 395 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetStringProperty(SDL_PropertiesID props, const char *name, const char *default_value); 400 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetStringProperty(SDL_PropertiesID props, const char *name, const char *default_value); 396 401 397 402 /** 398 403 * Get a number property from a group of properties.
+2 -2
include/SDL3/SDL_render.h
··· 163 163 * 164 164 * \sa SDL_GetNumRenderDrivers 165 165 */ 166 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetRenderDriver(int index); 166 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetRenderDriver(int index); 167 167 168 168 /** 169 169 * Create a window and default renderer. ··· 331 331 * \sa SDL_CreateRenderer 332 332 * \sa SDL_CreateRendererWithProperties 333 333 */ 334 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetRendererName(SDL_Renderer *renderer); 334 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetRendererName(SDL_Renderer *renderer); 335 335 336 336 /** 337 337 * Get the properties associated with a renderer.
+4 -4
include/SDL3/SDL_sensor.h
··· 149 149 * \param count a pointer filled in with the number of sensors returned, may 150 150 * be NULL. 151 151 * \returns a 0 terminated array of sensor instance IDs or NULL on failure; 152 - * call SDL_GetError() for more information. 152 + * call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed. 153 153 * 154 154 * \since This function is available since SDL 3.0.0. 155 155 */ 156 - extern SDL_DECLSPEC const SDL_SensorID * SDLCALL SDL_GetSensors(int *count); 156 + extern SDL_DECLSPEC SDL_SensorID * SDLCALL SDL_GetSensors(int *count); 157 157 158 158 /** 159 159 * Get the implementation dependent name of a sensor. ··· 165 165 * 166 166 * \since This function is available since SDL 3.0.0. 167 167 */ 168 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetSensorNameForID(SDL_SensorID instance_id); 168 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetSensorNameForID(SDL_SensorID instance_id); 169 169 170 170 /** 171 171 * Get the type of a sensor. ··· 235 235 * 236 236 * \since This function is available since SDL 3.0.0. 237 237 */ 238 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetSensorName(SDL_Sensor *sensor); 238 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetSensorName(SDL_Sensor *sensor); 239 239 240 240 /** 241 241 * Get the type of a sensor.
+3 -3
include/SDL3/SDL_stdinc.h
··· 527 527 #define SDL_stack_free(data) SDL_free(data) 528 528 #endif 529 529 530 - extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_malloc(size_t size); 531 - extern SDL_DECLSPEC SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void * SDLCALL SDL_calloc(size_t nmemb, size_t size); 532 - extern SDL_DECLSPEC SDL_ALLOC_SIZE(2) void * SDLCALL SDL_realloc(void *mem, size_t size); 530 + extern SDL_DECLSPEC_FREE SDL_MALLOC void * SDLCALL SDL_malloc(size_t size); 531 + extern SDL_DECLSPEC_FREE SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void * SDLCALL SDL_calloc(size_t nmemb, size_t size); 532 + extern SDL_DECLSPEC_FREE SDL_ALLOC_SIZE(2) void * SDLCALL SDL_realloc(void *mem, size_t size); 533 533 extern SDL_DECLSPEC void SDLCALL SDL_free(void *mem); 534 534 535 535 typedef void *(SDLCALL *SDL_malloc_func)(size_t size);
+2 -2
include/SDL3/SDL_storage.h
··· 410 410 * array. Can be NULL. 411 411 * \returns an array of strings on success or NULL on failure; call 412 412 * SDL_GetError() for more information. The caller should pass the 413 - * returned pointer to SDL_free when done with it. 413 + * returned pointer to SDL_free when done with it. This is a single allocation that should be freed with SDL_free() when it is no longer needed. 414 414 * 415 415 * \threadsafety It is safe to call this function from any thread, assuming 416 416 * the `storage` object is thread-safe. 417 417 * 418 418 * \since This function is available since SDL 3.0.0. 419 419 */ 420 - extern SDL_DECLSPEC_TEMP const char * const * SDLCALL SDL_GlobStorageDirectory(SDL_Storage *storage, const char *path, const char *pattern, SDL_GlobFlags flags, int *count); 420 + extern SDL_DECLSPEC_FREE char ** SDLCALL SDL_GlobStorageDirectory(SDL_Storage *storage, const char *path, const char *pattern, SDL_GlobFlags flags, int *count); 421 421 422 422 /* Ends C function definitions when using C++ */ 423 423 #ifdef __cplusplus
+4 -4
include/SDL3/SDL_system.h
··· 418 418 * 419 419 * \sa SDL_GetAndroidExternalStorageState 420 420 */ 421 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetAndroidInternalStoragePath(void); 421 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetAndroidInternalStoragePath(void); 422 422 423 423 /** 424 424 * Get the current state of external storage for this Android application. ··· 457 457 * 458 458 * \sa SDL_GetAndroidExternalStorageState 459 459 */ 460 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetAndroidExternalStoragePath(void); 460 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetAndroidExternalStoragePath(void); 461 461 462 462 /** 463 463 * Get the path used for caching data for this Android application. ··· 476 476 * 477 477 * \since This function is available since SDL 3.0.0. 478 478 */ 479 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetAndroidCachePath(void); 479 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetAndroidCachePath(void); 480 480 481 481 482 482 typedef void (SDLCALL *SDL_RequestAndroidPermissionCallback)(void *userdata, const char *permission, SDL_bool granted); ··· 630 630 * 631 631 * \since This function is available since SDL 3.0.0. 632 632 */ 633 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetWinRTFSPath(SDL_WinRT_Path pathType); 633 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetWinRTFSPath(SDL_WinRT_Path pathType); 634 634 635 635 /** 636 636 * Detects the device family of WinRT platform at runtime.
+1 -1
include/SDL3/SDL_thread.h
··· 336 336 * 337 337 * \since This function is available since SDL 3.0.0. 338 338 */ 339 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetThreadName(SDL_Thread *thread); 339 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetThreadName(SDL_Thread *thread); 340 340 341 341 /** 342 342 * Get the thread identifier for the current thread.
+5 -5
include/SDL3/SDL_touch.h
··· 86 86 * \param count a pointer filled in with the number of devices returned, may 87 87 * be NULL. 88 88 * \returns a 0 terminated array of touch device IDs or NULL on failure; call 89 - * SDL_GetError() for more information. 89 + * SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed. 90 90 * 91 91 * \since This function is available since SDL 3.0.0. 92 92 */ 93 - extern SDL_DECLSPEC_TEMP const SDL_TouchID * SDLCALL SDL_GetTouchDevices(int *count); 93 + extern SDL_DECLSPEC_FREE SDL_TouchID * SDLCALL SDL_GetTouchDevices(int *count); 94 94 95 95 /** 96 96 * Get the touch device name as reported from the driver. ··· 101 101 * 102 102 * \since This function is available since SDL 3.0.0. 103 103 */ 104 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetTouchDeviceName(SDL_TouchID touchID); 104 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetTouchDeviceName(SDL_TouchID touchID); 105 105 106 106 /** 107 107 * Get the type of the given touch device. ··· 120 120 * \param count a pointer filled in with the number of fingers returned, can 121 121 * be NULL. 122 122 * \returns a NULL terminated array of SDL_Finger pointers or NULL on failure; 123 - * call SDL_GetError() for more information. 123 + * call SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed. 124 124 * 125 125 * \since This function is available since SDL 3.0.0. 126 126 */ 127 - extern SDL_DECLSPEC_TEMP const SDL_Finger * const * SDLCALL SDL_GetTouchFingers(SDL_TouchID touchID, int *count); 127 + extern SDL_DECLSPEC_FREE SDL_Finger ** SDLCALL SDL_GetTouchFingers(SDL_TouchID touchID, int *count); 128 128 129 129 /* Ends C function definitions when using C++ */ 130 130 #ifdef __cplusplus
+20 -19
include/SDL3/SDL_video.h
··· 356 356 * 357 357 * \sa SDL_GetNumVideoDrivers 358 358 */ 359 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetVideoDriver(int index); 359 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetVideoDriver(int index); 360 360 361 361 /** 362 362 * Get the name of the currently initialized video driver. ··· 373 373 * \sa SDL_GetNumVideoDrivers 374 374 * \sa SDL_GetVideoDriver 375 375 */ 376 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetCurrentVideoDriver(void); 376 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentVideoDriver(void); 377 377 378 378 /** 379 379 * Get the current system theme. ··· 390 390 * \param count a pointer filled in with the number of displays returned, may 391 391 * be NULL. 392 392 * \returns a 0 terminated array of display instance IDs or NULL on failure; 393 - * call SDL_GetError() for more information. 393 + * call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed. 394 394 * 395 395 * \since This function is available since SDL 3.0.0. 396 396 */ 397 - extern SDL_DECLSPEC_TEMP const SDL_DisplayID * SDLCALL SDL_GetDisplays(int *count); 397 + extern SDL_DECLSPEC_FREE SDL_DisplayID * SDLCALL SDL_GetDisplays(int *count); 398 398 399 399 /** 400 400 * Return the primary display. ··· 448 448 * 449 449 * \sa SDL_GetDisplays 450 450 */ 451 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetDisplayName(SDL_DisplayID displayID); 451 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetDisplayName(SDL_DisplayID displayID); 452 452 453 453 /** 454 454 * Get the desktop area represented by a display. ··· 551 551 * \param count a pointer filled in with the number of display modes returned, 552 552 * may be NULL. 553 553 * \returns a NULL terminated array of display mode pointers or NULL on 554 - * failure; call SDL_GetError() for more information. 554 + * failure; call SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed. 555 555 * 556 556 * \since This function is available since SDL 3.0.0. 557 557 * 558 558 * \sa SDL_GetDisplays 559 559 */ 560 - extern SDL_DECLSPEC_TEMP const SDL_DisplayMode * const * SDLCALL SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *count); 560 + extern SDL_DECLSPEC_FREE SDL_DisplayMode ** SDLCALL SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *count); 561 561 562 562 /** 563 563 * Get the closest match to the requested display mode. ··· 576 576 * for the desktop refresh rate. 577 577 * \param include_high_density_modes boolean to include high density modes in 578 578 * the search. 579 - * \returns a pointer to the closest display mode equal to or larger than the 580 - * desired mode, or NULL on failure; call SDL_GetError() for more 581 - * information. 579 + * \param mode a pointer filled in with the closest display mode equal to or larger than the 580 + * desired mode. 581 + * \returns 0 on success or a negative error code on failure; call 582 + * SDL_GetError() for more information. 582 583 * 583 584 * \since This function is available since SDL 3.0.0. 584 585 * 585 586 * \sa SDL_GetDisplays 586 587 * \sa SDL_GetFullscreenDisplayModes 587 588 */ 588 - extern SDL_DECLSPEC_TEMP const SDL_DisplayMode * SDLCALL SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, float refresh_rate, SDL_bool include_high_density_modes); 589 + extern SDL_DECLSPEC int SDLCALL SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, float refresh_rate, SDL_bool include_high_density_modes, SDL_DisplayMode *mode); 589 590 590 591 /** 591 592 * Get information about the desktop's display mode. ··· 604 605 * \sa SDL_GetCurrentDisplayMode 605 606 * \sa SDL_GetDisplays 606 607 */ 607 - extern SDL_DECLSPEC_TEMP const SDL_DisplayMode * SDLCALL SDL_GetDesktopDisplayMode(SDL_DisplayID displayID); 608 + extern SDL_DECLSPEC const SDL_DisplayMode * SDLCALL SDL_GetDesktopDisplayMode(SDL_DisplayID displayID); 608 609 609 610 /** 610 611 * Get information about the current display mode. ··· 623 624 * \sa SDL_GetDesktopDisplayMode 624 625 * \sa SDL_GetDisplays 625 626 */ 626 - extern SDL_DECLSPEC_TEMP const SDL_DisplayMode * SDLCALL SDL_GetCurrentDisplayMode(SDL_DisplayID displayID); 627 + extern SDL_DECLSPEC const SDL_DisplayMode * SDLCALL SDL_GetCurrentDisplayMode(SDL_DisplayID displayID); 627 628 628 629 /** 629 630 * Get the display containing a point. ··· 753 754 * \sa SDL_SetWindowFullscreenMode 754 755 * \sa SDL_SetWindowFullscreen 755 756 */ 756 - extern SDL_DECLSPEC_TEMP const SDL_DisplayMode * SDLCALL SDL_GetWindowFullscreenMode(SDL_Window *window); 757 + extern SDL_DECLSPEC const SDL_DisplayMode * SDLCALL SDL_GetWindowFullscreenMode(SDL_Window *window); 757 758 758 759 /** 759 760 * Get the raw ICC profile data for the screen the window is currently on. ··· 761 762 * \param window the window to query. 762 763 * \param size the size of the ICC profile. 763 764 * \returns the raw ICC profile data on success or NULL on failure; call 764 - * SDL_GetError() for more information. 765 + * SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed. 765 766 * 766 767 * \since This function is available since SDL 3.0.0. 767 768 */ 768 - extern SDL_DECLSPEC_TEMP const void * SDLCALL SDL_GetWindowICCProfile(SDL_Window *window, size_t *size); 769 + extern SDL_DECLSPEC_FREE void * SDLCALL SDL_GetWindowICCProfile(SDL_Window *window, size_t *size); 769 770 770 771 /** 771 772 * Get the pixel format associated with the window. ··· 785 786 * \param count a pointer filled in with the number of windows returned, may 786 787 * be NULL. 787 788 * \returns a NULL terminated array of SDL_Window pointers or NULL on failure; 788 - * call SDL_GetError() for more information. 789 + * call SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed. 789 790 * 790 791 * \since This function is available since SDL 3.0.0. 791 792 */ 792 - extern SDL_DECLSPEC_TEMP SDL_Window * const * SDLCALL SDL_GetWindows(int *count); 793 + extern SDL_DECLSPEC_FREE SDL_Window ** SDLCALL SDL_GetWindows(int *count); 793 794 794 795 /** 795 796 * Create a window with the specified dimensions and flags. ··· 1322 1323 * 1323 1324 * \sa SDL_SetWindowTitle 1324 1325 */ 1325 - extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetWindowTitle(SDL_Window *window); 1326 + extern SDL_DECLSPEC const char * SDLCALL SDL_GetWindowTitle(SDL_Window *window); 1326 1327 1327 1328 /** 1328 1329 * Set the icon for a window.
+11 -8
src/SDL_guid.c
··· 21 21 #include "SDL_internal.h" 22 22 23 23 /* convert the guid to a printable string */ 24 - const char *SDL_GUIDToString(SDL_GUID guid) 24 + void SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID) 25 25 { 26 26 static const char k_rgchHexToASCII[] = "0123456789abcdef"; 27 27 int i; 28 - char string[sizeof(guid) * 2 + 1]; 29 28 30 - for (i = 0; i < sizeof(guid.data); ++i) { 29 + if ((!pszGUID) || (cbGUID <= 0)) { 30 + return; 31 + } 32 + 33 + for (i = 0; i < sizeof(guid.data) && i < (cbGUID - 1) / 2; i++) { 34 + /* each input byte writes 2 ascii chars, and might write a null byte. */ 35 + /* If we don't have room for next input byte, stop */ 31 36 unsigned char c = guid.data[i]; 32 37 33 - string[i * 2 + 0] = k_rgchHexToASCII[c >> 4]; 34 - string[i * 2 + 1] = k_rgchHexToASCII[c & 0x0F]; 38 + *pszGUID++ = k_rgchHexToASCII[c >> 4]; 39 + *pszGUID++ = k_rgchHexToASCII[c & 0x0F]; 35 40 } 36 - string[sizeof(string) -1] = '\0'; 37 - 38 - return SDL_CreateTemporaryString(string); 41 + *pszGUID = '\0'; 39 42 } 40 43 41 44 /*-----------------------------------------------------------------------------
+5 -5
src/SDL_hints.c
··· 74 74 entry->callback(entry->userdata, name, old_value, value); 75 75 entry = next; 76 76 } 77 - SDL_FreeLater(old_value); 77 + SDL_free(old_value); 78 78 } 79 79 hint->priority = priority; 80 80 return SDL_TRUE; ··· 118 118 entry = next; 119 119 } 120 120 } 121 - SDL_FreeLater(hint->value); 121 + SDL_free(hint->value); 122 122 hint->value = NULL; 123 123 hint->priority = SDL_HINT_DEFAULT; 124 124 return SDL_TRUE; ··· 145 145 entry = next; 146 146 } 147 147 } 148 - SDL_FreeLater(hint->value); 148 + SDL_free(hint->value); 149 149 hint->value = NULL; 150 150 hint->priority = SDL_HINT_DEFAULT; 151 151 } ··· 169 169 for (hint = SDL_hints; hint; hint = hint->next) { 170 170 if (SDL_strcmp(name, hint->name) == 0) { 171 171 if (!env || hint->priority == SDL_HINT_OVERRIDE) { 172 - return hint->value; 172 + return SDL_GetPersistentString(hint->value); 173 173 } 174 174 break; 175 175 } ··· 303 303 SDL_hints = hint->next; 304 304 305 305 SDL_free(hint->name); 306 - SDL_FreeLater(hint->value); 306 + SDL_free(hint->value); 307 307 for (entry = hint->callbacks; entry;) { 308 308 SDL_HintWatch *freeable = entry; 309 309 entry = entry->next;
+5 -10
src/SDL_internal.h
··· 279 279 #define SDL_MAIN_NOIMPL /* don't drag in header-only implementation of SDL_main */ 280 280 #include <SDL3/SDL_main.h> 281 281 282 - #include "SDL_utils_c.h" 283 - 284 - /* The internal implementations of these functions have up to nanosecond precision. 285 - We can expose these functions as part of the API if we want to later. 286 - */ 287 282 /* Set up for C function definitions, even when using C++ */ 288 283 #ifdef __cplusplus 289 284 extern "C" { 290 285 #endif 291 286 287 + #include "SDL_utils_c.h" 288 + 292 289 /* Do any initialization that needs to happen before threads are started */ 293 290 extern void SDL_InitMainThread(void); 294 291 292 + /* The internal implementations of these functions have up to nanosecond precision. 293 + We can expose these functions as part of the API if we want to later. 294 + */ 295 295 extern int SDLCALL SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS); 296 296 extern int SDLCALL SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS); 297 297 extern SDL_bool SDLCALL SDL_WaitEventTimeoutNS(SDL_Event *event, Sint64 timeoutNS); 298 - 299 - extern const char *SDL_CreateTemporaryString(const char *string); 300 - 301 - /* Add memory to the temporary memory pool, to be freed automatically later */ 302 - extern void *SDL_FreeLater(void *memory); 303 298 304 299 /* Ends C function definitions when using C++ */ 305 300 #ifdef __cplusplus
+2 -2
src/SDL_properties.c
··· 65 65 } 66 66 break; 67 67 case SDL_PROPERTY_TYPE_STRING: 68 - SDL_FreeLater(property->value.string_value); // SDL_GetStringProperty() returns this pointer 68 + SDL_free(property->value.string_value); 69 69 break; 70 70 default: 71 71 break; 72 72 } 73 - SDL_FreeLater(property->string_storage); // this pointer might be given to the app by SDL_GetStringProperty. 73 + SDL_free(property->string_storage); 74 74 } 75 75 SDL_free((void *)key); 76 76 SDL_free((void *)value);
+45
src/SDL_utils.c
··· 320 320 } 321 321 return -1; 322 322 } 323 + 324 + // This is a set of per-thread persistent strings that we can return from the SDL API. 325 + // This is used for short strings that might persist past the lifetime of the object 326 + // they are related to. 327 + 328 + static SDL_TLSID SDL_string_storage; 329 + 330 + static void SDL_FreePersistentStrings( void *value ) 331 + { 332 + SDL_HashTable *strings = (SDL_HashTable *)value; 333 + SDL_DestroyHashTable(strings); 334 + } 335 + 336 + const char *SDL_GetPersistentString(const char *string) 337 + { 338 + if (!string) { 339 + return NULL; 340 + } 341 + if (!*string) { 342 + return ""; 343 + } 344 + 345 + SDL_HashTable *strings = (SDL_HashTable *)SDL_GetTLS(&SDL_string_storage); 346 + if (!strings) { 347 + strings = SDL_CreateHashTable(NULL, 32, SDL_HashString, SDL_KeyMatchString, SDL_NukeFreeValue, SDL_FALSE); 348 + if (!strings) { 349 + return NULL; 350 + } 351 + 352 + SDL_SetTLS(&SDL_string_storage, strings, SDL_FreePersistentStrings); 353 + } 354 + 355 + const void *retval; 356 + if (!SDL_FindInHashTable(strings, string, &retval)) { 357 + char *new_string = SDL_strdup(string); 358 + if (!new_string) { 359 + return NULL; 360 + } 361 + 362 + // If the hash table insert fails, at least we can return the string we allocated 363 + retval = new_string; 364 + SDL_InsertIntoHashTable(strings, string, retval); 365 + } 366 + return (const char *)retval; 367 + }
+2
src/SDL_utils_c.h
··· 65 65 extern SDL_bool SDL_ObjectValid(void *object, SDL_ObjectType type); 66 66 extern void SDL_SetObjectsInvalid(void); 67 67 68 + extern const char *SDL_GetPersistentString(const char *string); 69 + 68 70 #endif /* SDL_utils_h_ */
+10 -10
src/audio/SDL_audio.c
··· 134 134 const char *SDL_GetAudioDriver(int index) 135 135 { 136 136 if (index >= 0 && index < SDL_GetNumAudioDrivers()) { 137 - return SDL_CreateTemporaryString(deduped_bootstrap[index]->name); 137 + return deduped_bootstrap[index]->name; 138 138 } 139 139 return NULL; 140 140 } 141 141 142 142 const char *SDL_GetCurrentAudioDriver(void) 143 143 { 144 - return SDL_CreateTemporaryString(current_audio.name); 144 + return current_audio.name; 145 145 } 146 146 147 147 static int GetDefaultSampleFramesFromFreq(const int freq) ··· 1336 1336 } 1337 1337 1338 1338 1339 - static const SDL_AudioDeviceID *GetAudioDevices(int *count, SDL_bool recording) 1339 + static SDL_AudioDeviceID *GetAudioDevices(int *count, SDL_bool recording) 1340 1340 { 1341 1341 SDL_AudioDeviceID *retval = NULL; 1342 1342 int num_devices = 0; ··· 1379 1379 *count = 0; 1380 1380 } 1381 1381 } 1382 - return SDL_FreeLater(retval); 1382 + return retval; 1383 1383 } 1384 1384 1385 - const SDL_AudioDeviceID *SDL_GetAudioPlaybackDevices(int *count) 1385 + SDL_AudioDeviceID *SDL_GetAudioPlaybackDevices(int *count) 1386 1386 { 1387 1387 return GetAudioDevices(count, SDL_FALSE); 1388 1388 } 1389 1389 1390 - const SDL_AudioDeviceID *SDL_GetAudioRecordingDevices(int *count) 1390 + SDL_AudioDeviceID *SDL_GetAudioRecordingDevices(int *count) 1391 1391 { 1392 1392 return GetAudioDevices(count, SDL_TRUE); 1393 1393 } ··· 1438 1438 const char *retval = NULL; 1439 1439 SDL_AudioDevice *device = ObtainPhysicalAudioDevice(devid); 1440 1440 if (device) { 1441 - retval = SDL_CreateTemporaryString(device->name); 1441 + retval = SDL_GetPersistentString(device->name); 1442 1442 } 1443 1443 ReleaseAudioDevice(device); 1444 1444 ··· 1465 1465 return retval; 1466 1466 } 1467 1467 1468 - const int *SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int *count) 1468 + int *SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int *count) 1469 1469 { 1470 - const int *retval = NULL; 1470 + int *retval = NULL; 1471 1471 int channels = 0; 1472 1472 SDL_AudioDevice *device = ObtainPhysicalAudioDeviceDefaultAllowed(devid); 1473 1473 if (device) { 1474 1474 channels = device->spec.channels; 1475 - retval = SDL_FreeLater(SDL_ChannelMapDup(device->chmap, channels)); 1475 + retval = SDL_ChannelMapDup(device->chmap, channels); 1476 1476 } 1477 1477 ReleaseAudioDevice(device); 1478 1478
+6 -6
src/audio/SDL_audiocvt.c
··· 636 636 return SetAudioStreamChannelMap(stream, &stream->dst_spec, &stream->dst_chmap, chmap, channels, SDL_FALSE); 637 637 } 638 638 639 - const int *SDL_GetAudioStreamInputChannelMap(SDL_AudioStream *stream, int *count) 639 + int *SDL_GetAudioStreamInputChannelMap(SDL_AudioStream *stream, int *count) 640 640 { 641 - const int *retval = NULL; 641 + int *retval = NULL; 642 642 int channels = 0; 643 643 if (stream) { 644 644 SDL_LockMutex(stream->lock); 645 645 channels = stream->src_spec.channels; 646 - retval = SDL_FreeLater(SDL_ChannelMapDup(stream->src_chmap, channels)); 646 + retval = SDL_ChannelMapDup(stream->src_chmap, channels); 647 647 SDL_UnlockMutex(stream->lock); 648 648 } 649 649 ··· 654 654 return retval; 655 655 } 656 656 657 - const int *SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream *stream, int *count) 657 + int *SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream *stream, int *count) 658 658 { 659 - const int *retval = NULL; 659 + int *retval = NULL; 660 660 int channels = 0; 661 661 if (stream) { 662 662 SDL_LockMutex(stream->lock); 663 663 channels = stream->dst_spec.channels; 664 - retval = SDL_FreeLater(SDL_ChannelMapDup(stream->dst_chmap, channels)); 664 + retval = SDL_ChannelMapDup(stream->dst_chmap, channels); 665 665 SDL_UnlockMutex(stream->lock); 666 666 } 667 667
+7 -7
src/camera/SDL_camera.c
··· 66 66 const char *SDL_GetCameraDriver(int index) 67 67 { 68 68 if (index >= 0 && index < SDL_GetNumCameraDrivers()) { 69 - return SDL_CreateTemporaryString(bootstrap[index]->name); 69 + return bootstrap[index]->name; 70 70 } 71 71 return NULL; 72 72 } 73 73 74 74 const char *SDL_GetCurrentCameraDriver(void) 75 75 { 76 - return SDL_CreateTemporaryString(camera_driver.name); 76 + return camera_driver.name; 77 77 } 78 78 79 79 char *SDL_GetCameraThreadName(SDL_Camera *device, char *buf, size_t buflen) ··· 675 675 const char *retval = NULL; 676 676 SDL_Camera *device = ObtainPhysicalCamera(instance_id); 677 677 if (device) { 678 - retval = SDL_CreateTemporaryString(device->name); 678 + retval = SDL_GetPersistentString(device->name); 679 679 ReleaseCamera(device); 680 680 } 681 681 return retval; ··· 693 693 } 694 694 695 695 696 - const SDL_CameraID *SDL_GetCameras(int *count) 696 + SDL_CameraID *SDL_GetCameras(int *count) 697 697 { 698 698 int dummy_count; 699 699 if (!count) { ··· 729 729 730 730 *count = num_devices; 731 731 732 - return SDL_FreeLater(retval); 732 + return retval; 733 733 } 734 734 735 - const SDL_CameraSpec * const *SDL_GetCameraSupportedFormats(SDL_CameraID instance_id, int *count) 735 + SDL_CameraSpec **SDL_GetCameraSupportedFormats(SDL_CameraID instance_id, int *count) 736 736 { 737 737 if (count) { 738 738 *count = 0; ··· 761 761 762 762 ReleaseCamera(device); 763 763 764 - return SDL_FreeLater(retval); 764 + return retval; 765 765 } 766 766 767 767
+3 -3
src/core/android/SDL_android.c
··· 2584 2584 2585 2585 LocalReferenceHolder_Cleanup(&refs); 2586 2586 } 2587 - return SDL_CreateTemporaryString(s_AndroidInternalFilesPath); 2587 + return s_AndroidInternalFilesPath; 2588 2588 } 2589 2589 2590 2590 Uint32 SDL_GetAndroidExternalStorageState(void) ··· 2669 2669 2670 2670 LocalReferenceHolder_Cleanup(&refs); 2671 2671 } 2672 - return SDL_CreateTemporaryString(s_AndroidExternalFilesPath); 2672 + return s_AndroidExternalFilesPath; 2673 2673 } 2674 2674 2675 2675 const char *SDL_GetAndroidCachePath(void) ··· 2715 2715 2716 2716 LocalReferenceHolder_Cleanup(&refs); 2717 2717 } 2718 - return SDL_CreateTemporaryString(s_AndroidCachePath); 2718 + return s_AndroidCachePath; 2719 2719 } 2720 2720 2721 2721 int SDL_ShowAndroidToast(const char *message, int duration, int gravity, int xOffset, int yOffset)
+33 -33
src/dynapi/SDL_dynapi_procs.h
··· 192 192 SDL_DYNAPI_PROC(int,SDL_GL_SetSwapInterval,(int a),(a),return) 193 193 SDL_DYNAPI_PROC(int,SDL_GL_SwapWindow,(SDL_Window *a),(a),return) 194 194 SDL_DYNAPI_PROC(void,SDL_GL_UnloadLibrary,(void),(),) 195 - SDL_DYNAPI_PROC(const char *,SDL_GUIDToString,(SDL_GUID a),(a),return) 195 + SDL_DYNAPI_PROC(void,SDL_GUIDToString,(SDL_GUID a, char *b, int c),(a,b,c),) 196 196 SDL_DYNAPI_PROC(SDL_bool,SDL_GamepadConnected,(SDL_Gamepad *a),(a),return) 197 197 SDL_DYNAPI_PROC(SDL_bool,SDL_GamepadEventsEnabled,(void),(),return) 198 198 SDL_DYNAPI_PROC(SDL_bool,SDL_GamepadHasAxis,(SDL_Gamepad *a, SDL_GamepadAxis b),(a,b),return) ··· 208 208 SDL_DYNAPI_PROC(int,SDL_GetAndroidSDKVersion,(void),(),return) 209 209 SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetAssertionHandler,(void **a),(a),return) 210 210 SDL_DYNAPI_PROC(const SDL_AssertData*,SDL_GetAssertionReport,(void),(),return) 211 - SDL_DYNAPI_PROC(const int*,SDL_GetAudioDeviceChannelMap,(SDL_AudioDeviceID a, int *b),(a,b),return) 211 + SDL_DYNAPI_PROC(int*,SDL_GetAudioDeviceChannelMap,(SDL_AudioDeviceID a, int *b),(a,b),return) 212 212 SDL_DYNAPI_PROC(int,SDL_GetAudioDeviceFormat,(SDL_AudioDeviceID a, SDL_AudioSpec *b, int *c),(a,b,c),return) 213 213 SDL_DYNAPI_PROC(float,SDL_GetAudioDeviceGain,(SDL_AudioDeviceID a),(a),return) 214 214 SDL_DYNAPI_PROC(const char*,SDL_GetAudioDeviceName,(SDL_AudioDeviceID a),(a),return) 215 215 SDL_DYNAPI_PROC(const char*,SDL_GetAudioDriver,(int a),(a),return) 216 - SDL_DYNAPI_PROC(const SDL_AudioDeviceID*,SDL_GetAudioPlaybackDevices,(int *a),(a),return) 217 - SDL_DYNAPI_PROC(const SDL_AudioDeviceID*,SDL_GetAudioRecordingDevices,(int *a),(a),return) 216 + SDL_DYNAPI_PROC(SDL_AudioDeviceID*,SDL_GetAudioPlaybackDevices,(int *a),(a),return) 217 + SDL_DYNAPI_PROC(SDL_AudioDeviceID*,SDL_GetAudioRecordingDevices,(int *a),(a),return) 218 218 SDL_DYNAPI_PROC(int,SDL_GetAudioStreamAvailable,(SDL_AudioStream *a),(a),return) 219 219 SDL_DYNAPI_PROC(int,SDL_GetAudioStreamData,(SDL_AudioStream *a, void *b, int c),(a,b,c),return) 220 220 SDL_DYNAPI_PROC(SDL_AudioDeviceID,SDL_GetAudioStreamDevice,(SDL_AudioStream *a),(a),return) 221 221 SDL_DYNAPI_PROC(int,SDL_GetAudioStreamFormat,(SDL_AudioStream *a, SDL_AudioSpec *b, SDL_AudioSpec *c),(a,b,c),return) 222 222 SDL_DYNAPI_PROC(float,SDL_GetAudioStreamFrequencyRatio,(SDL_AudioStream *a),(a),return) 223 223 SDL_DYNAPI_PROC(float,SDL_GetAudioStreamGain,(SDL_AudioStream *a),(a),return) 224 - SDL_DYNAPI_PROC(const int*,SDL_GetAudioStreamInputChannelMap,(SDL_AudioStream *a, int *b),(a,b),return) 225 - SDL_DYNAPI_PROC(const int*,SDL_GetAudioStreamOutputChannelMap,(SDL_AudioStream *a, int *b),(a,b),return) 224 + SDL_DYNAPI_PROC(int*,SDL_GetAudioStreamInputChannelMap,(SDL_AudioStream *a, int *b),(a,b),return) 225 + SDL_DYNAPI_PROC(int*,SDL_GetAudioStreamOutputChannelMap,(SDL_AudioStream *a, int *b),(a,b),return) 226 226 SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetAudioStreamProperties,(SDL_AudioStream *a),(a),return) 227 227 SDL_DYNAPI_PROC(int,SDL_GetAudioStreamQueued,(SDL_AudioStream *a),(a),return) 228 228 SDL_DYNAPI_PROC(const char*,SDL_GetBasePath,(void),(),return) ··· 236 236 SDL_DYNAPI_PROC(int,SDL_GetCameraPermissionState,(SDL_Camera *a),(a),return) 237 237 SDL_DYNAPI_PROC(SDL_CameraPosition,SDL_GetCameraPosition,(SDL_CameraID a),(a),return) 238 238 SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetCameraProperties,(SDL_Camera *a),(a),return) 239 - SDL_DYNAPI_PROC(const SDL_CameraSpec* const*,SDL_GetCameraSupportedFormats,(SDL_CameraID a, int *b),(a,b),return) 240 - SDL_DYNAPI_PROC(const SDL_CameraID*,SDL_GetCameras,(int *a),(a),return) 241 - SDL_DYNAPI_PROC(const void*,SDL_GetClipboardData,(const char *a, size_t *b),(a,b),return) 242 - SDL_DYNAPI_PROC(const char*,SDL_GetClipboardText,(void),(),return) 243 - SDL_DYNAPI_PROC(const SDL_DisplayMode*,SDL_GetClosestFullscreenDisplayMode,(SDL_DisplayID a, int b, int c, float d, SDL_bool e),(a,b,c,d,e),return) 239 + SDL_DYNAPI_PROC(SDL_CameraSpec**,SDL_GetCameraSupportedFormats,(SDL_CameraID a, int *b),(a,b),return) 240 + SDL_DYNAPI_PROC(SDL_CameraID*,SDL_GetCameras,(int *a),(a),return) 241 + SDL_DYNAPI_PROC(void*,SDL_GetClipboardData,(const char *a, size_t *b),(a,b),return) 242 + SDL_DYNAPI_PROC(char*,SDL_GetClipboardText,(void),(),return) 243 + SDL_DYNAPI_PROC(int,SDL_GetClosestFullscreenDisplayMode,(SDL_DisplayID a, int b, int c, float d, SDL_bool e, SDL_DisplayMode *f),(a,b,c,d,e,f),return) 244 244 SDL_DYNAPI_PROC(const char*,SDL_GetCurrentAudioDriver,(void),(),return) 245 245 SDL_DYNAPI_PROC(const char*,SDL_GetCurrentCameraDriver,(void),(),return) 246 246 SDL_DYNAPI_PROC(const SDL_DisplayMode*,SDL_GetCurrentDisplayMode,(SDL_DisplayID a),(a),return) ··· 269 269 SDL_DYNAPI_PROC(const char*,SDL_GetDisplayName,(SDL_DisplayID a),(a),return) 270 270 SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetDisplayProperties,(SDL_DisplayID a),(a),return) 271 271 SDL_DYNAPI_PROC(int,SDL_GetDisplayUsableBounds,(SDL_DisplayID a, SDL_Rect *b),(a,b),return) 272 - SDL_DYNAPI_PROC(const SDL_DisplayID*,SDL_GetDisplays,(int *a),(a),return) 272 + SDL_DYNAPI_PROC(SDL_DisplayID*,SDL_GetDisplays,(int *a),(a),return) 273 273 SDL_DYNAPI_PROC(const char*,SDL_GetError,(void),(),return) 274 274 SDL_DYNAPI_PROC(SDL_bool,SDL_GetEventFilter,(SDL_EventFilter *a, void **b),(a,b),return) 275 275 SDL_DYNAPI_PROC(float,SDL_GetFloatProperty,(SDL_PropertiesID a, const char *b, float c),(a,b,c),return) 276 - SDL_DYNAPI_PROC(const SDL_DisplayMode* const*,SDL_GetFullscreenDisplayModes,(SDL_DisplayID a, int *b),(a,b),return) 276 + SDL_DYNAPI_PROC(SDL_DisplayMode**,SDL_GetFullscreenDisplayModes,(SDL_DisplayID a, int *b),(a,b),return) 277 277 SDL_DYNAPI_PROC(int,SDL_GetGDKDefaultUser,(XUserHandle *a),(a),return) 278 278 SDL_DYNAPI_PROC(int,SDL_GetGDKTaskQueue,(XTaskQueueHandle *a),(a),return) 279 279 SDL_DYNAPI_PROC(const char*,SDL_GetGamepadAppleSFSymbolsNameForAxis,(SDL_Gamepad *a, SDL_GamepadAxis b),(a,b),return) 280 280 SDL_DYNAPI_PROC(const char*,SDL_GetGamepadAppleSFSymbolsNameForButton,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return) 281 281 SDL_DYNAPI_PROC(Sint16,SDL_GetGamepadAxis,(SDL_Gamepad *a, SDL_GamepadAxis b),(a,b),return) 282 282 SDL_DYNAPI_PROC(SDL_GamepadAxis,SDL_GetGamepadAxisFromString,(const char *a),(a),return) 283 - SDL_DYNAPI_PROC(const SDL_GamepadBinding* const*,SDL_GetGamepadBindings,(SDL_Gamepad *a, int *b),(a,b),return) 283 + SDL_DYNAPI_PROC(SDL_GamepadBinding**,SDL_GetGamepadBindings,(SDL_Gamepad *a, int *b),(a,b),return) 284 284 SDL_DYNAPI_PROC(Uint8,SDL_GetGamepadButton,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return) 285 285 SDL_DYNAPI_PROC(SDL_GamepadButton,SDL_GetGamepadButtonFromString,(const char *a),(a),return) 286 286 SDL_DYNAPI_PROC(SDL_GamepadButtonLabel,SDL_GetGamepadButtonLabel,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return) ··· 292 292 SDL_DYNAPI_PROC(SDL_GUID,SDL_GetGamepadGUIDForID,(SDL_JoystickID a),(a),return) 293 293 SDL_DYNAPI_PROC(SDL_JoystickID,SDL_GetGamepadID,(SDL_Gamepad *a),(a),return) 294 294 SDL_DYNAPI_PROC(SDL_Joystick*,SDL_GetGamepadJoystick,(SDL_Gamepad *a),(a),return) 295 - SDL_DYNAPI_PROC(const char*,SDL_GetGamepadMapping,(SDL_Gamepad *a),(a),return) 296 - SDL_DYNAPI_PROC(const char*,SDL_GetGamepadMappingForGUID,(SDL_GUID a),(a),return) 297 - SDL_DYNAPI_PROC(const char*,SDL_GetGamepadMappingForID,(SDL_JoystickID a),(a),return) 298 - SDL_DYNAPI_PROC(const char * const *,SDL_GetGamepadMappings,(int *a),(a),return) 295 + SDL_DYNAPI_PROC(char*,SDL_GetGamepadMapping,(SDL_Gamepad *a),(a),return) 296 + SDL_DYNAPI_PROC(char*,SDL_GetGamepadMappingForGUID,(SDL_GUID a),(a),return) 297 + SDL_DYNAPI_PROC(char*,SDL_GetGamepadMappingForID,(SDL_JoystickID a),(a),return) 298 + SDL_DYNAPI_PROC(char **,SDL_GetGamepadMappings,(int *a),(a),return) 299 299 SDL_DYNAPI_PROC(const char*,SDL_GetGamepadName,(SDL_Gamepad *a),(a),return) 300 300 SDL_DYNAPI_PROC(const char*,SDL_GetGamepadNameForID,(SDL_JoystickID a),(a),return) 301 301 SDL_DYNAPI_PROC(const char*,SDL_GetGamepadPath,(SDL_Gamepad *a),(a),return) ··· 321 321 SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetGamepadTypeFromString,(const char *a),(a),return) 322 322 SDL_DYNAPI_PROC(Uint16,SDL_GetGamepadVendor,(SDL_Gamepad *a),(a),return) 323 323 SDL_DYNAPI_PROC(Uint16,SDL_GetGamepadVendorForID,(SDL_JoystickID a),(a),return) 324 - SDL_DYNAPI_PROC(const SDL_JoystickID*,SDL_GetGamepads,(int *a),(a),return) 324 + SDL_DYNAPI_PROC(SDL_JoystickID*,SDL_GetGamepads,(int *a),(a),return) 325 325 SDL_DYNAPI_PROC(SDL_MouseButtonFlags,SDL_GetGlobalMouseState,(float *a, float *b),(a,b),return) 326 326 SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetGlobalProperties,(void),(),return) 327 327 SDL_DYNAPI_PROC(SDL_Window*,SDL_GetGrabbedWindow,(void),(),return) ··· 331 331 SDL_DYNAPI_PROC(SDL_HapticID,SDL_GetHapticID,(SDL_Haptic *a),(a),return) 332 332 SDL_DYNAPI_PROC(const char*,SDL_GetHapticName,(SDL_Haptic *a),(a),return) 333 333 SDL_DYNAPI_PROC(const char*,SDL_GetHapticNameForID,(SDL_HapticID a),(a),return) 334 - SDL_DYNAPI_PROC(const SDL_HapticID*,SDL_GetHaptics,(int *a),(a),return) 334 + SDL_DYNAPI_PROC(SDL_HapticID*,SDL_GetHaptics,(int *a),(a),return) 335 335 SDL_DYNAPI_PROC(const char*,SDL_GetHint,(const char *a),(a),return) 336 336 SDL_DYNAPI_PROC(SDL_bool,SDL_GetHintBoolean,(const char *a, SDL_bool b),(a,b),return) 337 337 SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetIOProperties,(SDL_IOStream *a),(a),return) ··· 367 367 SDL_DYNAPI_PROC(SDL_JoystickType,SDL_GetJoystickTypeForID,(SDL_JoystickID a),(a),return) 368 368 SDL_DYNAPI_PROC(Uint16,SDL_GetJoystickVendor,(SDL_Joystick *a),(a),return) 369 369 SDL_DYNAPI_PROC(Uint16,SDL_GetJoystickVendorForID,(SDL_JoystickID a),(a),return) 370 - SDL_DYNAPI_PROC(const SDL_JoystickID*,SDL_GetJoysticks,(int *a),(a),return) 370 + SDL_DYNAPI_PROC(SDL_JoystickID*,SDL_GetJoysticks,(int *a),(a),return) 371 371 SDL_DYNAPI_PROC(SDL_Keycode,SDL_GetKeyFromName,(const char *a),(a),return) 372 372 SDL_DYNAPI_PROC(SDL_Keycode,SDL_GetKeyFromScancode,(SDL_Scancode a, SDL_Keymod b),(a,b),return) 373 373 SDL_DYNAPI_PROC(const char*,SDL_GetKeyName,(SDL_Keycode a),(a),return) 374 374 SDL_DYNAPI_PROC(SDL_Window*,SDL_GetKeyboardFocus,(void),(),return) 375 375 SDL_DYNAPI_PROC(const char*,SDL_GetKeyboardNameForID,(SDL_KeyboardID a),(a),return) 376 376 SDL_DYNAPI_PROC(const Uint8*,SDL_GetKeyboardState,(int *a),(a),return) 377 - SDL_DYNAPI_PROC(const SDL_KeyboardID*,SDL_GetKeyboards,(int *a),(a),return) 377 + SDL_DYNAPI_PROC(SDL_KeyboardID*,SDL_GetKeyboards,(int *a),(a),return) 378 378 SDL_DYNAPI_PROC(void,SDL_GetLogOutputFunction,(SDL_LogOutputFunction *a, void **b),(a,b),) 379 379 SDL_DYNAPI_PROC(SDL_LogPriority,SDL_GetLogPriority,(int a),(a),return) 380 380 SDL_DYNAPI_PROC(int,SDL_GetMasksForPixelFormat,(SDL_PixelFormat a, int *b, Uint32 *c, Uint32 *d, Uint32 *e, Uint32 *f),(a,b,c,d,e,f),return) 381 381 SDL_DYNAPI_PROC(int,SDL_GetMaxHapticEffects,(SDL_Haptic *a),(a),return) 382 382 SDL_DYNAPI_PROC(int,SDL_GetMaxHapticEffectsPlaying,(SDL_Haptic *a),(a),return) 383 383 SDL_DYNAPI_PROC(void,SDL_GetMemoryFunctions,(SDL_malloc_func *a, SDL_calloc_func *b, SDL_realloc_func *c, SDL_free_func *d),(a,b,c,d),) 384 - SDL_DYNAPI_PROC(const SDL_MouseID*,SDL_GetMice,(int *a),(a),return) 384 + SDL_DYNAPI_PROC(SDL_MouseID*,SDL_GetMice,(int *a),(a),return) 385 385 SDL_DYNAPI_PROC(SDL_Keymod,SDL_GetModState,(void),(),return) 386 386 SDL_DYNAPI_PROC(SDL_Window*,SDL_GetMouseFocus,(void),(),return) 387 387 SDL_DYNAPI_PROC(const char*,SDL_GetMouseNameForID,(SDL_MouseID a),(a),return) ··· 417 417 SDL_DYNAPI_PROC(const char*,SDL_GetPlatform,(void),(),return) 418 418 SDL_DYNAPI_PROC(void*,SDL_GetPointerProperty,(SDL_PropertiesID a, const char *b, void *c),(a,b,c),return) 419 419 SDL_DYNAPI_PROC(SDL_PowerState,SDL_GetPowerInfo,(int *a, int *b),(a,b),return) 420 - SDL_DYNAPI_PROC(const char*,SDL_GetPrefPath,(const char *a, const char *b),(a,b),return) 421 - SDL_DYNAPI_PROC(const SDL_Locale* const*,SDL_GetPreferredLocales,(int *a),(a),return) 420 + SDL_DYNAPI_PROC(char*,SDL_GetPrefPath,(const char *a, const char *b),(a,b),return) 421 + SDL_DYNAPI_PROC(SDL_Locale**,SDL_GetPreferredLocales,(int *a),(a),return) 422 422 SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetPrimaryDisplay,(void),(),return) 423 - SDL_DYNAPI_PROC(const char*,SDL_GetPrimarySelectionText,(void),(),return) 423 + SDL_DYNAPI_PROC(char*,SDL_GetPrimarySelectionText,(void),(),return) 424 424 SDL_DYNAPI_PROC(SDL_PropertyType,SDL_GetPropertyType,(SDL_PropertiesID a, const char *b),(a,b),return) 425 425 SDL_DYNAPI_PROC(void,SDL_GetRGB,(Uint32 a, const SDL_PixelFormatDetails *b, const SDL_Palette *c, Uint8 *d, Uint8 *e, Uint8 *f),(a,b,c,d,e,f),) 426 426 SDL_DYNAPI_PROC(void,SDL_GetRGBA,(Uint32 a, const SDL_PixelFormatDetails *b, const SDL_Palette *c, Uint8 *d, Uint8 *e, Uint8 *f, Uint8 *g),(a,b,c,d,e,f,g),) ··· 473 473 SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetSensorProperties,(SDL_Sensor *a),(a),return) 474 474 SDL_DYNAPI_PROC(SDL_SensorType,SDL_GetSensorType,(SDL_Sensor *a),(a),return) 475 475 SDL_DYNAPI_PROC(SDL_SensorType,SDL_GetSensorTypeForID,(SDL_SensorID a),(a),return) 476 - SDL_DYNAPI_PROC(const SDL_SensorID*,SDL_GetSensors,(int *a),(a),return) 476 + SDL_DYNAPI_PROC(SDL_SensorID*,SDL_GetSensors,(int *a),(a),return) 477 477 SDL_DYNAPI_PROC(int,SDL_GetSilenceValueForFormat,(SDL_AudioFormat a),(a),return) 478 478 SDL_DYNAPI_PROC(int,SDL_GetStorageFileSize,(SDL_Storage *a, const char *b, Uint64 *c),(a,b,c),return) 479 479 SDL_DYNAPI_PROC(int,SDL_GetStoragePathInfo,(SDL_Storage *a, const char *b, SDL_PathInfo *c),(a,b,c),return) ··· 505 505 SDL_DYNAPI_PROC(Uint64,SDL_GetTicksNS,(void),(),return) 506 506 SDL_DYNAPI_PROC(const char*,SDL_GetTouchDeviceName,(SDL_TouchID a),(a),return) 507 507 SDL_DYNAPI_PROC(SDL_TouchDeviceType,SDL_GetTouchDeviceType,(SDL_TouchID a),(a),return) 508 - SDL_DYNAPI_PROC(const SDL_TouchID*,SDL_GetTouchDevices,(int *a),(a),return) 509 - SDL_DYNAPI_PROC(const SDL_Finger* const*,SDL_GetTouchFingers,(SDL_TouchID a, int *b),(a,b),return) 508 + SDL_DYNAPI_PROC(SDL_TouchID*,SDL_GetTouchDevices,(int *a),(a),return) 509 + SDL_DYNAPI_PROC(SDL_Finger**,SDL_GetTouchFingers,(SDL_TouchID a, int *b),(a,b),return) 510 510 SDL_DYNAPI_PROC(const char*,SDL_GetUserFolder,(SDL_Folder a),(a),return) 511 511 SDL_DYNAPI_PROC(int,SDL_GetVersion,(void),(),return) 512 512 SDL_DYNAPI_PROC(const char*,SDL_GetVideoDriver,(int a),(a),return) ··· 518 518 SDL_DYNAPI_PROC(SDL_WindowFlags,SDL_GetWindowFlags,(SDL_Window *a),(a),return) 519 519 SDL_DYNAPI_PROC(SDL_Window*,SDL_GetWindowFromID,(SDL_WindowID a),(a),return) 520 520 SDL_DYNAPI_PROC(const SDL_DisplayMode*,SDL_GetWindowFullscreenMode,(SDL_Window *a),(a),return) 521 - SDL_DYNAPI_PROC(const void*,SDL_GetWindowICCProfile,(SDL_Window *a, size_t *b),(a,b),return) 521 + SDL_DYNAPI_PROC(void*,SDL_GetWindowICCProfile,(SDL_Window *a, size_t *b),(a,b),return) 522 522 SDL_DYNAPI_PROC(SDL_WindowID,SDL_GetWindowID,(SDL_Window *a),(a),return) 523 523 SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowKeyboardGrab,(SDL_Window *a),(a),return) 524 524 SDL_DYNAPI_PROC(int,SDL_GetWindowMaximumSize,(SDL_Window *a, int *b, int *c),(a,b,c),return) ··· 537 537 SDL_DYNAPI_PROC(SDL_Surface*,SDL_GetWindowSurface,(SDL_Window *a),(a),return) 538 538 SDL_DYNAPI_PROC(int,SDL_GetWindowSurfaceVSync,(SDL_Window *a, int *b),(a,b),return) 539 539 SDL_DYNAPI_PROC(const char*,SDL_GetWindowTitle,(SDL_Window *a),(a),return) 540 - SDL_DYNAPI_PROC(SDL_Window* const*,SDL_GetWindows,(int *a),(a),return) 541 - SDL_DYNAPI_PROC(const char * const *,SDL_GlobDirectory,(const char *a, const char *b, SDL_GlobFlags c, int *d),(a,b,c,d),return) 542 - 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) 540 + SDL_DYNAPI_PROC(SDL_Window**,SDL_GetWindows,(int *a),(a),return) 541 + SDL_DYNAPI_PROC(char **,SDL_GlobDirectory,(const char *a, const char *b, SDL_GlobFlags c, int *d),(a,b,c,d),return) 542 + 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) 543 543 SDL_DYNAPI_PROC(SDL_bool,SDL_HapticEffectSupported,(SDL_Haptic *a, const SDL_HapticEffect *b),(a,b),return) 544 544 SDL_DYNAPI_PROC(SDL_bool,SDL_HapticRumbleSupported,(SDL_Haptic *a),(a),return) 545 545 SDL_DYNAPI_PROC(SDL_bool,SDL_HasARMSIMD,(void),(),return)
+1 -1
src/dynapi/gendynapi.py
··· 197 197 func_ret = func_ret.replace('extern', ' ') 198 198 func_ret = func_ret.replace('SDLCALL', ' ') 199 199 func_ret = func_ret.replace('SDL_DECLSPEC', ' ') 200 - func_ret = func_ret.replace('SDL_DECLSPEC_TEMP', ' ') 200 + func_ret = func_ret.replace('SDL_DECLSPEC_FREE', ' ') 201 201 # Remove trailing spaces in front of '*' 202 202 tmp = "" 203 203 while func_ret != tmp:
+5 -6
src/events/SDL_events.c
··· 236 236 SDL_LinkTemporaryMemoryToEvent(event, event->event.drop.data); 237 237 break; 238 238 default: 239 - if (event->event.type >= SDL_EVENT_USER && event->event.type <= SDL_EVENT_LAST-1) { 240 - SDL_LinkTemporaryMemoryToEvent(event, event->event.user.data1); 241 - SDL_LinkTemporaryMemoryToEvent(event, event->event.user.data2); 242 - } 243 239 break; 244 240 } 245 241 } ··· 266 262 event->memory = NULL; 267 263 } 268 264 269 - void *SDL_FreeLater(void *memory) 265 + static void *SDL_FreeLater(void *memory) 270 266 { 271 267 SDL_TemporaryMemoryState *state; 272 268 ··· 275 271 } 276 272 277 273 // Make sure we're not adding this to the list twice 278 - SDL_assert(!SDL_ClaimTemporaryMemory(memory)); 274 + //SDL_assert(!SDL_ClaimTemporaryMemory(memory)); 279 275 280 276 state = SDL_GetTemporaryMemoryState(SDL_TRUE); 281 277 if (!state) { ··· 1158 1154 /* Run the system dependent event loops */ 1159 1155 static void SDL_PumpEventsInternal(SDL_bool push_sentinel) 1160 1156 { 1157 + /* Free any temporary memory from old events */ 1158 + SDL_FreeTemporaryMemory(); 1159 + 1161 1160 /* Release any keys held down from last frame */ 1162 1161 SDL_ReleaseAutoReleaseKeys(); 1163 1162
+5
src/events/SDL_events_c.h
··· 45 45 extern int SDL_SendLocaleChangedEvent(void); 46 46 extern int SDL_SendSystemThemeChangedEvent(void); 47 47 48 + extern void *SDL_AllocateTemporaryMemory(size_t size); 49 + extern const char *SDL_CreateTemporaryString(const char *string); 50 + extern void *SDL_ClaimTemporaryMemory(const void *mem); 51 + extern void SDL_FreeTemporaryMemory(void); 52 + 48 53 extern int SDL_SendQuit(void); 49 54 50 55 extern int SDL_InitEvents(void);
+6 -6
src/events/SDL_keyboard.c
··· 177 177 return (SDL_keyboard_count > 0); 178 178 } 179 179 180 - const SDL_KeyboardID *SDL_GetKeyboards(int *count) 180 + SDL_KeyboardID *SDL_GetKeyboards(int *count) 181 181 { 182 182 int i; 183 183 SDL_KeyboardID *keyboards; ··· 198 198 } 199 199 } 200 200 201 - return SDL_FreeLater(keyboards); 201 + return keyboards; 202 202 } 203 203 204 204 const char *SDL_GetKeyboardNameForID(SDL_KeyboardID instance_id) ··· 207 207 if (keyboard_index < 0) { 208 208 return NULL; 209 209 } 210 - return SDL_CreateTemporaryString(SDL_keyboards[keyboard_index].name); 210 + return SDL_GetPersistentString(SDL_keyboards[keyboard_index].name); 211 211 } 212 212 213 213 void SDL_ResetKeyboard(void) ··· 762 762 763 763 static const char * const *CreateCandidatesForEvent(char **candidates, int num_candidates) 764 764 { 765 - char **event_candidates; 765 + const char **event_candidates; 766 766 int i; 767 767 char *ptr; 768 768 size_t total_length = (num_candidates + 1) * sizeof(*event_candidates); ··· 773 773 total_length += length; 774 774 } 775 775 776 - event_candidates = (char **)SDL_malloc(total_length); 776 + event_candidates = (const char **)SDL_AllocateTemporaryMemory(total_length); 777 777 if (!event_candidates) { 778 778 return NULL; 779 779 } ··· 788 788 } 789 789 event_candidates[i] = NULL; 790 790 791 - return SDL_FreeLater(event_candidates); 791 + return event_candidates; 792 792 } 793 793 794 794 int SDL_SendEditingTextCandidates(char **candidates, int num_candidates, int selected_candidate, SDL_bool horizontal)
+3 -2
src/events/SDL_keymap.c
··· 957 957 if (!name) { 958 958 name = ""; 959 959 } 960 - return SDL_CreateTemporaryString(name); 960 + // This is pointing to static memory or application managed memory 961 + return name; 961 962 } 962 963 963 964 SDL_Scancode SDL_GetScancodeFromName(const char *name) ··· 1015 1016 1016 1017 end = SDL_UCS4ToUTF8(key, name); 1017 1018 *end = '\0'; 1018 - return SDL_CreateTemporaryString(name); 1019 + return SDL_GetPersistentString(name); 1019 1020 } 1020 1021 } 1021 1022
+3 -3
src/events/SDL_mouse.c
··· 361 361 return (SDL_mouse_count > 0); 362 362 } 363 363 364 - const SDL_MouseID *SDL_GetMice(int *count) 364 + SDL_MouseID *SDL_GetMice(int *count) 365 365 { 366 366 int i; 367 367 SDL_MouseID *mice; ··· 382 382 } 383 383 } 384 384 385 - return SDL_FreeLater(mice); 385 + return mice; 386 386 } 387 387 388 388 const char *SDL_GetMouseNameForID(SDL_MouseID instance_id) ··· 391 391 if (mouse_index < 0) { 392 392 return NULL; 393 393 } 394 - return SDL_CreateTemporaryString(SDL_mice[mouse_index].name); 394 + return SDL_GetPersistentString(SDL_mice[mouse_index].name); 395 395 } 396 396 397 397 void SDL_SetDefaultCursor(SDL_Cursor *cursor)
+1 -1
src/events/SDL_pen.c
··· 213 213 { 214 214 const char *result; 215 215 SDL_LOAD_LOCK_PEN(pen, instance_id, NULL); 216 - result = pen->name; /* Allocated separately from the pen table, so it is safe to hand to client code */ 216 + result = SDL_GetPersistentString(pen->name); 217 217 SDL_UNLOCK_PENS(); 218 218 return result; 219 219 }
+5 -5
src/events/SDL_touch.c
··· 49 49 return SDL_num_touch > 0; 50 50 } 51 51 52 - const SDL_TouchID *SDL_GetTouchDevices(int *count) 52 + SDL_TouchID *SDL_GetTouchDevices(int *count) 53 53 { 54 54 if (count) { 55 55 *count = 0; ··· 67 67 } 68 68 } 69 69 70 - return SDL_FreeLater(retval); 70 + return retval; 71 71 } 72 72 73 73 static int SDL_GetTouchIndex(SDL_TouchID id) ··· 105 105 if (!touch) { 106 106 return NULL; 107 107 } 108 - return SDL_CreateTemporaryString(touch->name); 108 + return SDL_GetPersistentString(touch->name); 109 109 } 110 110 111 111 SDL_TouchDeviceType SDL_GetTouchDeviceType(SDL_TouchID id) ··· 134 134 return touch->fingers[index]; 135 135 } 136 136 137 - const SDL_Finger * const * SDL_GetTouchFingers(SDL_TouchID touchID, int *count) 137 + SDL_Finger **SDL_GetTouchFingers(SDL_TouchID touchID, int *count) 138 138 { 139 139 SDL_Finger **fingers; 140 140 SDL_Finger *finger_data; ··· 164 164 if (count) { 165 165 *count = touch->num_fingers; 166 166 } 167 - return SDL_FreeLater(fingers); 167 + return fingers; 168 168 } 169 169 170 170 int SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name)
+5 -5
src/filesystem/SDL_filesystem.c
··· 298 298 return retval; 299 299 } 300 300 301 - const char * const *SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata) 301 + char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata) 302 302 { 303 303 int dummycount; 304 304 if (!count) { ··· 393 393 SDL_free(folded); 394 394 SDL_free(pathcpy); 395 395 396 - return SDL_FreeLater(retval); 396 + return retval; 397 397 } 398 398 399 399 static int GlobDirectoryGetPathInfo(const char *path, SDL_PathInfo *info, void *userdata) ··· 406 406 return SDL_EnumerateDirectory(path, cb, cbuserdata); 407 407 } 408 408 409 - const char * const *SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count) 409 + char **SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count) 410 410 { 411 411 //SDL_Log("SDL_GlobDirectory('%s', '%s') ...", path, pattern); 412 412 return SDL_InternalGlobDirectory(path, pattern, flags, count, GlobDirectoryEnumerator, GlobDirectoryGetPathInfo, NULL); ··· 441 441 } 442 442 443 443 444 - const char *SDL_GetPrefPath(const char *org, const char *app) 444 + char *SDL_GetPrefPath(const char *org, const char *app) 445 445 { 446 446 char *path = SDL_SYS_GetPrefPath(org, app); 447 - return SDL_FreeLater(path); 447 + return path; 448 448 } 449 449 450 450
+1 -1
src/filesystem/SDL_sysfilesystem.h
··· 36 36 37 37 typedef int (*SDL_GlobEnumeratorFunc)(const char *path, SDL_EnumerateDirectoryCallback cb, void *cbuserdata, void *userdata); 38 38 typedef int (*SDL_GlobGetPathInfoFunc)(const char *path, SDL_PathInfo *info, void *userdata); 39 - const char * const *SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata); 39 + char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata); 40 40 41 41 #endif 42 42
+1 -1
src/filesystem/winrt/SDL_sysfilesystem.cpp
··· 115 115 char *utf8Path = WIN_StringToUTF8W(ucs2Path); 116 116 utf8Paths[pathType] = utf8Path; 117 117 SDL_free(utf8Path); 118 - return SDL_CreateTemporaryString(utf8Paths[pathType].c_str()); 118 + return SDL_GetPersistentString(utf8Paths[pathType].c_str()); 119 119 } 120 120 121 121 extern "C" char *SDL_SYS_GetBasePath(void)
+5 -5
src/haptic/SDL_haptic.c
··· 63 63 return SDL_FALSE; 64 64 } 65 65 66 - const SDL_HapticID *SDL_GetHaptics(int *count) 66 + SDL_HapticID *SDL_GetHaptics(int *count) 67 67 { 68 68 int device_index; 69 69 int haptic_index = 0, num_haptics = 0; ··· 89 89 } 90 90 } 91 91 92 - return SDL_FreeLater(haptics); 92 + return haptics; 93 93 } 94 94 95 95 const char *SDL_GetHapticNameForID(SDL_HapticID instance_id) ··· 98 98 const char *name = NULL; 99 99 100 100 if (SDL_GetHapticIndex(instance_id, &device_index)) { 101 - name = SDL_SYS_HapticName(device_index); 101 + name = SDL_GetPersistentString(SDL_SYS_HapticName(device_index)); 102 102 } 103 - return SDL_CreateTemporaryString(name); 103 + return name; 104 104 } 105 105 106 106 SDL_Haptic *SDL_OpenHaptic(SDL_HapticID instance_id) ··· 189 189 { 190 190 CHECK_HAPTIC_MAGIC(haptic, NULL); 191 191 192 - return SDL_CreateTemporaryString(haptic->name); 192 + return SDL_GetPersistentString(haptic->name); 193 193 } 194 194 195 195 SDL_bool SDL_IsMouseHaptic(void)
+33 -42
src/joystick/SDL_gamepad.c
··· 89 89 typedef struct 90 90 { 91 91 int refcount _guarded; 92 - const SDL_JoystickID *joysticks _guarded; 92 + SDL_JoystickID *joysticks _guarded; 93 93 GamepadMapping_t **joystick_mappings _guarded; 94 94 95 95 int num_changed_mappings _guarded; ··· 579 579 } 580 580 } 581 581 582 + SDL_free(tracker->joysticks); 582 583 SDL_free(tracker->joystick_mappings); 583 584 SDL_free(tracker->changed_mappings); 584 585 SDL_free(tracker); ··· 2075 2076 static char *CreateMappingString(GamepadMapping_t *mapping, SDL_GUID guid) 2076 2077 { 2077 2078 char *pMappingString, *pPlatformString; 2078 - const char *pchGUID; 2079 + char pchGUID[33]; 2079 2080 size_t needed; 2080 2081 SDL_bool need_platform = SDL_FALSE; 2081 2082 const char *platform = NULL; 2082 2083 2083 2084 SDL_AssertJoysticksLocked(); 2084 2085 2085 - pchGUID = SDL_GUIDToString(guid); 2086 + SDL_GUIDToString(guid, pchGUID, sizeof(pchGUID)); 2086 2087 2087 2088 /* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */ 2088 2089 needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1; ··· 2124 2125 return pMappingString; 2125 2126 } 2126 2127 2127 - const char * const *SDL_GetGamepadMappings(int *count) 2128 + char **SDL_GetGamepadMappings(int *count) 2128 2129 { 2129 2130 int num_mappings = 0; 2130 2131 char **retval = NULL; ··· 2197 2198 SDL_free(mappings); 2198 2199 } 2199 2200 2200 - return SDL_FreeLater(retval); 2201 + return retval; 2201 2202 } 2202 2203 2203 2204 /* 2204 2205 * Get the mapping string for this GUID 2205 2206 */ 2206 - const char *SDL_GetGamepadMappingForGUID(SDL_GUID guid) 2207 + char *SDL_GetGamepadMappingForGUID(SDL_GUID guid) 2207 2208 { 2208 2209 char *retval; 2209 2210 ··· 2219 2220 } 2220 2221 SDL_UnlockJoysticks(); 2221 2222 2222 - return SDL_FreeLater(retval); 2223 + return retval; 2223 2224 } 2224 2225 2225 2226 /* 2226 2227 * Get the mapping string for this device 2227 2228 */ 2228 - const char *SDL_GetGamepadMapping(SDL_Gamepad *gamepad) 2229 + char *SDL_GetGamepadMapping(SDL_Gamepad *gamepad) 2229 2230 { 2230 2231 char *retval; 2231 2232 ··· 2237 2238 } 2238 2239 SDL_UnlockJoysticks(); 2239 2240 2240 - return SDL_FreeLater(retval); 2241 + return retval; 2241 2242 } 2242 2243 2243 2244 /* ··· 2357 2358 int SDL_InitGamepads(void) 2358 2359 { 2359 2360 int i; 2360 - const SDL_JoystickID *joysticks; 2361 + SDL_JoystickID *joysticks; 2361 2362 2362 2363 SDL_gamepads_initialized = SDL_TRUE; 2363 2364 ··· 2372 2373 SDL_PrivateGamepadAdded(joysticks[i]); 2373 2374 } 2374 2375 } 2376 + SDL_free(joysticks); 2375 2377 } 2376 2378 2377 2379 return 0; ··· 2381 2383 { 2382 2384 int num_joysticks = 0; 2383 2385 int num_gamepads = 0; 2384 - const SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks); 2386 + SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks); 2385 2387 if (joysticks) { 2386 2388 int i; 2387 2389 for (i = num_joysticks - 1; i >= 0 && num_gamepads == 0; --i) { ··· 2389 2391 ++num_gamepads; 2390 2392 } 2391 2393 } 2394 + SDL_free(joysticks); 2392 2395 } 2393 2396 if (num_gamepads > 0) { 2394 2397 return SDL_TRUE; ··· 2396 2399 return SDL_FALSE; 2397 2400 } 2398 2401 2399 - const SDL_JoystickID *SDL_GetGamepads(int *count) 2402 + SDL_JoystickID *SDL_GetGamepads(int *count) 2400 2403 { 2401 2404 int num_joysticks = 0; 2402 2405 int num_gamepads = 0; 2403 - SDL_JoystickID *joysticks = SDL_ClaimTemporaryMemory(SDL_GetJoysticks(&num_joysticks)); 2406 + SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks); 2404 2407 if (joysticks) { 2405 2408 int i; 2406 2409 for (i = num_joysticks - 1; i >= 0; --i) { ··· 2414 2417 if (count) { 2415 2418 *count = num_gamepads; 2416 2419 } 2417 - return SDL_FreeLater(joysticks); 2420 + return joysticks; 2418 2421 } 2419 2422 2420 2423 const char *SDL_GetGamepadNameForID(SDL_JoystickID instance_id) ··· 2428 2431 if (SDL_strcmp(mapping->name, "*") == 0) { 2429 2432 retval = SDL_GetJoystickNameForID(instance_id); 2430 2433 } else { 2431 - retval = SDL_CreateTemporaryString(mapping->name); 2434 + retval = SDL_GetPersistentString(mapping->name); 2432 2435 } 2433 2436 } 2434 2437 } ··· 2516 2519 return type; 2517 2520 } 2518 2521 2519 - const char *SDL_GetGamepadMappingForID(SDL_JoystickID instance_id) 2522 + char *SDL_GetGamepadMappingForID(SDL_JoystickID instance_id) 2520 2523 { 2521 2524 char *retval = NULL; 2522 2525 ··· 2524 2527 { 2525 2528 GamepadMapping_t *mapping = SDL_PrivateGetGamepadMapping(instance_id, SDL_TRUE); 2526 2529 if (mapping) { 2527 - const char *pchGUID; 2528 - const SDL_GUID guid = SDL_GetJoystickGUIDForID(instance_id); 2529 - pchGUID = SDL_GUIDToString(guid); 2530 + char pchGUID[33]; 2531 + SDL_GUID guid = SDL_GetJoystickGUIDForID(instance_id); 2532 + SDL_GUIDToString(guid, pchGUID, sizeof(pchGUID)); 2530 2533 SDL_asprintf(&retval, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping); 2531 2534 } 2532 2535 } 2533 2536 SDL_UnlockJoysticks(); 2534 2537 2535 - return SDL_FreeLater(retval); 2538 + return retval; 2536 2539 } 2537 2540 2538 2541 /* ··· 3307 3310 gamepad->joystick->steam_handle != 0) { 3308 3311 retval = SDL_GetJoystickName(gamepad->joystick); 3309 3312 } else { 3310 - retval = SDL_CreateTemporaryString(gamepad->name); 3313 + retval = SDL_GetPersistentString(gamepad->name); 3311 3314 } 3312 3315 } 3313 3316 SDL_UnlockJoysticks(); ··· 3427 3430 if (!joystick) { 3428 3431 return NULL; 3429 3432 } 3430 - return SDL_GetJoystickSerial(joystick); // this already returns a SDL_FreeLater pointer. 3433 + return SDL_GetJoystickSerial(joystick); 3431 3434 3432 3435 } 3433 3436 ··· 3543 3546 /* 3544 3547 * Get the SDL joystick layer bindings for this gamepad 3545 3548 */ 3546 - const SDL_GamepadBinding * const*SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count) 3549 + SDL_GamepadBinding **SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count) 3547 3550 { 3548 3551 SDL_GamepadBinding **bindings = NULL; 3549 3552 ··· 3574 3577 } 3575 3578 SDL_UnlockJoysticks(); 3576 3579 3577 - return SDL_FreeLater(bindings); 3580 + return bindings; 3578 3581 } 3579 3582 3580 3583 int SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms) ··· 3845 3848 3846 3849 const char *SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button) 3847 3850 { 3851 + const char *retval = NULL; 3848 3852 #ifdef SDL_JOYSTICK_MFI 3849 - char *IOS_GetAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button); 3850 - char *retval; 3853 + const char *IOS_GetAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button); 3851 3854 3852 3855 SDL_LockJoysticks(); 3853 3856 { ··· 3856 3859 retval = IOS_GetAppleSFSymbolsNameForButton(gamepad, button); 3857 3860 } 3858 3861 SDL_UnlockJoysticks(); 3859 - 3860 - // retval was malloc'd by IOS_GetAppleSFSymbolsNameForButton 3861 - if (retval && *retval) { 3862 - return SDL_FreeLater(retval); 3863 - } 3864 - SDL_free(retval); 3865 3862 #endif 3866 - return NULL; 3863 + return retval; 3867 3864 } 3868 3865 3869 3866 const char *SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis) 3870 3867 { 3868 + const char *retval = NULL; 3871 3869 #ifdef SDL_JOYSTICK_MFI 3872 - char *IOS_GetAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis); 3873 - char *retval; 3870 + const char *IOS_GetAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis); 3874 3871 3875 3872 SDL_LockJoysticks(); 3876 3873 { ··· 3879 3876 retval = IOS_GetAppleSFSymbolsNameForAxis(gamepad, axis); 3880 3877 } 3881 3878 SDL_UnlockJoysticks(); 3882 - 3883 - // retval was malloc'd by IOS_GetAppleSFSymbolsNameForAxis 3884 - if (retval && *retval) { 3885 - return SDL_FreeLater(retval); 3886 - } 3887 - SDL_free(retval); 3888 3879 #endif 3889 - return NULL; 3880 + return retval; 3890 3881 }
+15 -12
src/joystick/SDL_joystick.c
··· 714 714 return SDL_FALSE; 715 715 } 716 716 717 - const SDL_JoystickID *SDL_GetJoysticks(int *count) 717 + SDL_JoystickID *SDL_GetJoysticks(int *count) 718 718 { 719 719 int i, num_joysticks, device_index; 720 720 int joystick_index = 0, total_joysticks = 0; ··· 751 751 } 752 752 SDL_UnlockJoysticks(); 753 753 754 - return SDL_FreeLater(joysticks); 754 + return joysticks; 755 755 } 756 756 757 757 const SDL_SteamVirtualGamepadInfo *SDL_GetJoystickVirtualGamepadInfoForID(SDL_JoystickID instance_id) ··· 780 780 SDL_LockJoysticks(); 781 781 info = SDL_GetJoystickVirtualGamepadInfoForID(instance_id); 782 782 if (info) { 783 - name = SDL_CreateTemporaryString(info->name); 783 + name = SDL_GetPersistentString(info->name); 784 784 } else if (SDL_GetDriverAndJoystickIndex(instance_id, &driver, &device_index)) { 785 - name = SDL_CreateTemporaryString(driver->GetDeviceName(device_index)); 785 + name = SDL_GetPersistentString(driver->GetDeviceName(device_index)); 786 786 } 787 787 SDL_UnlockJoysticks(); 788 788 ··· 800 800 801 801 SDL_LockJoysticks(); 802 802 if (SDL_GetDriverAndJoystickIndex(instance_id, &driver, &device_index)) { 803 - path = SDL_CreateTemporaryString(driver->GetDevicePath(device_index)); 803 + path = SDL_GetPersistentString(driver->GetDevicePath(device_index)); 804 804 } 805 805 SDL_UnlockJoysticks(); 806 806 ··· 858 858 SDL_bool has_ally_gyro = SDL_FALSE; 859 859 860 860 if (SDL_InitSubSystem(SDL_INIT_SENSOR) == 0) { 861 - const SDL_SensorID *sensors = SDL_GetSensors(NULL); 861 + SDL_SensorID *sensors = SDL_GetSensors(NULL); 862 862 if (sensors) { 863 863 int i; 864 864 for (i = 0; sensors[i]; ++i) { ··· 877 877 } 878 878 } 879 879 } 880 + SDL_free(sensors); 880 881 } 881 882 SDL_QuitSubSystem(SDL_INIT_SENSOR); 882 883 } ··· 951 952 952 953 static void AttemptSensorFusion(SDL_Joystick *joystick, SDL_bool invert_sensors) 953 954 { 954 - const SDL_SensorID *sensors; 955 + SDL_SensorID *sensors; 955 956 unsigned int i, j; 956 957 957 958 SDL_AssertJoysticksLocked(); ··· 980 981 SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 0.0f); 981 982 } 982 983 } 984 + SDL_free(sensors); 983 985 } 984 986 SDL_QuitSubSystem(SDL_INIT_SENSOR); 985 987 ··· 1651 1653 1652 1654 info = SDL_GetJoystickVirtualGamepadInfoForID(joystick->instance_id); 1653 1655 if (info) { 1654 - retval = SDL_CreateTemporaryString(info->name); 1656 + retval = SDL_GetPersistentString(info->name); 1655 1657 } else { 1656 - retval = SDL_CreateTemporaryString(joystick->name); 1658 + retval = SDL_GetPersistentString(joystick->name); 1657 1659 } 1658 1660 } 1659 1661 SDL_UnlockJoysticks(); ··· 1673 1675 CHECK_JOYSTICK_MAGIC(joystick, NULL); 1674 1676 1675 1677 if (joystick->path) { 1676 - retval = SDL_CreateTemporaryString(joystick->path); 1678 + retval = SDL_GetPersistentString(joystick->path); 1677 1679 } else { 1678 1680 SDL_Unsupported(); 1679 1681 retval = NULL; ··· 1903 1905 void SDL_QuitJoysticks(void) 1904 1906 { 1905 1907 int i; 1906 - const SDL_JoystickID *joysticks; 1908 + SDL_JoystickID *joysticks; 1907 1909 1908 1910 SDL_LockJoysticks(); 1909 1911 ··· 1914 1916 for (i = 0; joysticks[i]; ++i) { 1915 1917 SDL_PrivateJoystickRemoved(joysticks[i]); 1916 1918 } 1919 + SDL_free(joysticks); 1917 1920 } 1918 1921 1919 1922 while (SDL_joysticks) { ··· 3428 3431 { 3429 3432 CHECK_JOYSTICK_MAGIC(joystick, NULL); 3430 3433 3431 - retval = SDL_CreateTemporaryString(joystick->serial); 3434 + retval = SDL_GetPersistentString(joystick->serial); 3432 3435 } 3433 3436 SDL_UnlockJoysticks(); 3434 3437
+4 -4
src/joystick/apple/SDL_mfijoystick.m
··· 1916 1916 } 1917 1917 #endif /* SDL_JOYSTICK_MFI && ENABLE_PHYSICAL_INPUT_PROFILE */ 1918 1918 1919 - char *IOS_GetAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button) 1919 + const char *IOS_GetAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button) 1920 1920 { 1921 1921 char elementName[256]; 1922 1922 elementName[0] = '\0'; ··· 2031 2031 } 2032 2032 #endif 2033 2033 2034 - return SDL_strdup(elementName); 2034 + return *elementName ? SDL_GetPersistentString(elementName) : NULL; 2035 2035 } 2036 2036 2037 - char *IOS_GetAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis) 2037 + const char *IOS_GetAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis) 2038 2038 { 2039 2039 char elementName[256]; 2040 2040 elementName[0] = '\0'; ··· 2071 2071 } 2072 2072 } 2073 2073 #endif 2074 - return *elementName ? SDL_strdup(elementName) : NULL; 2074 + return *elementName ? SDL_GetPersistentString(elementName) : NULL; 2075 2075 } 2076 2076 2077 2077 SDL_JoystickDriver SDL_IOS_JoystickDriver = {
+3 -3
src/locale/SDL_locale.c
··· 22 22 #include "SDL_internal.h" 23 23 #include "SDL_syslocale.h" 24 24 25 - static const SDL_Locale * const *build_locales_from_csv_string(char *csv, int *count) 25 + static SDL_Locale **build_locales_from_csv_string(char *csv, int *count) 26 26 { 27 27 int i, num_locales; 28 28 size_t slen; ··· 95 95 *count = num_locales; 96 96 } 97 97 98 - return SDL_FreeLater(retval); 98 + return retval; 99 99 } 100 100 101 - const SDL_Locale * const *SDL_GetPreferredLocales(int *count) 101 + SDL_Locale **SDL_GetPreferredLocales(int *count) 102 102 { 103 103 char locbuf[128]; /* enough for 21 "xx_YY," language strings. */ 104 104 const char *hint = SDL_GetHint(SDL_HINT_PREFERRED_LOCALES);
+2 -2
src/render/SDL_render.c
··· 811 811 SDL_GetNumRenderDrivers() - 1); 812 812 return NULL; 813 813 } 814 - return SDL_CreateTemporaryString(render_drivers[index]->name); 814 + return render_drivers[index]->name; 815 815 #else 816 816 SDL_SetError("SDL not built with rendering support"); 817 817 return NULL; ··· 1204 1204 { 1205 1205 CHECK_RENDERER_MAGIC(renderer, NULL); 1206 1206 1207 - return renderer->name; 1207 + return SDL_GetPersistentString(renderer->name); 1208 1208 } 1209 1209 1210 1210 SDL_PropertiesID SDL_GetRendererProperties(SDL_Renderer *renderer)
+4 -4
src/sensor/SDL_sensor.c
··· 170 170 return opened; 171 171 } 172 172 173 - const SDL_SensorID *SDL_GetSensors(int *count) 173 + SDL_SensorID *SDL_GetSensors(int *count) 174 174 { 175 175 int i, num_sensors, device_index; 176 176 int sensor_index = 0, total_sensors = 0; ··· 207 207 } 208 208 SDL_UnlockSensors(); 209 209 210 - return SDL_FreeLater(sensors); 210 + return sensors; 211 211 } 212 212 213 213 /* ··· 246 246 247 247 SDL_LockSensors(); 248 248 if (SDL_GetDriverAndSensorIndex(instance_id, &driver, &device_index)) { 249 - name = SDL_CreateTemporaryString(driver->GetDeviceName(device_index)); 249 + name = SDL_GetPersistentString(driver->GetDeviceName(device_index)); 250 250 } 251 251 SDL_UnlockSensors(); 252 252 ··· 407 407 { 408 408 CHECK_SENSOR_MAGIC(sensor, NULL); 409 409 410 - retval = SDL_CreateTemporaryString(sensor->name); 410 + retval = SDL_GetPersistentString(sensor->name); 411 411 } 412 412 SDL_UnlockSensors(); 413 413
+11 -6
src/stdlib/SDL_getenv.c
··· 185 185 const char *SDL_getenv(const char *name) 186 186 { 187 187 DWORD length, maxlen = 0; 188 - char *retval = NULL; 188 + char *string = NULL; 189 + const char *retval = NULL; 189 190 190 191 /* Input validation */ 191 192 if (!name || *name == '\0') { ··· 193 194 } 194 195 195 196 for ( ; ; ) { 196 - length = GetEnvironmentVariableA(name, retval, maxlen); 197 + length = GetEnvironmentVariableA(name, string, maxlen); 197 198 198 199 if (length > maxlen) { 199 - char *string = (char *)SDL_realloc(retval, length); 200 - if (!string) { 200 + char *temp = (char *)SDL_realloc(string, length); 201 + if (!temp) { 201 202 return NULL; 202 203 } 203 - retval = string; 204 + string = temp; 204 205 maxlen = length; 205 206 } else { 206 207 break; 207 208 } 208 209 } 209 - return SDL_FreeLater(retval); 210 + if (string) { 211 + retval = SDL_GetPersistentString(string); 212 + SDL_free(string); 213 + } 214 + return retval; 210 215 } 211 216 #else 212 217 const char *SDL_getenv(const char *name)
+1 -1
src/storage/SDL_storage.c
··· 353 353 return SDL_EnumerateStorageDirectory((SDL_Storage *) userdata, path, cb, cbuserdata); 354 354 } 355 355 356 - const char * const *SDL_GlobStorageDirectory(SDL_Storage *storage, const char *path, const char *pattern, SDL_GlobFlags flags, int *count) 356 + char **SDL_GlobStorageDirectory(SDL_Storage *storage, const char *path, const char *pattern, SDL_GlobFlags flags, int *count) 357 357 { 358 358 CHECK_STORAGE_MAGIC_RET(NULL) 359 359 return SDL_InternalGlobDirectory(path, pattern, flags, count, GlobStorageDirectoryEnumerator, GlobStorageDirectoryGetPathInfo, storage);
+3 -9
src/storage/generic/SDL_genericstorage.c
··· 203 203 if (override != NULL) { 204 204 basepath = SDL_strdup(override); 205 205 } else { 206 - const char *sdlbasepath = SDL_GetBasePath(); 207 - if (sdlbasepath) { 208 - basepath = SDL_strdup(sdlbasepath); 209 - } 206 + const char *base = SDL_GetBasePath(); 207 + basepath = base ? SDL_strdup(base) : NULL; 210 208 } 211 209 212 210 if (basepath != NULL) { ··· 242 240 static SDL_Storage *GENERIC_User_Create(const char *org, const char *app, SDL_PropertiesID props) 243 241 { 244 242 SDL_Storage *result; 245 - char *prefpath = NULL; 246 - const char *sdlprefpath = SDL_GetPrefPath(org, app); 247 - if (sdlprefpath) { 248 - prefpath = SDL_strdup(sdlprefpath); 249 - } 243 + char *prefpath = SDL_GetPrefPath(org, app); 250 244 if (prefpath == NULL) { 251 245 return NULL; 252 246 }
+19 -15
src/test/SDL_test_common.c
··· 1130 1130 SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state) 1131 1131 { 1132 1132 int i, j, m, n, w, h; 1133 - const SDL_DisplayMode *fullscreen_mode; 1134 1133 char text[1024]; 1135 1134 1136 1135 if (state->flags & SDL_INIT_VIDEO) { ··· 1192 1191 } 1193 1192 1194 1193 if (state->verbose & VERBOSE_MODES) { 1195 - const SDL_DisplayID *displays; 1194 + SDL_DisplayID *displays; 1196 1195 SDL_Rect bounds, usablebounds; 1197 - const SDL_DisplayMode * const *modes; 1196 + SDL_DisplayMode **modes; 1198 1197 const SDL_DisplayMode *mode; 1199 1198 int bpp; 1200 1199 Uint32 Rmask, Gmask, Bmask, Amask; ··· 1258 1257 } 1259 1258 } 1260 1259 } 1260 + SDL_free(modes); 1261 1261 1262 1262 #if defined(SDL_VIDEO_DRIVER_WINDOWS) && !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES) 1263 1263 /* Print the D3D9 adapter index */ ··· 1269 1269 SDL_Log("DXGI Adapter Index: %d Output Index: %d", adapterIndex, outputIndex); 1270 1270 #endif 1271 1271 } 1272 + SDL_free(displays); 1272 1273 } 1273 1274 1274 1275 if (state->verbose & VERBOSE_RENDER) { ··· 1285 1286 1286 1287 state->displayID = SDL_GetPrimaryDisplay(); 1287 1288 if (state->display_index > 0) { 1288 - const SDL_DisplayID *displays = SDL_GetDisplays(&n); 1289 + SDL_DisplayID *displays = SDL_GetDisplays(&n); 1289 1290 if (state->display_index < n) { 1290 1291 state->displayID = displays[state->display_index]; 1291 1292 } 1293 + SDL_free(displays); 1292 1294 1293 1295 if (SDL_WINDOWPOS_ISUNDEFINED(state->window_x)) { 1294 1296 state->window_x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->displayID); ··· 1304 1306 if (state->window_flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) { 1305 1307 include_high_density_modes = SDL_TRUE; 1306 1308 } 1307 - fullscreen_mode = SDL_GetClosestFullscreenDisplayMode(state->displayID, state->window_w, state->window_h, state->refresh_rate, include_high_density_modes); 1308 - if (fullscreen_mode) { 1309 - SDL_memcpy(&state->fullscreen_mode, fullscreen_mode, sizeof(state->fullscreen_mode)); 1310 - } 1309 + SDL_GetClosestFullscreenDisplayMode(state->displayID, state->window_w, state->window_h, state->refresh_rate, include_high_density_modes, &state->fullscreen_mode); 1311 1310 } 1312 1311 1313 1312 state->windows = ··· 1622 1621 SDL_Rect rect; 1623 1622 1624 1623 SDL_GetWindowSafeArea(SDL_GetWindowFromID(event->window.windowID), &rect); 1625 - SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " changed safe area to: %d,%d %dx%d\n", 1624 + SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " changed safe area to: %d,%d %dx%d\n", 1626 1625 event->window.windowID, rect.x, rect.y, rect.w, rect.h); 1627 1626 break; 1628 1627 } ··· 2008 2007 2009 2008 for (i = 0; i < SDL_arraysize(image_formats); ++i) { 2010 2009 size_t size; 2011 - const void *data = SDL_GetClipboardData(image_formats[i], &size); 2010 + void *data = SDL_GetClipboardData(image_formats[i], &size); 2012 2011 if (data) { 2013 2012 char filename[16]; 2014 2013 SDL_IOStream *file; ··· 2020 2019 SDL_WriteIO(file, data, size); 2021 2020 SDL_CloseIO(file); 2022 2021 } 2022 + SDL_free(data); 2023 2023 return; 2024 2024 } 2025 2025 } ··· 2029 2029 static void FullscreenTo(SDLTest_CommonState *state, int index, int windowId) 2030 2030 { 2031 2031 int num_displays; 2032 - const SDL_DisplayID *displays; 2032 + SDL_DisplayID *displays; 2033 2033 SDL_Window *window; 2034 2034 SDL_WindowFlags flags; 2035 2035 const SDL_DisplayMode *mode; ··· 2060 2060 if (state->window_flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) { 2061 2061 include_high_density_modes = SDL_TRUE; 2062 2062 } 2063 - mode = SDL_GetClosestFullscreenDisplayMode(displays[index], state->window_w, state->window_h, state->refresh_rate, include_high_density_modes); 2064 - SDL_SetWindowFullscreenMode(window, mode); 2063 + if (SDL_GetClosestFullscreenDisplayMode(displays[index], state->window_w, state->window_h, state->refresh_rate, include_high_density_modes, &new_mode) == 0) { 2064 + SDL_SetWindowFullscreenMode(window, &new_mode); 2065 + } 2065 2066 } 2066 2067 } 2067 2068 if (!mode) { ··· 2070 2071 SDL_SetWindowFullscreen(window, SDL_TRUE); 2071 2072 } 2072 2073 } 2074 + SDL_free(displays); 2073 2075 } 2074 2076 2075 2077 int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event *event) ··· 2270 2272 case SDLK_V: 2271 2273 if (withAlt) { 2272 2274 /* Alt-V paste awesome text from the primary selection! */ 2273 - const char *text = SDL_GetPrimarySelectionText(); 2275 + char *text = SDL_GetPrimarySelectionText(); 2274 2276 if (*text) { 2275 2277 SDL_Log("Primary selection: %s\n", text); 2276 2278 } else { 2277 2279 SDL_Log("Primary selection is empty\n"); 2278 2280 } 2281 + SDL_free(text); 2279 2282 2280 2283 } else if (withControl) { 2281 2284 if (withShift) { ··· 2283 2286 SDLTest_PasteScreenShot(); 2284 2287 } else { 2285 2288 /* Ctrl-V paste awesome text! */ 2286 - const char *text = SDL_GetClipboardText(); 2289 + char *text = SDL_GetClipboardText(); 2287 2290 if (*text) { 2288 2291 SDL_Log("Clipboard: %s\n", text); 2289 2292 } else { 2290 2293 SDL_Log("Clipboard is empty\n"); 2291 2294 } 2295 + SDL_free(text); 2292 2296 } 2293 2297 } 2294 2298 break;
+2 -2
src/thread/SDL_thread.c
··· 433 433 const char *SDL_GetThreadName(SDL_Thread *thread) 434 434 { 435 435 if (thread) { 436 - return thread->name; 436 + return SDL_GetPersistentString(thread->name); 437 437 } else { 438 438 return NULL; 439 439 } ··· 451 451 if (status) { 452 452 *status = thread->status; 453 453 } 454 - SDL_FreeLater(thread->name); 454 + SDL_free(thread->name); 455 455 SDL_free(thread); 456 456 } 457 457 }
+13 -13
src/video/SDL_clipboard.c
··· 162 162 return data; 163 163 } 164 164 165 - const void *SDL_GetClipboardData(const char *mime_type, size_t *size) 165 + void *SDL_GetClipboardData(const char *mime_type, size_t *size) 166 166 { 167 167 SDL_VideoDevice *_this = SDL_GetVideoDevice(); 168 168 ··· 184 184 *size = 0; 185 185 186 186 if (_this->GetClipboardData) { 187 - return SDL_FreeLater(_this->GetClipboardData(_this, mime_type, size)); 187 + return _this->GetClipboardData(_this, mime_type, size); 188 188 } else if (_this->GetClipboardText && SDL_IsTextMimeType(mime_type)) { 189 189 char *text = _this->GetClipboardText(_this); 190 190 if (text && *text == '\0') { 191 191 SDL_free(text); 192 192 text = NULL; 193 193 } 194 - return SDL_FreeLater(text); 194 + return text; 195 195 } else { 196 - return SDL_FreeLater(SDL_GetInternalClipboardData(_this, mime_type, size)); 196 + return SDL_GetInternalClipboardData(_this, mime_type, size); 197 197 } 198 198 } 199 199 ··· 282 282 return SDL_ClearClipboardData(); 283 283 } 284 284 285 - const char *SDL_GetClipboardText(void) 285 + char *SDL_GetClipboardText(void) 286 286 { 287 287 SDL_VideoDevice *_this = SDL_GetVideoDevice(); 288 288 size_t i, num_mime_types; 289 289 const char **text_mime_types; 290 290 size_t length; 291 - const char *text = NULL; 291 + char *text = NULL; 292 292 293 293 if (!_this) { 294 294 SDL_SetError("Video subsystem must be initialized to get clipboard text"); 295 - return ""; 295 + return SDL_strdup(""); 296 296 } 297 297 298 298 text_mime_types = SDL_GetTextMimeTypes(_this, &num_mime_types); 299 299 for (i = 0; i < num_mime_types; ++i) { 300 - const void *clipdata = SDL_GetClipboardData(text_mime_types[i], &length); 300 + void *clipdata = SDL_GetClipboardData(text_mime_types[i], &length); 301 301 if (clipdata) { 302 - text = (const char *)clipdata; 302 + text = (char *)clipdata; 303 303 break; 304 304 } 305 305 } 306 306 307 307 if (!text) { 308 - text = SDL_CreateTemporaryString(""); 308 + text = SDL_strdup(""); 309 309 } 310 310 return text; 311 311 } ··· 356 356 return 0; 357 357 } 358 358 359 - const char *SDL_GetPrimarySelectionText(void) 359 + char *SDL_GetPrimarySelectionText(void) 360 360 { 361 361 SDL_VideoDevice *_this = SDL_GetVideoDevice(); 362 362 ··· 366 366 } 367 367 368 368 if (_this->GetPrimarySelectionText) { 369 - return SDL_FreeLater(_this->GetPrimarySelectionText(_this)); 369 + return _this->GetPrimarySelectionText(_this); 370 370 } else { 371 371 const char *text = _this->primary_selection_text; 372 372 if (!text) { 373 373 text = ""; 374 374 } 375 - return SDL_CreateTemporaryString(text); 375 + return SDL_strdup(text); 376 376 } 377 377 } 378 378
+35 -52
src/video/SDL_video.c
··· 519 519 const char *SDL_GetVideoDriver(int index) 520 520 { 521 521 if (index >= 0 && index < SDL_GetNumVideoDrivers()) { 522 - return SDL_CreateTemporaryString(bootstrap[index]->name); 522 + return bootstrap[index]->name; 523 523 } 524 524 return NULL; 525 525 } ··· 663 663 SDL_UninitializedVideo(); 664 664 return NULL; 665 665 } 666 - return SDL_CreateTemporaryString(_this->name); 666 + return _this->name; 667 667 } 668 668 669 669 SDL_VideoDevice *SDL_GetVideoDevice(void) ··· 698 698 SDL_Rect rect; 699 699 SDL_zero(rect); 700 700 701 - const SDL_DisplayID *displays = SDL_GetDisplays(NULL); 701 + SDL_DisplayID *displays = SDL_GetDisplays(NULL); 702 702 if (displays) { 703 703 for (int i = 0; displays[i]; ++i) { 704 704 SDL_Rect bounds; ··· 710 710 } 711 711 } 712 712 } 713 + SDL_free(displays); 713 714 } 714 715 SDL_copyp(&_this->desktop_bounds, &rect); 715 716 } ··· 848 849 SDL_UpdateDesktopBounds(); 849 850 } 850 851 851 - const SDL_DisplayID *SDL_GetDisplays(int *count) 852 + SDL_DisplayID *SDL_GetDisplays(int *count) 852 853 { 853 854 int i; 854 855 SDL_DisplayID *displays; ··· 877 878 *count = 0; 878 879 } 879 880 } 880 - return SDL_FreeLater(displays); 881 + return displays; 881 882 } 882 883 883 884 SDL_VideoDisplay *SDL_GetVideoDisplay(SDL_DisplayID displayID) ··· 1115 1116 } 1116 1117 } 1117 1118 1118 - static const SDL_DisplayMode *SDL_CreateTemporaryDisplayMode(const SDL_DisplayMode *mode) 1119 - { 1120 - SDL_DisplayMode *retval = NULL; 1121 - 1122 - if (mode) { 1123 - retval = (SDL_DisplayMode *)SDL_malloc(sizeof(*retval)); 1124 - if (retval) { 1125 - SDL_copyp(retval, mode); 1126 - } 1127 - } 1128 - return SDL_FreeLater(retval); 1129 - } 1130 - 1131 1119 // Return the matching mode as a pointer into our current mode list 1132 1120 static const SDL_DisplayMode *SDL_GetFullscreenModeMatch(const SDL_DisplayMode *mode) 1133 1121 { ··· 1174 1162 return mode; 1175 1163 } 1176 1164 1177 - // Return the window's fullscreen mode as a pointer into our current mode list 1178 - static const SDL_DisplayMode *SDL_GetWindowFullscreenModeInternal(SDL_Window *window) 1179 - { 1180 - if (window->flags & SDL_WINDOW_FULLSCREEN) { 1181 - return SDL_GetFullscreenModeMatch(&window->current_fullscreen_mode); 1182 - } else { 1183 - return SDL_GetFullscreenModeMatch(&window->requested_fullscreen_mode); 1184 - } 1185 - } 1186 - 1187 1165 SDL_bool SDL_AddFullscreenDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode) 1188 1166 { 1189 1167 SDL_DisplayMode *modes; ··· 1250 1228 display->current_mode = &display->desktop_mode; 1251 1229 } 1252 1230 1253 - const SDL_DisplayMode * const *SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *count) 1231 + SDL_DisplayMode **SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *count) 1254 1232 { 1255 1233 int i; 1256 1234 int num_modes; ··· 1283 1261 *count = 0; 1284 1262 } 1285 1263 } 1286 - return SDL_FreeLater(retval); 1264 + return retval; 1287 1265 } 1288 1266 1289 - const SDL_DisplayMode *SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, float refresh_rate, SDL_bool include_high_density_modes) 1267 + int SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, float refresh_rate, SDL_bool include_high_density_modes, SDL_DisplayMode *result) 1290 1268 { 1291 1269 const SDL_DisplayMode *mode, *closest = NULL; 1292 1270 float aspect_ratio; 1293 1271 int i; 1294 1272 SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID); 1295 1273 1296 - CHECK_DISPLAY_MAGIC(display, NULL); 1274 + if (result) { 1275 + SDL_zerop(result); 1276 + } 1277 + 1278 + CHECK_DISPLAY_MAGIC(display, -1); 1297 1279 1298 1280 if (h > 0) { 1299 1281 aspect_ratio = (float)w / h; ··· 1340 1322 1341 1323 closest = mode; 1342 1324 } 1343 - return SDL_CreateTemporaryDisplayMode(closest); 1325 + if (!closest) { 1326 + return SDL_SetError("Couldn't find any matching video modes"); 1327 + } 1328 + if (result) { 1329 + SDL_copyp(result, closest); 1330 + } 1331 + return 0; 1344 1332 } 1345 1333 1346 1334 static SDL_bool DisplayModeChanged(const SDL_DisplayMode *old, const SDL_DisplayMode *new) ··· 1379 1367 1380 1368 CHECK_DISPLAY_MAGIC(display, NULL); 1381 1369 1382 - return SDL_CreateTemporaryDisplayMode(&display->desktop_mode); 1370 + return &display->desktop_mode; 1383 1371 } 1384 1372 1385 1373 void SDL_SetCurrentDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode) ··· 1408 1396 /* Make sure our mode list is updated */ 1409 1397 SDL_UpdateFullscreenDisplayModes(display); 1410 1398 1411 - return SDL_CreateTemporaryDisplayMode(display->current_mode); 1399 + return display->current_mode; 1412 1400 } 1413 1401 1414 1402 int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay *display, SDL_DisplayMode *mode) ··· 1771 1759 } 1772 1760 1773 1761 if (fullscreen) { 1774 - mode = (SDL_DisplayMode *)SDL_GetWindowFullscreenModeInternal(window); 1762 + mode = (SDL_DisplayMode *)SDL_GetWindowFullscreenMode(window); 1775 1763 if (mode) { 1776 1764 window->fullscreen_exclusive = SDL_TRUE; 1777 1765 } else { ··· 2014 2002 2015 2003 const SDL_DisplayMode *SDL_GetWindowFullscreenMode(SDL_Window *window) 2016 2004 { 2017 - const SDL_DisplayMode *retval; 2018 - 2019 2005 CHECK_WINDOW_MAGIC(window, NULL); 2020 2006 CHECK_WINDOW_NOT_POPUP(window, NULL); 2021 2007 2022 - retval = SDL_GetWindowFullscreenModeInternal(window); 2023 - 2024 - return SDL_CreateTemporaryDisplayMode(retval); 2008 + if (window->flags & SDL_WINDOW_FULLSCREEN) { 2009 + return SDL_GetFullscreenModeMatch(&window->current_fullscreen_mode); 2010 + } else { 2011 + return SDL_GetFullscreenModeMatch(&window->requested_fullscreen_mode); 2012 + } 2025 2013 } 2026 2014 2027 - const void *SDL_GetWindowICCProfile(SDL_Window *window, size_t *size) 2015 + void *SDL_GetWindowICCProfile(SDL_Window *window, size_t *size) 2028 2016 { 2029 2017 if (!_this->GetWindowICCProfile) { 2030 2018 SDL_Unsupported(); 2031 2019 return NULL; 2032 2020 } 2033 - return SDL_FreeLater(_this->GetWindowICCProfile(_this, window, size)); 2021 + return _this->GetWindowICCProfile(_this, window, size); 2034 2022 } 2035 2023 2036 2024 SDL_PixelFormat SDL_GetWindowPixelFormat(SDL_Window *window) ··· 2080 2068 } 2081 2069 } 2082 2070 2083 - SDL_Window * const *SDLCALL SDL_GetWindows(int *count) 2071 + SDL_Window **SDLCALL SDL_GetWindows(int *count) 2084 2072 { 2085 2073 if (count) { 2086 2074 *count = 0; ··· 2115 2103 if (count) { 2116 2104 *count = num_added; 2117 2105 } 2118 - return SDL_FreeLater(windows); 2106 + return windows; 2119 2107 } 2120 2108 2121 2109 static void ApplyWindowFlags(SDL_Window *window, SDL_WindowFlags flags) ··· 3033 3021 3034 3022 SDL_GetWindowSize(window, w, h); 3035 3023 3036 - if ((window->flags & SDL_WINDOW_FULLSCREEN) && SDL_GetWindowFullscreenModeInternal(window)) { 3024 + if ((window->flags & SDL_WINDOW_FULLSCREEN) && SDL_GetWindowFullscreenMode(window)) { 3037 3025 mode = SDL_GetCurrentDisplayMode(displayID); 3038 3026 } else { 3039 3027 mode = SDL_GetDesktopDisplayMode(displayID); ··· 3786 3774 { 3787 3775 if (window->flags & SDL_WINDOW_FULLSCREEN) { 3788 3776 SDL_DisplayID displayID = SDL_GetDisplayForWindowPosition(window); 3789 - const SDL_DisplayMode *new_mode = NULL; 3790 3777 3791 3778 if (window->requested_fullscreen_mode.w != 0 || window->requested_fullscreen_mode.h != 0) { 3792 3779 SDL_bool include_high_density_modes = SDL_FALSE; ··· 3794 3781 if (window->requested_fullscreen_mode.pixel_density > 1.0f) { 3795 3782 include_high_density_modes = SDL_TRUE; 3796 3783 } 3797 - new_mode = SDL_GetClosestFullscreenDisplayMode(displayID, window->requested_fullscreen_mode.w, window->requested_fullscreen_mode.h, window->requested_fullscreen_mode.refresh_rate, include_high_density_modes); 3798 - } 3799 - 3800 - if (new_mode) { 3801 - SDL_copyp(&window->current_fullscreen_mode, new_mode); 3784 + SDL_GetClosestFullscreenDisplayMode(displayID, window->requested_fullscreen_mode.w, window->requested_fullscreen_mode.h, window->requested_fullscreen_mode.refresh_rate, include_high_density_modes, &window->current_fullscreen_mode); 3802 3785 } else { 3803 3786 SDL_zero(window->current_fullscreen_mode); 3804 3787 }
+2 -1
src/video/cocoa/SDL_cocoawindow.m
··· 1803 1803 } 1804 1804 if (existingTouchCount == 0) { 1805 1805 int numFingers; 1806 - const SDL_Finger * const *fingers = SDL_GetTouchFingers(touchID, &numFingers); 1806 + SDL_Finger **fingers = SDL_GetTouchFingers(touchID, &numFingers); 1807 1807 if (fingers) { 1808 1808 DLog("Reset Lost Fingers: %d", numFingers); 1809 1809 for (--numFingers; numFingers >= 0; --numFingers) { ··· 1816 1816 SDL_Window *window = NULL; 1817 1817 SDL_SendTouch(Cocoa_GetEventTimestamp([theEvent timestamp]), touchID, finger->id, window, SDL_FALSE, 0, 0, 0); 1818 1818 } 1819 + SDL_free(fingers); 1819 1820 } 1820 1821 } 1821 1822
+2 -1
src/video/kmsdrm/SDL_kmsdrmmouse.c
··· 315 315 This happens on video quit, where we get here after 316 316 the mouse focus has been unset, yet SDL wants to 317 317 restore the system default cursor (makes no sense here). */ 318 - const SDL_DisplayID *displays = SDL_GetDisplays(NULL); 318 + SDL_DisplayID *displays = SDL_GetDisplays(NULL); 319 319 if (displays) { 320 320 /* Iterate on the displays, hiding the cursor. */ 321 321 for (i = 0; i < displays[i]; i++) { 322 322 display = SDL_GetVideoDisplay(displays[i]); 323 323 ret = KMSDRM_RemoveCursorFromBO(display); 324 324 } 325 + SDL_free(displays); 325 326 } 326 327 } else { 327 328 display = SDL_GetVideoDisplayForWindow(window);
+5 -5
src/video/kmsdrm/SDL_kmsdrmvideo.c
··· 514 514 SDL_DisplayData *dispdata = display->internal; 515 515 drmModeConnector *connector = dispdata->connector; 516 516 517 - const SDL_DisplayMode *closest; 517 + SDL_DisplayMode closest; 518 518 drmModeModeInfo *drm_mode; 519 519 520 - closest = SDL_GetClosestFullscreenDisplayMode(display->id, width, height, 0.0f, SDL_FALSE); 521 - if (closest) { 522 - const SDL_DisplayModeData *modedata = closest->internal; 520 + if (SDL_GetClosestFullscreenDisplayMode(display->id, width, height, 0.0f, SDL_FALSE, &closest) == 0) { 521 + const SDL_DisplayModeData *modedata = closest.internal; 523 522 drm_mode = &connector->modes[modedata->mode_index]; 524 523 return drm_mode; 525 524 } else { ··· 535 534 /* Deinitializes the internal of the SDL Displays in the SDL display list. */ 536 535 static void KMSDRM_DeinitDisplays(SDL_VideoDevice *_this) 537 536 { 538 - const SDL_DisplayID *displays; 537 + SDL_DisplayID *displays; 539 538 SDL_DisplayData *dispdata; 540 539 int i; 541 540 ··· 559 558 dispdata->crtc = NULL; 560 559 } 561 560 } 561 + SDL_free(displays); 562 562 } 563 563 } 564 564
+2 -1
src/video/uikit/SDL_uikitmodes.m
··· 310 310 311 311 void UIKit_DelDisplay(UIScreen *uiscreen, SDL_bool send_event) 312 312 { 313 - const SDL_DisplayID *displays; 313 + SDL_DisplayID *displays; 314 314 int i; 315 315 316 316 displays = SDL_GetDisplays(NULL); ··· 326 326 break; 327 327 } 328 328 } 329 + SDL_free(displays); 329 330 } 330 331 } 331 332
+4 -5
src/video/uikit/SDL_uikitwindow.m
··· 172 172 #if !defined(SDL_PLATFORM_TVOS) && !defined(SDL_PLATFORM_VISIONOS) 173 173 const CGSize origsize = data.uiscreen.currentMode.size; 174 174 if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) { 175 - const SDL_DisplayMode *bestmode; 175 + SDL_DisplayMode bestmode; 176 176 SDL_bool include_high_density_modes = SDL_FALSE; 177 177 if (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) { 178 178 include_high_density_modes = SDL_TRUE; 179 179 } 180 - bestmode = SDL_GetClosestFullscreenDisplayMode(display->id, window->w, window->h, 0.0f, include_high_density_modes); 181 - if (bestmode) { 182 - SDL_UIKitDisplayModeData *modedata = (__bridge SDL_UIKitDisplayModeData *)bestmode->internal; 180 + if (SDL_GetClosestFullscreenDisplayMode(display->id, window->w, window->h, 0.0f, include_high_density_modes, &bestmode) == 0) { 181 + SDL_UIKitDisplayModeData *modedata = (__bridge SDL_UIKitDisplayModeData *)bestmode.internal; 183 182 [data.uiscreen setCurrentMode:modedata.uiscreenmode]; 184 183 185 184 /* desktop_mode doesn't change here (the higher level will 186 185 * use it to set all the screens back to their defaults 187 186 * upon window destruction, SDL_Quit(), etc. */ 188 - SDL_SetCurrentDisplayMode(display, bestmode); 187 + SDL_SetCurrentDisplayMode(display, &bestmode); 189 188 } 190 189 } 191 190
+2 -1
src/video/wayland/SDL_waylandwindow.c
··· 516 516 { 517 517 SDL_WindowData *wind = window->internal; 518 518 SDL_DisplayData *display; 519 - const SDL_DisplayID *displays; 519 + SDL_DisplayID *displays; 520 520 521 521 if (wind->outputs && wind->num_outputs) { 522 522 display = wind->outputs[wind->num_outputs - 1]; ··· 559 559 break; 560 560 } 561 561 } 562 + SDL_free(displays); 562 563 } 563 564 } 564 565
+4 -2
src/video/windows/SDL_windowsevents.c
··· 867 867 PRAWINPUTDEVICELIST raw_devices = NULL; 868 868 UINT raw_device_count = 0; 869 869 int old_keyboard_count = 0; 870 - const SDL_KeyboardID *old_keyboards = NULL; 870 + SDL_KeyboardID *old_keyboards = NULL; 871 871 int new_keyboard_count = 0; 872 872 SDL_KeyboardID *new_keyboards = NULL; 873 873 int old_mouse_count = 0; 874 - const SDL_MouseID *old_mice = NULL; 874 + SDL_MouseID *old_mice = NULL; 875 875 int new_mouse_count = 0; 876 876 SDL_MouseID *new_mice = NULL; 877 877 SDL_bool send_event = !initial_check; ··· 982 982 } 983 983 } 984 984 985 + SDL_free(old_keyboards); 985 986 SDL_free(new_keyboards); 987 + SDL_free(old_mice); 986 988 SDL_free(new_mice); 987 989 988 990 SetupDiDestroyDeviceInfoList(devinfo);
+2 -1
src/video/x11/SDL_x11modes.c
··· 686 686 687 687 static void X11_HandleXRandROutputChange(SDL_VideoDevice *_this, const XRROutputChangeNotifyEvent *ev) 688 688 { 689 - const SDL_DisplayID *displays; 689 + SDL_DisplayID *displays; 690 690 SDL_VideoDisplay *display = NULL; 691 691 int i; 692 692 ··· 704 704 break; 705 705 } 706 706 } 707 + SDL_free(displays); 707 708 } 708 709 709 710 if (ev->connection == RR_Disconnected) { /* output is going away */
+2 -1
src/video/x11/SDL_x11mouse.c
··· 418 418 static SDL_MouseButtonFlags X11_GetGlobalMouseState(float *x, float *y) 419 419 { 420 420 SDL_VideoData *videodata = SDL_GetVideoDevice()->internal; 421 - const SDL_DisplayID *displays; 421 + SDL_DisplayID *displays; 422 422 Display *display = GetDisplay(); 423 423 int i; 424 424 ··· 460 460 } 461 461 } 462 462 } 463 + SDL_free(displays); 463 464 } 464 465 } 465 466
+36 -21
src/video/x11/SDL_x11xinput2.c
··· 725 725 return SDL_FALSE; 726 726 } 727 727 728 + static void AddDeviceID64(Uint64 deviceID, Uint64 **list, int *count) 729 + { 730 + int new_count = (*count + 1); 731 + Uint64 *new_list = (Uint64 *)SDL_realloc(*list, new_count * sizeof(*new_list)); 732 + if (!new_list) { 733 + /* Oh well, we'll drop this one */ 734 + return; 735 + } 736 + new_list[new_count - 1] = deviceID; 737 + 738 + *count = new_count; 739 + *list = new_list; 740 + } 741 + 742 + static SDL_bool HasDeviceID64(Uint64 deviceID, const Uint64 *list, int count) 743 + { 744 + for (int i = 0; i < count; ++i) { 745 + if (deviceID == list[i]) { 746 + return SDL_TRUE; 747 + } 748 + } 749 + return SDL_FALSE; 750 + } 751 + 728 752 #endif // SDL_VIDEO_DRIVER_X11_XINPUT2 729 753 730 754 void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, SDL_bool initial_check) ··· 734 758 XIDeviceInfo *info; 735 759 int ndevices; 736 760 int old_keyboard_count = 0; 737 - const SDL_KeyboardID *old_keyboards = NULL; 761 + SDL_KeyboardID *old_keyboards = NULL; 738 762 int new_keyboard_count = 0; 739 763 SDL_KeyboardID *new_keyboards = NULL; 740 764 int old_mouse_count = 0; 741 - const SDL_MouseID *old_mice = NULL; 765 + SDL_MouseID *old_mice = NULL; 742 766 int new_mouse_count = 0; 743 767 SDL_MouseID *new_mice = NULL; 744 768 int old_touch_count = 0; 745 - const SDL_TouchID *old_touch_devices64 = NULL; 746 - Uint32 *old_touch_devices = NULL; 769 + Uint64 *old_touch_devices = NULL; 747 770 int new_touch_count = 0; 748 - Uint32 *new_touch_devices = NULL; 771 + Uint64 *new_touch_devices = NULL; 749 772 SDL_bool send_event = !initial_check; 750 773 751 774 SDL_assert(X11_Xinput2IsInitialized()); ··· 754 777 755 778 old_keyboards = SDL_GetKeyboards(&old_keyboard_count); 756 779 old_mice = SDL_GetMice(&old_mouse_count); 757 - 758 - /* SDL_TouchID is 64-bit, but our helper functions take Uint32 */ 759 - old_touch_devices64 = SDL_GetTouchDevices(&old_touch_count); 760 - if (old_touch_count > 0) { 761 - old_touch_devices = (Uint32 *)SDL_malloc(old_touch_count * sizeof(*old_touch_devices)); 762 - if (old_touch_devices) { 763 - for (int i = 0; i < old_touch_count; ++i) { 764 - old_touch_devices[i] = (Uint32)old_touch_devices64[i]; 765 - } 766 - } 767 - } 780 + old_touch_devices = SDL_GetTouchDevices(&old_touch_count); 768 781 769 782 for (int i = 0; i < ndevices; i++) { 770 783 XIDeviceInfo *dev = &info[i]; ··· 796 809 797 810 #ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH 798 811 for (int j = 0; j < dev->num_classes; j++) { 799 - Uint32 touchID; 812 + Uint64 touchID; 800 813 SDL_TouchDeviceType touchType; 801 814 XIAnyClassInfo *class = dev->classes[j]; 802 815 XITouchClassInfo *t = (XITouchClassInfo *)class; ··· 806 819 continue; 807 820 } 808 821 809 - touchID = (Uint32)t->sourceid; 810 - AddDeviceID(touchID, &new_touch_devices, &new_touch_count); 811 - if (!HasDeviceID(touchID, old_touch_devices, old_touch_count)) { 822 + touchID = (Uint64)t->sourceid; 823 + AddDeviceID64(touchID, &new_touch_devices, &new_touch_count); 824 + if (!HasDeviceID64(touchID, old_touch_devices, old_touch_count)) { 812 825 if (t->mode == XIDependentTouch) { 813 826 touchType = SDL_TOUCH_DEVICE_INDIRECT_RELATIVE; 814 827 } else { /* XIDirectTouch */ ··· 833 846 } 834 847 835 848 for (int i = old_touch_count; i--;) { 836 - if (!HasDeviceID(old_touch_devices[i], new_touch_devices, new_touch_count)) { 849 + if (!HasDeviceID64(old_touch_devices[i], new_touch_devices, new_touch_count)) { 837 850 SDL_DelTouch(old_touch_devices[i]); 838 851 } 839 852 } 840 853 854 + SDL_free(old_keyboards); 841 855 SDL_free(new_keyboards); 856 + SDL_free(old_mice); 842 857 SDL_free(new_mice); 843 858 SDL_free(old_touch_devices); 844 859 SDL_free(new_touch_devices);
+4 -2
test/gamepadutils.c
··· 416 416 } 417 417 418 418 ctx->type = SDL_GetGamepadType(gamepad); 419 - const char *mapping = SDL_GetGamepadMapping(gamepad); 419 + char *mapping = SDL_GetGamepadMapping(gamepad); 420 420 if (mapping) { 421 421 if (SDL_strstr(mapping, "SDL_GAMECONTROLLER_USE_BUTTON_LABELS")) { 422 422 /* Just for display purposes */ 423 423 ctx->type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO; 424 424 } 425 + SDL_free(mapping); 425 426 } 426 427 427 428 for (i = 0; i < SDL_GAMEPAD_BUTTON_TOUCHPAD; ++i) { ··· 1021 1022 const float arrow_extent = 48.0f; 1022 1023 SDL_FRect dst, rect, highlight; 1023 1024 Uint8 r, g, b, a; 1024 - const char *mapping = NULL; 1025 + char *mapping; 1025 1026 SDL_bool has_accel; 1026 1027 SDL_bool has_gyro; 1027 1028 ··· 1285 1286 } 1286 1287 } 1287 1288 } 1289 + SDL_free(mapping); 1288 1290 } 1289 1291 1290 1292 void DestroyGamepadDisplay(GamepadDisplay *ctx)
+1 -1
test/pretest.c
··· 27 27 (void)argv; 28 28 SDL_Init(0); 29 29 start = SDL_GetTicks(); 30 - SDL_GetPrefPath("libsdl", "test_filesystem"); 30 + SDL_free(SDL_GetPrefPath("libsdl", "test_filesystem")); 31 31 prequit = SDL_GetTicks(); 32 32 SDL_Log("SDL_GetPrefPath took %" SDL_PRIu64 "ms", prequit - start); 33 33 SDL_Quit();
+2 -1
test/testaudioinfo.c
··· 20 20 const char *typestr = (recording ? "recording" : "playback"); 21 21 int n = 0; 22 22 int frames; 23 - const SDL_AudioDeviceID *devices = recording ? SDL_GetAudioRecordingDevices(&n) : SDL_GetAudioPlaybackDevices(&n); 23 + SDL_AudioDeviceID *devices = recording ? SDL_GetAudioRecordingDevices(&n) : SDL_GetAudioPlaybackDevices(&n); 24 24 25 25 if (!devices) { 26 26 SDL_Log(" Driver failed to report %s devices: %s\n\n", typestr, SDL_GetError()); ··· 46 46 } 47 47 SDL_Log("\n"); 48 48 } 49 + SDL_free(devices); 49 50 } 50 51 51 52 int main(int argc, char **argv)
+6 -1
test/testaudiorecording.c
··· 23 23 24 24 int SDL_AppInit(void **appstate, int argc, char **argv) 25 25 { 26 - const SDL_AudioDeviceID *devices; 26 + SDL_AudioDeviceID *devices; 27 27 SDL_AudioSpec outspec; 28 28 SDL_AudioSpec inspec; 29 29 SDL_AudioDeviceID device; ··· 103 103 device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, NULL); 104 104 if (!device) { 105 105 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for playback: %s!\n", SDL_GetError()); 106 + SDL_free(devices); 106 107 return SDL_APP_FAILURE; 107 108 } 108 109 SDL_PauseAudioDevice(device); ··· 110 111 stream_out = SDL_CreateAudioStream(&outspec, &outspec); 111 112 if (!stream_out) { 112 113 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for playback: %s!\n", SDL_GetError()); 114 + SDL_free(devices); 113 115 return SDL_APP_FAILURE; 114 116 } else if (SDL_BindAudioStream(device, stream_out) == -1) { 115 117 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for playback: %s!\n", SDL_GetError()); 118 + SDL_free(devices); 116 119 return SDL_APP_FAILURE; 117 120 } 118 121 ··· 124 127 device = SDL_OpenAudioDevice(want_device, NULL); 125 128 if (!device) { 126 129 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for recording: %s!\n", SDL_GetError()); 130 + SDL_free(devices); 127 131 return SDL_APP_FAILURE; 128 132 } 133 + SDL_free(devices); 129 134 SDL_PauseAudioDevice(device); 130 135 SDL_GetAudioDeviceFormat(device, &inspec, NULL); 131 136 stream_in = SDL_CreateAudioStream(&inspec, &inspec);
+2 -1
test/testautomation_audio.c
··· 366 366 int t; 367 367 int i, n; 368 368 const char *name; 369 - const SDL_AudioDeviceID *devices = NULL; 369 + SDL_AudioDeviceID *devices; 370 370 371 371 /* Iterate over types: t=0 playback device, t=1 recording device */ 372 372 for (t = 0; t < 2; t++) { ··· 388 388 } 389 389 } 390 390 } 391 + SDL_free(devices); 391 392 } 392 393 393 394 return TEST_COMPLETED;
+20 -6
test/testautomation_clipboard.c
··· 86 86 int last_clipboard_update_count; 87 87 int last_clipboard_callback_count; 88 88 int last_clipboard_cleanup_count; 89 - const void *data; 89 + void *data; 90 90 size_t size; 91 - const char *text; 91 + char *text; 92 92 const char *expected_text; 93 93 94 94 TestClipboardData test_data1 = { ··· 163 163 clipboard_cleanup_count - last_clipboard_cleanup_count); 164 164 165 165 expected_text = "TEST"; 166 - text = (char *) SDL_GetClipboardText(); 166 + text = SDL_GetClipboardText(); 167 167 SDLTest_AssertCheck( 168 168 text && SDL_strcmp(text, expected_text) == 0, 169 169 "Verify clipboard text, expected \"%s\", got \"%s\"", 170 170 expected_text, text); 171 + SDL_free(text); 171 172 172 173 boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT]); 173 174 SDLTest_AssertCheck( ··· 186 187 size == SDL_strlen(expected_text), 187 188 "Verify test text size, expected %d, got %d", 188 189 (int)SDL_strlen(expected_text), (int)size); 190 + SDL_free(text); 189 191 190 192 expected_text = "CUSTOM"; 191 193 boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT]); ··· 205 207 size == SDL_strlen(expected_text), 206 208 "Verify test text size, expected %d, got %d", 207 209 (int)SDL_strlen(expected_text), (int)size); 210 + SDL_free(text); 208 211 209 212 boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_DATA]); 210 213 SDLTest_AssertCheck( ··· 218 221 size == test_data1.data_size, 219 222 "Verify test data size, expected %d, got %d", 220 223 (int)test_data1.data_size, (int)size); 224 + SDL_free(data); 221 225 222 226 boolResult = SDL_HasClipboardData("test/invalid"); 223 227 SDLTest_AssertCheck( ··· 232 236 size == 0, 233 237 "Verify invalid data size, expected 0, got %d", 234 238 (int)size); 239 + SDL_free(data); 235 240 236 241 #if 0 /* There's no guarantee how or when the callback is called */ 237 242 SDLTest_AssertCheck( ··· 260 265 clipboard_cleanup_count - last_clipboard_cleanup_count); 261 266 262 267 expected_text = "TEST"; 263 - text = (char *) SDL_GetClipboardText(); 268 + text = SDL_GetClipboardText(); 264 269 SDLTest_AssertCheck( 265 270 text && SDL_strcmp(text, expected_text) == 0, 266 271 "Verify clipboard text, expected \"%s\", got \"%s\"", 267 272 expected_text, text); 273 + SDL_free(text); 268 274 269 275 boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT]); 270 276 SDLTest_AssertCheck( ··· 283 289 size == SDL_strlen(expected_text), 284 290 "Verify test text size, expected %d, got %d", 285 291 (int)SDL_strlen(expected_text), (int)size); 292 + SDL_free(text); 286 293 287 294 expected_text = "CUSTOM"; 288 295 boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT]); ··· 302 309 size == SDL_strlen(expected_text), 303 310 "Verify test text size, expected %d, got %d", 304 311 (int)SDL_strlen(expected_text), (int)size); 312 + SDL_free(text); 305 313 306 314 data = SDL_GetClipboardData(test_mime_types[TEST_MIME_TYPE_DATA], &size); 307 315 SDLTest_AssertCheck( ··· 311 319 size == test_data2.data_size, 312 320 "Verify test data size, expected %d, got %d", 313 321 (int)test_data2.data_size, (int)size); 322 + SDL_free(data); 314 323 315 324 data = SDL_GetClipboardData("test/invalid", &size); 316 325 SDLTest_AssertCheck( ··· 321 330 size == 0, 322 331 "Verify invalid data size, expected 0, got %d", 323 332 (int)size); 333 + SDL_free(data); 324 334 325 335 #if 0 /* There's no guarantee how or when the callback is called */ 326 336 SDLTest_AssertCheck( ··· 376 386 char *text = SDL_strdup(textRef); 377 387 SDL_bool boolResult; 378 388 int intResult; 379 - const char *charResult; 389 + char *charResult; 380 390 int last_clipboard_update_count; 381 391 382 392 SDL_AddEventWatch(ClipboardEventWatch, NULL); ··· 393 403 charResult && SDL_strcmp(charResult, "") == 0, 394 404 "Verify SDL_GetClipboardText returned \"\", got %s", 395 405 charResult); 406 + SDL_free(charResult); 396 407 boolResult = SDL_HasClipboardText(); 397 408 SDLTest_AssertCheck( 398 409 boolResult == SDL_FALSE, ··· 425 436 charResult && SDL_strcmp(textRef, charResult) == 0, 426 437 "Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'", 427 438 textRef, charResult); 439 + SDL_free(charResult); 428 440 SDLTest_AssertCheck( 429 441 clipboard_update_count == last_clipboard_update_count + 1, 430 442 "Verify clipboard update count incremented by 1, got %d", ··· 458 470 char *text = SDL_strdup(textRef); 459 471 SDL_bool boolResult; 460 472 int intResult; 461 - const char *charResult; 473 + char *charResult; 462 474 int last_clipboard_update_count; 463 475 464 476 SDL_AddEventWatch(ClipboardEventWatch, NULL); ··· 475 487 charResult && SDL_strcmp(charResult, "") == 0, 476 488 "Verify SDL_GetPrimarySelectionText returned \"\", got %s", 477 489 charResult); 490 + SDL_free(charResult); 478 491 boolResult = SDL_HasPrimarySelectionText(); 479 492 SDLTest_AssertCheck( 480 493 boolResult == SDL_FALSE, ··· 506 519 charResult && SDL_strcmp(textRef, charResult) == 0, 507 520 "Verify SDL_GetPrimarySelectionText returned correct string, expected '%s', got '%s'", 508 521 textRef, charResult); 522 + SDL_free(charResult); 509 523 SDLTest_AssertCheck( 510 524 clipboard_update_count == last_clipboard_update_count + 1, 511 525 "Verify clipboard update count incremented by 1, got %d",
+1 -66
test/testautomation_events.c
··· 175 175 return TEST_COMPLETED; 176 176 } 177 177 178 - /** 179 - * Creates and validates temporary event memory 180 - */ 181 - static int events_temporaryMemory(void *arg) 182 - { 183 - SDL_Event event; 184 - void *mem, *claimed, *tmp; 185 - SDL_bool found; 186 - 187 - { 188 - /* Create and claim event memory */ 189 - mem = SDL_AllocateTemporaryMemory(1); 190 - SDLTest_AssertCheck(mem != NULL, "SDL_AllocateTemporaryMemory()"); 191 - *(char *)mem = '1'; 192 - 193 - claimed = SDL_ClaimTemporaryMemory(mem); 194 - SDLTest_AssertCheck(claimed != NULL, "SDL_ClaimTemporaryMemory() returned a valid pointer"); 195 - 196 - /* Verify that we can't claim it again */ 197 - tmp = SDL_ClaimTemporaryMemory(mem); 198 - SDLTest_AssertCheck(tmp == NULL, "SDL_ClaimTemporaryMemory() can't claim memory twice"); 199 - 200 - /* Clean up */ 201 - SDL_free(claimed); 202 - } 203 - 204 - { 205 - /* Create event memory and queue it */ 206 - mem = SDL_AllocateTemporaryMemory(1); 207 - SDLTest_AssertCheck(mem != NULL, "SDL_AllocateTemporaryMemory()"); 208 - *(char *)mem = '2'; 209 - 210 - SDL_zero(event); 211 - event.type = SDL_EVENT_USER; 212 - event.user.data1 = mem; 213 - SDL_PushEvent(&event); 214 - 215 - /* Verify that we can't claim the memory once it's on the queue */ 216 - claimed = SDL_ClaimTemporaryMemory(mem); 217 - SDLTest_AssertCheck(claimed == NULL, "SDL_ClaimTemporaryMemory() can't claim memory on the event queue"); 218 - 219 - /* Get the event and verify the memory is valid */ 220 - found = SDL_FALSE; 221 - while (SDL_PollEvent(&event)) { 222 - if (event.type == SDL_EVENT_USER && event.user.data1 == mem) { 223 - found = SDL_TRUE; 224 - } 225 - } 226 - SDLTest_AssertCheck(found, "SDL_PollEvent() returned queued event"); 227 - 228 - /* Verify that we can claim the memory now that we've dequeued it */ 229 - claimed = SDL_ClaimTemporaryMemory(mem); 230 - SDLTest_AssertCheck(claimed != NULL, "SDL_ClaimTemporaryMemory() can claim memory after dequeuing event"); 231 - 232 - /* Clean up */ 233 - SDL_free(claimed); 234 - } 235 - 236 - return TEST_COMPLETED; 237 - } 238 - 239 178 /* ================= Test References ================== */ 240 179 241 180 /* Events test cases */ ··· 251 190 (SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED 252 191 }; 253 192 254 - static const SDLTest_TestCaseReference eventsTestTemporaryMemory = { 255 - (SDLTest_TestCaseFp)events_temporaryMemory, "events_temporaryMemory", "Creates and validates temporary event memory", TEST_ENABLED 256 - }; 257 - 258 193 /* Sequence of Events test cases */ 259 194 static const SDLTest_TestCaseReference *eventsTests[] = { 260 - &eventsTest1, &eventsTest2, &eventsTest3, &eventsTestTemporaryMemory, NULL 195 + &eventsTest1, &eventsTest2, &eventsTest3, NULL 261 196 }; 262 197 263 198 /* Events test suite (global) */
+2 -2
test/testautomation_guid.c
··· 106 106 107 107 SDLTest_AssertPass("Call to SDL_GUIDToString"); 108 108 for (i = 0; i < NUM_TEST_GUIDS; ++i) { 109 - const char *guid_str; 109 + char guid_str[33]; 110 110 SDL_GUID guid; 111 111 112 112 upper_lower_to_bytestring(guid.data, 113 113 test_guids[i].upper, test_guids[i].lower); 114 114 115 - guid_str = SDL_GUIDToString(guid); 115 + SDL_GUIDToString(guid, guid_str, sizeof(guid_str)); 116 116 SDLTest_AssertCheck(SDL_strcmp(guid_str, test_guids[i].str) == 0, "Checking whether strings match, expected %s, got %s\n", test_guids[i].str, guid_str); 117 117 } 118 118
+8 -4
test/testautomation_joystick.c
··· 64 64 gamepad = SDL_OpenGamepad(SDL_GetJoystickID(joystick)); 65 65 SDLTest_AssertCheck(gamepad != NULL, "SDL_OpenGamepad() succeeded"); 66 66 if (gamepad) { 67 - SDLTest_AssertCheck(SDL_strcmp(SDL_GetGamepadName(gamepad), desc.name) == 0, "SDL_GetGamepadName()"); 67 + const char *name = SDL_GetGamepadName(gamepad); 68 + SDLTest_AssertCheck(name && SDL_strcmp(name, desc.name) == 0, "SDL_GetGamepadName()"); 68 69 SDLTest_AssertCheck(SDL_GetGamepadVendor(gamepad) == desc.vendor_id, "SDL_GetGamepadVendor()"); 69 70 SDLTest_AssertCheck(SDL_GetGamepadProduct(gamepad) == desc.product_id, "SDL_GetGamepadProduct()"); 70 71 71 72 /* Set an explicit mapping with a different name */ 72 73 SDL_SetGamepadMapping(SDL_GetJoystickID(joystick), "ff0013db5669727475616c2043007601,Virtual Gamepad,a:b0,b:b1,x:b2,y:b3,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,"); 73 - SDLTest_AssertCheck(SDL_strcmp(SDL_GetGamepadName(gamepad), "Virtual Gamepad") == 0, "SDL_GetGamepadName() == Virtual Gamepad"); 74 + name = SDL_GetGamepadName(gamepad); 75 + SDLTest_AssertCheck(name && SDL_strcmp(name, "Virtual Gamepad") == 0, "SDL_GetGamepadName() == Virtual Gamepad"); 74 76 SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_A, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_A"); 75 77 76 78 /* Set the south button and verify that the gamepad responds */ ··· 84 86 85 87 /* Set an explicit mapping with legacy Nintendo style buttons */ 86 88 SDL_SetGamepadMapping(SDL_GetJoystickID(joystick), "ff0013db5669727475616c2043007601,Virtual Nintendo Gamepad,a:b1,b:b0,x:b3,y:b2,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,hint:SDL_GAMECONTROLLER_USE_BUTTON_LABELS:=1,"); 87 - SDLTest_AssertCheck(SDL_strcmp(SDL_GetGamepadName(gamepad), "Virtual Nintendo Gamepad") == 0, "SDL_GetGamepadName() == Virtual Nintendo Gamepad"); 89 + name = SDL_GetGamepadName(gamepad); 90 + SDLTest_AssertCheck(name && SDL_strcmp(name, "Virtual Nintendo Gamepad") == 0, "SDL_GetGamepadName() == Virtual Nintendo Gamepad"); 88 91 SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_B, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_B"); 89 92 90 93 /* Set the south button and verify that the gamepad responds */ ··· 98 101 99 102 /* Set an explicit mapping with PS4 style buttons */ 100 103 SDL_SetGamepadMapping(SDL_GetJoystickID(joystick), "ff0013db5669727475616c2043007601,Virtual PS4 Gamepad,type:ps4,a:b0,b:b1,x:b2,y:b3,back:b4,guide:b5,start:b6,leftstick:b7,rightstick:b8,leftshoulder:b9,rightshoulder:b10,dpup:b11,dpdown:b12,dpleft:b13,dpright:b14,misc1:b15,paddle1:b16,paddle2:b17,paddle3:b18,paddle4:b19,leftx:a0,lefty:a1,rightx:a2,righty:a3,lefttrigger:a4,righttrigger:a5,"); 101 - SDLTest_AssertCheck(SDL_strcmp(SDL_GetGamepadName(gamepad), "Virtual PS4 Gamepad") == 0, "SDL_GetGamepadName() == Virtual PS4 Gamepad"); 104 + name = SDL_GetGamepadName(gamepad); 105 + SDLTest_AssertCheck(name && SDL_strcmp(name, "Virtual PS4 Gamepad") == 0, "SDL_GetGamepadName() == Virtual PS4 Gamepad"); 102 106 SDLTest_AssertCheck(SDL_GetGamepadButtonLabel(gamepad, SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_CROSS, "SDL_GetGamepadButtonLabel(SDL_GAMEPAD_BUTTON_SOUTH) == SDL_GAMEPAD_BUTTON_LABEL_CROSS"); 103 107 104 108 /* Set the south button and verify that the gamepad responds */
+1
test/testautomation_pen.c
··· 38 38 #define SDL_GetPenName SDL_SUT_GetPenName 39 39 #define SDL_GetPenCapabilities SDL_SUT_GetPenCapabilities 40 40 #define SDL_GetPenType SDL_SUT_GetPenType 41 + #define SDL_GetPersistentString(X) X 41 42 42 43 #define SDL_GetPenPtr SDL_SUT_GetPenPtr 43 44 #define SDL_PenModifyBegin SDL_SUT_PenModifyBegin
+25 -17
test/testautomation_video.c
··· 13 13 static SDL_Window *createVideoSuiteTestWindow(const char *title) 14 14 { 15 15 SDL_Window *window; 16 - SDL_Window * const *windows; 16 + SDL_Window **windows; 17 17 SDL_Event event; 18 18 int w, h; 19 19 int count; ··· 34 34 windows = SDL_GetWindows(&count); 35 35 SDLTest_AssertCheck(windows != NULL, "Validate that returned window list is not NULL"); 36 36 SDLTest_AssertCheck(windows[0] == window, "Validate that the window is first in the window list"); 37 + SDL_free(windows); 37 38 38 39 /* Wayland and XWayland windows require that a frame be presented before they are fully mapped and visible onscreen. 39 40 * This is required for the mouse/keyboard grab tests to pass. ··· 305 306 */ 306 307 static int video_getFullscreenDisplayModes(void *arg) 307 308 { 308 - const SDL_DisplayID *displays; 309 - const SDL_DisplayMode * const *modes; 309 + SDL_DisplayID *displays; 310 + SDL_DisplayMode **modes; 310 311 int count; 311 312 int i; 312 313 ··· 321 322 SDLTest_AssertPass("Call to SDL_GetFullscreenDisplayModes(%" SDL_PRIu32 ")", displays[i]); 322 323 SDLTest_AssertCheck(modes != NULL, "Validate returned value from function; expected != NULL; got: %p", modes); 323 324 SDLTest_AssertCheck(count >= 0, "Validate number of modes; expected: >= 0; got: %d", count); 325 + SDL_free(modes); 324 326 } 327 + SDL_free(displays); 325 328 } 326 329 327 330 return TEST_COMPLETED; ··· 332 335 */ 333 336 static int video_getClosestDisplayModeCurrentResolution(void *arg) 334 337 { 335 - const SDL_DisplayID *displays; 336 - const SDL_DisplayMode * const *modes; 338 + SDL_DisplayID *displays; 339 + SDL_DisplayMode **modes; 337 340 SDL_DisplayMode current; 338 - const SDL_DisplayMode *closest; 339 - int i, num_modes; 341 + SDL_DisplayMode closest; 342 + int i, result, num_modes; 340 343 341 344 /* Get number of displays */ 342 345 displays = SDL_GetDisplays(NULL); ··· 355 358 SDL_memcpy(&current, modes[0], sizeof(current)); 356 359 357 360 /* Make call */ 358 - closest = SDL_GetClosestFullscreenDisplayMode(displays[i], current.w, current.h, current.refresh_rate, SDL_FALSE); 361 + result = SDL_GetClosestFullscreenDisplayMode(displays[i], current.w, current.h, current.refresh_rate, SDL_FALSE, &closest); 359 362 SDLTest_AssertPass("Call to SDL_GetClosestFullscreenDisplayMode(target=current)"); 360 - SDLTest_Assert(closest != NULL, "Verify returned value is not NULL"); 363 + SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result); 361 364 362 365 /* Check that one gets the current resolution back again */ 363 - if (closest) { 364 - SDLTest_AssertCheck(closest->w == current.w, 366 + if (result == 0) { 367 + SDLTest_AssertCheck(closest.w == current.w, 365 368 "Verify returned width matches current width; expected: %d, got: %d", 366 - current.w, closest->w); 367 - SDLTest_AssertCheck(closest->h == current.h, 369 + current.w, closest.w); 370 + SDLTest_AssertCheck(closest.h == current.h, 368 371 "Verify returned height matches current height; expected: %d, got: %d", 369 - current.h, closest->h); 372 + current.h, closest.h); 370 373 } 371 374 } 375 + SDL_free(modes); 372 376 } 377 + SDL_free(displays); 373 378 } 374 379 375 380 return TEST_COMPLETED; ··· 380 385 */ 381 386 static int video_getClosestDisplayModeRandomResolution(void *arg) 382 387 { 383 - const SDL_DisplayID *displays; 388 + SDL_DisplayID *displays; 384 389 SDL_DisplayMode target; 390 + SDL_DisplayMode closest; 385 391 int i; 386 392 int variation; 387 393 ··· 403 409 target.refresh_rate = (variation & 8) ? (float)SDLTest_RandomIntegerInRange(25, 120) : 0.0f; 404 410 405 411 /* Make call; may or may not find anything, so don't validate any further */ 406 - SDL_GetClosestFullscreenDisplayMode(displays[i], target.w, target.h, target.refresh_rate, SDL_FALSE); 412 + SDL_GetClosestFullscreenDisplayMode(displays[i], target.w, target.h, target.refresh_rate, SDL_FALSE, &closest); 407 413 SDLTest_AssertPass("Call to SDL_GetClosestFullscreenDisplayMode(target=random/variation%d)", variation); 408 414 } 409 415 } 416 + SDL_free(displays); 410 417 } 411 418 412 419 return TEST_COMPLETED; ··· 1668 1675 */ 1669 1676 static int video_setWindowCenteredOnDisplay(void *arg) 1670 1677 { 1671 - const SDL_DisplayID *displays; 1678 + SDL_DisplayID *displays; 1672 1679 SDL_Window *window; 1673 1680 const char *title = "video_setWindowCenteredOnDisplay Test Window"; 1674 1681 int x, y, w, h; ··· 1864 1871 destroyVideoSuiteTestWindow(window); 1865 1872 } 1866 1873 } 1874 + SDL_free(displays); 1867 1875 } 1868 1876 1869 1877 return TEST_COMPLETED;
+2 -1
test/testbounds.c
··· 16 16 17 17 int main(int argc, char **argv) 18 18 { 19 - const SDL_DisplayID *displays; 19 + SDL_DisplayID *displays; 20 20 int i; 21 21 SDLTest_CommonState *state; 22 22 ··· 47 47 bounds.x, bounds.y, bounds.w, bounds.h, 48 48 usable.x, usable.y, usable.w, usable.h); 49 49 } 50 + SDL_free(displays); 50 51 } 51 52 52 53 SDL_Quit();
+4 -2
test/testcamera.c
··· 28 28 29 29 static void PrintCameraSpecs(SDL_CameraID camera_id) 30 30 { 31 - const SDL_CameraSpec *const *specs = SDL_GetCameraSupportedFormats(camera_id, NULL); 31 + SDL_CameraSpec **specs = SDL_GetCameraSupportedFormats(camera_id, NULL); 32 32 if (specs) { 33 33 int i; 34 34 ··· 37 37 const SDL_CameraSpec *s = specs[i]; 38 38 SDL_Log(" %dx%d %.2f FPS %s\n", s->width, s->height, (float)s->framerate_numerator / s->framerate_denominator, SDL_GetPixelFormatName(s->format)); 39 39 } 40 + SDL_free(specs); 40 41 } 41 42 } 42 43 ··· 101 102 return SDL_APP_FAILURE; 102 103 } 103 104 104 - const SDL_CameraID *devices = SDL_GetCameras(&devcount); 105 + SDL_CameraID *devices = SDL_GetCameras(&devcount); 105 106 if (!devices) { 106 107 SDL_Log("SDL_GetCameras failed: %s", SDL_GetError()); 107 108 return SDL_APP_FAILURE; ··· 139 140 camera_id = devices[0]; 140 141 } 141 142 } 143 + SDL_free(devices); 142 144 143 145 if (!camera_id) { 144 146 SDL_Log("No cameras available?");
+12 -11
test/testcontroller.c
··· 351 351 } 352 352 } 353 353 354 - SDL_free(controller_name); 355 354 if (name) { 356 355 controller_name = SDL_strdup(name); 357 356 } else { ··· 680 679 static void PasteMapping(void) 681 680 { 682 681 if (controller) { 683 - const char *mapping = SDL_GetClipboardText(); 682 + char *mapping = SDL_GetClipboardText(); 684 683 if (MappingHasBindings(mapping)) { 685 684 StopBinding(); 686 685 SDL_SetGamepadMapping(controller->id, mapping); ··· 688 687 } else { 689 688 /* Not a valid mapping, ignore it */ 690 689 } 690 + SDL_free(mapping); 691 691 } 692 692 } 693 693 ··· 742 742 static void PasteControllerName(void) 743 743 { 744 744 SDL_free(controller_name); 745 - controller_name = SDL_strdup(SDL_GetClipboardText()); 745 + controller_name = SDL_GetClipboardText(); 746 746 CommitControllerName(); 747 747 } 748 748 ··· 918 918 if (verbose && !SDL_IsGamepad(id)) { 919 919 const char *name = SDL_GetJoystickName(joystick); 920 920 const char *path = SDL_GetJoystickPath(joystick); 921 - const char *guid; 921 + char guid[33]; 922 922 SDL_Log("Opened joystick %s%s%s\n", name, path ? ", " : "", path ? path : ""); 923 - guid = SDL_GUIDToString(SDL_GetJoystickGUID(joystick)); 923 + SDL_GUIDToString(SDL_GetJoystickGUID(joystick), guid, sizeof(guid)); 924 924 SDL_Log("No gamepad mapping for %s\n", guid); 925 925 } 926 926 } else { ··· 973 973 974 974 static void HandleGamepadRemapped(SDL_JoystickID id) 975 975 { 976 - const char *sdlmapping; 977 976 char *mapping; 978 977 int i = FindController(id); 979 978 ··· 988 987 } 989 988 990 989 /* Get the current mapping */ 991 - sdlmapping = SDL_GetGamepadMapping(controllers[i].gamepad); 992 - mapping = sdlmapping ? SDL_strdup(sdlmapping) : NULL; 990 + mapping = SDL_GetGamepadMapping(controllers[i].gamepad); 993 991 994 992 /* Make sure the mapping has a valid name */ 995 993 if (mapping && !MappingHasName(mapping)) { ··· 1065 1063 } 1066 1064 1067 1065 if (verbose) { 1068 - const char *mapping = SDL_GetGamepadMapping(gamepad); 1066 + char *mapping = SDL_GetGamepadMapping(gamepad); 1069 1067 if (mapping) { 1070 1068 SDL_Log("Mapping: %s\n", mapping); 1069 + SDL_free(mapping); 1071 1070 } 1072 1071 } 1073 1072 } else { ··· 1187 1186 static void CloseVirtualGamepad(void) 1188 1187 { 1189 1188 int i; 1190 - const SDL_JoystickID *joysticks = SDL_GetJoysticks(NULL); 1189 + SDL_JoystickID *joysticks = SDL_GetJoysticks(NULL); 1191 1190 if (joysticks) { 1192 1191 for (i = 0; joysticks[i]; ++i) { 1193 1192 SDL_JoystickID instance_id = joysticks[i]; ··· 1195 1194 SDL_DetachVirtualJoystick(instance_id); 1196 1195 } 1197 1196 } 1197 + SDL_free(joysticks); 1198 1198 } 1199 1199 1200 1200 if (virtual_joystick) { ··· 2053 2053 2054 2054 if (show_mappings) { 2055 2055 int count = 0; 2056 - const char * const *mappings = SDL_GetGamepadMappings(&count); 2056 + char **mappings = SDL_GetGamepadMappings(&count); 2057 2057 int map_i; 2058 2058 SDL_Log("Supported mappings:\n"); 2059 2059 for (map_i = 0; map_i < count; ++map_i) { 2060 2060 SDL_Log("\t%s\n", mappings[map_i]); 2061 2061 } 2062 2062 SDL_Log("\n"); 2063 + SDL_free(mappings); 2063 2064 } 2064 2065 2065 2066 /* Create a window to display gamepad state */
+2 -1
test/testdialog.c
··· 44 44 } 45 45 } 46 46 47 - int main(int argc, char *argv[]) { 47 + int main(int argc, char *argv[]) 48 + { 48 49 SDL_Window *w; 49 50 SDL_Renderer *r; 50 51 SDLTest_CommonState *state;
+4 -2
test/testdisplayinfo.c
··· 33 33 34 34 int main(int argc, char *argv[]) 35 35 { 36 - const SDL_DisplayID *displays; 37 - const SDL_DisplayMode * const *modes; 36 + SDL_DisplayID *displays; 37 + SDL_DisplayMode **modes; 38 38 const SDL_DisplayMode *mode; 39 39 int num_displays, i; 40 40 SDLTest_CommonState *state; ··· 94 94 (void)SDL_snprintf(prefix, sizeof(prefix), " MODE %d", m); 95 95 print_mode(prefix, modes[m]); 96 96 } 97 + SDL_free(modes); 97 98 98 99 SDL_Log("\n"); 99 100 } 101 + SDL_free(displays); 100 102 101 103 SDL_Quit(); 102 104 SDLTest_CommonDestroyState(state);
+5 -2
test/testfilesystem.c
··· 61 61 int main(int argc, char *argv[]) 62 62 { 63 63 SDLTest_CommonState *state; 64 - const char *pref_path; 64 + char *pref_path; 65 65 const char *base_path; 66 66 67 67 /* Initialize test framework */ ··· 98 98 } else { 99 99 SDL_Log("pref path: '%s'\n", pref_path); 100 100 } 101 + SDL_free(pref_path); 101 102 102 103 pref_path = SDL_GetPrefPath(NULL, "test_filesystem"); 103 104 if (!pref_path) { ··· 106 107 } else { 107 108 SDL_Log("pref path: '%s'\n", pref_path); 108 109 } 110 + SDL_free(pref_path); 109 111 110 112 if (base_path) { 111 - const char * const *globlist; 113 + char **globlist; 112 114 SDL_IOStream *stream; 113 115 const char *text = "foo\n"; 114 116 ··· 124 126 for (i = 0; globlist[i]; i++) { 125 127 SDL_Log("GLOB[%d]: '%s'", i, globlist[i]); 126 128 } 129 + SDL_free(globlist); 127 130 } 128 131 129 132 /* !!! FIXME: put this in a subroutine and make it test more thoroughly (and put it in testautomation). */
+32 -29
test/testhaptic.c
··· 40 40 int id[9]; 41 41 int nefx; 42 42 unsigned int supported; 43 - const SDL_HapticID *haptics; 43 + SDL_HapticID *haptics; 44 44 int num_haptics; 45 45 46 46 /* Initialize test framework */ ··· 88 88 for (i = 0; i < num_haptics; ++i) { 89 89 SDL_Log(" %s\n", SDL_GetHapticNameForID(haptics[i])); 90 90 } 91 - if (haptics) { 92 - if (num_haptics == 0) { 93 - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n"); 94 - return 1; 95 - } 91 + if (num_haptics == 0) { 92 + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n"); 93 + SDL_free(haptics); 94 + return 1; 95 + } 96 96 97 - /* We'll just use index or the first force feedback device found */ 98 - if (!name) { 99 - i = (index != -1) ? index : 0; 97 + /* We'll just use index or the first force feedback device found */ 98 + if (!name) { 99 + i = (index != -1) ? index : 0; 100 100 101 - if (i >= num_haptics) { 102 - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Index out of range, aborting.\n"); 103 - return 1; 104 - } 101 + if (i >= num_haptics) { 102 + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Index out of range, aborting.\n"); 103 + SDL_free(haptics); 104 + return 1; 105 105 } 106 - /* Try to find matching device */ 107 - else { 108 - for (i = 0; i < num_haptics; i++) { 109 - if (SDL_strstr(SDL_GetHapticNameForID(haptics[i]), name) != NULL) { 110 - break; 111 - } 112 - } 113 - 114 - if (i >= num_haptics) { 115 - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n", name); 116 - return 1; 106 + } 107 + /* Try to find matching device */ 108 + else { 109 + for (i = 0; i < num_haptics; i++) { 110 + if (SDL_strstr(SDL_GetHapticNameForID(haptics[i]), name) != NULL) { 111 + break; 117 112 } 118 113 } 119 114 120 - haptic = SDL_OpenHaptic(haptics[i]); 121 - if (!haptic) { 122 - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n", SDL_GetError()); 115 + if (i >= num_haptics) { 116 + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n", name); 117 + SDL_free(haptics); 123 118 return 1; 124 119 } 125 - SDL_Log("Device: %s\n", SDL_GetHapticName(haptic)); 126 - HapticPrintSupported(haptic); 127 120 } 121 + 122 + haptic = SDL_OpenHaptic(haptics[i]); 123 + if (!haptic) { 124 + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n", SDL_GetError()); 125 + SDL_free(haptics); 126 + return 1; 127 + } 128 + SDL_Log("Device: %s\n", SDL_GetHapticName(haptic)); 129 + HapticPrintSupported(haptic); 130 + SDL_free(haptics); 128 131 129 132 /* We only want force feedback errors. */ 130 133 SDL_ClearError();
+4 -4
test/testhotplug.c
··· 80 80 //SDL_CreateWindow("Dummy", 128, 128, 0); 81 81 */ 82 82 83 - SDL_GetKeyboards(&num_keyboards); 83 + SDL_free(SDL_GetKeyboards(&num_keyboards)); 84 84 SDL_Log("There are %d keyboards at startup\n", num_keyboards); 85 85 86 - SDL_GetMice(&num_mice); 86 + SDL_free(SDL_GetMice(&num_mice)); 87 87 SDL_Log("There are %d mice at startup\n", num_mice); 88 88 89 - SDL_GetJoysticks(&num_joysticks); 89 + SDL_free(SDL_GetJoysticks(&num_joysticks)); 90 90 SDL_Log("There are %d joysticks at startup\n", num_joysticks); 91 91 92 92 if (enable_haptic) { 93 93 int num_haptics; 94 - SDL_GetHaptics(&num_haptics); 94 + SDL_free(SDL_GetHaptics(&num_haptics)); 95 95 SDL_Log("There are %d haptic devices at startup\n", num_haptics); 96 96 } 97 97
+16 -3
test/testime.c
··· 53 53 static SDL_bool cursor_visible; 54 54 static Uint64 last_cursor_change; 55 55 static SDL_BlendMode highlight_mode; 56 - static const char **candidates; 56 + static char **candidates; 57 57 static int num_candidates; 58 58 static int selected_candidate; 59 59 static SDL_bool horizontal_candidates; ··· 476 476 477 477 static void ClearCandidates(void) 478 478 { 479 + int i; 480 + 481 + for (i = 0; i < num_candidates; ++i) { 482 + SDL_free(candidates[i]); 483 + } 479 484 SDL_free(candidates); 480 485 candidates = NULL; 481 486 num_candidates = 0; ··· 483 488 484 489 static void SaveCandidates(SDL_Event *event) 485 490 { 491 + int i; 492 + 486 493 ClearCandidates(); 487 494 488 495 num_candidates = event->edit_candidates.num_candidates; 489 496 if (num_candidates > 0) { 490 - candidates = (const char **)SDL_ClaimTemporaryMemory(event->edit_candidates.candidates); 491 - SDL_assert(candidates); 497 + candidates = (char **)SDL_malloc(num_candidates * sizeof(*candidates)); 498 + if (!candidates) { 499 + num_candidates = 0; 500 + return; 501 + } 502 + for (i = 0; i < num_candidates; ++i) { 503 + candidates[i] = SDL_strdup(event->edit_candidates.candidates[i]); 504 + } 492 505 selected_candidate = event->edit_candidates.selected_candidate; 493 506 horizontal_candidates = event->edit_candidates.horizontal; 494 507 }
+2 -1
test/testlocale.c
··· 15 15 16 16 static void log_locales(void) 17 17 { 18 - const SDL_Locale * const *locales = SDL_GetPreferredLocales(NULL); 18 + SDL_Locale **locales = SDL_GetPreferredLocales(NULL); 19 19 if (!locales) { 20 20 SDL_Log("Couldn't determine locales: %s", SDL_GetError()); 21 21 } else { ··· 29 29 total++; 30 30 } 31 31 SDL_Log("%u locales seen.", total); 32 + SDL_free(locales); 32 33 } 33 34 } 34 35
+2 -1
test/testmultiaudio.c
··· 135 135 136 136 int main(int argc, char **argv) 137 137 { 138 - const SDL_AudioDeviceID *devices = NULL; 138 + SDL_AudioDeviceID *devices; 139 139 int devcount = 0; 140 140 int i; 141 141 char *filename = NULL; ··· 192 192 test_multi_audio(devices, devcount); 193 193 SDL_free(sound); 194 194 } 195 + SDL_free(devices); 195 196 } 196 197 197 198 SDL_free(filename);
+2 -2
test/testpen.c
··· 222 222 for (i = 0; i < pens_nr; ++i) { 223 223 SDL_PenID penid = pens[i]; 224 224 SDL_GUID guid = SDL_GetPenGUID(penid); 225 - const char *guid_str; 225 + char guid_str[33]; 226 226 float axes[SDL_PEN_NUM_AXES]; 227 227 float x, y; 228 228 int k; ··· 232 232 char *type; 233 233 char *buttons_str; 234 234 235 - guid_str = SDL_GUIDToString(guid); 235 + SDL_GUIDToString(guid, guid_str, sizeof(guid_str)); 236 236 237 237 switch (SDL_GetPenType(penid)) { 238 238 case SDL_PEN_TYPE_ERASER:
+31 -28
test/testrumble.c
··· 39 39 char *name = NULL; 40 40 int index; 41 41 SDLTest_CommonState *state; 42 - const SDL_HapticID *haptics; 42 + SDL_HapticID *haptics; 43 43 int num_haptics; 44 44 45 45 /* Initialize test framework */ ··· 89 89 SDL_INIT_HAPTIC); 90 90 haptics = SDL_GetHaptics(&num_haptics); 91 91 SDL_Log("%d Haptic devices detected.\n", num_haptics); 92 - if (haptics) { 93 - if (num_haptics == 0) { 94 - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n"); 95 - return 1; 96 - } 92 + if (num_haptics == 0) { 93 + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n"); 94 + SDL_free(haptics); 95 + return 1; 96 + } 97 97 98 - /* We'll just use index or the first force feedback device found */ 99 - if (!name) { 100 - i = (index != -1) ? index : 0; 98 + /* We'll just use index or the first force feedback device found */ 99 + if (!name) { 100 + i = (index != -1) ? index : 0; 101 101 102 - if (i >= num_haptics) { 103 - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Index out of range, aborting.\n"); 104 - return 1; 105 - } 102 + if (i >= num_haptics) { 103 + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Index out of range, aborting.\n"); 104 + SDL_free(haptics); 105 + return 1; 106 106 } 107 - /* Try to find matching device */ 108 - else { 109 - for (i = 0; i < num_haptics; i++) { 110 - if (SDL_strstr(SDL_GetHapticNameForID(haptics[i]), name) != NULL) { 111 - break; 112 - } 113 - } 114 - 115 - if (i >= num_haptics) { 116 - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n", name); 117 - return 1; 107 + } 108 + /* Try to find matching device */ 109 + else { 110 + for (i = 0; i < num_haptics; i++) { 111 + if (SDL_strstr(SDL_GetHapticNameForID(haptics[i]), name) != NULL) { 112 + break; 118 113 } 119 114 } 120 115 121 - haptic = SDL_OpenHaptic(haptics[i]); 122 - if (!haptic) { 123 - SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n", SDL_GetError()); 116 + if (i >= num_haptics) { 117 + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n", name); 118 + SDL_free(haptics); 124 119 return 1; 125 120 } 126 - SDL_Log("Device: %s\n", SDL_GetHapticName(haptic)); 127 121 } 122 + 123 + haptic = SDL_OpenHaptic(haptics[i]); 124 + if (!haptic) { 125 + SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n", SDL_GetError()); 126 + SDL_free(haptics); 127 + return 1; 128 + } 129 + SDL_Log("Device: %s\n", SDL_GetHapticName(haptic)); 130 + SDL_free(haptics); 128 131 129 132 /* We only want force feedback errors. */ 130 133 SDL_ClearError();
+2 -1
test/testsensor.c
··· 58 58 59 59 int main(int argc, char **argv) 60 60 { 61 - const SDL_SensorID *sensors; 61 + SDL_SensorID *sensors; 62 62 int i, num_sensors, num_opened; 63 63 SDLTest_CommonState *state; 64 64 ··· 104 104 } 105 105 } 106 106 } 107 + SDL_free(sensors); 107 108 } 108 109 SDL_Log("Opened %d sensors\n", num_opened); 109 110
+2 -2
test/testsurround.c
··· 146 146 147 147 int main(int argc, char *argv[]) 148 148 { 149 - const SDL_AudioDeviceID *devices = NULL; 149 + SDL_AudioDeviceID *devices; 150 150 SDLTest_CommonState *state; 151 151 int devcount = 0; 152 152 int i; ··· 181 181 devices = SDL_GetAudioPlaybackDevices(&devcount); 182 182 if (!devices) { 183 183 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GetAudioPlaybackDevices() failed: %s\n", SDL_GetError()); 184 - devcount = 0; 185 184 } 186 185 187 186 SDL_Log("Available audio devices:"); ··· 233 232 234 233 SDL_DestroyAudioStream(stream); 235 234 } 235 + SDL_free(devices); 236 236 237 237 SDL_Quit(); 238 238 return 0;
+4 -3
test/testwm.c
··· 53 53 static void 54 54 draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport) 55 55 { 56 - const SDL_DisplayMode * const *modes; 56 + SDL_DisplayMode **modes; 57 57 char text[1024]; 58 58 const int lineHeight = 10; 59 59 int i, j; ··· 62 62 float x, y; 63 63 float table_top; 64 64 SDL_FPoint mouse_pos = { -1.0f, -1.0f }; 65 - const SDL_DisplayID *displays; 65 + SDL_DisplayID *displays; 66 66 67 67 /* Get mouse position */ 68 68 if (SDL_GetMouseFocus() == window) { ··· 99 99 } 100 100 101 101 displays = SDL_GetDisplays(NULL); 102 - 103 102 if (displays) { 104 103 for (i = 0; displays[i]; ++i) { 105 104 SDL_DisplayID display = displays[i]; ··· 143 142 column_chars = 0; 144 143 } 145 144 } 145 + SDL_free(modes); 146 146 } 147 + SDL_free(displays); 147 148 } 148 149 } 149 150