mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-09-20 02:08:13 +00:00
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.
This commit is contained in:
@@ -54,14 +54,12 @@ SDL_HashTable *SDL_CreateHashTable(void *data, const Uint32 num_buckets, const S
|
||||
|
||||
table = (SDL_HashTable *) SDL_calloc(1, sizeof (SDL_HashTable));
|
||||
if (!table) {
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
table->table = (SDL_HashItem **) SDL_calloc(num_buckets, sizeof (SDL_HashItem *));
|
||||
if (!table->table) {
|
||||
SDL_free(table);
|
||||
SDL_OutOfMemory();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -92,7 +90,6 @@ SDL_bool SDL_InsertIntoHashTable(SDL_HashTable *table, const void *key, const vo
|
||||
// !!! FIXME: grow and rehash table if it gets too saturated.
|
||||
item = (SDL_HashItem *) SDL_malloc(sizeof (SDL_HashItem));
|
||||
if (!item) {
|
||||
SDL_OutOfMemory();
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user