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.
This commit is contained in:
Sam Lantinga 2024-07-26 18:57:18 -07:00
parent 21411c6418
commit 4f55271571
100 changed files with 737 additions and 853 deletions

View File

@ -158,9 +158,9 @@ Rather than iterating over audio devices using a device index, there are new fun
if (devices) {
for (i = 0; i < num_devices; ++i) {
SDL_AudioDeviceID instance_id = devices[i];
const char *name = SDL_GetAudioDeviceName(instance_id);
SDL_Log("AudioDevice %" SDL_PRIu32 ": %s\n", instance_id, name);
SDL_Log("AudioDevice %" SDL_PRIu32 ": %s\n", instance_id, SDL_GetAudioDeviceName(instance_id));
}
SDL_free(devices);
}
SDL_QuitSubSystem(SDL_INIT_AUDIO);
}
@ -298,10 +298,6 @@ The following symbols have been renamed:
The following symbols have been removed:
* SDL_MIX_MAXVOLUME - mixer volume is now a float between 0.0 and 1.0
## SDL_clipboard.h
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.
## SDL_cpuinfo.h
The intrinsics headers (mmintrin.h, etc.) have been moved to `<SDL3/SDL_intrin.h>` and are no longer automatically included in SDL.h.
@ -458,10 +454,6 @@ The following functions have been removed:
The following enums have been renamed:
* SDL_eventaction => SDL_EventAction
## SDL_filesystem.h
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.
## SDL_gamecontroller.h
SDL_gamecontroller.h has been renamed SDL_gamepad.h, and all APIs have been renamed to match.
@ -710,15 +702,13 @@ Rather than iterating over haptic devices using device index, there is a new fun
{
if (SDL_InitSubSystem(SDL_INIT_HAPTIC) == 0) {
int i, num_haptics;
const SDL_HapticID *haptics = SDL_GetHaptics(&num_haptics);
SDL_HapticID *haptics = SDL_GetHaptics(&num_haptics);
if (haptics) {
for (i = 0; i < num_haptics; ++i) {
SDL_HapticID instance_id = haptics[i];
const char *name = SDL_GetHapticNameForID(instance_id);
SDL_Log("Haptic %" SDL_PRIu32 ": %s\n",
instance_id, name ? name : "Unknown");
SDL_Log("Haptic %" SDL_PRIu32 ": %s\n", instance_id, SDL_GetHapticNameForID(instance_id));
}
SDL_free(haptics);
}
SDL_QuitSubSystem(SDL_INIT_HAPTIC);
}
@ -840,7 +830,7 @@ Rather than iterating over joysticks using device index, there is a new function
{
if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == 0) {
int i, num_joysticks;
const SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks);
SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks);
if (joysticks) {
for (i = 0; i < num_joysticks; ++i) {
SDL_JoystickID instance_id = joysticks[i];
@ -850,6 +840,7 @@ Rather than iterating over joysticks using device index, there is a new function
SDL_Log("Joystick %" SDL_PRIu32 ": %s%s%s VID 0x%.4x, PID 0x%.4x\n",
instance_id, name ? name : "Unknown", path ? ", " : "", path ? path : "", SDL_GetJoystickVendorForID(instance_id), SDL_GetJoystickProductForID(instance_id));
}
SDL_free(joysticks);
}
SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
}
@ -1034,10 +1025,6 @@ The following symbols have been renamed:
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.
## SDL_locale.h
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.
## SDL_log.h
The following macros have been removed:
@ -1588,7 +1575,7 @@ Rather than iterating over sensors using device index, there is a new function S
{
if (SDL_InitSubSystem(SDL_INIT_SENSOR) == 0) {
int i, num_sensors;
const SDL_SensorID *sensors = SDL_GetSensors(&num_sensors);
SDL_SensorID *sensors = SDL_GetSensors(&num_sensors);
if (sensors) {
for (i = 0; i < num_sensors; ++i) {
SDL_Log("Sensor %" SDL_PRIu32 ": %s, type %d, platform type %d\n",
@ -1597,6 +1584,7 @@ Rather than iterating over sensors using device index, there is a new function S
SDL_GetSensorTypeForID(sensors[i]),
SDL_GetSensorNonPortableTypeForID(sensors[i]));
}
SDL_free(sensors);
}
SDL_QuitSubSystem(SDL_INIT_SENSOR);
}
@ -1996,7 +1984,7 @@ Rather than iterating over displays using display index, there is a new function
{
if (SDL_InitSubSystem(SDL_INIT_VIDEO) == 0) {
int i, num_displays = 0;
const SDL_DisplayID *displays = SDL_GetDisplays(&num_displays);
SDL_DisplayID *displays = SDL_GetDisplays(&num_displays);
if (displays) {
for (i = 0; i < num_displays; ++i) {
SDL_DisplayID instance_id = displays[i];
@ -2004,6 +1992,7 @@ Rather than iterating over displays using display index, there is a new function
SDL_Log("Display %" SDL_PRIu32 ": %s\n", instance_id, name ? name : "Unknown");
}
SDL_free(displays);
}
SDL_QuitSubSystem(SDL_INIT_VIDEO);
}
@ -2041,13 +2030,14 @@ Rather than iterating over display modes using an index, there is a new function
{
SDL_DisplayID display = SDL_GetPrimaryDisplay();
int num_modes = 0;
const SDL_DisplayMode * const *modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
SDL_DisplayMode **modes = SDL_GetFullscreenDisplayModes(display, &num_modes);
if (modes) {
for (i = 0; i < num_modes; ++i) {
SDL_DisplayMode *mode = modes[i];
SDL_Log("Display %" SDL_PRIu32 " mode %d: %dx%d@%gx %gHz\n",
display, i, mode->w, mode->h, mode->pixel_density, mode->refresh_rate);
}
SDL_free(modes);
}
}
```
@ -2080,8 +2070,6 @@ SDL_WindowFlags is used instead of Uint32 for API functions that refer to window
SDL_GetWindowOpacity() directly returns the opacity instead of using an out parameter.
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.
The following functions have been renamed:
* SDL_GL_DeleteContext() => SDL_GL_DestroyContext()
* SDL_GetClosestDisplayMode() => SDL_GetClosestFullscreenDisplayMode()

View File

@ -5,55 +5,3 @@
Unless otherwise specified, all strings in SDL, across all platforms, are
UTF-8 encoded and can represent the full range of [Unicode](https://unicode.org).
## The SDL Get String Rule.
Did you see 'SDL_GetStringRule' in the wiki or headers? Here are the details
that aren't worth copying across dozens of functions' documentation.
tl;dr: If an SDL function returns a `const char *` string, do not modify or
free it, and if you need to save it, make a copy right away.
In several cases, SDL wants to return a string to the app, and the question
in any library that does this is: _who owns this thing?_
The answer in almost all cases, is that SDL does, but not for long.
The pointer is only guaranteed to be valid until the next time the event
queue is updated, or SDL_Quit is called.
The reason for this is memory safety.
There are several strings that SDL provides that could be freed at
any moment. For example, an app calls SDL_GetAudioDeviceName(), which returns
a string that is part of the internal audio device structure. But, while this
function is returning, the user yanks the USB audio device out of the
computer, and SDL decides to deallocate the structure...and the string!
Now the app is holding a pointer that didn't live long enough to be useful,
and could crash if accessed.
To avoid this, instead of calling SDL_free on a string as soon as it's done
with it, SDL adds the pointer to a list. This list is freed at specific
points: when the event queue is run (for ongoing cleanup) and when SDL_Quit
is called (to catch things that are just hanging around). This allows the
app to use a string without worrying about it becoming bogus in the middle
of a printf() call. If the app needs it for longer, it should copy it.
When does "the event queue run"? There are several points:
- If the app calls SDL_PumpEvents() _from any thread_.
- SDL_PumpEvents is also called by several other APIs internally:
SDL_PollEvent(), SDL_PeepEvents(), SDL_WaitEvent(),
SDL_WaitEventTimeout(), and maybe others.
- If you are using [the main callbacks](main-functions#main-callbacks-in-sdl3),
the event queue can run immediately after any of the callback functions
return.
Note that these are just guaranteed minimum lifespans; any given string
might live much longer--some might even be static memory that is _never_
deallocated--but this rule promises that the app has a safe window.
Note that none of this applies if the return value is `char *` instead of
`const char *`. Please see the specific function's documentation for how
to handle those pointers.

View File

@ -95,45 +95,6 @@ Here is a rough list of what works, and what doesn't:
Upgrade Notes
-------------
#### SDL_GetPrefPath() usage when upgrading WinRT apps from SDL 2.0.3
SDL 2.0.4 fixes two bugs found in the WinRT version of SDL_GetPrefPath().
The fixes may affect older, SDL 2.0.3-based apps' save data. Please note
that these changes only apply to SDL-based WinRT apps, and not to apps for
any other platform.
1. SDL_GetPrefPath() would return an invalid path, one in which the path's
directory had not been created. Attempts to create files there
(via fopen(), for example), would fail, unless that directory was
explicitly created beforehand.
2. SDL_GetPrefPath(), for non-WinPhone-based apps, would return a path inside
a WinRT 'Roaming' folder, the contents of which get automatically
synchronized across multiple devices. This process can occur while an
application runs, and can cause existing save-data to be overwritten
at unexpected times, with data from other devices. (Windows Phone apps
written with SDL 2.0.3 did not utilize a Roaming folder, due to API
restrictions in Windows Phone 8.0).
SDL_GetPrefPath(), starting with SDL 2.0.4, addresses these by:
1. making sure that SDL_GetPrefPath() returns a directory in which data
can be written to immediately, without first needing to create directories.
2. basing SDL_GetPrefPath() off of a different, non-Roaming folder, the
contents of which do not automatically get synchronized across devices
(and which require less work to use safely, in terms of data integrity).
Apps that wish to get their Roaming folder's path can do so either by using
SDL_GetWinRTFSPath(), or directly through the WinRT class,
Windows.Storage.ApplicationData.
Setup, High-Level Steps
-----------------------

View File

@ -411,7 +411,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumAudioDrivers(void);
*
* \sa SDL_GetNumAudioDrivers
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetAudioDriver(int index);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetAudioDriver(int index);
/* @} */
/**
@ -428,7 +428,7 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetAudioDriver(int index);
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetCurrentAudioDriver(void);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentAudioDriver(void);
/**
* Get a list of currently-connected audio playback devices.
@ -447,7 +447,7 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetCurrentAudioDriver(void);
* \param count a pointer filled in with the number of devices returned, may
* be NULL.
* \returns a 0 terminated array of device instance IDs or NULL on error; call
* SDL_GetError() for more information.
* SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \threadsafety It is safe to call this function from any thread.
*
@ -456,7 +456,7 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetCurrentAudioDriver(void);
* \sa SDL_OpenAudioDevice
* \sa SDL_GetAudioRecordingDevices
*/
extern SDL_DECLSPEC_TEMP const SDL_AudioDeviceID * SDLCALL SDL_GetAudioPlaybackDevices(int *count);
extern SDL_DECLSPEC_FREE SDL_AudioDeviceID * SDLCALL SDL_GetAudioPlaybackDevices(int *count);
/**
* Get a list of currently-connected audio recording devices.
@ -475,7 +475,7 @@ extern SDL_DECLSPEC_TEMP const SDL_AudioDeviceID * SDLCALL SDL_GetAudioPlaybackD
* \param count a pointer filled in with the number of devices returned, may
* be NULL.
* \returns a 0 terminated array of device instance IDs, or NULL on failure;
* call SDL_GetError() for more information.
* call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \threadsafety It is safe to call this function from any thread.
*
@ -484,7 +484,7 @@ extern SDL_DECLSPEC_TEMP const SDL_AudioDeviceID * SDLCALL SDL_GetAudioPlaybackD
* \sa SDL_OpenAudioDevice
* \sa SDL_GetAudioPlaybackDevices
*/
extern SDL_DECLSPEC_TEMP const SDL_AudioDeviceID * SDLCALL SDL_GetAudioRecordingDevices(int *count);
extern SDL_DECLSPEC_FREE SDL_AudioDeviceID * SDLCALL SDL_GetAudioRecordingDevices(int *count);
/**
* Get the human-readable name of a specific audio device.
@ -501,7 +501,7 @@ extern SDL_DECLSPEC_TEMP const SDL_AudioDeviceID * SDLCALL SDL_GetAudioRecording
* \sa SDL_GetAudioRecordingDevices
* \sa SDL_GetDefaultAudioInfo
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetAudioDeviceName(SDL_AudioDeviceID devid);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetAudioDeviceName(SDL_AudioDeviceID devid);
/**
* Get the current audio format of a specific audio device.
@ -550,7 +550,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid
* \param devid the instance ID of the device to query.
* \param count On output, set to number of channels in the map. Can be NULL.
* \returns an array of the current channel mapping, with as many elements as
* the current output spec's channels, or NULL if default.
* the current output spec's channels, or NULL if default. This should be freed with SDL_free() when it is no longer needed.
*
* \threadsafety It is safe to call this function from any thread.
*
@ -558,7 +558,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid
*
* \sa SDL_SetAudioStreamInputChannelMap
*/
extern SDL_DECLSPEC_TEMP const int * SDLCALL SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int *count);
extern SDL_DECLSPEC_FREE int * SDLCALL SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int *count);
/**
* Open a specific audio device.
@ -1098,7 +1098,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamGain(SDL_AudioStream *stream,
* \param stream the SDL_AudioStream to query.
* \param count On output, set to number of channels in the map. Can be NULL.
* \returns an array of the current channel mapping, with as many elements as
* the current output spec's channels, or NULL if default.
* the current output spec's channels, or NULL if default. This should be freed with SDL_free() when it is no longer needed.
*
* \threadsafety It is safe to call this function from any thread, as it holds
* a stream-specific mutex while running.
@ -1107,7 +1107,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetAudioStreamGain(SDL_AudioStream *stream,
*
* \sa SDL_SetAudioStreamInputChannelMap
*/
extern SDL_DECLSPEC_TEMP const int * SDLCALL SDL_GetAudioStreamInputChannelMap(SDL_AudioStream *stream, int *count);
extern SDL_DECLSPEC_FREE int * SDLCALL SDL_GetAudioStreamInputChannelMap(SDL_AudioStream *stream, int *count);
/**
* Get the current output channel map of an audio stream.
@ -1121,7 +1121,7 @@ extern SDL_DECLSPEC_TEMP const int * SDLCALL SDL_GetAudioStreamInputChannelMap(S
* \param stream the SDL_AudioStream to query.
* \param count On output, set to number of channels in the map. Can be NULL.
* \returns an array of the current channel mapping, with as many elements as
* the current output spec's channels, or NULL if default.
* the current output spec's channels, or NULL if default. This should be freed with SDL_free() when it is no longer needed.
*
* \threadsafety It is safe to call this function from any thread, as it holds
* a stream-specific mutex while running.
@ -1130,7 +1130,7 @@ extern SDL_DECLSPEC_TEMP const int * SDLCALL SDL_GetAudioStreamInputChannelMap(S
*
* \sa SDL_SetAudioStreamInputChannelMap
*/
extern SDL_DECLSPEC_TEMP const int * SDLCALL SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream *stream, int *count);
extern SDL_DECLSPEC_FREE int * SDLCALL SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream *stream, int *count);
/**
* Set the current input channel map of an audio stream.

View File

@ -67,8 +67,11 @@
# endif
# endif
#endif
/* This is used to mark functions that return temporary memory */
#define SDL_DECLSPEC_TEMP SDL_DECLSPEC
/* This is used to mark functions that return memory that need to be freed with SDL_free() */
#ifndef SDL_DECLSPEC_FREE
#define SDL_DECLSPEC_FREE SDL_DECLSPEC
#endif
/* By default SDL uses the C calling convention */
#ifndef SDLCALL

View File

@ -145,7 +145,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumCameraDrivers(void);
*
* \sa SDL_GetNumCameraDrivers
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetCameraDriver(int index);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetCameraDriver(int index);
/**
* Get the name of the current camera driver.
@ -161,7 +161,7 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetCameraDriver(int index);
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetCurrentCameraDriver(void);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentCameraDriver(void);
/**
* Get a list of currently connected camera devices.
@ -169,7 +169,7 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetCurrentCameraDriver(void);
* \param count a pointer filled in with the number of cameras returned, may
* be NULL.
* \returns a 0 terminated array of camera instance IDs or NULL on failure;
* call SDL_GetError() for more information.
* call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \threadsafety It is safe to call this function from any thread.
*
@ -177,7 +177,7 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetCurrentCameraDriver(void);
*
* \sa SDL_OpenCamera
*/
extern SDL_DECLSPEC_TEMP const SDL_CameraID * SDLCALL SDL_GetCameras(int *count);
extern SDL_DECLSPEC_FREE SDL_CameraID * SDLCALL SDL_GetCameras(int *count);
/**
* Get the list of native formats/sizes a camera supports.
@ -205,7 +205,7 @@ extern SDL_DECLSPEC_TEMP const SDL_CameraID * SDLCALL SDL_GetCameras(int *count)
* \param count a pointer filled in with the number of elements in the list,
* may be NULL.
* \returns a NULL terminated array of pointers to SDL_CameraSpec or NULL on
* failure; call SDL_GetError() for more information.
* 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.
*
* \threadsafety It is safe to call this function from any thread.
*
@ -214,7 +214,7 @@ extern SDL_DECLSPEC_TEMP const SDL_CameraID * SDLCALL SDL_GetCameras(int *count)
* \sa SDL_GetCameras
* \sa SDL_OpenCamera
*/
extern SDL_DECLSPEC_TEMP const SDL_CameraSpec * const * SDLCALL SDL_GetCameraSupportedFormats(SDL_CameraID devid, int *count);
extern SDL_DECLSPEC_FREE SDL_CameraSpec ** SDLCALL SDL_GetCameraSupportedFormats(SDL_CameraID devid, int *count);
/**
* Get the human-readable device name for a camera.
@ -229,7 +229,7 @@ extern SDL_DECLSPEC_TEMP const SDL_CameraSpec * const * SDLCALL SDL_GetCameraSup
*
* \sa SDL_GetCameras
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetCameraName(SDL_CameraID instance_id);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetCameraName(SDL_CameraID instance_id);
/**
* Get the position of the camera in relation to the system.

View File

@ -63,14 +63,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetClipboardText(const char *text);
* a copy of the clipboard's content.
*
* \returns the clipboard text on success or an empty string on failure; call
* SDL_GetError() for more information.
* SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_HasClipboardText
* \sa SDL_SetClipboardText
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetClipboardText(void);
extern SDL_DECLSPEC_FREE char * SDLCALL SDL_GetClipboardText(void);
/**
* Query whether the clipboard exists and contains a non-empty text string.
@ -105,14 +105,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetPrimarySelectionText(const char *text);
* a copy of the primary selection's content.
*
* \returns the primary selection text on success or an empty string on
* failure; call SDL_GetError() for more information.
* failure; call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_HasPrimarySelectionText
* \sa SDL_SetPrimarySelectionText
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetPrimarySelectionText(void);
extern SDL_DECLSPEC_FREE char * SDLCALL SDL_GetPrimarySelectionText(void);
/**
* Query whether the primary selection exists and contains a non-empty text
@ -215,14 +215,14 @@ extern SDL_DECLSPEC int SDLCALL SDL_ClearClipboardData(void);
* \param mime_type the mime type to read from the clipboard.
* \param size a pointer filled in with the length of the returned data.
* \returns the retrieved data buffer or NULL on failure; call SDL_GetError()
* for more information.
* for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_HasClipboardData
* \sa SDL_SetClipboardData
*/
extern SDL_DECLSPEC_TEMP const void * SDLCALL SDL_GetClipboardData(const char *mime_type, size_t *size);
extern SDL_DECLSPEC_FREE void * SDLCALL SDL_GetClipboardData(const char *mime_type, size_t *size);
/**
* Query whether there is data in the clipboard for the provided mime type.

View File

@ -352,10 +352,6 @@ typedef struct SDL_KeyboardEvent
* will be inserted into the editing text. The length is the number of UTF-8
* characters that will be replaced by new typing.
*
* The text string is temporary memory which will be freed in
* SDL_FreeTemporaryMemory() and can be claimed with
* SDL_ClaimTemporaryMemory().
*
* \since This struct is available since SDL 3.0.0.
*/
typedef struct SDL_TextEditingEvent
@ -372,10 +368,6 @@ typedef struct SDL_TextEditingEvent
/**
* Keyboard IME candidates event structure (event.edit_candidates.*)
*
* The candidates are a single allocation of temporary memory which will be
* freed in SDL_FreeTemporaryMemory() and can be claimed with
* SDL_ClaimTemporaryMemory().
*
* \since This struct is available since SDL 3.0.0.
*/
typedef struct SDL_TextEditingCandidatesEvent
@ -393,10 +385,6 @@ typedef struct SDL_TextEditingCandidatesEvent
/**
* Keyboard text input event structure (event.text.*)
*
* The text string is temporary memory which will be freed in
* SDL_FreeTemporaryMemory() and can be claimed with
* SDL_ClaimTemporaryMemory().
*
* This event will never be delivered unless text input is enabled by calling
* SDL_StartTextInput(). Text input is disabled by default!
*
@ -792,10 +780,6 @@ typedef struct SDL_PenButtonEvent
* An event used to drop text or request a file open by the system
* (event.drop.*)
*
* The source and data strings are temporary memory which will be freed in
* SDL_FreeTemporaryMemory() and can be claimed with
* SDL_ClaimTemporaryMemory().
*
* \since This struct is available since SDL 3.0.0.
*/
typedef struct SDL_DropEvent
@ -859,10 +843,6 @@ typedef struct SDL_QuitEvent
* the programmer; the only requirement is that '''type''' is a value obtained
* from SDL_RegisterEvents().
*
* If the data pointers are temporary memory, they will be automatically
* transfered to the thread that pulls the event from the queue, or freed if
* the event is flushed.
*
* \since This struct is available since SDL 3.0.0.
*/
typedef struct SDL_UserEvent
@ -1420,65 +1400,6 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_EventEnabled(Uint32 type);
*/
extern SDL_DECLSPEC Uint32 SDLCALL SDL_RegisterEvents(int numevents);
/**
* Allocate temporary memory.
*
* You can use this to allocate memory from the temporary memory pool for the
* current thread.
*
* \param size the amount of memory to allocate.
* \returns a pointer to the memory allocated or NULL on failure; call
* SDL_GetError() for more information.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_ClaimTemporaryMemory
* \sa SDL_FreeTemporaryMemory
*/
extern SDL_DECLSPEC void * SDLCALL SDL_AllocateTemporaryMemory(size_t size);
/**
* Claim ownership of temporary memory.
*
* This function removes memory from the temporary memory pool for the current
* thread and gives ownership to the application. The application should use
* SDL_free() to free it when it is done using it.
*
* \param mem a pointer allocated with SDL_AllocateTemporaryMemory().
* \returns a pointer to the memory now owned by the application, which must
* be freed using SDL_free(), or NULL if the memory is not in the
* temporary memory pool for the current thread.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_AllocateTemporaryMemory
* \sa SDL_free
*/
extern SDL_DECLSPEC void * SDLCALL SDL_ClaimTemporaryMemory(const void *mem);
/**
* Free temporary memory for the current thread.
*
* This function frees all temporary memory for the current thread. If you
* would like to hold onto a specific pointer beyond this call, you should
* call SDL_ClaimTemporaryMemory() to move it out of the temporary memory
* pool.
*
* This function is automatically called in SDL_Quit() on the main thread and
* in SDL_CleanupTLS() when other threads complete.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_AllocateTemporaryMemory
* \sa SDL_ClaimTemporaryMemory
*/
extern SDL_DECLSPEC void SDLCALL SDL_FreeTemporaryMemory(void);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -77,7 +77,7 @@ extern "C" {
*
* \sa SDL_GetPrefPath
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetBasePath(void);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetBasePath(void);
/**
* Get the user-and-app-specific path where files can be written.
@ -125,13 +125,13 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetBasePath(void);
* \param app the name of your application.
* \returns a UTF-8 string of the user directory in platform-dependent
* notation. NULL if there's a problem (creating directory failed,
* etc.).
* etc.). This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetBasePath
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetPrefPath(const char *org, const char *app);
extern SDL_DECLSPEC_FREE char * SDLCALL SDL_GetPrefPath(const char *org, const char *app);
/**
* The type of the OS-provided default folder for a specific purpose.
@ -227,7 +227,7 @@ typedef enum SDL_Folder
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetUserFolder(SDL_Folder folder);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetUserFolder(SDL_Folder folder);
/* Abstract filesystem interface */
@ -367,13 +367,13 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetPathInfo(const char *path, SDL_PathInfo *
* \param count on return, will be set to the number of items in the returned
* array. Can be NULL.
* \returns an array of strings on success or NULL on failure; call
* SDL_GetError() for more information.
* SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const char * const * SDLCALL SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count);
extern SDL_DECLSPEC_FREE char ** SDLCALL SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -392,25 +392,25 @@ extern SDL_DECLSPEC int SDLCALL SDL_ReloadGamepadMappings(void);
* \param count a pointer filled in with the number of mappings returned, can
* be NULL.
* \returns an array of the mapping strings, NULL-terminated, or NULL on
* failure; call SDL_GetError() for more information.
* 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.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const char * const * SDLCALL SDL_GetGamepadMappings(int *count);
extern SDL_DECLSPEC_FREE char ** SDLCALL SDL_GetGamepadMappings(int *count);
/**
* Get the gamepad mapping string for a given GUID.
*
* \param guid a structure containing the GUID for which a mapping is desired.
* \returns a mapping string or NULL on failure; call SDL_GetError() for more
* information.
* information. This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetJoystickGUIDForID
* \sa SDL_GetJoystickGUID
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_GUID guid);
extern SDL_DECLSPEC_FREE char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_GUID guid);
/**
* Get the current mapping of a gamepad.
@ -419,7 +419,7 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_G
*
* \param gamepad the gamepad you want to get the current mapping for.
* \returns a string that has the gamepad's mapping or NULL if no mapping is
* available; call SDL_GetError() for more information.
* available; call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*
@ -428,7 +428,7 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadMappingForGUID(SDL_G
* \sa SDL_GetGamepadMappingForGUID
* \sa SDL_SetGamepadMapping
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad);
extern SDL_DECLSPEC_FREE char * SDLCALL SDL_GetGamepadMapping(SDL_Gamepad *gamepad);
/**
* Set the current mapping of a joystick or gamepad.
@ -465,14 +465,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasGamepad(void);
* \param count a pointer filled in with the number of gamepads returned, may
* be NULL.
* \returns a 0 terminated array of joystick instance IDs or NULL on failure;
* call SDL_GetError() for more information.
* call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_HasGamepad
* \sa SDL_OpenGamepad
*/
extern SDL_DECLSPEC_TEMP const SDL_JoystickID * SDLCALL SDL_GetGamepads(int *count);
extern SDL_DECLSPEC_FREE SDL_JoystickID * SDLCALL SDL_GetGamepads(int *count);
/**
* Check if the given joystick is supported by the gamepad interface.
@ -502,7 +502,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_IsGamepad(SDL_JoystickID instance_id);
* \sa SDL_GetGamepadName
* \sa SDL_GetGamepads
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadNameForID(SDL_JoystickID instance_id);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadNameForID(SDL_JoystickID instance_id);
/**
* Get the implementation dependent path of a gamepad.
@ -518,7 +518,7 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadNameForID(SDL_Joysti
* \sa SDL_GetGamepadPath
* \sa SDL_GetGamepads
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadPathForID(SDL_JoystickID instance_id);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadPathForID(SDL_JoystickID instance_id);
/**
* Get the player index of a gamepad.
@ -640,14 +640,14 @@ extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetRealGamepadTypeForID(SDL_Joys
* This can be called before any gamepads are opened.
*
* \param instance_id the joystick instance ID.
* \returns the mapping string. Returns NULL if no mapping is available.
* \returns the mapping string. Returns NULL if no mapping is available. This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetGamepads
* \sa SDL_GetGamepadMapping
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadMappingForID(SDL_JoystickID instance_id);
extern SDL_DECLSPEC_FREE char * SDLCALL SDL_GetGamepadMappingForID(SDL_JoystickID instance_id);
/**
* Open a gamepad for use.
@ -745,7 +745,7 @@ extern SDL_DECLSPEC SDL_JoystickID SDLCALL SDL_GetGamepadID(SDL_Gamepad *gamepad
*
* \sa SDL_GetGamepadNameForID
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadName(SDL_Gamepad *gamepad);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadName(SDL_Gamepad *gamepad);
/**
* Get the implementation-dependent path for an opened gamepad.
@ -759,7 +759,7 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadName(SDL_Gamepad *ga
*
* \sa SDL_GetGamepadPathForID
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadPath(SDL_Gamepad *gamepad);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadPath(SDL_Gamepad *gamepad);
/**
* Get the type of an opened gamepad.
@ -880,7 +880,7 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetGamepadFirmwareVersion(SDL_Gamepad *ga
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadSerial(SDL_Gamepad *gamepad);
/**
* Get the Steam Input handle of an opened gamepad, if available.
@ -995,11 +995,11 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_GamepadEventsEnabled(void);
* \param gamepad a gamepad.
* \param count a pointer filled in with the number of bindings returned.
* \returns a NULL terminated array of pointers to bindings or NULL on
* failure; call SDL_GetError() for more information.
* 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.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const SDL_GamepadBinding * const * SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count);
extern SDL_DECLSPEC_FREE SDL_GamepadBinding ** SDLCALL SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count);
/**
* Manually pump gamepad updates if not using the loop.
@ -1042,7 +1042,7 @@ extern SDL_DECLSPEC SDL_GamepadType SDLCALL SDL_GetGamepadTypeFromString(const c
*
* \sa SDL_GetGamepadTypeFromString
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadStringForType(SDL_GamepadType type);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForType(SDL_GamepadType type);
/**
* Convert a string into SDL_GamepadAxis enum.
@ -1078,7 +1078,7 @@ extern SDL_DECLSPEC SDL_GamepadAxis SDLCALL SDL_GetGamepadAxisFromString(const c
*
* \sa SDL_GetGamepadAxisFromString
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis);
/**
* Query whether a gamepad has a given axis.
@ -1151,7 +1151,7 @@ extern SDL_DECLSPEC SDL_GamepadButton SDLCALL SDL_GetGamepadButtonFromString(con
*
* \sa SDL_GetGamepadButtonFromString
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadStringForButton(SDL_GamepadButton button);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadStringForButton(SDL_GamepadButton button);
/**
* Query whether a gamepad has a given button.
@ -1436,7 +1436,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_CloseGamepad(SDL_Gamepad *gamepad);
*
* \sa SDL_GetGamepadAppleSFSymbolsNameForAxis
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
/**
* Return the sfSymbolsName for a given axis on a gamepad on Apple platforms.
@ -1449,7 +1449,7 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameFo
*
* \sa SDL_GetGamepadAppleSFSymbolsNameForButton
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
/* Ends C function definitions when using C++ */

View File

@ -67,14 +67,14 @@ typedef struct SDL_GUID {
* Get an ASCII string representation for a given SDL_GUID.
*
* \param guid the SDL_GUID you wish to convert to string.
* \returns the string representation of the GUID or NULL on failure; call
* SDL_GetError() for more information.
* \param pszGUID buffer in which to write the ASCII string.
* \param cbGUID the size of pszGUID, should be at least 33 bytes.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_StringToGUID
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GUIDToString(SDL_GUID guid);
extern SDL_DECLSPEC void SDLCALL SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID);
/**
* Convert a GUID string into a SDL_GUID structure.

View File

@ -45,6 +45,7 @@
* SDL_HapticID *haptics = SDL_GetHaptics(NULL);
* if (haptics) {
* haptic = SDL_OpenHaptic(haptics[0]);
* SDL_free(haptics);
* }
* if (haptic == NULL)
* return -1;
@ -934,13 +935,13 @@ typedef Uint32 SDL_HapticID;
* \param count a pointer filled in with the number of haptic devices
* returned, may be NULL.
* \returns a 0 terminated array of haptic device instance IDs or NULL on
* failure; call SDL_GetError() for more information.
* failure; call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_OpenHaptic
*/
extern SDL_DECLSPEC_TEMP const SDL_HapticID * SDLCALL SDL_GetHaptics(int *count);
extern SDL_DECLSPEC_FREE SDL_HapticID * SDLCALL SDL_GetHaptics(int *count);
/**
* Get the implementation dependent name of a haptic device.
@ -957,7 +958,7 @@ extern SDL_DECLSPEC_TEMP const SDL_HapticID * SDLCALL SDL_GetHaptics(int *count)
* \sa SDL_GetHapticName
* \sa SDL_OpenHaptic
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetHapticNameForID(SDL_HapticID instance_id);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetHapticNameForID(SDL_HapticID instance_id);
/**
* Open a haptic device for use.
@ -1019,7 +1020,7 @@ extern SDL_DECLSPEC SDL_HapticID SDLCALL SDL_GetHapticID(SDL_Haptic *haptic);
*
* \sa SDL_GetHapticNameForID
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetHapticName(SDL_Haptic *haptic);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetHapticName(SDL_Haptic *haptic);
/**
* Query whether or not the current mouse has haptic capabilities.

View File

@ -3880,7 +3880,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_ResetHints(void);
* \sa SDL_SetHint
* \sa SDL_SetHintWithPriority
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetHint(const char *name);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetHint(const char *name);
/**
* Get the boolean value of a hint variable.

View File

@ -204,14 +204,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasJoystick(void);
* \param count a pointer filled in with the number of joysticks returned, may
* be NULL.
* \returns a 0 terminated array of joystick instance IDs or NULL on failure;
* call SDL_GetError() for more information.
* call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_HasJoystick
* \sa SDL_OpenJoystick
*/
extern SDL_DECLSPEC_TEMP const SDL_JoystickID * SDLCALL SDL_GetJoysticks(int *count);
extern SDL_DECLSPEC_FREE SDL_JoystickID * SDLCALL SDL_GetJoysticks(int *count);
/**
* Get the implementation dependent name of a joystick.
@ -227,7 +227,7 @@ extern SDL_DECLSPEC_TEMP const SDL_JoystickID * SDLCALL SDL_GetJoysticks(int *co
* \sa SDL_GetJoystickName
* \sa SDL_GetJoysticks
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetJoystickNameForID(SDL_JoystickID instance_id);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickNameForID(SDL_JoystickID instance_id);
/**
* Get the implementation dependent path of a joystick.
@ -243,7 +243,7 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetJoystickNameForID(SDL_Joyst
* \sa SDL_GetJoystickPath
* \sa SDL_GetJoysticks
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetJoystickPathForID(SDL_JoystickID instance_id);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPathForID(SDL_JoystickID instance_id);
/**
* Get the player index of a joystick.
@ -661,7 +661,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetJoystickProperties(SDL_Joyst
*
* \sa SDL_GetJoystickNameForID
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetJoystickName(SDL_Joystick *joystick);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickName(SDL_Joystick *joystick);
/**
* Get the implementation dependent path of a joystick.
@ -674,7 +674,7 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetJoystickName(SDL_Joystick *
*
* \sa SDL_GetJoystickPathForID
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetJoystickPath(SDL_Joystick *joystick);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickPath(SDL_Joystick *joystick);
/**
* Get the player index of an opened joystick.
@ -789,7 +789,7 @@ extern SDL_DECLSPEC Uint16 SDLCALL SDL_GetJoystickFirmwareVersion(SDL_Joystick *
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joystick);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetJoystickSerial(SDL_Joystick *joystick);
/**
* Get the type of an opened joystick.

View File

@ -76,14 +76,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasKeyboard(void);
* \param count a pointer filled in with the number of keyboards returned, may
* be NULL.
* \returns a 0 terminated array of keyboards instance IDs or NULL on failure;
* call SDL_GetError() for more information.
* call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetKeyboardNameForID
* \sa SDL_HasKeyboard
*/
extern SDL_DECLSPEC_TEMP const SDL_KeyboardID * SDLCALL SDL_GetKeyboards(int *count);
extern SDL_DECLSPEC_FREE SDL_KeyboardID * SDLCALL SDL_GetKeyboards(int *count);
/**
* Get the name of a keyboard.
@ -98,7 +98,7 @@ extern SDL_DECLSPEC_TEMP const SDL_KeyboardID * SDLCALL SDL_GetKeyboards(int *co
*
* \sa SDL_GetKeyboards
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetKeyboardNameForID(SDL_KeyboardID instance_id);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetKeyboardNameForID(SDL_KeyboardID instance_id);
/**
* Query the window which currently has keyboard focus.
@ -297,7 +297,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetScancodeName(SDL_Scancode scancode, const
* \sa SDL_GetScancodeFromName
* \sa SDL_SetScancodeName
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetScancodeName(SDL_Scancode scancode);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetScancodeName(SDL_Scancode scancode);
/**
* Get a scancode from a human-readable name.
@ -331,7 +331,7 @@ extern SDL_DECLSPEC SDL_Scancode SDLCALL SDL_GetScancodeFromName(const char *nam
* \sa SDL_GetKeyFromScancode
* \sa SDL_GetScancodeFromKey
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetKeyName(SDL_Keycode key);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetKeyName(SDL_Keycode key);
/**
* Get a key code from a human-readable name.

View File

@ -92,11 +92,11 @@ typedef struct SDL_Locale
* \param count a pointer filled in with the number of locales returned, may
* be NULL.
* \returns a NULL terminated array of locale pointers, or NULL on failure;
* call SDL_GetError() for more information.
* call SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const SDL_Locale * const * SDLCALL SDL_GetPreferredLocales(int *count);
extern SDL_DECLSPEC_FREE SDL_Locale ** SDLCALL SDL_GetPreferredLocales(int *count);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -138,14 +138,14 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_HasMouse(void);
* \param count a pointer filled in with the number of mice returned, may be
* NULL.
* \returns a 0 terminated array of mouse instance IDs or NULL on failure;
* call SDL_GetError() for more information.
* call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetMouseNameForID
* \sa SDL_HasMouse
*/
extern SDL_DECLSPEC_TEMP const SDL_MouseID * SDLCALL SDL_GetMice(int *count);
extern SDL_DECLSPEC_FREE SDL_MouseID * SDLCALL SDL_GetMice(int *count);
/**
* Get the name of a mouse.
@ -160,7 +160,7 @@ extern SDL_DECLSPEC_TEMP const SDL_MouseID * SDLCALL SDL_GetMice(int *count);
*
* \sa SDL_GetMice
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetMouseNameForID(SDL_MouseID instance_id);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetMouseNameForID(SDL_MouseID instance_id);
/**
* Get the window which currently has mouse focus.

View File

@ -235,7 +235,7 @@ extern SDL_DECLSPEC SDL_bool SDLCALL SDL_PenConnected(SDL_PenID instance_id);
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetPenName(SDL_PenID instance_id);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetPenName(SDL_PenID instance_id);
/**
* Pen capabilities, as reported by SDL_GetPenCapabilities()

View File

@ -384,7 +384,12 @@ extern SDL_DECLSPEC void * SDLCALL SDL_GetPointerProperty(SDL_PropertiesID props
* \returns the value of the property, or `default_value` if it is not set or
* not a string property.
*
* \threadsafety It is safe to call this function from any thread.
* \threadsafety It is safe to call this function from any thread, although
* the data returned is not protected and could potentially be
* freed if you call SDL_SetStringProperty() or
* SDL_ClearProperty() on these properties from another thread.
* If you need to avoid this, use SDL_LockProperties() and
* SDL_UnlockProperties().
*
* \since This function is available since SDL 3.0.0.
*
@ -392,7 +397,7 @@ extern SDL_DECLSPEC void * SDLCALL SDL_GetPointerProperty(SDL_PropertiesID props
* \sa SDL_HasProperty
* \sa SDL_SetStringProperty
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetStringProperty(SDL_PropertiesID props, const char *name, const char *default_value);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetStringProperty(SDL_PropertiesID props, const char *name, const char *default_value);
/**
* Get a number property from a group of properties.

View File

@ -163,7 +163,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumRenderDrivers(void);
*
* \sa SDL_GetNumRenderDrivers
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetRenderDriver(int index);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetRenderDriver(int index);
/**
* Create a window and default renderer.
@ -331,7 +331,7 @@ extern SDL_DECLSPEC SDL_Window * SDLCALL SDL_GetRenderWindow(SDL_Renderer *rende
* \sa SDL_CreateRenderer
* \sa SDL_CreateRendererWithProperties
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetRendererName(SDL_Renderer *renderer);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetRendererName(SDL_Renderer *renderer);
/**
* Get the properties associated with a renderer.

View File

@ -149,11 +149,11 @@ typedef enum SDL_SensorType
* \param count a pointer filled in with the number of sensors returned, may
* be NULL.
* \returns a 0 terminated array of sensor instance IDs or NULL on failure;
* call SDL_GetError() for more information.
* call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC const SDL_SensorID * SDLCALL SDL_GetSensors(int *count);
extern SDL_DECLSPEC SDL_SensorID * SDLCALL SDL_GetSensors(int *count);
/**
* Get the implementation dependent name of a sensor.
@ -165,7 +165,7 @@ extern SDL_DECLSPEC const SDL_SensorID * SDLCALL SDL_GetSensors(int *count);
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetSensorNameForID(SDL_SensorID instance_id);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetSensorNameForID(SDL_SensorID instance_id);
/**
* Get the type of a sensor.
@ -235,7 +235,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetSensorProperties(SDL_Sensor
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetSensorName(SDL_Sensor *sensor);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetSensorName(SDL_Sensor *sensor);
/**
* Get the type of a sensor.

View File

@ -527,9 +527,9 @@ extern "C" {
#define SDL_stack_free(data) SDL_free(data)
#endif
extern SDL_DECLSPEC SDL_MALLOC void * SDLCALL SDL_malloc(size_t size);
extern SDL_DECLSPEC SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
extern SDL_DECLSPEC SDL_ALLOC_SIZE(2) void * SDLCALL SDL_realloc(void *mem, size_t size);
extern SDL_DECLSPEC_FREE SDL_MALLOC void * SDLCALL SDL_malloc(size_t size);
extern SDL_DECLSPEC_FREE SDL_MALLOC SDL_ALLOC_SIZE2(1, 2) void * SDLCALL SDL_calloc(size_t nmemb, size_t size);
extern SDL_DECLSPEC_FREE SDL_ALLOC_SIZE(2) void * SDLCALL SDL_realloc(void *mem, size_t size);
extern SDL_DECLSPEC void SDLCALL SDL_free(void *mem);
typedef void *(SDLCALL *SDL_malloc_func)(size_t size);

View File

@ -410,14 +410,14 @@ extern SDL_DECLSPEC Uint64 SDLCALL SDL_GetStorageSpaceRemaining(SDL_Storage *sto
* array. Can be NULL.
* \returns an array of strings on success or NULL on failure; call
* SDL_GetError() for more information. The caller should pass the
* returned pointer to SDL_free when done with it.
* 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.
*
* \threadsafety It is safe to call this function from any thread, assuming
* the `storage` object is thread-safe.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const char * const * SDLCALL SDL_GlobStorageDirectory(SDL_Storage *storage, const char *path, const char *pattern, SDL_GlobFlags flags, int *count);
extern SDL_DECLSPEC_FREE char ** SDLCALL SDL_GlobStorageDirectory(SDL_Storage *storage, const char *path, const char *pattern, SDL_GlobFlags flags, int *count);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -418,7 +418,7 @@ extern SDL_DECLSPEC void SDLCALL SDL_SendAndroidBackButton(void);
*
* \sa SDL_GetAndroidExternalStorageState
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetAndroidInternalStoragePath(void);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetAndroidInternalStoragePath(void);
/**
* Get the current state of external storage for this Android application.
@ -457,7 +457,7 @@ extern SDL_DECLSPEC Uint32 SDLCALL SDL_GetAndroidExternalStorageState(void);
*
* \sa SDL_GetAndroidExternalStorageState
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetAndroidExternalStoragePath(void);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetAndroidExternalStoragePath(void);
/**
* Get the path used for caching data for this Android application.
@ -476,7 +476,7 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetAndroidExternalStoragePath(
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetAndroidCachePath(void);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetAndroidCachePath(void);
typedef void (SDLCALL *SDL_RequestAndroidPermissionCallback)(void *userdata, const char *permission, SDL_bool granted);
@ -630,7 +630,7 @@ typedef enum SDL_WinRT_DeviceFamily
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetWinRTFSPath(SDL_WinRT_Path pathType);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetWinRTFSPath(SDL_WinRT_Path pathType);
/**
* Detects the device family of WinRT platform at runtime.

View File

@ -336,7 +336,7 @@ extern SDL_DECLSPEC SDL_Thread * SDLCALL SDL_CreateThreadWithPropertiesRuntime(S
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetThreadName(SDL_Thread *thread);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetThreadName(SDL_Thread *thread);
/**
* Get the thread identifier for the current thread.

View File

@ -86,11 +86,11 @@ typedef struct SDL_Finger
* \param count a pointer filled in with the number of devices returned, may
* be NULL.
* \returns a 0 terminated array of touch device IDs or NULL on failure; call
* SDL_GetError() for more information.
* SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const SDL_TouchID * SDLCALL SDL_GetTouchDevices(int *count);
extern SDL_DECLSPEC_FREE SDL_TouchID * SDLCALL SDL_GetTouchDevices(int *count);
/**
* Get the touch device name as reported from the driver.
@ -101,7 +101,7 @@ extern SDL_DECLSPEC_TEMP const SDL_TouchID * SDLCALL SDL_GetTouchDevices(int *co
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetTouchDeviceName(SDL_TouchID touchID);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetTouchDeviceName(SDL_TouchID touchID);
/**
* Get the type of the given touch device.
@ -120,11 +120,11 @@ extern SDL_DECLSPEC SDL_TouchDeviceType SDLCALL SDL_GetTouchDeviceType(SDL_Touch
* \param count a pointer filled in with the number of fingers returned, can
* be NULL.
* \returns a NULL terminated array of SDL_Finger pointers or NULL on failure;
* call SDL_GetError() for more information.
* call SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const SDL_Finger * const * SDLCALL SDL_GetTouchFingers(SDL_TouchID touchID, int *count);
extern SDL_DECLSPEC_FREE SDL_Finger ** SDLCALL SDL_GetTouchFingers(SDL_TouchID touchID, int *count);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus

View File

@ -356,7 +356,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_GetNumVideoDrivers(void);
*
* \sa SDL_GetNumVideoDrivers
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetVideoDriver(int index);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetVideoDriver(int index);
/**
* Get the name of the currently initialized video driver.
@ -373,7 +373,7 @@ extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetVideoDriver(int index);
* \sa SDL_GetNumVideoDrivers
* \sa SDL_GetVideoDriver
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetCurrentVideoDriver(void);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetCurrentVideoDriver(void);
/**
* Get the current system theme.
@ -390,11 +390,11 @@ extern SDL_DECLSPEC SDL_SystemTheme SDLCALL SDL_GetSystemTheme(void);
* \param count a pointer filled in with the number of displays returned, may
* be NULL.
* \returns a 0 terminated array of display instance IDs or NULL on failure;
* call SDL_GetError() for more information.
* call SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const SDL_DisplayID * SDLCALL SDL_GetDisplays(int *count);
extern SDL_DECLSPEC_FREE SDL_DisplayID * SDLCALL SDL_GetDisplays(int *count);
/**
* Return the primary display.
@ -448,7 +448,7 @@ extern SDL_DECLSPEC SDL_PropertiesID SDLCALL SDL_GetDisplayProperties(SDL_Displa
*
* \sa SDL_GetDisplays
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetDisplayName(SDL_DisplayID displayID);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetDisplayName(SDL_DisplayID displayID);
/**
* Get the desktop area represented by a display.
@ -551,13 +551,13 @@ extern SDL_DECLSPEC float SDLCALL SDL_GetDisplayContentScale(SDL_DisplayID displ
* \param count a pointer filled in with the number of display modes returned,
* may be NULL.
* \returns a NULL terminated array of display mode pointers or NULL on
* failure; call SDL_GetError() for more information.
* 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.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetDisplays
*/
extern SDL_DECLSPEC_TEMP const SDL_DisplayMode * const * SDLCALL SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *count);
extern SDL_DECLSPEC_FREE SDL_DisplayMode ** SDLCALL SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *count);
/**
* Get the closest match to the requested display mode.
@ -576,16 +576,17 @@ extern SDL_DECLSPEC_TEMP const SDL_DisplayMode * const * SDLCALL SDL_GetFullscre
* for the desktop refresh rate.
* \param include_high_density_modes boolean to include high density modes in
* the search.
* \returns a pointer to the closest display mode equal to or larger than the
* desired mode, or NULL on failure; call SDL_GetError() for more
* information.
* \param mode a pointer filled in with the closest display mode equal to or larger than the
* desired mode.
* \returns 0 on success or a negative error code on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 3.0.0.
*
* \sa SDL_GetDisplays
* \sa SDL_GetFullscreenDisplayModes
*/
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);
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);
/**
* Get information about the desktop's display mode.
@ -604,7 +605,7 @@ extern SDL_DECLSPEC_TEMP const SDL_DisplayMode * SDLCALL SDL_GetClosestFullscree
* \sa SDL_GetCurrentDisplayMode
* \sa SDL_GetDisplays
*/
extern SDL_DECLSPEC_TEMP const SDL_DisplayMode * SDLCALL SDL_GetDesktopDisplayMode(SDL_DisplayID displayID);
extern SDL_DECLSPEC const SDL_DisplayMode * SDLCALL SDL_GetDesktopDisplayMode(SDL_DisplayID displayID);
/**
* Get information about the current display mode.
@ -623,7 +624,7 @@ extern SDL_DECLSPEC_TEMP const SDL_DisplayMode * SDLCALL SDL_GetDesktopDisplayMo
* \sa SDL_GetDesktopDisplayMode
* \sa SDL_GetDisplays
*/
extern SDL_DECLSPEC_TEMP const SDL_DisplayMode * SDLCALL SDL_GetCurrentDisplayMode(SDL_DisplayID displayID);
extern SDL_DECLSPEC const SDL_DisplayMode * SDLCALL SDL_GetCurrentDisplayMode(SDL_DisplayID displayID);
/**
* Get the display containing a point.
@ -753,7 +754,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowFullscreenMode(SDL_Window *window,
* \sa SDL_SetWindowFullscreenMode
* \sa SDL_SetWindowFullscreen
*/
extern SDL_DECLSPEC_TEMP const SDL_DisplayMode * SDLCALL SDL_GetWindowFullscreenMode(SDL_Window *window);
extern SDL_DECLSPEC const SDL_DisplayMode * SDLCALL SDL_GetWindowFullscreenMode(SDL_Window *window);
/**
* Get the raw ICC profile data for the screen the window is currently on.
@ -761,11 +762,11 @@ extern SDL_DECLSPEC_TEMP const SDL_DisplayMode * SDLCALL SDL_GetWindowFullscreen
* \param window the window to query.
* \param size the size of the ICC profile.
* \returns the raw ICC profile data on success or NULL on failure; call
* SDL_GetError() for more information.
* SDL_GetError() for more information. This should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP const void * SDLCALL SDL_GetWindowICCProfile(SDL_Window *window, size_t *size);
extern SDL_DECLSPEC_FREE void * SDLCALL SDL_GetWindowICCProfile(SDL_Window *window, size_t *size);
/**
* Get the pixel format associated with the window.
@ -785,11 +786,11 @@ extern SDL_DECLSPEC SDL_PixelFormat SDLCALL SDL_GetWindowPixelFormat(SDL_Window
* \param count a pointer filled in with the number of windows returned, may
* be NULL.
* \returns a NULL terminated array of SDL_Window pointers or NULL on failure;
* call SDL_GetError() for more information.
* call SDL_GetError() for more information. This is a single allocation that should be freed with SDL_free() when it is no longer needed.
*
* \since This function is available since SDL 3.0.0.
*/
extern SDL_DECLSPEC_TEMP SDL_Window * const * SDLCALL SDL_GetWindows(int *count);
extern SDL_DECLSPEC_FREE SDL_Window ** SDLCALL SDL_GetWindows(int *count);
/**
* Create a window with the specified dimensions and flags.
@ -1322,7 +1323,7 @@ extern SDL_DECLSPEC int SDLCALL SDL_SetWindowTitle(SDL_Window *window, const cha
*
* \sa SDL_SetWindowTitle
*/
extern SDL_DECLSPEC_TEMP const char * SDLCALL SDL_GetWindowTitle(SDL_Window *window);
extern SDL_DECLSPEC const char * SDLCALL SDL_GetWindowTitle(SDL_Window *window);
/**
* Set the icon for a window.

View File

@ -21,21 +21,24 @@
#include "SDL_internal.h"
/* convert the guid to a printable string */
const char *SDL_GUIDToString(SDL_GUID guid)
void SDL_GUIDToString(SDL_GUID guid, char *pszGUID, int cbGUID)
{
static const char k_rgchHexToASCII[] = "0123456789abcdef";
int i;
char string[sizeof(guid) * 2 + 1];
for (i = 0; i < sizeof(guid.data); ++i) {
if ((!pszGUID) || (cbGUID <= 0)) {
return;
}
for (i = 0; i < sizeof(guid.data) && i < (cbGUID - 1) / 2; i++) {
/* each input byte writes 2 ascii chars, and might write a null byte. */
/* If we don't have room for next input byte, stop */
unsigned char c = guid.data[i];
string[i * 2 + 0] = k_rgchHexToASCII[c >> 4];
string[i * 2 + 1] = k_rgchHexToASCII[c & 0x0F];
*pszGUID++ = k_rgchHexToASCII[c >> 4];
*pszGUID++ = k_rgchHexToASCII[c & 0x0F];
}
string[sizeof(string) -1] = '\0';
return SDL_CreateTemporaryString(string);
*pszGUID = '\0';
}
/*-----------------------------------------------------------------------------

View File

@ -74,7 +74,7 @@ SDL_bool SDL_SetHintWithPriority(const char *name, const char *value, SDL_HintPr
entry->callback(entry->userdata, name, old_value, value);
entry = next;
}
SDL_FreeLater(old_value);
SDL_free(old_value);
}
hint->priority = priority;
return SDL_TRUE;
@ -118,7 +118,7 @@ SDL_bool SDL_ResetHint(const char *name)
entry = next;
}
}
SDL_FreeLater(hint->value);
SDL_free(hint->value);
hint->value = NULL;
hint->priority = SDL_HINT_DEFAULT;
return SDL_TRUE;
@ -145,7 +145,7 @@ void SDL_ResetHints(void)
entry = next;
}
}
SDL_FreeLater(hint->value);
SDL_free(hint->value);
hint->value = NULL;
hint->priority = SDL_HINT_DEFAULT;
}
@ -169,7 +169,7 @@ const char *SDL_GetHint(const char *name)
for (hint = SDL_hints; hint; hint = hint->next) {
if (SDL_strcmp(name, hint->name) == 0) {
if (!env || hint->priority == SDL_HINT_OVERRIDE) {
return hint->value;
return SDL_GetPersistentString(hint->value);
}
break;
}
@ -303,7 +303,7 @@ void SDL_ClearHints(void)
SDL_hints = hint->next;
SDL_free(hint->name);
SDL_FreeLater(hint->value);
SDL_free(hint->value);
for (entry = hint->callbacks; entry;) {
SDL_HintWatch *freeable = entry;
entry = entry->next;

View File

@ -279,28 +279,23 @@
#define SDL_MAIN_NOIMPL /* don't drag in header-only implementation of SDL_main */
#include <SDL3/SDL_main.h>
#include "SDL_utils_c.h"
/* The internal implementations of these functions have up to nanosecond precision.
We can expose these functions as part of the API if we want to later.
*/
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
#include "SDL_utils_c.h"
/* Do any initialization that needs to happen before threads are started */
extern void SDL_InitMainThread(void);
/* The internal implementations of these functions have up to nanosecond precision.
We can expose these functions as part of the API if we want to later.
*/
extern int SDLCALL SDL_WaitSemaphoreTimeoutNS(SDL_Semaphore *sem, Sint64 timeoutNS);
extern int SDLCALL SDL_WaitConditionTimeoutNS(SDL_Condition *cond, SDL_Mutex *mutex, Sint64 timeoutNS);
extern SDL_bool SDLCALL SDL_WaitEventTimeoutNS(SDL_Event *event, Sint64 timeoutNS);
extern const char *SDL_CreateTemporaryString(const char *string);
/* Add memory to the temporary memory pool, to be freed automatically later */
extern void *SDL_FreeLater(void *memory);
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}

View File

@ -65,12 +65,12 @@ static void SDL_FreePropertyWithCleanup(const void *key, const void *value, void
}
break;
case SDL_PROPERTY_TYPE_STRING:
SDL_FreeLater(property->value.string_value); // SDL_GetStringProperty() returns this pointer
SDL_free(property->value.string_value);
break;
default:
break;
}
SDL_FreeLater(property->string_storage); // this pointer might be given to the app by SDL_GetStringProperty.
SDL_free(property->string_storage);
}
SDL_free((void *)key);
SDL_free((void *)value);

View File

@ -320,3 +320,48 @@ int SDL_URIToLocal(const char *src, char *dst)
}
return -1;
}
// This is a set of per-thread persistent strings that we can return from the SDL API.
// This is used for short strings that might persist past the lifetime of the object
// they are related to.
static SDL_TLSID SDL_string_storage;
static void SDL_FreePersistentStrings( void *value )
{
SDL_HashTable *strings = (SDL_HashTable *)value;
SDL_DestroyHashTable(strings);
}
const char *SDL_GetPersistentString(const char *string)
{
if (!string) {
return NULL;
}
if (!*string) {
return "";
}
SDL_HashTable *strings = (SDL_HashTable *)SDL_GetTLS(&SDL_string_storage);
if (!strings) {
strings = SDL_CreateHashTable(NULL, 32, SDL_HashString, SDL_KeyMatchString, SDL_NukeFreeValue, SDL_FALSE);
if (!strings) {
return NULL;
}
SDL_SetTLS(&SDL_string_storage, strings, SDL_FreePersistentStrings);
}
const void *retval;
if (!SDL_FindInHashTable(strings, string, &retval)) {
char *new_string = SDL_strdup(string);
if (!new_string) {
return NULL;
}
// If the hash table insert fails, at least we can return the string we allocated
retval = new_string;
SDL_InsertIntoHashTable(strings, string, retval);
}
return (const char *)retval;
}

View File

@ -65,4 +65,6 @@ extern void SDL_SetObjectValid(void *object, SDL_ObjectType type, SDL_bool valid
extern SDL_bool SDL_ObjectValid(void *object, SDL_ObjectType type);
extern void SDL_SetObjectsInvalid(void);
extern const char *SDL_GetPersistentString(const char *string);
#endif /* SDL_utils_h_ */

View File

@ -134,14 +134,14 @@ int SDL_GetNumAudioDrivers(void)
const char *SDL_GetAudioDriver(int index)
{
if (index >= 0 && index < SDL_GetNumAudioDrivers()) {
return SDL_CreateTemporaryString(deduped_bootstrap[index]->name);
return deduped_bootstrap[index]->name;
}
return NULL;
}
const char *SDL_GetCurrentAudioDriver(void)
{
return SDL_CreateTemporaryString(current_audio.name);
return current_audio.name;
}
static int GetDefaultSampleFramesFromFreq(const int freq)
@ -1336,7 +1336,7 @@ static int SDLCALL RecordingAudioThread(void *devicep) // thread entry point
}
static const SDL_AudioDeviceID *GetAudioDevices(int *count, SDL_bool recording)
static SDL_AudioDeviceID *GetAudioDevices(int *count, SDL_bool recording)
{
SDL_AudioDeviceID *retval = NULL;
int num_devices = 0;
@ -1379,15 +1379,15 @@ static const SDL_AudioDeviceID *GetAudioDevices(int *count, SDL_bool recording)
*count = 0;
}
}
return SDL_FreeLater(retval);
return retval;
}
const SDL_AudioDeviceID *SDL_GetAudioPlaybackDevices(int *count)
SDL_AudioDeviceID *SDL_GetAudioPlaybackDevices(int *count)
{
return GetAudioDevices(count, SDL_FALSE);
}
const SDL_AudioDeviceID *SDL_GetAudioRecordingDevices(int *count)
SDL_AudioDeviceID *SDL_GetAudioRecordingDevices(int *count)
{
return GetAudioDevices(count, SDL_TRUE);
}
@ -1438,7 +1438,7 @@ const char *SDL_GetAudioDeviceName(SDL_AudioDeviceID devid)
const char *retval = NULL;
SDL_AudioDevice *device = ObtainPhysicalAudioDevice(devid);
if (device) {
retval = SDL_CreateTemporaryString(device->name);
retval = SDL_GetPersistentString(device->name);
}
ReleaseAudioDevice(device);
@ -1465,14 +1465,14 @@ int SDL_GetAudioDeviceFormat(SDL_AudioDeviceID devid, SDL_AudioSpec *spec, int *
return retval;
}
const int *SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int *count)
int *SDL_GetAudioDeviceChannelMap(SDL_AudioDeviceID devid, int *count)
{
const int *retval = NULL;
int *retval = NULL;
int channels = 0;
SDL_AudioDevice *device = ObtainPhysicalAudioDeviceDefaultAllowed(devid);
if (device) {
channels = device->spec.channels;
retval = SDL_FreeLater(SDL_ChannelMapDup(device->chmap, channels));
retval = SDL_ChannelMapDup(device->chmap, channels);
}
ReleaseAudioDevice(device);

View File

@ -636,14 +636,14 @@ int SDL_SetAudioStreamOutputChannelMap(SDL_AudioStream *stream, const int *chmap
return SetAudioStreamChannelMap(stream, &stream->dst_spec, &stream->dst_chmap, chmap, channels, SDL_FALSE);
}
const int *SDL_GetAudioStreamInputChannelMap(SDL_AudioStream *stream, int *count)
int *SDL_GetAudioStreamInputChannelMap(SDL_AudioStream *stream, int *count)
{
const int *retval = NULL;
int *retval = NULL;
int channels = 0;
if (stream) {
SDL_LockMutex(stream->lock);
channels = stream->src_spec.channels;
retval = SDL_FreeLater(SDL_ChannelMapDup(stream->src_chmap, channels));
retval = SDL_ChannelMapDup(stream->src_chmap, channels);
SDL_UnlockMutex(stream->lock);
}
@ -654,14 +654,14 @@ const int *SDL_GetAudioStreamInputChannelMap(SDL_AudioStream *stream, int *count
return retval;
}
const int *SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream *stream, int *count)
int *SDL_GetAudioStreamOutputChannelMap(SDL_AudioStream *stream, int *count)
{
const int *retval = NULL;
int *retval = NULL;
int channels = 0;
if (stream) {
SDL_LockMutex(stream->lock);
channels = stream->dst_spec.channels;
retval = SDL_FreeLater(SDL_ChannelMapDup(stream->dst_chmap, channels));
retval = SDL_ChannelMapDup(stream->dst_chmap, channels);
SDL_UnlockMutex(stream->lock);
}

View File

@ -66,14 +66,14 @@ int SDL_GetNumCameraDrivers(void)
const char *SDL_GetCameraDriver(int index)
{
if (index >= 0 && index < SDL_GetNumCameraDrivers()) {
return SDL_CreateTemporaryString(bootstrap[index]->name);
return bootstrap[index]->name;
}
return NULL;
}
const char *SDL_GetCurrentCameraDriver(void)
{
return SDL_CreateTemporaryString(camera_driver.name);
return camera_driver.name;
}
char *SDL_GetCameraThreadName(SDL_Camera *device, char *buf, size_t buflen)
@ -675,7 +675,7 @@ const char *SDL_GetCameraName(SDL_CameraID instance_id)
const char *retval = NULL;
SDL_Camera *device = ObtainPhysicalCamera(instance_id);
if (device) {
retval = SDL_CreateTemporaryString(device->name);
retval = SDL_GetPersistentString(device->name);
ReleaseCamera(device);
}
return retval;
@ -693,7 +693,7 @@ SDL_CameraPosition SDL_GetCameraPosition(SDL_CameraID instance_id)
}
const SDL_CameraID *SDL_GetCameras(int *count)
SDL_CameraID *SDL_GetCameras(int *count)
{
int dummy_count;
if (!count) {
@ -729,10 +729,10 @@ const SDL_CameraID *SDL_GetCameras(int *count)
*count = num_devices;
return SDL_FreeLater(retval);
return retval;
}
const SDL_CameraSpec * const *SDL_GetCameraSupportedFormats(SDL_CameraID instance_id, int *count)
SDL_CameraSpec **SDL_GetCameraSupportedFormats(SDL_CameraID instance_id, int *count)
{
if (count) {
*count = 0;
@ -761,7 +761,7 @@ const SDL_CameraSpec * const *SDL_GetCameraSupportedFormats(SDL_CameraID instanc
ReleaseCamera(device);
return SDL_FreeLater(retval);
return retval;
}

View File

@ -2584,7 +2584,7 @@ const char *SDL_GetAndroidInternalStoragePath(void)
LocalReferenceHolder_Cleanup(&refs);
}
return SDL_CreateTemporaryString(s_AndroidInternalFilesPath);
return s_AndroidInternalFilesPath;
}
Uint32 SDL_GetAndroidExternalStorageState(void)
@ -2669,7 +2669,7 @@ const char *SDL_GetAndroidExternalStoragePath(void)
LocalReferenceHolder_Cleanup(&refs);
}
return SDL_CreateTemporaryString(s_AndroidExternalFilesPath);
return s_AndroidExternalFilesPath;
}
const char *SDL_GetAndroidCachePath(void)
@ -2715,7 +2715,7 @@ const char *SDL_GetAndroidCachePath(void)
LocalReferenceHolder_Cleanup(&refs);
}
return SDL_CreateTemporaryString(s_AndroidCachePath);
return s_AndroidCachePath;
}
int SDL_ShowAndroidToast(const char *message, int duration, int gravity, int xOffset, int yOffset)

View File

@ -192,7 +192,7 @@ SDL_DYNAPI_PROC(int,SDL_GL_SetAttribute,(SDL_GLattr a, int b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GL_SetSwapInterval,(int a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GL_SwapWindow,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_GL_UnloadLibrary,(void),(),)
SDL_DYNAPI_PROC(const char *,SDL_GUIDToString,(SDL_GUID a),(a),return)
SDL_DYNAPI_PROC(void,SDL_GUIDToString,(SDL_GUID a, char *b, int c),(a,b,c),)
SDL_DYNAPI_PROC(SDL_bool,SDL_GamepadConnected,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GamepadEventsEnabled,(void),(),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GamepadHasAxis,(SDL_Gamepad *a, SDL_GamepadAxis b),(a,b),return)
@ -208,21 +208,21 @@ SDL_DYNAPI_PROC(void*,SDL_GetAndroidJNIEnv,(void),(),return)
SDL_DYNAPI_PROC(int,SDL_GetAndroidSDKVersion,(void),(),return)
SDL_DYNAPI_PROC(SDL_AssertionHandler,SDL_GetAssertionHandler,(void **a),(a),return)
SDL_DYNAPI_PROC(const SDL_AssertData*,SDL_GetAssertionReport,(void),(),return)
SDL_DYNAPI_PROC(const int*,SDL_GetAudioDeviceChannelMap,(SDL_AudioDeviceID a, int *b),(a,b),return)
SDL_DYNAPI_PROC(int*,SDL_GetAudioDeviceChannelMap,(SDL_AudioDeviceID a, int *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetAudioDeviceFormat,(SDL_AudioDeviceID a, SDL_AudioSpec *b, int *c),(a,b,c),return)
SDL_DYNAPI_PROC(float,SDL_GetAudioDeviceGain,(SDL_AudioDeviceID a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetAudioDeviceName,(SDL_AudioDeviceID a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetAudioDriver,(int a),(a),return)
SDL_DYNAPI_PROC(const SDL_AudioDeviceID*,SDL_GetAudioPlaybackDevices,(int *a),(a),return)
SDL_DYNAPI_PROC(const SDL_AudioDeviceID*,SDL_GetAudioRecordingDevices,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_AudioDeviceID*,SDL_GetAudioPlaybackDevices,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_AudioDeviceID*,SDL_GetAudioRecordingDevices,(int *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetAudioStreamAvailable,(SDL_AudioStream *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetAudioStreamData,(SDL_AudioStream *a, void *b, int c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_AudioDeviceID,SDL_GetAudioStreamDevice,(SDL_AudioStream *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetAudioStreamFormat,(SDL_AudioStream *a, SDL_AudioSpec *b, SDL_AudioSpec *c),(a,b,c),return)
SDL_DYNAPI_PROC(float,SDL_GetAudioStreamFrequencyRatio,(SDL_AudioStream *a),(a),return)
SDL_DYNAPI_PROC(float,SDL_GetAudioStreamGain,(SDL_AudioStream *a),(a),return)
SDL_DYNAPI_PROC(const int*,SDL_GetAudioStreamInputChannelMap,(SDL_AudioStream *a, int *b),(a,b),return)
SDL_DYNAPI_PROC(const int*,SDL_GetAudioStreamOutputChannelMap,(SDL_AudioStream *a, int *b),(a,b),return)
SDL_DYNAPI_PROC(int*,SDL_GetAudioStreamInputChannelMap,(SDL_AudioStream *a, int *b),(a,b),return)
SDL_DYNAPI_PROC(int*,SDL_GetAudioStreamOutputChannelMap,(SDL_AudioStream *a, int *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetAudioStreamProperties,(SDL_AudioStream *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetAudioStreamQueued,(SDL_AudioStream *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetBasePath,(void),(),return)
@ -236,11 +236,11 @@ SDL_DYNAPI_PROC(const char*,SDL_GetCameraName,(SDL_CameraID a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetCameraPermissionState,(SDL_Camera *a),(a),return)
SDL_DYNAPI_PROC(SDL_CameraPosition,SDL_GetCameraPosition,(SDL_CameraID a),(a),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetCameraProperties,(SDL_Camera *a),(a),return)
SDL_DYNAPI_PROC(const SDL_CameraSpec* const*,SDL_GetCameraSupportedFormats,(SDL_CameraID a, int *b),(a,b),return)
SDL_DYNAPI_PROC(const SDL_CameraID*,SDL_GetCameras,(int *a),(a),return)
SDL_DYNAPI_PROC(const void*,SDL_GetClipboardData,(const char *a, size_t *b),(a,b),return)
SDL_DYNAPI_PROC(const char*,SDL_GetClipboardText,(void),(),return)
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)
SDL_DYNAPI_PROC(SDL_CameraSpec**,SDL_GetCameraSupportedFormats,(SDL_CameraID a, int *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_CameraID*,SDL_GetCameras,(int *a),(a),return)
SDL_DYNAPI_PROC(void*,SDL_GetClipboardData,(const char *a, size_t *b),(a,b),return)
SDL_DYNAPI_PROC(char*,SDL_GetClipboardText,(void),(),return)
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)
SDL_DYNAPI_PROC(const char*,SDL_GetCurrentAudioDriver,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_GetCurrentCameraDriver,(void),(),return)
SDL_DYNAPI_PROC(const SDL_DisplayMode*,SDL_GetCurrentDisplayMode,(SDL_DisplayID a),(a),return)
@ -269,18 +269,18 @@ SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetDisplayForWindow,(SDL_Window *a),(a),return
SDL_DYNAPI_PROC(const char*,SDL_GetDisplayName,(SDL_DisplayID a),(a),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetDisplayProperties,(SDL_DisplayID a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetDisplayUsableBounds,(SDL_DisplayID a, SDL_Rect *b),(a,b),return)
SDL_DYNAPI_PROC(const SDL_DisplayID*,SDL_GetDisplays,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_DisplayID*,SDL_GetDisplays,(int *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetError,(void),(),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GetEventFilter,(SDL_EventFilter *a, void **b),(a,b),return)
SDL_DYNAPI_PROC(float,SDL_GetFloatProperty,(SDL_PropertiesID a, const char *b, float c),(a,b,c),return)
SDL_DYNAPI_PROC(const SDL_DisplayMode* const*,SDL_GetFullscreenDisplayModes,(SDL_DisplayID a, int *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_DisplayMode**,SDL_GetFullscreenDisplayModes,(SDL_DisplayID a, int *b),(a,b),return)
SDL_DYNAPI_PROC(int,SDL_GetGDKDefaultUser,(XUserHandle *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetGDKTaskQueue,(XTaskQueueHandle *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadAppleSFSymbolsNameForAxis,(SDL_Gamepad *a, SDL_GamepadAxis b),(a,b),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadAppleSFSymbolsNameForButton,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return)
SDL_DYNAPI_PROC(Sint16,SDL_GetGamepadAxis,(SDL_Gamepad *a, SDL_GamepadAxis b),(a,b),return)
SDL_DYNAPI_PROC(SDL_GamepadAxis,SDL_GetGamepadAxisFromString,(const char *a),(a),return)
SDL_DYNAPI_PROC(const SDL_GamepadBinding* const*,SDL_GetGamepadBindings,(SDL_Gamepad *a, int *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_GamepadBinding**,SDL_GetGamepadBindings,(SDL_Gamepad *a, int *b),(a,b),return)
SDL_DYNAPI_PROC(Uint8,SDL_GetGamepadButton,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return)
SDL_DYNAPI_PROC(SDL_GamepadButton,SDL_GetGamepadButtonFromString,(const char *a),(a),return)
SDL_DYNAPI_PROC(SDL_GamepadButtonLabel,SDL_GetGamepadButtonLabel,(SDL_Gamepad *a, SDL_GamepadButton b),(a,b),return)
@ -292,10 +292,10 @@ SDL_DYNAPI_PROC(SDL_Gamepad*,SDL_GetGamepadFromPlayerIndex,(int a),(a),return)
SDL_DYNAPI_PROC(SDL_GUID,SDL_GetGamepadGUIDForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(SDL_JoystickID,SDL_GetGamepadID,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(SDL_Joystick*,SDL_GetGamepadJoystick,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadMapping,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadMappingForGUID,(SDL_GUID a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadMappingForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(const char * const *,SDL_GetGamepadMappings,(int *a),(a),return)
SDL_DYNAPI_PROC(char*,SDL_GetGamepadMapping,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(char*,SDL_GetGamepadMappingForGUID,(SDL_GUID a),(a),return)
SDL_DYNAPI_PROC(char*,SDL_GetGamepadMappingForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(char **,SDL_GetGamepadMappings,(int *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadName,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadNameForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetGamepadPath,(SDL_Gamepad *a),(a),return)
@ -321,7 +321,7 @@ SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetGamepadTypeForID,(SDL_JoystickID a),(a),r
SDL_DYNAPI_PROC(SDL_GamepadType,SDL_GetGamepadTypeFromString,(const char *a),(a),return)
SDL_DYNAPI_PROC(Uint16,SDL_GetGamepadVendor,(SDL_Gamepad *a),(a),return)
SDL_DYNAPI_PROC(Uint16,SDL_GetGamepadVendorForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(const SDL_JoystickID*,SDL_GetGamepads,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_JoystickID*,SDL_GetGamepads,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_MouseButtonFlags,SDL_GetGlobalMouseState,(float *a, float *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetGlobalProperties,(void),(),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_GetGrabbedWindow,(void),(),return)
@ -331,7 +331,7 @@ SDL_DYNAPI_PROC(SDL_Haptic*,SDL_GetHapticFromID,(SDL_HapticID a),(a),return)
SDL_DYNAPI_PROC(SDL_HapticID,SDL_GetHapticID,(SDL_Haptic *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetHapticName,(SDL_Haptic *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetHapticNameForID,(SDL_HapticID a),(a),return)
SDL_DYNAPI_PROC(const SDL_HapticID*,SDL_GetHaptics,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_HapticID*,SDL_GetHaptics,(int *a),(a),return)
SDL_DYNAPI_PROC(const char*,SDL_GetHint,(const char *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GetHintBoolean,(const char *a, SDL_bool b),(a,b),return)
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetIOProperties,(SDL_IOStream *a),(a),return)
@ -367,21 +367,21 @@ SDL_DYNAPI_PROC(SDL_JoystickType,SDL_GetJoystickType,(SDL_Joystick *a),(a),retur
SDL_DYNAPI_PROC(SDL_JoystickType,SDL_GetJoystickTypeForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(Uint16,SDL_GetJoystickVendor,(SDL_Joystick *a),(a),return)
SDL_DYNAPI_PROC(Uint16,SDL_GetJoystickVendorForID,(SDL_JoystickID a),(a),return)
SDL_DYNAPI_PROC(const SDL_JoystickID*,SDL_GetJoysticks,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_JoystickID*,SDL_GetJoysticks,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_Keycode,SDL_GetKeyFromName,(const char *a),(a),return)
SDL_DYNAPI_PROC(SDL_Keycode,SDL_GetKeyFromScancode,(SDL_Scancode a, SDL_Keymod b),(a,b),return)
SDL_DYNAPI_PROC(const char*,SDL_GetKeyName,(SDL_Keycode a),(a),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_GetKeyboardFocus,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_GetKeyboardNameForID,(SDL_KeyboardID a),(a),return)
SDL_DYNAPI_PROC(const Uint8*,SDL_GetKeyboardState,(int *a),(a),return)
SDL_DYNAPI_PROC(const SDL_KeyboardID*,SDL_GetKeyboards,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_KeyboardID*,SDL_GetKeyboards,(int *a),(a),return)
SDL_DYNAPI_PROC(void,SDL_GetLogOutputFunction,(SDL_LogOutputFunction *a, void **b),(a,b),)
SDL_DYNAPI_PROC(SDL_LogPriority,SDL_GetLogPriority,(int a),(a),return)
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)
SDL_DYNAPI_PROC(int,SDL_GetMaxHapticEffects,(SDL_Haptic *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetMaxHapticEffectsPlaying,(SDL_Haptic *a),(a),return)
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),)
SDL_DYNAPI_PROC(const SDL_MouseID*,SDL_GetMice,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_MouseID*,SDL_GetMice,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_Keymod,SDL_GetModState,(void),(),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_GetMouseFocus,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_GetMouseNameForID,(SDL_MouseID a),(a),return)
@ -417,10 +417,10 @@ SDL_DYNAPI_PROC(const char*,SDL_GetPixelFormatName,(SDL_PixelFormat a),(a),retur
SDL_DYNAPI_PROC(const char*,SDL_GetPlatform,(void),(),return)
SDL_DYNAPI_PROC(void*,SDL_GetPointerProperty,(SDL_PropertiesID a, const char *b, void *c),(a,b,c),return)
SDL_DYNAPI_PROC(SDL_PowerState,SDL_GetPowerInfo,(int *a, int *b),(a,b),return)
SDL_DYNAPI_PROC(const char*,SDL_GetPrefPath,(const char *a, const char *b),(a,b),return)
SDL_DYNAPI_PROC(const SDL_Locale* const*,SDL_GetPreferredLocales,(int *a),(a),return)
SDL_DYNAPI_PROC(char*,SDL_GetPrefPath,(const char *a, const char *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_Locale**,SDL_GetPreferredLocales,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_DisplayID,SDL_GetPrimaryDisplay,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_GetPrimarySelectionText,(void),(),return)
SDL_DYNAPI_PROC(char*,SDL_GetPrimarySelectionText,(void),(),return)
SDL_DYNAPI_PROC(SDL_PropertyType,SDL_GetPropertyType,(SDL_PropertiesID a, const char *b),(a,b),return)
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),)
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,7 +473,7 @@ SDL_DYNAPI_PROC(int,SDL_GetSensorNonPortableTypeForID,(SDL_SensorID a),(a),retur
SDL_DYNAPI_PROC(SDL_PropertiesID,SDL_GetSensorProperties,(SDL_Sensor *a),(a),return)
SDL_DYNAPI_PROC(SDL_SensorType,SDL_GetSensorType,(SDL_Sensor *a),(a),return)
SDL_DYNAPI_PROC(SDL_SensorType,SDL_GetSensorTypeForID,(SDL_SensorID a),(a),return)
SDL_DYNAPI_PROC(const SDL_SensorID*,SDL_GetSensors,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_SensorID*,SDL_GetSensors,(int *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetSilenceValueForFormat,(SDL_AudioFormat a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetStorageFileSize,(SDL_Storage *a, const char *b, Uint64 *c),(a,b,c),return)
SDL_DYNAPI_PROC(int,SDL_GetStoragePathInfo,(SDL_Storage *a, const char *b, SDL_PathInfo *c),(a,b,c),return)
@ -505,8 +505,8 @@ SDL_DYNAPI_PROC(Uint64,SDL_GetTicks,(void),(),return)
SDL_DYNAPI_PROC(Uint64,SDL_GetTicksNS,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_GetTouchDeviceName,(SDL_TouchID a),(a),return)
SDL_DYNAPI_PROC(SDL_TouchDeviceType,SDL_GetTouchDeviceType,(SDL_TouchID a),(a),return)
SDL_DYNAPI_PROC(const SDL_TouchID*,SDL_GetTouchDevices,(int *a),(a),return)
SDL_DYNAPI_PROC(const SDL_Finger* const*,SDL_GetTouchFingers,(SDL_TouchID a, int *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_TouchID*,SDL_GetTouchDevices,(int *a),(a),return)
SDL_DYNAPI_PROC(SDL_Finger**,SDL_GetTouchFingers,(SDL_TouchID a, int *b),(a,b),return)
SDL_DYNAPI_PROC(const char*,SDL_GetUserFolder,(SDL_Folder a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetVersion,(void),(),return)
SDL_DYNAPI_PROC(const char*,SDL_GetVideoDriver,(int a),(a),return)
@ -518,7 +518,7 @@ SDL_DYNAPI_PROC(float,SDL_GetWindowDisplayScale,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(SDL_WindowFlags,SDL_GetWindowFlags,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(SDL_Window*,SDL_GetWindowFromID,(SDL_WindowID a),(a),return)
SDL_DYNAPI_PROC(const SDL_DisplayMode*,SDL_GetWindowFullscreenMode,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(const void*,SDL_GetWindowICCProfile,(SDL_Window *a, size_t *b),(a,b),return)
SDL_DYNAPI_PROC(void*,SDL_GetWindowICCProfile,(SDL_Window *a, size_t *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_WindowID,SDL_GetWindowID,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_GetWindowKeyboardGrab,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetWindowMaximumSize,(SDL_Window *a, int *b, int *c),(a,b,c),return)
@ -537,9 +537,9 @@ SDL_DYNAPI_PROC(int,SDL_GetWindowSizeInPixels,(SDL_Window *a, int *b, int *c),(a
SDL_DYNAPI_PROC(SDL_Surface*,SDL_GetWindowSurface,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(int,SDL_GetWindowSurfaceVSync,(SDL_Window *a, int *b),(a,b),return)
SDL_DYNAPI_PROC(const char*,SDL_GetWindowTitle,(SDL_Window *a),(a),return)
SDL_DYNAPI_PROC(SDL_Window* const*,SDL_GetWindows,(int *a),(a),return)
SDL_DYNAPI_PROC(const char * const *,SDL_GlobDirectory,(const char *a, const char *b, SDL_GlobFlags c, int *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(const char * const *,SDL_GlobStorageDirectory,(SDL_Storage *a, const char *b, const char *c, SDL_GlobFlags d, int *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(SDL_Window**,SDL_GetWindows,(int *a),(a),return)
SDL_DYNAPI_PROC(char **,SDL_GlobDirectory,(const char *a, const char *b, SDL_GlobFlags c, int *d),(a,b,c,d),return)
SDL_DYNAPI_PROC(char **,SDL_GlobStorageDirectory,(SDL_Storage *a, const char *b, const char *c, SDL_GlobFlags d, int *e),(a,b,c,d,e),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_HapticEffectSupported,(SDL_Haptic *a, const SDL_HapticEffect *b),(a,b),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_HapticRumbleSupported,(SDL_Haptic *a),(a),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_HasARMSIMD,(void),(),return)

View File

@ -197,7 +197,7 @@ def main():
func_ret = func_ret.replace('extern', ' ')
func_ret = func_ret.replace('SDLCALL', ' ')
func_ret = func_ret.replace('SDL_DECLSPEC', ' ')
func_ret = func_ret.replace('SDL_DECLSPEC_TEMP', ' ')
func_ret = func_ret.replace('SDL_DECLSPEC_FREE', ' ')
# Remove trailing spaces in front of '*'
tmp = ""
while func_ret != tmp:

View File

@ -236,10 +236,6 @@ static void SDL_TransferTemporaryMemoryToEvent(SDL_EventEntry *event)
SDL_LinkTemporaryMemoryToEvent(event, event->event.drop.data);
break;
default:
if (event->event.type >= SDL_EVENT_USER && event->event.type <= SDL_EVENT_LAST-1) {
SDL_LinkTemporaryMemoryToEvent(event, event->event.user.data1);
SDL_LinkTemporaryMemoryToEvent(event, event->event.user.data2);
}
break;
}
}
@ -266,7 +262,7 @@ static void SDL_TransferTemporaryMemoryFromEvent(SDL_EventEntry *event)
event->memory = NULL;
}
void *SDL_FreeLater(void *memory)
static void *SDL_FreeLater(void *memory)
{
SDL_TemporaryMemoryState *state;
@ -275,7 +271,7 @@ void *SDL_FreeLater(void *memory)
}
// Make sure we're not adding this to the list twice
SDL_assert(!SDL_ClaimTemporaryMemory(memory));
//SDL_assert(!SDL_ClaimTemporaryMemory(memory));
state = SDL_GetTemporaryMemoryState(SDL_TRUE);
if (!state) {
@ -1158,6 +1154,9 @@ void SDL_FlushEvents(Uint32 minType, Uint32 maxType)
/* Run the system dependent event loops */
static void SDL_PumpEventsInternal(SDL_bool push_sentinel)
{
/* Free any temporary memory from old events */
SDL_FreeTemporaryMemory();
/* Release any keys held down from last frame */
SDL_ReleaseAutoReleaseKeys();

View File

@ -45,6 +45,11 @@ extern int SDL_SendKeymapChangedEvent(void);
extern int SDL_SendLocaleChangedEvent(void);
extern int SDL_SendSystemThemeChangedEvent(void);
extern void *SDL_AllocateTemporaryMemory(size_t size);
extern const char *SDL_CreateTemporaryString(const char *string);
extern void *SDL_ClaimTemporaryMemory(const void *mem);
extern void SDL_FreeTemporaryMemory(void);
extern int SDL_SendQuit(void);
extern int SDL_InitEvents(void);

View File

@ -177,7 +177,7 @@ SDL_bool SDL_HasKeyboard(void)
return (SDL_keyboard_count > 0);
}
const SDL_KeyboardID *SDL_GetKeyboards(int *count)
SDL_KeyboardID *SDL_GetKeyboards(int *count)
{
int i;
SDL_KeyboardID *keyboards;
@ -198,7 +198,7 @@ const SDL_KeyboardID *SDL_GetKeyboards(int *count)
}
}
return SDL_FreeLater(keyboards);
return keyboards;
}
const char *SDL_GetKeyboardNameForID(SDL_KeyboardID instance_id)
@ -207,7 +207,7 @@ const char *SDL_GetKeyboardNameForID(SDL_KeyboardID instance_id)
if (keyboard_index < 0) {
return NULL;
}
return SDL_CreateTemporaryString(SDL_keyboards[keyboard_index].name);
return SDL_GetPersistentString(SDL_keyboards[keyboard_index].name);
}
void SDL_ResetKeyboard(void)
@ -762,7 +762,7 @@ int SDL_SendEditingText(const char *text, int start, int length)
static const char * const *CreateCandidatesForEvent(char **candidates, int num_candidates)
{
char **event_candidates;
const char **event_candidates;
int i;
char *ptr;
size_t total_length = (num_candidates + 1) * sizeof(*event_candidates);
@ -773,7 +773,7 @@ static const char * const *CreateCandidatesForEvent(char **candidates, int num_c
total_length += length;
}
event_candidates = (char **)SDL_malloc(total_length);
event_candidates = (const char **)SDL_AllocateTemporaryMemory(total_length);
if (!event_candidates) {
return NULL;
}
@ -788,7 +788,7 @@ static const char * const *CreateCandidatesForEvent(char **candidates, int num_c
}
event_candidates[i] = NULL;
return SDL_FreeLater(event_candidates);
return event_candidates;
}
int SDL_SendEditingTextCandidates(char **candidates, int num_candidates, int selected_candidate, SDL_bool horizontal)

View File

@ -957,7 +957,8 @@ const char *SDL_GetScancodeName(SDL_Scancode scancode)
if (!name) {
name = "";
}
return SDL_CreateTemporaryString(name);
// This is pointing to static memory or application managed memory
return name;
}
SDL_Scancode SDL_GetScancodeFromName(const char *name)
@ -1015,7 +1016,7 @@ const char *SDL_GetKeyName(SDL_Keycode key)
end = SDL_UCS4ToUTF8(key, name);
*end = '\0';
return SDL_CreateTemporaryString(name);
return SDL_GetPersistentString(name);
}
}

View File

@ -361,7 +361,7 @@ SDL_bool SDL_HasMouse(void)
return (SDL_mouse_count > 0);
}
const SDL_MouseID *SDL_GetMice(int *count)
SDL_MouseID *SDL_GetMice(int *count)
{
int i;
SDL_MouseID *mice;
@ -382,7 +382,7 @@ const SDL_MouseID *SDL_GetMice(int *count)
}
}
return SDL_FreeLater(mice);
return mice;
}
const char *SDL_GetMouseNameForID(SDL_MouseID instance_id)
@ -391,7 +391,7 @@ const char *SDL_GetMouseNameForID(SDL_MouseID instance_id)
if (mouse_index < 0) {
return NULL;
}
return SDL_CreateTemporaryString(SDL_mice[mouse_index].name);
return SDL_GetPersistentString(SDL_mice[mouse_index].name);
}
void SDL_SetDefaultCursor(SDL_Cursor *cursor)

View File

@ -213,7 +213,7 @@ const char *SDL_GetPenName(SDL_PenID instance_id)
{
const char *result;
SDL_LOAD_LOCK_PEN(pen, instance_id, NULL);
result = pen->name; /* Allocated separately from the pen table, so it is safe to hand to client code */
result = SDL_GetPersistentString(pen->name);
SDL_UNLOCK_PENS();
return result;
}

View File

@ -49,7 +49,7 @@ SDL_bool SDL_TouchDevicesAvailable(void)
return SDL_num_touch > 0;
}
const SDL_TouchID *SDL_GetTouchDevices(int *count)
SDL_TouchID *SDL_GetTouchDevices(int *count)
{
if (count) {
*count = 0;
@ -67,7 +67,7 @@ const SDL_TouchID *SDL_GetTouchDevices(int *count)
}
}
return SDL_FreeLater(retval);
return retval;
}
static int SDL_GetTouchIndex(SDL_TouchID id)
@ -105,7 +105,7 @@ const char *SDL_GetTouchDeviceName(SDL_TouchID id)
if (!touch) {
return NULL;
}
return SDL_CreateTemporaryString(touch->name);
return SDL_GetPersistentString(touch->name);
}
SDL_TouchDeviceType SDL_GetTouchDeviceType(SDL_TouchID id)
@ -134,7 +134,7 @@ static SDL_Finger *SDL_GetFinger(const SDL_Touch *touch, SDL_FingerID id)
return touch->fingers[index];
}
const SDL_Finger * const * SDL_GetTouchFingers(SDL_TouchID touchID, int *count)
SDL_Finger **SDL_GetTouchFingers(SDL_TouchID touchID, int *count)
{
SDL_Finger **fingers;
SDL_Finger *finger_data;
@ -164,7 +164,7 @@ const SDL_Finger * const * SDL_GetTouchFingers(SDL_TouchID touchID, int *count)
if (count) {
*count = touch->num_fingers;
}
return SDL_FreeLater(fingers);
return fingers;
}
int SDL_AddTouch(SDL_TouchID touchID, SDL_TouchDeviceType type, const char *name)

View File

@ -298,7 +298,7 @@ static int SDLCALL GlobDirectoryCallback(void *userdata, const char *dirname, co
return retval;
}
const char * const *SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata)
char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata)
{
int dummycount;
if (!count) {
@ -393,7 +393,7 @@ const char * const *SDL_InternalGlobDirectory(const char *path, const char *patt
SDL_free(folded);
SDL_free(pathcpy);
return SDL_FreeLater(retval);
return retval;
}
static int GlobDirectoryGetPathInfo(const char *path, SDL_PathInfo *info, void *userdata)
@ -406,7 +406,7 @@ static int GlobDirectoryEnumerator(const char *path, SDL_EnumerateDirectoryCallb
return SDL_EnumerateDirectory(path, cb, cbuserdata);
}
const char * const *SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count)
char **SDL_GlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count)
{
//SDL_Log("SDL_GlobDirectory('%s', '%s') ...", path, pattern);
return SDL_InternalGlobDirectory(path, pattern, flags, count, GlobDirectoryEnumerator, GlobDirectoryGetPathInfo, NULL);
@ -441,10 +441,10 @@ const char *SDL_GetUserFolder(SDL_Folder folder)
}
const char *SDL_GetPrefPath(const char *org, const char *app)
char *SDL_GetPrefPath(const char *org, const char *app)
{
char *path = SDL_SYS_GetPrefPath(org, app);
return SDL_FreeLater(path);
return path;
}

View File

@ -36,7 +36,7 @@ int SDL_SYS_GetPathInfo(const char *path, SDL_PathInfo *info);
typedef int (*SDL_GlobEnumeratorFunc)(const char *path, SDL_EnumerateDirectoryCallback cb, void *cbuserdata, void *userdata);
typedef int (*SDL_GlobGetPathInfoFunc)(const char *path, SDL_PathInfo *info, void *userdata);
const char * const *SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata);
char **SDL_InternalGlobDirectory(const char *path, const char *pattern, SDL_GlobFlags flags, int *count, SDL_GlobEnumeratorFunc enumerator, SDL_GlobGetPathInfoFunc getpathinfo, void *userdata);
#endif

View File

@ -115,7 +115,7 @@ extern "C" const char *SDL_GetWinRTFSPath(SDL_WinRT_Path pathType)
char *utf8Path = WIN_StringToUTF8W(ucs2Path);
utf8Paths[pathType] = utf8Path;
SDL_free(utf8Path);
return SDL_CreateTemporaryString(utf8Paths[pathType].c_str());
return SDL_GetPersistentString(utf8Paths[pathType].c_str());
}
extern "C" char *SDL_SYS_GetBasePath(void)

View File

@ -63,7 +63,7 @@ static SDL_bool SDL_GetHapticIndex(SDL_HapticID instance_id, int *driver_index)
return SDL_FALSE;
}
const SDL_HapticID *SDL_GetHaptics(int *count)
SDL_HapticID *SDL_GetHaptics(int *count)
{
int device_index;
int haptic_index = 0, num_haptics = 0;
@ -89,7 +89,7 @@ const SDL_HapticID *SDL_GetHaptics(int *count)
}
}
return SDL_FreeLater(haptics);
return haptics;
}
const char *SDL_GetHapticNameForID(SDL_HapticID instance_id)
@ -98,9 +98,9 @@ const char *SDL_GetHapticNameForID(SDL_HapticID instance_id)
const char *name = NULL;
if (SDL_GetHapticIndex(instance_id, &device_index)) {
name = SDL_SYS_HapticName(device_index);
name = SDL_GetPersistentString(SDL_SYS_HapticName(device_index));
}
return SDL_CreateTemporaryString(name);
return name;
}
SDL_Haptic *SDL_OpenHaptic(SDL_HapticID instance_id)
@ -189,7 +189,7 @@ const char *SDL_GetHapticName(SDL_Haptic *haptic)
{
CHECK_HAPTIC_MAGIC(haptic, NULL);
return SDL_CreateTemporaryString(haptic->name);
return SDL_GetPersistentString(haptic->name);
}
SDL_bool SDL_IsMouseHaptic(void)

View File

@ -89,7 +89,7 @@ typedef struct GamepadMapping_t
typedef struct
{
int refcount _guarded;
const SDL_JoystickID *joysticks _guarded;
SDL_JoystickID *joysticks _guarded;
GamepadMapping_t **joystick_mappings _guarded;
int num_changed_mappings _guarded;
@ -579,6 +579,7 @@ static void PopMappingChangeTracking(void)
}
}
SDL_free(tracker->joysticks);
SDL_free(tracker->joystick_mappings);
SDL_free(tracker->changed_mappings);
SDL_free(tracker);
@ -2075,14 +2076,14 @@ int SDL_AddGamepadMapping(const char *mapping)
static char *CreateMappingString(GamepadMapping_t *mapping, SDL_GUID guid)
{
char *pMappingString, *pPlatformString;
const char *pchGUID;
char pchGUID[33];
size_t needed;
SDL_bool need_platform = SDL_FALSE;
const char *platform = NULL;
SDL_AssertJoysticksLocked();
pchGUID = SDL_GUIDToString(guid);
SDL_GUIDToString(guid, pchGUID, sizeof(pchGUID));
/* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
@ -2124,7 +2125,7 @@ static char *CreateMappingString(GamepadMapping_t *mapping, SDL_GUID guid)
return pMappingString;
}
const char * const *SDL_GetGamepadMappings(int *count)
char **SDL_GetGamepadMappings(int *count)
{
int num_mappings = 0;
char **retval = NULL;
@ -2197,13 +2198,13 @@ const char * const *SDL_GetGamepadMappings(int *count)
SDL_free(mappings);
}
return SDL_FreeLater(retval);
return retval;
}
/*
* Get the mapping string for this GUID
*/
const char *SDL_GetGamepadMappingForGUID(SDL_GUID guid)
char *SDL_GetGamepadMappingForGUID(SDL_GUID guid)
{
char *retval;
@ -2219,13 +2220,13 @@ const char *SDL_GetGamepadMappingForGUID(SDL_GUID guid)
}
SDL_UnlockJoysticks();
return SDL_FreeLater(retval);
return retval;
}
/*
* Get the mapping string for this device
*/
const char *SDL_GetGamepadMapping(SDL_Gamepad *gamepad)
char *SDL_GetGamepadMapping(SDL_Gamepad *gamepad)
{
char *retval;
@ -2237,7 +2238,7 @@ const char *SDL_GetGamepadMapping(SDL_Gamepad *gamepad)
}
SDL_UnlockJoysticks();
return SDL_FreeLater(retval);
return retval;
}
/*
@ -2357,7 +2358,7 @@ int SDL_InitGamepadMappings(void)
int SDL_InitGamepads(void)
{
int i;
const SDL_JoystickID *joysticks;
SDL_JoystickID *joysticks;
SDL_gamepads_initialized = SDL_TRUE;
@ -2372,6 +2373,7 @@ int SDL_InitGamepads(void)
SDL_PrivateGamepadAdded(joysticks[i]);
}
}
SDL_free(joysticks);
}
return 0;
@ -2381,7 +2383,7 @@ SDL_bool SDL_HasGamepad(void)
{
int num_joysticks = 0;
int num_gamepads = 0;
const SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks);
SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks);
if (joysticks) {
int i;
for (i = num_joysticks - 1; i >= 0 && num_gamepads == 0; --i) {
@ -2389,6 +2391,7 @@ SDL_bool SDL_HasGamepad(void)
++num_gamepads;
}
}
SDL_free(joysticks);
}
if (num_gamepads > 0) {
return SDL_TRUE;
@ -2396,11 +2399,11 @@ SDL_bool SDL_HasGamepad(void)
return SDL_FALSE;
}
const SDL_JoystickID *SDL_GetGamepads(int *count)
SDL_JoystickID *SDL_GetGamepads(int *count)
{
int num_joysticks = 0;
int num_gamepads = 0;
SDL_JoystickID *joysticks = SDL_ClaimTemporaryMemory(SDL_GetJoysticks(&num_joysticks));
SDL_JoystickID *joysticks = SDL_GetJoysticks(&num_joysticks);
if (joysticks) {
int i;
for (i = num_joysticks - 1; i >= 0; --i) {
@ -2414,7 +2417,7 @@ const SDL_JoystickID *SDL_GetGamepads(int *count)
if (count) {
*count = num_gamepads;
}
return SDL_FreeLater(joysticks);
return joysticks;
}
const char *SDL_GetGamepadNameForID(SDL_JoystickID instance_id)
@ -2428,7 +2431,7 @@ const char *SDL_GetGamepadNameForID(SDL_JoystickID instance_id)
if (SDL_strcmp(mapping->name, "*") == 0) {
retval = SDL_GetJoystickNameForID(instance_id);
} else {
retval = SDL_CreateTemporaryString(mapping->name);
retval = SDL_GetPersistentString(mapping->name);
}
}
}
@ -2516,7 +2519,7 @@ SDL_GamepadType SDL_GetRealGamepadTypeForID(SDL_JoystickID instance_id)
return type;
}
const char *SDL_GetGamepadMappingForID(SDL_JoystickID instance_id)
char *SDL_GetGamepadMappingForID(SDL_JoystickID instance_id)
{
char *retval = NULL;
@ -2524,15 +2527,15 @@ const char *SDL_GetGamepadMappingForID(SDL_JoystickID instance_id)
{
GamepadMapping_t *mapping = SDL_PrivateGetGamepadMapping(instance_id, SDL_TRUE);
if (mapping) {
const char *pchGUID;
const SDL_GUID guid = SDL_GetJoystickGUIDForID(instance_id);
pchGUID = SDL_GUIDToString(guid);
char pchGUID[33];
SDL_GUID guid = SDL_GetJoystickGUIDForID(instance_id);
SDL_GUIDToString(guid, pchGUID, sizeof(pchGUID));
SDL_asprintf(&retval, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
}
}
SDL_UnlockJoysticks();
return SDL_FreeLater(retval);
return retval;
}
/*
@ -3307,7 +3310,7 @@ const char *SDL_GetGamepadName(SDL_Gamepad *gamepad)
gamepad->joystick->steam_handle != 0) {
retval = SDL_GetJoystickName(gamepad->joystick);
} else {
retval = SDL_CreateTemporaryString(gamepad->name);
retval = SDL_GetPersistentString(gamepad->name);
}
}
SDL_UnlockJoysticks();
@ -3427,7 +3430,7 @@ const char * SDL_GetGamepadSerial(SDL_Gamepad *gamepad)
if (!joystick) {
return NULL;
}
return SDL_GetJoystickSerial(joystick); // this already returns a SDL_FreeLater pointer.
return SDL_GetJoystickSerial(joystick);
}
@ -3543,7 +3546,7 @@ SDL_Gamepad *SDL_GetGamepadFromPlayerIndex(int player_index)
/*
* Get the SDL joystick layer bindings for this gamepad
*/
const SDL_GamepadBinding * const*SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count)
SDL_GamepadBinding **SDL_GetGamepadBindings(SDL_Gamepad *gamepad, int *count)
{
SDL_GamepadBinding **bindings = NULL;
@ -3574,7 +3577,7 @@ const SDL_GamepadBinding * const*SDL_GetGamepadBindings(SDL_Gamepad *gamepad, in
}
SDL_UnlockJoysticks();
return SDL_FreeLater(bindings);
return bindings;
}
int SDL_RumbleGamepad(SDL_Gamepad *gamepad, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble, Uint32 duration_ms)
@ -3845,9 +3848,9 @@ void SDL_GamepadHandleDelayedGuideButton(SDL_Joystick *joystick)
const char *SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button)
{
const char *retval = NULL;
#ifdef SDL_JOYSTICK_MFI
char *IOS_GetAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
char *retval;
const char *IOS_GetAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button);
SDL_LockJoysticks();
{
@ -3856,21 +3859,15 @@ const char *SDL_GetGamepadAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_
retval = IOS_GetAppleSFSymbolsNameForButton(gamepad, button);
}
SDL_UnlockJoysticks();
// retval was malloc'd by IOS_GetAppleSFSymbolsNameForButton
if (retval && *retval) {
return SDL_FreeLater(retval);
}
SDL_free(retval);
#endif
return NULL;
return retval;
}
const char *SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis)
{
const char *retval = NULL;
#ifdef SDL_JOYSTICK_MFI
char *IOS_GetAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
char *retval;
const char *IOS_GetAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis);
SDL_LockJoysticks();
{
@ -3879,12 +3876,6 @@ const char *SDL_GetGamepadAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_Ga
retval = IOS_GetAppleSFSymbolsNameForAxis(gamepad, axis);
}
SDL_UnlockJoysticks();
// retval was malloc'd by IOS_GetAppleSFSymbolsNameForAxis
if (retval && *retval) {
return SDL_FreeLater(retval);
}
SDL_free(retval);
#endif
return NULL;
return retval;
}

View File

@ -714,7 +714,7 @@ SDL_bool SDL_HasJoystick(void)
return SDL_FALSE;
}
const SDL_JoystickID *SDL_GetJoysticks(int *count)
SDL_JoystickID *SDL_GetJoysticks(int *count)
{
int i, num_joysticks, device_index;
int joystick_index = 0, total_joysticks = 0;
@ -751,7 +751,7 @@ const SDL_JoystickID *SDL_GetJoysticks(int *count)
}
SDL_UnlockJoysticks();
return SDL_FreeLater(joysticks);
return joysticks;
}
const SDL_SteamVirtualGamepadInfo *SDL_GetJoystickVirtualGamepadInfoForID(SDL_JoystickID instance_id)
@ -780,9 +780,9 @@ const char *SDL_GetJoystickNameForID(SDL_JoystickID instance_id)
SDL_LockJoysticks();
info = SDL_GetJoystickVirtualGamepadInfoForID(instance_id);
if (info) {
name = SDL_CreateTemporaryString(info->name);
name = SDL_GetPersistentString(info->name);
} else if (SDL_GetDriverAndJoystickIndex(instance_id, &driver, &device_index)) {
name = SDL_CreateTemporaryString(driver->GetDeviceName(device_index));
name = SDL_GetPersistentString(driver->GetDeviceName(device_index));
}
SDL_UnlockJoysticks();
@ -800,7 +800,7 @@ const char *SDL_GetJoystickPathForID(SDL_JoystickID instance_id)
SDL_LockJoysticks();
if (SDL_GetDriverAndJoystickIndex(instance_id, &driver, &device_index)) {
path = SDL_CreateTemporaryString(driver->GetDevicePath(device_index));
path = SDL_GetPersistentString(driver->GetDevicePath(device_index));
}
SDL_UnlockJoysticks();
@ -858,7 +858,7 @@ static SDL_bool IsROGAlly(SDL_Joystick *joystick)
SDL_bool has_ally_gyro = SDL_FALSE;
if (SDL_InitSubSystem(SDL_INIT_SENSOR) == 0) {
const SDL_SensorID *sensors = SDL_GetSensors(NULL);
SDL_SensorID *sensors = SDL_GetSensors(NULL);
if (sensors) {
int i;
for (i = 0; sensors[i]; ++i) {
@ -877,6 +877,7 @@ static SDL_bool IsROGAlly(SDL_Joystick *joystick)
}
}
}
SDL_free(sensors);
}
SDL_QuitSubSystem(SDL_INIT_SENSOR);
}
@ -951,7 +952,7 @@ static SDL_bool ShouldAttemptSensorFusion(SDL_Joystick *joystick, SDL_bool *inve
static void AttemptSensorFusion(SDL_Joystick *joystick, SDL_bool invert_sensors)
{
const SDL_SensorID *sensors;
SDL_SensorID *sensors;
unsigned int i, j;
SDL_AssertJoysticksLocked();
@ -980,6 +981,7 @@ static void AttemptSensorFusion(SDL_Joystick *joystick, SDL_bool invert_sensors)
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 0.0f);
}
}
SDL_free(sensors);
}
SDL_QuitSubSystem(SDL_INIT_SENSOR);
@ -1651,9 +1653,9 @@ const char *SDL_GetJoystickName(SDL_Joystick *joystick)
info = SDL_GetJoystickVirtualGamepadInfoForID(joystick->instance_id);
if (info) {
retval = SDL_CreateTemporaryString(info->name);
retval = SDL_GetPersistentString(info->name);
} else {
retval = SDL_CreateTemporaryString(joystick->name);
retval = SDL_GetPersistentString(joystick->name);
}
}
SDL_UnlockJoysticks();
@ -1673,7 +1675,7 @@ const char *SDL_GetJoystickPath(SDL_Joystick *joystick)
CHECK_JOYSTICK_MAGIC(joystick, NULL);
if (joystick->path) {
retval = SDL_CreateTemporaryString(joystick->path);
retval = SDL_GetPersistentString(joystick->path);
} else {
SDL_Unsupported();
retval = NULL;
@ -1903,7 +1905,7 @@ void SDL_CloseJoystick(SDL_Joystick *joystick)
void SDL_QuitJoysticks(void)
{
int i;
const SDL_JoystickID *joysticks;
SDL_JoystickID *joysticks;
SDL_LockJoysticks();
@ -1914,6 +1916,7 @@ void SDL_QuitJoysticks(void)
for (i = 0; joysticks[i]; ++i) {
SDL_PrivateJoystickRemoved(joysticks[i]);
}
SDL_free(joysticks);
}
while (SDL_joysticks) {
@ -3428,7 +3431,7 @@ const char *SDL_GetJoystickSerial(SDL_Joystick *joystick)
{
CHECK_JOYSTICK_MAGIC(joystick, NULL);
retval = SDL_CreateTemporaryString(joystick->serial);
retval = SDL_GetPersistentString(joystick->serial);
}
SDL_UnlockJoysticks();

View File

@ -1916,7 +1916,7 @@ static GCControllerDirectionPad *GetDirectionalPadForController(GCController *co
}
#endif /* SDL_JOYSTICK_MFI && ENABLE_PHYSICAL_INPUT_PROFILE */
char *IOS_GetAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button)
const char *IOS_GetAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton button)
{
char elementName[256];
elementName[0] = '\0';
@ -2031,10 +2031,10 @@ char *IOS_GetAppleSFSymbolsNameForButton(SDL_Gamepad *gamepad, SDL_GamepadButton
}
#endif
return SDL_strdup(elementName);
return *elementName ? SDL_GetPersistentString(elementName) : NULL;
}
char *IOS_GetAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis)
const char *IOS_GetAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axis)
{
char elementName[256];
elementName[0] = '\0';
@ -2071,7 +2071,7 @@ char *IOS_GetAppleSFSymbolsNameForAxis(SDL_Gamepad *gamepad, SDL_GamepadAxis axi
}
}
#endif
return *elementName ? SDL_strdup(elementName) : NULL;
return *elementName ? SDL_GetPersistentString(elementName) : NULL;
}
SDL_JoystickDriver SDL_IOS_JoystickDriver = {

View File

@ -22,7 +22,7 @@
#include "SDL_internal.h"
#include "SDL_syslocale.h"
static const SDL_Locale * const *build_locales_from_csv_string(char *csv, int *count)
static SDL_Locale **build_locales_from_csv_string(char *csv, int *count)
{
int i, num_locales;
size_t slen;
@ -95,10 +95,10 @@ static const SDL_Locale * const *build_locales_from_csv_string(char *csv, int *c
*count = num_locales;
}
return SDL_FreeLater(retval);
return retval;
}
const SDL_Locale * const *SDL_GetPreferredLocales(int *count)
SDL_Locale **SDL_GetPreferredLocales(int *count)
{
char locbuf[128]; /* enough for 21 "xx_YY," language strings. */
const char *hint = SDL_GetHint(SDL_HINT_PREFERRED_LOCALES);

View File

@ -811,7 +811,7 @@ const char *SDL_GetRenderDriver(int index)
SDL_GetNumRenderDrivers() - 1);
return NULL;
}
return SDL_CreateTemporaryString(render_drivers[index]->name);
return render_drivers[index]->name;
#else
SDL_SetError("SDL not built with rendering support");
return NULL;
@ -1204,7 +1204,7 @@ const char *SDL_GetRendererName(SDL_Renderer *renderer)
{
CHECK_RENDERER_MAGIC(renderer, NULL);
return renderer->name;
return SDL_GetPersistentString(renderer->name);
}
SDL_PropertiesID SDL_GetRendererProperties(SDL_Renderer *renderer)

View File

@ -170,7 +170,7 @@ SDL_bool SDL_SensorsOpened(void)
return opened;
}
const SDL_SensorID *SDL_GetSensors(int *count)
SDL_SensorID *SDL_GetSensors(int *count)
{
int i, num_sensors, device_index;
int sensor_index = 0, total_sensors = 0;
@ -207,7 +207,7 @@ const SDL_SensorID *SDL_GetSensors(int *count)
}
SDL_UnlockSensors();
return SDL_FreeLater(sensors);
return sensors;
}
/*
@ -246,7 +246,7 @@ const char *SDL_GetSensorNameForID(SDL_SensorID instance_id)
SDL_LockSensors();
if (SDL_GetDriverAndSensorIndex(instance_id, &driver, &device_index)) {
name = SDL_CreateTemporaryString(driver->GetDeviceName(device_index));
name = SDL_GetPersistentString(driver->GetDeviceName(device_index));
}
SDL_UnlockSensors();
@ -407,7 +407,7 @@ const char *SDL_GetSensorName(SDL_Sensor *sensor)
{
CHECK_SENSOR_MAGIC(sensor, NULL);
retval = SDL_CreateTemporaryString(sensor->name);
retval = SDL_GetPersistentString(sensor->name);
}
SDL_UnlockSensors();

View File

@ -185,7 +185,8 @@ const char *SDL_getenv(const char *name)
const char *SDL_getenv(const char *name)
{
DWORD length, maxlen = 0;
char *retval = NULL;
char *string = NULL;
const char *retval = NULL;
/* Input validation */
if (!name || *name == '\0') {
@ -193,20 +194,24 @@ const char *SDL_getenv(const char *name)
}
for ( ; ; ) {
length = GetEnvironmentVariableA(name, retval, maxlen);
length = GetEnvironmentVariableA(name, string, maxlen);
if (length > maxlen) {
char *string = (char *)SDL_realloc(retval, length);
if (!string) {
char *temp = (char *)SDL_realloc(string, length);
if (!temp) {
return NULL;
}
retval = string;
string = temp;
maxlen = length;
} else {
break;
}
}
return SDL_FreeLater(retval);
if (string) {
retval = SDL_GetPersistentString(string);
SDL_free(string);
}
return retval;
}
#else
const char *SDL_getenv(const char *name)

View File

@ -353,7 +353,7 @@ static int GlobStorageDirectoryEnumerator(const char *path, SDL_EnumerateDirecto
return SDL_EnumerateStorageDirectory((SDL_Storage *) userdata, path, cb, cbuserdata);
}
const char * const *SDL_GlobStorageDirectory(SDL_Storage *storage, const char *path, const char *pattern, SDL_GlobFlags flags, int *count)
char **SDL_GlobStorageDirectory(SDL_Storage *storage, const char *path, const char *pattern, SDL_GlobFlags flags, int *count)
{
CHECK_STORAGE_MAGIC_RET(NULL)
return SDL_InternalGlobDirectory(path, pattern, flags, count, GlobStorageDirectoryEnumerator, GlobStorageDirectoryGetPathInfo, storage);

View File

@ -203,10 +203,8 @@ static SDL_Storage *GENERIC_Title_Create(const char *override, SDL_PropertiesID
if (override != NULL) {
basepath = SDL_strdup(override);
} else {
const char *sdlbasepath = SDL_GetBasePath();
if (sdlbasepath) {
basepath = SDL_strdup(sdlbasepath);
}
const char *base = SDL_GetBasePath();
basepath = base ? SDL_strdup(base) : NULL;
}
if (basepath != NULL) {
@ -242,11 +240,7 @@ static const SDL_StorageInterface GENERIC_user_iface = {
static SDL_Storage *GENERIC_User_Create(const char *org, const char *app, SDL_PropertiesID props)
{
SDL_Storage *result;
char *prefpath = NULL;
const char *sdlprefpath = SDL_GetPrefPath(org, app);
if (sdlprefpath) {
prefpath = SDL_strdup(sdlprefpath);
}
char *prefpath = SDL_GetPrefPath(org, app);
if (prefpath == NULL) {
return NULL;
}

View File

@ -1130,7 +1130,6 @@ static SDL_HitTestResult SDLCALL SDLTest_ExampleHitTestCallback(SDL_Window *win,
SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
{
int i, j, m, n, w, h;
const SDL_DisplayMode *fullscreen_mode;
char text[1024];
if (state->flags & SDL_INIT_VIDEO) {
@ -1192,9 +1191,9 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
}
if (state->verbose & VERBOSE_MODES) {
const SDL_DisplayID *displays;
SDL_DisplayID *displays;
SDL_Rect bounds, usablebounds;
const SDL_DisplayMode * const *modes;
SDL_DisplayMode **modes;
const SDL_DisplayMode *mode;
int bpp;
Uint32 Rmask, Gmask, Bmask, Amask;
@ -1258,6 +1257,7 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
}
}
}
SDL_free(modes);
#if defined(SDL_VIDEO_DRIVER_WINDOWS) && !defined(SDL_PLATFORM_XBOXONE) && !defined(SDL_PLATFORM_XBOXSERIES)
/* Print the D3D9 adapter index */
@ -1269,6 +1269,7 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
SDL_Log("DXGI Adapter Index: %d Output Index: %d", adapterIndex, outputIndex);
#endif
}
SDL_free(displays);
}
if (state->verbose & VERBOSE_RENDER) {
@ -1285,10 +1286,11 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
state->displayID = SDL_GetPrimaryDisplay();
if (state->display_index > 0) {
const SDL_DisplayID *displays = SDL_GetDisplays(&n);
SDL_DisplayID *displays = SDL_GetDisplays(&n);
if (state->display_index < n) {
state->displayID = displays[state->display_index];
}
SDL_free(displays);
if (SDL_WINDOWPOS_ISUNDEFINED(state->window_x)) {
state->window_x = SDL_WINDOWPOS_UNDEFINED_DISPLAY(state->displayID);
@ -1304,10 +1306,7 @@ SDL_bool SDLTest_CommonInit(SDLTest_CommonState *state)
if (state->window_flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) {
include_high_density_modes = SDL_TRUE;
}
fullscreen_mode = SDL_GetClosestFullscreenDisplayMode(state->displayID, state->window_w, state->window_h, state->refresh_rate, include_high_density_modes);
if (fullscreen_mode) {
SDL_memcpy(&state->fullscreen_mode, fullscreen_mode, sizeof(state->fullscreen_mode));
}
SDL_GetClosestFullscreenDisplayMode(state->displayID, state->window_w, state->window_h, state->refresh_rate, include_high_density_modes, &state->fullscreen_mode);
}
state->windows =
@ -1622,7 +1621,7 @@ static void SDLTest_PrintEvent(const SDL_Event *event)
SDL_Rect rect;
SDL_GetWindowSafeArea(SDL_GetWindowFromID(event->window.windowID), &rect);
SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " changed safe area to: %d,%d %dx%d\n",
SDL_Log("SDL EVENT: Window %" SDL_PRIu32 " changed safe area to: %d,%d %dx%d\n",
event->window.windowID, rect.x, rect.y, rect.w, rect.h);
break;
}
@ -2008,7 +2007,7 @@ static void SDLTest_PasteScreenShot(void)
for (i = 0; i < SDL_arraysize(image_formats); ++i) {
size_t size;
const void *data = SDL_GetClipboardData(image_formats[i], &size);
void *data = SDL_GetClipboardData(image_formats[i], &size);
if (data) {
char filename[16];
SDL_IOStream *file;
@ -2020,6 +2019,7 @@ static void SDLTest_PasteScreenShot(void)
SDL_WriteIO(file, data, size);
SDL_CloseIO(file);
}
SDL_free(data);
return;
}
}
@ -2029,7 +2029,7 @@ static void SDLTest_PasteScreenShot(void)
static void FullscreenTo(SDLTest_CommonState *state, int index, int windowId)
{
int num_displays;
const SDL_DisplayID *displays;
SDL_DisplayID *displays;
SDL_Window *window;
SDL_WindowFlags flags;
const SDL_DisplayMode *mode;
@ -2060,8 +2060,9 @@ static void FullscreenTo(SDLTest_CommonState *state, int index, int windowId)
if (state->window_flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) {
include_high_density_modes = SDL_TRUE;
}
mode = SDL_GetClosestFullscreenDisplayMode(displays[index], state->window_w, state->window_h, state->refresh_rate, include_high_density_modes);
SDL_SetWindowFullscreenMode(window, mode);
if (SDL_GetClosestFullscreenDisplayMode(displays[index], state->window_w, state->window_h, state->refresh_rate, include_high_density_modes, &new_mode) == 0) {
SDL_SetWindowFullscreenMode(window, &new_mode);
}
}
}
if (!mode) {
@ -2070,6 +2071,7 @@ static void FullscreenTo(SDLTest_CommonState *state, int index, int windowId)
SDL_SetWindowFullscreen(window, SDL_TRUE);
}
}
SDL_free(displays);
}
int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event *event)
@ -2270,12 +2272,13 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event
case SDLK_V:
if (withAlt) {
/* Alt-V paste awesome text from the primary selection! */
const char *text = SDL_GetPrimarySelectionText();
char *text = SDL_GetPrimarySelectionText();
if (*text) {
SDL_Log("Primary selection: %s\n", text);
} else {
SDL_Log("Primary selection is empty\n");
}
SDL_free(text);
} else if (withControl) {
if (withShift) {
@ -2283,12 +2286,13 @@ int SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const SDL_Event
SDLTest_PasteScreenShot();
} else {
/* Ctrl-V paste awesome text! */
const char *text = SDL_GetClipboardText();
char *text = SDL_GetClipboardText();
if (*text) {
SDL_Log("Clipboard: %s\n", text);
} else {
SDL_Log("Clipboard is empty\n");
}
SDL_free(text);
}
}
break;

View File

@ -433,7 +433,7 @@ SDL_ThreadID SDL_GetThreadID(SDL_Thread *thread)
const char *SDL_GetThreadName(SDL_Thread *thread)
{
if (thread) {
return thread->name;
return SDL_GetPersistentString(thread->name);
} else {
return NULL;
}
@ -451,7 +451,7 @@ void SDL_WaitThread(SDL_Thread *thread, int *status)
if (status) {
*status = thread->status;
}
SDL_FreeLater(thread->name);
SDL_free(thread->name);
SDL_free(thread);
}
}

View File

@ -162,7 +162,7 @@ void *SDL_GetInternalClipboardData(SDL_VideoDevice *_this, const char *mime_type
return data;
}
const void *SDL_GetClipboardData(const char *mime_type, size_t *size)
void *SDL_GetClipboardData(const char *mime_type, size_t *size)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
@ -184,16 +184,16 @@ const void *SDL_GetClipboardData(const char *mime_type, size_t *size)
*size = 0;
if (_this->GetClipboardData) {
return SDL_FreeLater(_this->GetClipboardData(_this, mime_type, size));
return _this->GetClipboardData(_this, mime_type, size);
} else if (_this->GetClipboardText && SDL_IsTextMimeType(mime_type)) {
char *text = _this->GetClipboardText(_this);
if (text && *text == '\0') {
SDL_free(text);
text = NULL;
}
return SDL_FreeLater(text);
return text;
} else {
return SDL_FreeLater(SDL_GetInternalClipboardData(_this, mime_type, size));
return SDL_GetInternalClipboardData(_this, mime_type, size);
}
}
@ -282,30 +282,30 @@ int SDL_SetClipboardText(const char *text)
return SDL_ClearClipboardData();
}
const char *SDL_GetClipboardText(void)
char *SDL_GetClipboardText(void)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
size_t i, num_mime_types;
const char **text_mime_types;
size_t length;
const char *text = NULL;
char *text = NULL;
if (!_this) {
SDL_SetError("Video subsystem must be initialized to get clipboard text");
return "";
return SDL_strdup("");
}
text_mime_types = SDL_GetTextMimeTypes(_this, &num_mime_types);
for (i = 0; i < num_mime_types; ++i) {
const void *clipdata = SDL_GetClipboardData(text_mime_types[i], &length);
void *clipdata = SDL_GetClipboardData(text_mime_types[i], &length);
if (clipdata) {
text = (const char *)clipdata;
text = (char *)clipdata;
break;
}
}
if (!text) {
text = SDL_CreateTemporaryString("");
text = SDL_strdup("");
}
return text;
}
@ -356,7 +356,7 @@ int SDL_SetPrimarySelectionText(const char *text)
return 0;
}
const char *SDL_GetPrimarySelectionText(void)
char *SDL_GetPrimarySelectionText(void)
{
SDL_VideoDevice *_this = SDL_GetVideoDevice();
@ -366,13 +366,13 @@ const char *SDL_GetPrimarySelectionText(void)
}
if (_this->GetPrimarySelectionText) {
return SDL_FreeLater(_this->GetPrimarySelectionText(_this));
return _this->GetPrimarySelectionText(_this);
} else {
const char *text = _this->primary_selection_text;
if (!text) {
text = "";
}
return SDL_CreateTemporaryString(text);
return SDL_strdup(text);
}
}

View File

@ -519,7 +519,7 @@ int SDL_GetNumVideoDrivers(void)
const char *SDL_GetVideoDriver(int index)
{
if (index >= 0 && index < SDL_GetNumVideoDrivers()) {
return SDL_CreateTemporaryString(bootstrap[index]->name);
return bootstrap[index]->name;
}
return NULL;
}
@ -663,7 +663,7 @@ const char *SDL_GetCurrentVideoDriver(void)
SDL_UninitializedVideo();
return NULL;
}
return SDL_CreateTemporaryString(_this->name);
return _this->name;
}
SDL_VideoDevice *SDL_GetVideoDevice(void)
@ -698,7 +698,7 @@ static void SDL_UpdateDesktopBounds(void)
SDL_Rect rect;
SDL_zero(rect);
const SDL_DisplayID *displays = SDL_GetDisplays(NULL);
SDL_DisplayID *displays = SDL_GetDisplays(NULL);
if (displays) {
for (int i = 0; displays[i]; ++i) {
SDL_Rect bounds;
@ -710,6 +710,7 @@ static void SDL_UpdateDesktopBounds(void)
}
}
}
SDL_free(displays);
}
SDL_copyp(&_this->desktop_bounds, &rect);
}
@ -848,7 +849,7 @@ void SDL_DelVideoDisplay(SDL_DisplayID displayID, SDL_bool send_event)
SDL_UpdateDesktopBounds();
}
const SDL_DisplayID *SDL_GetDisplays(int *count)
SDL_DisplayID *SDL_GetDisplays(int *count)
{
int i;
SDL_DisplayID *displays;
@ -877,7 +878,7 @@ const SDL_DisplayID *SDL_GetDisplays(int *count)
*count = 0;
}
}
return SDL_FreeLater(displays);
return displays;
}
SDL_VideoDisplay *SDL_GetVideoDisplay(SDL_DisplayID displayID)
@ -1115,19 +1116,6 @@ static void SDL_UpdateFullscreenDisplayModes(SDL_VideoDisplay *display)
}
}
static const SDL_DisplayMode *SDL_CreateTemporaryDisplayMode(const SDL_DisplayMode *mode)
{
SDL_DisplayMode *retval = NULL;
if (mode) {
retval = (SDL_DisplayMode *)SDL_malloc(sizeof(*retval));
if (retval) {
SDL_copyp(retval, mode);
}
}
return SDL_FreeLater(retval);
}
// Return the matching mode as a pointer into our current mode list
static const SDL_DisplayMode *SDL_GetFullscreenModeMatch(const SDL_DisplayMode *mode)
{
@ -1174,16 +1162,6 @@ static const SDL_DisplayMode *SDL_GetFullscreenModeMatch(const SDL_DisplayMode *
return mode;
}
// Return the window's fullscreen mode as a pointer into our current mode list
static const SDL_DisplayMode *SDL_GetWindowFullscreenModeInternal(SDL_Window *window)
{
if (window->flags & SDL_WINDOW_FULLSCREEN) {
return SDL_GetFullscreenModeMatch(&window->current_fullscreen_mode);
} else {
return SDL_GetFullscreenModeMatch(&window->requested_fullscreen_mode);
}
}
SDL_bool SDL_AddFullscreenDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
{
SDL_DisplayMode *modes;
@ -1250,7 +1228,7 @@ void SDL_ResetFullscreenDisplayModes(SDL_VideoDisplay *display)
display->current_mode = &display->desktop_mode;
}
const SDL_DisplayMode * const *SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *count)
SDL_DisplayMode **SDL_GetFullscreenDisplayModes(SDL_DisplayID displayID, int *count)
{
int i;
int num_modes;
@ -1283,17 +1261,21 @@ const SDL_DisplayMode * const *SDL_GetFullscreenDisplayModes(SDL_DisplayID displ
*count = 0;
}
}
return SDL_FreeLater(retval);
return retval;
}
const SDL_DisplayMode *SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, float refresh_rate, SDL_bool include_high_density_modes)
int SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID displayID, int w, int h, float refresh_rate, SDL_bool include_high_density_modes, SDL_DisplayMode *result)
{
const SDL_DisplayMode *mode, *closest = NULL;
float aspect_ratio;
int i;
SDL_VideoDisplay *display = SDL_GetVideoDisplay(displayID);
CHECK_DISPLAY_MAGIC(display, NULL);
if (result) {
SDL_zerop(result);
}
CHECK_DISPLAY_MAGIC(display, -1);
if (h > 0) {
aspect_ratio = (float)w / h;
@ -1340,7 +1322,13 @@ const SDL_DisplayMode *SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID display
closest = mode;
}
return SDL_CreateTemporaryDisplayMode(closest);
if (!closest) {
return SDL_SetError("Couldn't find any matching video modes");
}
if (result) {
SDL_copyp(result, closest);
}
return 0;
}
static SDL_bool DisplayModeChanged(const SDL_DisplayMode *old, const SDL_DisplayMode *new)
@ -1379,7 +1367,7 @@ const SDL_DisplayMode *SDL_GetDesktopDisplayMode(SDL_DisplayID displayID)
CHECK_DISPLAY_MAGIC(display, NULL);
return SDL_CreateTemporaryDisplayMode(&display->desktop_mode);
return &display->desktop_mode;
}
void SDL_SetCurrentDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
@ -1408,7 +1396,7 @@ const SDL_DisplayMode *SDL_GetCurrentDisplayMode(SDL_DisplayID displayID)
/* Make sure our mode list is updated */
SDL_UpdateFullscreenDisplayModes(display);
return SDL_CreateTemporaryDisplayMode(display->current_mode);
return display->current_mode;
}
int SDL_SetDisplayModeForDisplay(SDL_VideoDisplay *display, SDL_DisplayMode *mode)
@ -1771,7 +1759,7 @@ int SDL_UpdateFullscreenMode(SDL_Window *window, SDL_FullscreenOp fullscreen, SD
}
if (fullscreen) {
mode = (SDL_DisplayMode *)SDL_GetWindowFullscreenModeInternal(window);
mode = (SDL_DisplayMode *)SDL_GetWindowFullscreenMode(window);
if (mode) {
window->fullscreen_exclusive = SDL_TRUE;
} else {
@ -2014,23 +2002,23 @@ int SDL_SetWindowFullscreenMode(SDL_Window *window, const SDL_DisplayMode *mode)
const SDL_DisplayMode *SDL_GetWindowFullscreenMode(SDL_Window *window)
{
const SDL_DisplayMode *retval;
CHECK_WINDOW_MAGIC(window, NULL);
CHECK_WINDOW_NOT_POPUP(window, NULL);
retval = SDL_GetWindowFullscreenModeInternal(window);
return SDL_CreateTemporaryDisplayMode(retval);
if (window->flags & SDL_WINDOW_FULLSCREEN) {
return SDL_GetFullscreenModeMatch(&window->current_fullscreen_mode);
} else {
return SDL_GetFullscreenModeMatch(&window->requested_fullscreen_mode);
}
}
const void *SDL_GetWindowICCProfile(SDL_Window *window, size_t *size)
void *SDL_GetWindowICCProfile(SDL_Window *window, size_t *size)
{
if (!_this->GetWindowICCProfile) {
SDL_Unsupported();
return NULL;
}
return SDL_FreeLater(_this->GetWindowICCProfile(_this, window, size));
return _this->GetWindowICCProfile(_this, window, size);
}
SDL_PixelFormat SDL_GetWindowPixelFormat(SDL_Window *window)
@ -2080,7 +2068,7 @@ void SDL_ToggleDragAndDropSupport(void)
}
}
SDL_Window * const *SDLCALL SDL_GetWindows(int *count)
SDL_Window **SDLCALL SDL_GetWindows(int *count)
{
if (count) {
*count = 0;
@ -2115,7 +2103,7 @@ SDL_Window * const *SDLCALL SDL_GetWindows(int *count)
if (count) {
*count = num_added;
}
return SDL_FreeLater(windows);
return windows;
}
static void ApplyWindowFlags(SDL_Window *window, SDL_WindowFlags flags)
@ -3033,7 +3021,7 @@ int SDL_GetWindowSizeInPixels(SDL_Window *window, int *w, int *h)
SDL_GetWindowSize(window, w, h);
if ((window->flags & SDL_WINDOW_FULLSCREEN) && SDL_GetWindowFullscreenModeInternal(window)) {
if ((window->flags & SDL_WINDOW_FULLSCREEN) && SDL_GetWindowFullscreenMode(window)) {
mode = SDL_GetCurrentDisplayMode(displayID);
} else {
mode = SDL_GetDesktopDisplayMode(displayID);
@ -3786,7 +3774,6 @@ void SDL_OnWindowDisplayChanged(SDL_Window *window)
{
if (window->flags & SDL_WINDOW_FULLSCREEN) {
SDL_DisplayID displayID = SDL_GetDisplayForWindowPosition(window);
const SDL_DisplayMode *new_mode = NULL;
if (window->requested_fullscreen_mode.w != 0 || window->requested_fullscreen_mode.h != 0) {
SDL_bool include_high_density_modes = SDL_FALSE;
@ -3794,11 +3781,7 @@ void SDL_OnWindowDisplayChanged(SDL_Window *window)
if (window->requested_fullscreen_mode.pixel_density > 1.0f) {
include_high_density_modes = SDL_TRUE;
}
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);
}
if (new_mode) {
SDL_copyp(&window->current_fullscreen_mode, 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, &window->current_fullscreen_mode);
} else {
SDL_zero(window->current_fullscreen_mode);
}

View File

@ -1803,7 +1803,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
}
if (existingTouchCount == 0) {
int numFingers;
const SDL_Finger * const *fingers = SDL_GetTouchFingers(touchID, &numFingers);
SDL_Finger **fingers = SDL_GetTouchFingers(touchID, &numFingers);
if (fingers) {
DLog("Reset Lost Fingers: %d", numFingers);
for (--numFingers; numFingers >= 0; --numFingers) {
@ -1816,6 +1816,7 @@ static int Cocoa_SendMouseButtonClicks(SDL_Mouse *mouse, NSEvent *theEvent, SDL_
SDL_Window *window = NULL;
SDL_SendTouch(Cocoa_GetEventTimestamp([theEvent timestamp]), touchID, finger->id, window, SDL_FALSE, 0, 0, 0);
}
SDL_free(fingers);
}
}

View File

@ -315,13 +315,14 @@ static int KMSDRM_ShowCursor(SDL_Cursor *cursor)
This happens on video quit, where we get here after
the mouse focus has been unset, yet SDL wants to
restore the system default cursor (makes no sense here). */
const SDL_DisplayID *displays = SDL_GetDisplays(NULL);
SDL_DisplayID *displays = SDL_GetDisplays(NULL);
if (displays) {
/* Iterate on the displays, hiding the cursor. */
for (i = 0; i < displays[i]; i++) {
display = SDL_GetVideoDisplay(displays[i]);
ret = KMSDRM_RemoveCursorFromBO(display);
}
SDL_free(displays);
}
} else {
display = SDL_GetVideoDisplayForWindow(window);

View File

@ -514,12 +514,11 @@ static drmModeModeInfo *KMSDRM_GetClosestDisplayMode(SDL_VideoDisplay *display,
SDL_DisplayData *dispdata = display->internal;
drmModeConnector *connector = dispdata->connector;
const SDL_DisplayMode *closest;
SDL_DisplayMode closest;
drmModeModeInfo *drm_mode;
closest = SDL_GetClosestFullscreenDisplayMode(display->id, width, height, 0.0f, SDL_FALSE);
if (closest) {
const SDL_DisplayModeData *modedata = closest->internal;
if (SDL_GetClosestFullscreenDisplayMode(display->id, width, height, 0.0f, SDL_FALSE, &closest) == 0) {
const SDL_DisplayModeData *modedata = closest.internal;
drm_mode = &connector->modes[modedata->mode_index];
return drm_mode;
} else {
@ -535,7 +534,7 @@ static drmModeModeInfo *KMSDRM_GetClosestDisplayMode(SDL_VideoDisplay *display,
/* Deinitializes the internal of the SDL Displays in the SDL display list. */
static void KMSDRM_DeinitDisplays(SDL_VideoDevice *_this)
{
const SDL_DisplayID *displays;
SDL_DisplayID *displays;
SDL_DisplayData *dispdata;
int i;
@ -559,6 +558,7 @@ static void KMSDRM_DeinitDisplays(SDL_VideoDevice *_this)
dispdata->crtc = NULL;
}
}
SDL_free(displays);
}
}

View File

@ -310,7 +310,7 @@ int UIKit_AddDisplay(SDL_bool send_event){
void UIKit_DelDisplay(UIScreen *uiscreen, SDL_bool send_event)
{
const SDL_DisplayID *displays;
SDL_DisplayID *displays;
int i;
displays = SDL_GetDisplays(NULL);
@ -326,6 +326,7 @@ void UIKit_DelDisplay(UIScreen *uiscreen, SDL_bool send_event)
break;
}
}
SDL_free(displays);
}
}

View File

@ -172,20 +172,19 @@ int UIKit_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Propertie
#if !defined(SDL_PLATFORM_TVOS) && !defined(SDL_PLATFORM_VISIONOS)
const CGSize origsize = data.uiscreen.currentMode.size;
if ((origsize.width == 0.0f) && (origsize.height == 0.0f)) {
const SDL_DisplayMode *bestmode;
SDL_DisplayMode bestmode;
SDL_bool include_high_density_modes = SDL_FALSE;
if (window->flags & SDL_WINDOW_HIGH_PIXEL_DENSITY) {
include_high_density_modes = SDL_TRUE;
}
bestmode = SDL_GetClosestFullscreenDisplayMode(display->id, window->w, window->h, 0.0f, include_high_density_modes);
if (bestmode) {
SDL_UIKitDisplayModeData *modedata = (__bridge SDL_UIKitDisplayModeData *)bestmode->internal;
if (SDL_GetClosestFullscreenDisplayMode(display->id, window->w, window->h, 0.0f, include_high_density_modes, &bestmode) == 0) {
SDL_UIKitDisplayModeData *modedata = (__bridge SDL_UIKitDisplayModeData *)bestmode.internal;
[data.uiscreen setCurrentMode:modedata.uiscreenmode];
/* desktop_mode doesn't change here (the higher level will
* use it to set all the screens back to their defaults
* upon window destruction, SDL_Quit(), etc. */
SDL_SetCurrentDisplayMode(display, bestmode);
SDL_SetCurrentDisplayMode(display, &bestmode);
}
}

View File

@ -516,7 +516,7 @@ static void Wayland_move_window(SDL_Window *window)
{
SDL_WindowData *wind = window->internal;
SDL_DisplayData *display;
const SDL_DisplayID *displays;
SDL_DisplayID *displays;
if (wind->outputs && wind->num_outputs) {
display = wind->outputs[wind->num_outputs - 1];
@ -559,6 +559,7 @@ static void Wayland_move_window(SDL_Window *window)
break;
}
}
SDL_free(displays);
}
}

View File

@ -867,11 +867,11 @@ void WIN_CheckKeyboardAndMouseHotplug(SDL_VideoDevice *_this, SDL_bool initial_c
PRAWINPUTDEVICELIST raw_devices = NULL;
UINT raw_device_count = 0;
int old_keyboard_count = 0;
const SDL_KeyboardID *old_keyboards = NULL;
SDL_KeyboardID *old_keyboards = NULL;
int new_keyboard_count = 0;
SDL_KeyboardID *new_keyboards = NULL;
int old_mouse_count = 0;
const SDL_MouseID *old_mice = NULL;
SDL_MouseID *old_mice = NULL;
int new_mouse_count = 0;
SDL_MouseID *new_mice = NULL;
SDL_bool send_event = !initial_check;
@ -982,7 +982,9 @@ void WIN_CheckKeyboardAndMouseHotplug(SDL_VideoDevice *_this, SDL_bool initial_c
}
}
SDL_free(old_keyboards);
SDL_free(new_keyboards);
SDL_free(old_mice);
SDL_free(new_mice);
SetupDiDestroyDeviceInfoList(devinfo);

View File

@ -686,7 +686,7 @@ static int X11_UpdateXRandRDisplay(SDL_VideoDevice *_this, Display *dpy, int scr
static void X11_HandleXRandROutputChange(SDL_VideoDevice *_this, const XRROutputChangeNotifyEvent *ev)
{
const SDL_DisplayID *displays;
SDL_DisplayID *displays;
SDL_VideoDisplay *display = NULL;
int i;
@ -704,6 +704,7 @@ static void X11_HandleXRandROutputChange(SDL_VideoDevice *_this, const XRROutput
break;
}
}
SDL_free(displays);
}
if (ev->connection == RR_Disconnected) { /* output is going away */

View File

@ -418,7 +418,7 @@ static int X11_CaptureMouse(SDL_Window *window)
static SDL_MouseButtonFlags X11_GetGlobalMouseState(float *x, float *y)
{
SDL_VideoData *videodata = SDL_GetVideoDevice()->internal;
const SDL_DisplayID *displays;
SDL_DisplayID *displays;
Display *display = GetDisplay();
int i;
@ -460,6 +460,7 @@ static SDL_MouseButtonFlags X11_GetGlobalMouseState(float *x, float *y)
}
}
}
SDL_free(displays);
}
}

View File

@ -725,6 +725,30 @@ static SDL_bool HasDeviceID(Uint32 deviceID, const Uint32 *list, int count)
return SDL_FALSE;
}
static void AddDeviceID64(Uint64 deviceID, Uint64 **list, int *count)
{
int new_count = (*count + 1);
Uint64 *new_list = (Uint64 *)SDL_realloc(*list, new_count * sizeof(*new_list));
if (!new_list) {
/* Oh well, we'll drop this one */
return;
}
new_list[new_count - 1] = deviceID;
*count = new_count;
*list = new_list;
}
static SDL_bool HasDeviceID64(Uint64 deviceID, const Uint64 *list, int count)
{
for (int i = 0; i < count; ++i) {
if (deviceID == list[i]) {
return SDL_TRUE;
}
}
return SDL_FALSE;
}
#endif // SDL_VIDEO_DRIVER_X11_XINPUT2
void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, SDL_bool initial_check)
@ -734,18 +758,17 @@ void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, SDL_bool initial_check)
XIDeviceInfo *info;
int ndevices;
int old_keyboard_count = 0;
const SDL_KeyboardID *old_keyboards = NULL;
SDL_KeyboardID *old_keyboards = NULL;
int new_keyboard_count = 0;
SDL_KeyboardID *new_keyboards = NULL;
int old_mouse_count = 0;
const SDL_MouseID *old_mice = NULL;
SDL_MouseID *old_mice = NULL;
int new_mouse_count = 0;
SDL_MouseID *new_mice = NULL;
int old_touch_count = 0;
const SDL_TouchID *old_touch_devices64 = NULL;
Uint32 *old_touch_devices = NULL;
Uint64 *old_touch_devices = NULL;
int new_touch_count = 0;
Uint32 *new_touch_devices = NULL;
Uint64 *new_touch_devices = NULL;
SDL_bool send_event = !initial_check;
SDL_assert(X11_Xinput2IsInitialized());
@ -754,17 +777,7 @@ void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, SDL_bool initial_check)
old_keyboards = SDL_GetKeyboards(&old_keyboard_count);
old_mice = SDL_GetMice(&old_mouse_count);
/* SDL_TouchID is 64-bit, but our helper functions take Uint32 */
old_touch_devices64 = SDL_GetTouchDevices(&old_touch_count);
if (old_touch_count > 0) {
old_touch_devices = (Uint32 *)SDL_malloc(old_touch_count * sizeof(*old_touch_devices));
if (old_touch_devices) {
for (int i = 0; i < old_touch_count; ++i) {
old_touch_devices[i] = (Uint32)old_touch_devices64[i];
}
}
}
old_touch_devices = SDL_GetTouchDevices(&old_touch_count);
for (int i = 0; i < ndevices; i++) {
XIDeviceInfo *dev = &info[i];
@ -796,7 +809,7 @@ void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, SDL_bool initial_check)
#ifdef SDL_VIDEO_DRIVER_X11_XINPUT2_SUPPORTS_MULTITOUCH
for (int j = 0; j < dev->num_classes; j++) {
Uint32 touchID;
Uint64 touchID;
SDL_TouchDeviceType touchType;
XIAnyClassInfo *class = dev->classes[j];
XITouchClassInfo *t = (XITouchClassInfo *)class;
@ -806,9 +819,9 @@ void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, SDL_bool initial_check)
continue;
}
touchID = (Uint32)t->sourceid;
AddDeviceID(touchID, &new_touch_devices, &new_touch_count);
if (!HasDeviceID(touchID, old_touch_devices, old_touch_count)) {
touchID = (Uint64)t->sourceid;
AddDeviceID64(touchID, &new_touch_devices, &new_touch_count);
if (!HasDeviceID64(touchID, old_touch_devices, old_touch_count)) {
if (t->mode == XIDependentTouch) {
touchType = SDL_TOUCH_DEVICE_INDIRECT_RELATIVE;
} else { /* XIDirectTouch */
@ -833,12 +846,14 @@ void X11_Xinput2UpdateDevices(SDL_VideoDevice *_this, SDL_bool initial_check)
}
for (int i = old_touch_count; i--;) {
if (!HasDeviceID(old_touch_devices[i], new_touch_devices, new_touch_count)) {
if (!HasDeviceID64(old_touch_devices[i], new_touch_devices, new_touch_count)) {
SDL_DelTouch(old_touch_devices[i]);
}
}
SDL_free(old_keyboards);
SDL_free(new_keyboards);
SDL_free(old_mice);
SDL_free(new_mice);
SDL_free(old_touch_devices);
SDL_free(new_touch_devices);

View File

@ -416,12 +416,13 @@ void UpdateGamepadImageFromGamepad(GamepadImage *ctx, SDL_Gamepad *gamepad)
}
ctx->type = SDL_GetGamepadType(gamepad);
const char *mapping = SDL_GetGamepadMapping(gamepad);
char *mapping = SDL_GetGamepadMapping(gamepad);
if (mapping) {
if (SDL_strstr(mapping, "SDL_GAMECONTROLLER_USE_BUTTON_LABELS")) {
/* Just for display purposes */
ctx->type = SDL_GAMEPAD_TYPE_NINTENDO_SWITCH_PRO;
}
SDL_free(mapping);
}
for (i = 0; i < SDL_GAMEPAD_BUTTON_TOUCHPAD; ++i) {
@ -1021,7 +1022,7 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
const float arrow_extent = 48.0f;
SDL_FRect dst, rect, highlight;
Uint8 r, g, b, a;
const char *mapping = NULL;
char *mapping;
SDL_bool has_accel;
SDL_bool has_gyro;
@ -1285,6 +1286,7 @@ void RenderGamepadDisplay(GamepadDisplay *ctx, SDL_Gamepad *gamepad)
}
}
}
SDL_free(mapping);
}
void DestroyGamepadDisplay(GamepadDisplay *ctx)

View File

@ -27,7 +27,7 @@ int main(int argc, char *argv[])
(void)argv;
SDL_Init(0);
start = SDL_GetTicks();
SDL_GetPrefPath("libsdl", "test_filesystem");
SDL_free(SDL_GetPrefPath("libsdl", "test_filesystem"));
prequit = SDL_GetTicks();
SDL_Log("SDL_GetPrefPath took %" SDL_PRIu64 "ms", prequit - start);
SDL_Quit();

View File

@ -20,7 +20,7 @@ print_devices(SDL_bool recording)
const char *typestr = (recording ? "recording" : "playback");
int n = 0;
int frames;
const SDL_AudioDeviceID *devices = recording ? SDL_GetAudioRecordingDevices(&n) : SDL_GetAudioPlaybackDevices(&n);
SDL_AudioDeviceID *devices = recording ? SDL_GetAudioRecordingDevices(&n) : SDL_GetAudioPlaybackDevices(&n);
if (!devices) {
SDL_Log(" Driver failed to report %s devices: %s\n\n", typestr, SDL_GetError());
@ -46,6 +46,7 @@ print_devices(SDL_bool recording)
}
SDL_Log("\n");
}
SDL_free(devices);
}
int main(int argc, char **argv)

View File

@ -23,7 +23,7 @@ static SDLTest_CommonState *state = NULL;
int SDL_AppInit(void **appstate, int argc, char **argv)
{
const SDL_AudioDeviceID *devices;
SDL_AudioDeviceID *devices;
SDL_AudioSpec outspec;
SDL_AudioSpec inspec;
SDL_AudioDeviceID device;
@ -103,6 +103,7 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, NULL);
if (!device) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for playback: %s!\n", SDL_GetError());
SDL_free(devices);
return SDL_APP_FAILURE;
}
SDL_PauseAudioDevice(device);
@ -110,9 +111,11 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
stream_out = SDL_CreateAudioStream(&outspec, &outspec);
if (!stream_out) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create an audio stream for playback: %s!\n", SDL_GetError());
SDL_free(devices);
return SDL_APP_FAILURE;
} else if (SDL_BindAudioStream(device, stream_out) == -1) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't bind an audio stream for playback: %s!\n", SDL_GetError());
SDL_free(devices);
return SDL_APP_FAILURE;
}
@ -124,8 +127,10 @@ int SDL_AppInit(void **appstate, int argc, char **argv)
device = SDL_OpenAudioDevice(want_device, NULL);
if (!device) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open an audio device for recording: %s!\n", SDL_GetError());
SDL_free(devices);
return SDL_APP_FAILURE;
}
SDL_free(devices);
SDL_PauseAudioDevice(device);
SDL_GetAudioDeviceFormat(device, &inspec, NULL);
stream_in = SDL_CreateAudioStream(&inspec, &inspec);

View File

@ -366,7 +366,7 @@ static int audio_enumerateAndNameAudioDevices(void *arg)
int t;
int i, n;
const char *name;
const SDL_AudioDeviceID *devices = NULL;
SDL_AudioDeviceID *devices;
/* Iterate over types: t=0 playback device, t=1 recording device */
for (t = 0; t < 2; t++) {
@ -388,6 +388,7 @@ static int audio_enumerateAndNameAudioDevices(void *arg)
}
}
}
SDL_free(devices);
}
return TEST_COMPLETED;

View File

@ -86,9 +86,9 @@ static int clipboard_testClipboardDataFunctions(void *arg)
int last_clipboard_update_count;
int last_clipboard_callback_count;
int last_clipboard_cleanup_count;
const void *data;
void *data;
size_t size;
const char *text;
char *text;
const char *expected_text;
TestClipboardData test_data1 = {
@ -163,11 +163,12 @@ static int clipboard_testClipboardDataFunctions(void *arg)
clipboard_cleanup_count - last_clipboard_cleanup_count);
expected_text = "TEST";
text = (char *) SDL_GetClipboardText();
text = SDL_GetClipboardText();
SDLTest_AssertCheck(
text && SDL_strcmp(text, expected_text) == 0,
"Verify clipboard text, expected \"%s\", got \"%s\"",
expected_text, text);
SDL_free(text);
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT]);
SDLTest_AssertCheck(
@ -186,6 +187,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
size == SDL_strlen(expected_text),
"Verify test text size, expected %d, got %d",
(int)SDL_strlen(expected_text), (int)size);
SDL_free(text);
expected_text = "CUSTOM";
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT]);
@ -205,6 +207,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
size == SDL_strlen(expected_text),
"Verify test text size, expected %d, got %d",
(int)SDL_strlen(expected_text), (int)size);
SDL_free(text);
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_DATA]);
SDLTest_AssertCheck(
@ -218,6 +221,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
size == test_data1.data_size,
"Verify test data size, expected %d, got %d",
(int)test_data1.data_size, (int)size);
SDL_free(data);
boolResult = SDL_HasClipboardData("test/invalid");
SDLTest_AssertCheck(
@ -232,6 +236,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
size == 0,
"Verify invalid data size, expected 0, got %d",
(int)size);
SDL_free(data);
#if 0 /* There's no guarantee how or when the callback is called */
SDLTest_AssertCheck(
@ -260,11 +265,12 @@ static int clipboard_testClipboardDataFunctions(void *arg)
clipboard_cleanup_count - last_clipboard_cleanup_count);
expected_text = "TEST";
text = (char *) SDL_GetClipboardText();
text = SDL_GetClipboardText();
SDLTest_AssertCheck(
text && SDL_strcmp(text, expected_text) == 0,
"Verify clipboard text, expected \"%s\", got \"%s\"",
expected_text, text);
SDL_free(text);
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_TEXT]);
SDLTest_AssertCheck(
@ -283,6 +289,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
size == SDL_strlen(expected_text),
"Verify test text size, expected %d, got %d",
(int)SDL_strlen(expected_text), (int)size);
SDL_free(text);
expected_text = "CUSTOM";
boolResult = SDL_HasClipboardData(test_mime_types[TEST_MIME_TYPE_CUSTOM_TEXT]);
@ -302,6 +309,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
size == SDL_strlen(expected_text),
"Verify test text size, expected %d, got %d",
(int)SDL_strlen(expected_text), (int)size);
SDL_free(text);
data = SDL_GetClipboardData(test_mime_types[TEST_MIME_TYPE_DATA], &size);
SDLTest_AssertCheck(
@ -311,6 +319,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
size == test_data2.data_size,
"Verify test data size, expected %d, got %d",
(int)test_data2.data_size, (int)size);
SDL_free(data);
data = SDL_GetClipboardData("test/invalid", &size);
SDLTest_AssertCheck(
@ -321,6 +330,7 @@ static int clipboard_testClipboardDataFunctions(void *arg)
size == 0,
"Verify invalid data size, expected 0, got %d",
(int)size);
SDL_free(data);
#if 0 /* There's no guarantee how or when the callback is called */
SDLTest_AssertCheck(
@ -376,7 +386,7 @@ static int clipboard_testClipboardTextFunctions(void *arg)
char *text = SDL_strdup(textRef);
SDL_bool boolResult;
int intResult;
const char *charResult;
char *charResult;
int last_clipboard_update_count;
SDL_AddEventWatch(ClipboardEventWatch, NULL);
@ -393,6 +403,7 @@ static int clipboard_testClipboardTextFunctions(void *arg)
charResult && SDL_strcmp(charResult, "") == 0,
"Verify SDL_GetClipboardText returned \"\", got %s",
charResult);
SDL_free(charResult);
boolResult = SDL_HasClipboardText();
SDLTest_AssertCheck(
boolResult == SDL_FALSE,
@ -425,6 +436,7 @@ static int clipboard_testClipboardTextFunctions(void *arg)
charResult && SDL_strcmp(textRef, charResult) == 0,
"Verify SDL_GetClipboardText returned correct string, expected '%s', got '%s'",
textRef, charResult);
SDL_free(charResult);
SDLTest_AssertCheck(
clipboard_update_count == last_clipboard_update_count + 1,
"Verify clipboard update count incremented by 1, got %d",
@ -458,7 +470,7 @@ static int clipboard_testPrimarySelectionTextFunctions(void *arg)
char *text = SDL_strdup(textRef);
SDL_bool boolResult;
int intResult;
const char *charResult;
char *charResult;
int last_clipboard_update_count;
SDL_AddEventWatch(ClipboardEventWatch, NULL);
@ -475,6 +487,7 @@ static int clipboard_testPrimarySelectionTextFunctions(void *arg)
charResult && SDL_strcmp(charResult, "") == 0,
"Verify SDL_GetPrimarySelectionText returned \"\", got %s",
charResult);
SDL_free(charResult);
boolResult = SDL_HasPrimarySelectionText();
SDLTest_AssertCheck(
boolResult == SDL_FALSE,
@ -506,6 +519,7 @@ static int clipboard_testPrimarySelectionTextFunctions(void *arg)
charResult && SDL_strcmp(textRef, charResult) == 0,
"Verify SDL_GetPrimarySelectionText returned correct string, expected '%s', got '%s'",
textRef, charResult);
SDL_free(charResult);
SDLTest_AssertCheck(
clipboard_update_count == last_clipboard_update_count + 1,
"Verify clipboard update count incremented by 1, got %d",

View File

@ -175,67 +175,6 @@ static int events_addDelEventWatchWithUserdata(void *arg)
return TEST_COMPLETED;
}
/**
* Creates and validates temporary event memory
*/
static int events_temporaryMemory(void *arg)
{
SDL_Event event;
void *mem, *claimed, *tmp;
SDL_bool found;
{
/* Create and claim event memory */
mem = SDL_AllocateTemporaryMemory(1);
SDLTest_AssertCheck(mem != NULL, "SDL_AllocateTemporaryMemory()");
*(char *)mem = '1';
claimed = SDL_ClaimTemporaryMemory(mem);
SDLTest_AssertCheck(claimed != NULL, "SDL_ClaimTemporaryMemory() returned a valid pointer");
/* Verify that we can't claim it again */
tmp = SDL_ClaimTemporaryMemory(mem);
SDLTest_AssertCheck(tmp == NULL, "SDL_ClaimTemporaryMemory() can't claim memory twice");
/* Clean up */
SDL_free(claimed);
}
{
/* Create event memory and queue it */
mem = SDL_AllocateTemporaryMemory(1);
SDLTest_AssertCheck(mem != NULL, "SDL_AllocateTemporaryMemory()");
*(char *)mem = '2';
SDL_zero(event);
event.type = SDL_EVENT_USER;
event.user.data1 = mem;
SDL_PushEvent(&event);
/* Verify that we can't claim the memory once it's on the queue */
claimed = SDL_ClaimTemporaryMemory(mem);
SDLTest_AssertCheck(claimed == NULL, "SDL_ClaimTemporaryMemory() can't claim memory on the event queue");
/* Get the event and verify the memory is valid */
found = SDL_FALSE;
while (SDL_PollEvent(&event)) {
if (event.type == SDL_EVENT_USER && event.user.data1 == mem) {
found = SDL_TRUE;
}
}
SDLTest_AssertCheck(found, "SDL_PollEvent() returned queued event");
/* Verify that we can claim the memory now that we've dequeued it */
claimed = SDL_ClaimTemporaryMemory(mem);
SDLTest_AssertCheck(claimed != NULL, "SDL_ClaimTemporaryMemory() can claim memory after dequeuing event");
/* Clean up */
SDL_free(claimed);
}
return TEST_COMPLETED;
}
/* ================= Test References ================== */
/* Events test cases */
@ -251,13 +190,9 @@ static const SDLTest_TestCaseReference eventsTest3 = {
(SDLTest_TestCaseFp)events_addDelEventWatchWithUserdata, "events_addDelEventWatchWithUserdata", "Adds and deletes an event watch function with userdata", TEST_ENABLED
};
static const SDLTest_TestCaseReference eventsTestTemporaryMemory = {
(SDLTest_TestCaseFp)events_temporaryMemory, "events_temporaryMemory", "Creates and validates temporary event memory", TEST_ENABLED
};
/* Sequence of Events test cases */
static const SDLTest_TestCaseReference *eventsTests[] = {
&eventsTest1, &eventsTest2, &eventsTest3, &eventsTestTemporaryMemory, NULL
&eventsTest1, &eventsTest2, &eventsTest3, NULL
};
/* Events test suite (global) */

View File

@ -106,13 +106,13 @@ TestGUIDToString(void *arg)
SDLTest_AssertPass("Call to SDL_GUIDToString");
for (i = 0; i < NUM_TEST_GUIDS; ++i) {
const char *guid_str;
char guid_str[33];
SDL_GUID guid;
upper_lower_to_bytestring(guid.data,
test_guids[i].upper, test_guids[i].lower);
guid_str = SDL_GUIDToString(guid);
SDL_GUIDToString(guid, guid_str, sizeof(guid_str));
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);
}

View File

@ -64,13 +64,15 @@ static int TestVirtualJoystick(void *arg)
gamepad = SDL_OpenGamepad(SDL_GetJoystickID(joystick));
SDLTest_AssertCheck(gamepad != NULL, "SDL_OpenGamepad() succeeded");
if (gamepad) {
SDLTest_AssertCheck(SDL_strcmp(SDL_GetGamepadName(gamepad), desc.name) == 0, "SDL_GetGamepadName()");
const char *name = SDL_GetGamepadName(gamepad);
SDLTest_AssertCheck(name && SDL_strcmp(name, desc.name) == 0, "SDL_GetGamepadName()");
SDLTest_AssertCheck(SDL_GetGamepadVendor(gamepad) == desc.vendor_id, "SDL_GetGamepadVendor()");
SDLTest_AssertCheck(SDL_GetGamepadProduct(gamepad) == desc.product_id, "SDL_GetGamepadProduct()");
/* Set an explicit mapping with a different name */
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,");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetGamepadName(gamepad), "Virtual Gamepad") == 0, "SDL_GetGamepadName() == Virtual Gamepad");
name = SDL_GetGamepadName(gamepad);
SDLTest_AssertCheck(name && SDL_strcmp(name, "Virtual Gamepad") == 0, "SDL_GetGamepadName() == Virtual Gamepad");
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");
/* Set the south button and verify that the gamepad responds */
@ -84,7 +86,8 @@ static int TestVirtualJoystick(void *arg)
/* Set an explicit mapping with legacy Nintendo style buttons */
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,");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetGamepadName(gamepad), "Virtual Nintendo Gamepad") == 0, "SDL_GetGamepadName() == Virtual Nintendo Gamepad");
name = SDL_GetGamepadName(gamepad);
SDLTest_AssertCheck(name && SDL_strcmp(name, "Virtual Nintendo Gamepad") == 0, "SDL_GetGamepadName() == Virtual Nintendo Gamepad");
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");
/* Set the south button and verify that the gamepad responds */
@ -98,7 +101,8 @@ static int TestVirtualJoystick(void *arg)
/* Set an explicit mapping with PS4 style buttons */
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,");
SDLTest_AssertCheck(SDL_strcmp(SDL_GetGamepadName(gamepad), "Virtual PS4 Gamepad") == 0, "SDL_GetGamepadName() == Virtual PS4 Gamepad");
name = SDL_GetGamepadName(gamepad);
SDLTest_AssertCheck(name && SDL_strcmp(name, "Virtual PS4 Gamepad") == 0, "SDL_GetGamepadName() == Virtual PS4 Gamepad");
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");
/* Set the south button and verify that the gamepad responds */

View File

@ -38,6 +38,7 @@
#define SDL_GetPenName SDL_SUT_GetPenName
#define SDL_GetPenCapabilities SDL_SUT_GetPenCapabilities
#define SDL_GetPenType SDL_SUT_GetPenType
#define SDL_GetPersistentString(X) X
#define SDL_GetPenPtr SDL_SUT_GetPenPtr
#define SDL_PenModifyBegin SDL_SUT_PenModifyBegin

View File

@ -13,7 +13,7 @@
static SDL_Window *createVideoSuiteTestWindow(const char *title)
{
SDL_Window *window;
SDL_Window * const *windows;
SDL_Window **windows;
SDL_Event event;
int w, h;
int count;
@ -34,6 +34,7 @@ static SDL_Window *createVideoSuiteTestWindow(const char *title)
windows = SDL_GetWindows(&count);
SDLTest_AssertCheck(windows != NULL, "Validate that returned window list is not NULL");
SDLTest_AssertCheck(windows[0] == window, "Validate that the window is first in the window list");
SDL_free(windows);
/* Wayland and XWayland windows require that a frame be presented before they are fully mapped and visible onscreen.
* This is required for the mouse/keyboard grab tests to pass.
@ -305,8 +306,8 @@ static int video_getWindowFlags(void *arg)
*/
static int video_getFullscreenDisplayModes(void *arg)
{
const SDL_DisplayID *displays;
const SDL_DisplayMode * const *modes;
SDL_DisplayID *displays;
SDL_DisplayMode **modes;
int count;
int i;
@ -321,7 +322,9 @@ static int video_getFullscreenDisplayModes(void *arg)
SDLTest_AssertPass("Call to SDL_GetFullscreenDisplayModes(%" SDL_PRIu32 ")", displays[i]);
SDLTest_AssertCheck(modes != NULL, "Validate returned value from function; expected != NULL; got: %p", modes);
SDLTest_AssertCheck(count >= 0, "Validate number of modes; expected: >= 0; got: %d", count);
SDL_free(modes);
}
SDL_free(displays);
}
return TEST_COMPLETED;
@ -332,11 +335,11 @@ static int video_getFullscreenDisplayModes(void *arg)
*/
static int video_getClosestDisplayModeCurrentResolution(void *arg)
{
const SDL_DisplayID *displays;
const SDL_DisplayMode * const *modes;
SDL_DisplayID *displays;
SDL_DisplayMode **modes;
SDL_DisplayMode current;
const SDL_DisplayMode *closest;
int i, num_modes;
SDL_DisplayMode closest;
int i, result, num_modes;
/* Get number of displays */
displays = SDL_GetDisplays(NULL);
@ -355,21 +358,23 @@ static int video_getClosestDisplayModeCurrentResolution(void *arg)
SDL_memcpy(&current, modes[0], sizeof(current));
/* Make call */
closest = SDL_GetClosestFullscreenDisplayMode(displays[i], current.w, current.h, current.refresh_rate, SDL_FALSE);
result = SDL_GetClosestFullscreenDisplayMode(displays[i], current.w, current.h, current.refresh_rate, SDL_FALSE, &closest);
SDLTest_AssertPass("Call to SDL_GetClosestFullscreenDisplayMode(target=current)");
SDLTest_Assert(closest != NULL, "Verify returned value is not NULL");
SDLTest_AssertCheck(result == 0, "Verify return value; expected: 0, got: %d", result);
/* Check that one gets the current resolution back again */
if (closest) {
SDLTest_AssertCheck(closest->w == current.w,
if (result == 0) {
SDLTest_AssertCheck(closest.w == current.w,
"Verify returned width matches current width; expected: %d, got: %d",
current.w, closest->w);
SDLTest_AssertCheck(closest->h == current.h,
current.w, closest.w);
SDLTest_AssertCheck(closest.h == current.h,
"Verify returned height matches current height; expected: %d, got: %d",
current.h, closest->h);
current.h, closest.h);
}
}
SDL_free(modes);
}
SDL_free(displays);
}
return TEST_COMPLETED;
@ -380,8 +385,9 @@ static int video_getClosestDisplayModeCurrentResolution(void *arg)
*/
static int video_getClosestDisplayModeRandomResolution(void *arg)
{
const SDL_DisplayID *displays;
SDL_DisplayID *displays;
SDL_DisplayMode target;
SDL_DisplayMode closest;
int i;
int variation;
@ -403,10 +409,11 @@ static int video_getClosestDisplayModeRandomResolution(void *arg)
target.refresh_rate = (variation & 8) ? (float)SDLTest_RandomIntegerInRange(25, 120) : 0.0f;
/* Make call; may or may not find anything, so don't validate any further */
SDL_GetClosestFullscreenDisplayMode(displays[i], target.w, target.h, target.refresh_rate, SDL_FALSE);
SDL_GetClosestFullscreenDisplayMode(displays[i], target.w, target.h, target.refresh_rate, SDL_FALSE, &closest);
SDLTest_AssertPass("Call to SDL_GetClosestFullscreenDisplayMode(target=random/variation%d)", variation);
}
}
SDL_free(displays);
}
return TEST_COMPLETED;
@ -1668,7 +1675,7 @@ cleanup:
*/
static int video_setWindowCenteredOnDisplay(void *arg)
{
const SDL_DisplayID *displays;
SDL_DisplayID *displays;
SDL_Window *window;
const char *title = "video_setWindowCenteredOnDisplay Test Window";
int x, y, w, h;
@ -1864,6 +1871,7 @@ static int video_setWindowCenteredOnDisplay(void *arg)
destroyVideoSuiteTestWindow(window);
}
}
SDL_free(displays);
}
return TEST_COMPLETED;

View File

@ -16,7 +16,7 @@
int main(int argc, char **argv)
{
const SDL_DisplayID *displays;
SDL_DisplayID *displays;
int i;
SDLTest_CommonState *state;
@ -47,6 +47,7 @@ int main(int argc, char **argv)
bounds.x, bounds.y, bounds.w, bounds.h,
usable.x, usable.y, usable.w, usable.h);
}
SDL_free(displays);
}
SDL_Quit();

View File

@ -28,7 +28,7 @@ static SDL_CameraID back_camera = 0;
static void PrintCameraSpecs(SDL_CameraID camera_id)
{
const SDL_CameraSpec *const *specs = SDL_GetCameraSupportedFormats(camera_id, NULL);
SDL_CameraSpec **specs = SDL_GetCameraSupportedFormats(camera_id, NULL);
if (specs) {
int i;
@ -37,6 +37,7 @@ static void PrintCameraSpecs(SDL_CameraID camera_id)
const SDL_CameraSpec *s = specs[i];
SDL_Log(" %dx%d %.2f FPS %s\n", s->width, s->height, (float)s->framerate_numerator / s->framerate_denominator, SDL_GetPixelFormatName(s->format));
}
SDL_free(specs);
}
}
@ -101,7 +102,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
return SDL_APP_FAILURE;
}
const SDL_CameraID *devices = SDL_GetCameras(&devcount);
SDL_CameraID *devices = SDL_GetCameras(&devcount);
if (!devices) {
SDL_Log("SDL_GetCameras failed: %s", SDL_GetError());
return SDL_APP_FAILURE;
@ -139,6 +140,7 @@ int SDL_AppInit(void **appstate, int argc, char *argv[])
camera_id = devices[0];
}
}
SDL_free(devices);
if (!camera_id) {
SDL_Log("No cameras available?");

View File

@ -351,7 +351,6 @@ static void RefreshControllerName(void)
}
}
SDL_free(controller_name);
if (name) {
controller_name = SDL_strdup(name);
} else {
@ -680,7 +679,7 @@ static void CopyMapping(void)
static void PasteMapping(void)
{
if (controller) {
const char *mapping = SDL_GetClipboardText();
char *mapping = SDL_GetClipboardText();
if (MappingHasBindings(mapping)) {
StopBinding();
SDL_SetGamepadMapping(controller->id, mapping);
@ -688,6 +687,7 @@ static void PasteMapping(void)
} else {
/* Not a valid mapping, ignore it */
}
SDL_free(mapping);
}
}
@ -742,7 +742,7 @@ static void CopyControllerName(void)
static void PasteControllerName(void)
{
SDL_free(controller_name);
controller_name = SDL_strdup(SDL_GetClipboardText());
controller_name = SDL_GetClipboardText();
CommitControllerName();
}
@ -918,9 +918,9 @@ static void AddController(SDL_JoystickID id, SDL_bool verbose)
if (verbose && !SDL_IsGamepad(id)) {
const char *name = SDL_GetJoystickName(joystick);
const char *path = SDL_GetJoystickPath(joystick);
const char *guid;
char guid[33];
SDL_Log("Opened joystick %s%s%s\n", name, path ? ", " : "", path ? path : "");
guid = SDL_GUIDToString(SDL_GetJoystickGUID(joystick));
SDL_GUIDToString(SDL_GetJoystickGUID(joystick), guid, sizeof(guid));
SDL_Log("No gamepad mapping for %s\n", guid);
}
} else {
@ -973,7 +973,6 @@ static void DelController(SDL_JoystickID id)
static void HandleGamepadRemapped(SDL_JoystickID id)
{
const char *sdlmapping;
char *mapping;
int i = FindController(id);
@ -988,8 +987,7 @@ static void HandleGamepadRemapped(SDL_JoystickID id)
}
/* Get the current mapping */
sdlmapping = SDL_GetGamepadMapping(controllers[i].gamepad);
mapping = sdlmapping ? SDL_strdup(sdlmapping) : NULL;
mapping = SDL_GetGamepadMapping(controllers[i].gamepad);
/* Make sure the mapping has a valid name */
if (mapping && !MappingHasName(mapping)) {
@ -1065,9 +1063,10 @@ static void HandleGamepadAdded(SDL_JoystickID id, SDL_bool verbose)
}
if (verbose) {
const char *mapping = SDL_GetGamepadMapping(gamepad);
char *mapping = SDL_GetGamepadMapping(gamepad);
if (mapping) {
SDL_Log("Mapping: %s\n", mapping);
SDL_free(mapping);
}
}
} else {
@ -1187,7 +1186,7 @@ static void OpenVirtualGamepad(void)
static void CloseVirtualGamepad(void)
{
int i;
const SDL_JoystickID *joysticks = SDL_GetJoysticks(NULL);
SDL_JoystickID *joysticks = SDL_GetJoysticks(NULL);
if (joysticks) {
for (i = 0; joysticks[i]; ++i) {
SDL_JoystickID instance_id = joysticks[i];
@ -1195,6 +1194,7 @@ static void CloseVirtualGamepad(void)
SDL_DetachVirtualJoystick(instance_id);
}
}
SDL_free(joysticks);
}
if (virtual_joystick) {
@ -2053,13 +2053,14 @@ int main(int argc, char *argv[])
if (show_mappings) {
int count = 0;
const char * const *mappings = SDL_GetGamepadMappings(&count);
char **mappings = SDL_GetGamepadMappings(&count);
int map_i;
SDL_Log("Supported mappings:\n");
for (map_i = 0; map_i < count; ++map_i) {
SDL_Log("\t%s\n", mappings[map_i]);
}
SDL_Log("\n");
SDL_free(mappings);
}
/* Create a window to display gamepad state */

View File

@ -44,7 +44,8 @@ static void SDLCALL callback(void* userdata, const char* const* files, int filte
}
}
int main(int argc, char *argv[]) {
int main(int argc, char *argv[])
{
SDL_Window *w;
SDL_Renderer *r;
SDLTest_CommonState *state;

View File

@ -33,8 +33,8 @@ print_mode(const char *prefix, const SDL_DisplayMode *mode)
int main(int argc, char *argv[])
{
const SDL_DisplayID *displays;
const SDL_DisplayMode * const *modes;
SDL_DisplayID *displays;
SDL_DisplayMode **modes;
const SDL_DisplayMode *mode;
int num_displays, i;
SDLTest_CommonState *state;
@ -94,9 +94,11 @@ int main(int argc, char *argv[])
(void)SDL_snprintf(prefix, sizeof(prefix), " MODE %d", m);
print_mode(prefix, modes[m]);
}
SDL_free(modes);
SDL_Log("\n");
}
SDL_free(displays);
SDL_Quit();
SDLTest_CommonDestroyState(state);

View File

@ -61,7 +61,7 @@ static int SDLCALL enum_callback(void *userdata, const char *origdir, const char
int main(int argc, char *argv[])
{
SDLTest_CommonState *state;
const char *pref_path;
char *pref_path;
const char *base_path;
/* Initialize test framework */
@ -98,6 +98,7 @@ int main(int argc, char *argv[])
} else {
SDL_Log("pref path: '%s'\n", pref_path);
}
SDL_free(pref_path);
pref_path = SDL_GetPrefPath(NULL, "test_filesystem");
if (!pref_path) {
@ -106,9 +107,10 @@ int main(int argc, char *argv[])
} else {
SDL_Log("pref path: '%s'\n", pref_path);
}
SDL_free(pref_path);
if (base_path) {
const char * const *globlist;
char **globlist;
SDL_IOStream *stream;
const char *text = "foo\n";
@ -124,6 +126,7 @@ int main(int argc, char *argv[])
for (i = 0; globlist[i]; i++) {
SDL_Log("GLOB[%d]: '%s'", i, globlist[i]);
}
SDL_free(globlist);
}
/* !!! FIXME: put this in a subroutine and make it test more thoroughly (and put it in testautomation). */

View File

@ -40,7 +40,7 @@ int main(int argc, char **argv)
int id[9];
int nefx;
unsigned int supported;
const SDL_HapticID *haptics;
SDL_HapticID *haptics;
int num_haptics;
/* Initialize test framework */
@ -88,44 +88,47 @@ int main(int argc, char **argv)
for (i = 0; i < num_haptics; ++i) {
SDL_Log(" %s\n", SDL_GetHapticNameForID(haptics[i]));
}
if (haptics) {
if (num_haptics == 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
return 1;
}
/* We'll just use index or the first force feedback device found */
if (!name) {
i = (index != -1) ? index : 0;
if (i >= num_haptics) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Index out of range, aborting.\n");
return 1;
}
}
/* Try to find matching device */
else {
for (i = 0; i < num_haptics; i++) {
if (SDL_strstr(SDL_GetHapticNameForID(haptics[i]), name) != NULL) {
break;
}
}
if (i >= num_haptics) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n", name);
return 1;
}
}
haptic = SDL_OpenHaptic(haptics[i]);
if (!haptic) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n", SDL_GetError());
return 1;
}
SDL_Log("Device: %s\n", SDL_GetHapticName(haptic));
HapticPrintSupported(haptic);
if (num_haptics == 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
SDL_free(haptics);
return 1;
}
/* We'll just use index or the first force feedback device found */
if (!name) {
i = (index != -1) ? index : 0;
if (i >= num_haptics) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Index out of range, aborting.\n");
SDL_free(haptics);
return 1;
}
}
/* Try to find matching device */
else {
for (i = 0; i < num_haptics; i++) {
if (SDL_strstr(SDL_GetHapticNameForID(haptics[i]), name) != NULL) {
break;
}
}
if (i >= num_haptics) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n", name);
SDL_free(haptics);
return 1;
}
}
haptic = SDL_OpenHaptic(haptics[i]);
if (!haptic) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n", SDL_GetError());
SDL_free(haptics);
return 1;
}
SDL_Log("Device: %s\n", SDL_GetHapticName(haptic));
HapticPrintSupported(haptic);
SDL_free(haptics);
/* We only want force feedback errors. */
SDL_ClearError();

View File

@ -80,18 +80,18 @@ int main(int argc, char *argv[])
//SDL_CreateWindow("Dummy", 128, 128, 0);
*/
SDL_GetKeyboards(&num_keyboards);
SDL_free(SDL_GetKeyboards(&num_keyboards));
SDL_Log("There are %d keyboards at startup\n", num_keyboards);
SDL_GetMice(&num_mice);
SDL_free(SDL_GetMice(&num_mice));
SDL_Log("There are %d mice at startup\n", num_mice);
SDL_GetJoysticks(&num_joysticks);
SDL_free(SDL_GetJoysticks(&num_joysticks));
SDL_Log("There are %d joysticks at startup\n", num_joysticks);
if (enable_haptic) {
int num_haptics;
SDL_GetHaptics(&num_haptics);
SDL_free(SDL_GetHaptics(&num_haptics));
SDL_Log("There are %d haptic devices at startup\n", num_haptics);
}

View File

@ -53,7 +53,7 @@ static int cursor_length = 0;
static SDL_bool cursor_visible;
static Uint64 last_cursor_change;
static SDL_BlendMode highlight_mode;
static const char **candidates;
static char **candidates;
static int num_candidates;
static int selected_candidate;
static SDL_bool horizontal_candidates;
@ -476,6 +476,11 @@ static void InitInput(void)
static void ClearCandidates(void)
{
int i;
for (i = 0; i < num_candidates; ++i) {
SDL_free(candidates[i]);
}
SDL_free(candidates);
candidates = NULL;
num_candidates = 0;
@ -483,12 +488,20 @@ static void ClearCandidates(void)
static void SaveCandidates(SDL_Event *event)
{
int i;
ClearCandidates();
num_candidates = event->edit_candidates.num_candidates;
if (num_candidates > 0) {
candidates = (const char **)SDL_ClaimTemporaryMemory(event->edit_candidates.candidates);
SDL_assert(candidates);
candidates = (char **)SDL_malloc(num_candidates * sizeof(*candidates));
if (!candidates) {
num_candidates = 0;
return;
}
for (i = 0; i < num_candidates; ++i) {
candidates[i] = SDL_strdup(event->edit_candidates.candidates[i]);
}
selected_candidate = event->edit_candidates.selected_candidate;
horizontal_candidates = event->edit_candidates.horizontal;
}

View File

@ -15,7 +15,7 @@
static void log_locales(void)
{
const SDL_Locale * const *locales = SDL_GetPreferredLocales(NULL);
SDL_Locale **locales = SDL_GetPreferredLocales(NULL);
if (!locales) {
SDL_Log("Couldn't determine locales: %s", SDL_GetError());
} else {
@ -29,6 +29,7 @@ static void log_locales(void)
total++;
}
SDL_Log("%u locales seen.", total);
SDL_free(locales);
}
}

View File

@ -135,7 +135,7 @@ test_multi_audio(const SDL_AudioDeviceID *devices, int devcount)
int main(int argc, char **argv)
{
const SDL_AudioDeviceID *devices = NULL;
SDL_AudioDeviceID *devices;
int devcount = 0;
int i;
char *filename = NULL;
@ -192,6 +192,7 @@ int main(int argc, char **argv)
test_multi_audio(devices, devcount);
SDL_free(sound);
}
SDL_free(devices);
}
SDL_free(filename);

View File

@ -222,7 +222,7 @@ static void dump_state(void)
for (i = 0; i < pens_nr; ++i) {
SDL_PenID penid = pens[i];
SDL_GUID guid = SDL_GetPenGUID(penid);
const char *guid_str;
char guid_str[33];
float axes[SDL_PEN_NUM_AXES];
float x, y;
int k;
@ -232,7 +232,7 @@ static void dump_state(void)
char *type;
char *buttons_str;
guid_str = SDL_GUIDToString(guid);
SDL_GUIDToString(guid, guid_str, sizeof(guid_str));
switch (SDL_GetPenType(penid)) {
case SDL_PEN_TYPE_ERASER:

View File

@ -39,7 +39,7 @@ int main(int argc, char **argv)
char *name = NULL;
int index;
SDLTest_CommonState *state;
const SDL_HapticID *haptics;
SDL_HapticID *haptics;
int num_haptics;
/* Initialize test framework */
@ -89,43 +89,46 @@ int main(int argc, char **argv)
SDL_INIT_HAPTIC);
haptics = SDL_GetHaptics(&num_haptics);
SDL_Log("%d Haptic devices detected.\n", num_haptics);
if (haptics) {
if (num_haptics == 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
return 1;
}
/* We'll just use index or the first force feedback device found */
if (!name) {
i = (index != -1) ? index : 0;
if (i >= num_haptics) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Index out of range, aborting.\n");
return 1;
}
}
/* Try to find matching device */
else {
for (i = 0; i < num_haptics; i++) {
if (SDL_strstr(SDL_GetHapticNameForID(haptics[i]), name) != NULL) {
break;
}
}
if (i >= num_haptics) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n", name);
return 1;
}
}
haptic = SDL_OpenHaptic(haptics[i]);
if (!haptic) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n", SDL_GetError());
return 1;
}
SDL_Log("Device: %s\n", SDL_GetHapticName(haptic));
if (num_haptics == 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "No Haptic devices found!\n");
SDL_free(haptics);
return 1;
}
/* We'll just use index or the first force feedback device found */
if (!name) {
i = (index != -1) ? index : 0;
if (i >= num_haptics) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Index out of range, aborting.\n");
SDL_free(haptics);
return 1;
}
}
/* Try to find matching device */
else {
for (i = 0; i < num_haptics; i++) {
if (SDL_strstr(SDL_GetHapticNameForID(haptics[i]), name) != NULL) {
break;
}
}
if (i >= num_haptics) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to find device matching '%s', aborting.\n", name);
SDL_free(haptics);
return 1;
}
}
haptic = SDL_OpenHaptic(haptics[i]);
if (!haptic) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to create the haptic device: %s\n", SDL_GetError());
SDL_free(haptics);
return 1;
}
SDL_Log("Device: %s\n", SDL_GetHapticName(haptic));
SDL_free(haptics);
/* We only want force feedback errors. */
SDL_ClearError();

View File

@ -58,7 +58,7 @@ static void HandleSensorEvent(SDL_SensorEvent *event)
int main(int argc, char **argv)
{
const SDL_SensorID *sensors;
SDL_SensorID *sensors;
int i, num_sensors, num_opened;
SDLTest_CommonState *state;
@ -104,6 +104,7 @@ int main(int argc, char **argv)
}
}
}
SDL_free(sensors);
}
SDL_Log("Opened %d sensors\n", num_opened);

View File

@ -146,7 +146,7 @@ static void SDLCALL fill_buffer(void *userdata, SDL_AudioStream *stream, int len
int main(int argc, char *argv[])
{
const SDL_AudioDeviceID *devices = NULL;
SDL_AudioDeviceID *devices;
SDLTest_CommonState *state;
int devcount = 0;
int i;
@ -181,7 +181,6 @@ int main(int argc, char *argv[])
devices = SDL_GetAudioPlaybackDevices(&devcount);
if (!devices) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "SDL_GetAudioPlaybackDevices() failed: %s\n", SDL_GetError());
devcount = 0;
}
SDL_Log("Available audio devices:");
@ -233,6 +232,7 @@ int main(int argc, char *argv[])
SDL_DestroyAudioStream(stream);
}
SDL_free(devices);
SDL_Quit();
return 0;

View File

@ -53,7 +53,7 @@ static const SDL_DisplayMode *highlighted_mode = NULL;
static void
draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
{
const SDL_DisplayMode * const *modes;
SDL_DisplayMode **modes;
char text[1024];
const int lineHeight = 10;
int i, j;
@ -62,7 +62,7 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
float x, y;
float table_top;
SDL_FPoint mouse_pos = { -1.0f, -1.0f };
const SDL_DisplayID *displays;
SDL_DisplayID *displays;
/* Get mouse position */
if (SDL_GetMouseFocus() == window) {
@ -99,7 +99,6 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
}
displays = SDL_GetDisplays(NULL);
if (displays) {
for (i = 0; displays[i]; ++i) {
SDL_DisplayID display = displays[i];
@ -143,7 +142,9 @@ draw_modes_menu(SDL_Window *window, SDL_Renderer *renderer, SDL_FRect viewport)
column_chars = 0;
}
}
SDL_free(modes);
}
SDL_free(displays);
}
}