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 committed 2024-07-26 20:59:14 -07:00
1 parent 21411c6418
commit 4f55271571
100 files changed
+737 -853

No files matched your search

+11 -8
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';
}
/*-----------------------------------------------------------------------------
+5 -5
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;
+5 -10
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
}
+2 -2
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);
+45
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;
}
+2
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_ */
+10 -10
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);
+6 -6
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);
}
+7 -7
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;
}
+3 -3
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)
+33 -33
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)
+1 -1
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:
+5 -6
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();
+5
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);
+6 -6
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)
+3 -2
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);
}
}
+3 -3
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)
+1 -1
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;
}
+5 -5
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)
+5 -5
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;
}
+1 -1
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
+1 -1
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)
+5 -5
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)
+33 -42
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;
}
+15 -12
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();
+4 -4
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 = {
+3 -3
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);
+2 -2
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)
+4 -4
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();
+11 -6
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)
+1 -1
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);
+3 -9
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;
}
+19 -15
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;
+2 -2
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);
}
}
+13 -13
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);
}
}
+35 -52
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);
}
+2 -1
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);
}
}
+2 -1
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);
+5 -5
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);
}
}
+2 -1
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);
}
}
+4 -5
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);
}
}
+2 -1
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);
}
}
+4 -2
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);
+2 -1
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 */
+2 -1
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);
}
}
+36 -21
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);