Commit graph

15 commits

Author SHA1 Message Date
Sam Lantinga
6cfce101fb Don't call the property cleanup function if setting the property fails
Fixes https://github.com/libsdl-org/SDL/issues/8659
2023-12-04 07:48:13 -08:00
Ryan C. Gordon
447b508a77
error: SDL's allocators now call SDL_OutOfMemory on error.
This means the allocator's caller doesn't need to use SDL_OutOfMemory directly
if the allocation fails.

This applies to the usual allocators: SDL_malloc, SDL_calloc, SDL_realloc
(all of these regardless of if the app supplied a custom allocator or we're
using system malloc() or an internal copy of dlmalloc under the hood),
SDL_aligned_alloc, SDL_small_alloc, SDL_strdup, SDL_asprintf, SDL_wcsdup...
probably others. If it returns something you can pass to SDL_free, it should
work.

The caller might still need to use SDL_OutOfMemory if something that wasn't
SDL allocated the memory: operator new in C++ code, Objective-C's alloc
message, win32 GlobalAlloc, etc.

Fixes #8642.
2023-11-30 00:14:27 -05:00
Frank Praznik
861b1ebd12 properties: Use a mutex instead of an RWLock to guard the hash table
The hash table can be recursively locked from the same thread, which can cause issues with RWLocks, as locking them recursively can result in undefined behavior or deadlocks. Use a mutex instead, as it can be safely recursively locked.
2023-11-13 18:28:24 -05:00
Sam Lantinga
6afae6681b Allow casting properties of different types 2023-11-12 21:58:58 -08:00
Sam Lantinga
bd269b0f41 Added SDL_SetBooleanProperty() and SDL_GetBooleanProperty() 2023-11-12 21:58:58 -08:00
Sam Lantinga
0907f345cb Added property types: pointer, string, number, float 2023-11-12 10:48:38 -08:00
Mathieu Eyraud
dfb87e1099 Fix uninitialised variable 'properties'
If SDL_CreateHashTable() fails, properties->lock is not initialised, SDL_FreeProperties() is called and destroys the uninitialised lock.
2023-11-10 06:32:15 -08:00
Sam Lantinga
407a3cb4e0 Fixed infinite recursion initializing properties 2023-11-08 12:38:04 -08:00
Sam Lantinga
979214363f Added SDL_GetGlobalProperties()
We'll undoubtedly want to have global properties available
2023-11-08 12:01:48 -08:00
Sam Lantinga
aea6e6de6f Simplified SDL_SetProperty() and added SDL_SetPropertyWithCleanup()
Most of the time people won't need to set a cleanup callback, so we can simplify the more commonly used API.
2023-11-08 12:01:48 -08:00
Ryan C. Gordon
899eb0d042 thread: Locking mutexes and rwlocks are now void functions.
Almost nothing checks these return values, and there's no reason a valid
lock should fail to operate. The cases where a lock isn't valid (it's a
bogus pointer, it was previously destroyed, a thread is unlocking a lock it
doesn't own, etc) are undefined behavior and always were, and should be
treated as an application bug.

Reference Issue #8096.
2023-10-26 08:57:34 -04:00
Sam Lantinga
48d80efb51 Fixed warning C4701: potentially uninitialized local variable 'props' used 2023-10-18 09:04:05 -07:00
Sam Lantinga
b79db0a6ea Fixed potential wraparound issue with property IDs 2023-10-12 06:22:34 -07:00
Sam Lantinga
4368f70ff9 Added properties to various SDL objects
The following objects now have properties that can be user modified:
* SDL_AudioStream
* SDL_Gamepad
* SDL_Joystick
* SDL_RWops
* SDL_Renderer
* SDL_Sensor
* SDL_Surface
* SDL_Texture
* SDL_Window
2023-10-11 22:38:00 -07:00
Sam Lantinga
973c8b3273 Added SDL properties API
Fixes https://github.com/libsdl-org/SDL/issues/7799
2023-10-11 22:38:00 -07:00