From dbdbfe79d25e5dd0d8a88af1af1a9af3cee85408 Mon Sep 17 00:00:00 2001 From: Richard Stanway Date: Wed, 13 Jul 2022 00:05:37 +0200 Subject: [PATCH] libobs: Deprecate base_set_allocator and make it no-op Hopefully nothing is actually using this in the first place. As a library libobs has alignment requirements so we should probably not allow an application to replace our aligned mallocs with something else. This also allows more aggressive optimizations inside libobs as the call can be completely inlined into a libc malloc. --- libobs/util/bmem.c | 18 +++++++----------- libobs/util/bmem.h | 2 +- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/libobs/util/bmem.c b/libobs/util/bmem.c index de60498de..e7017c7e3 100644 --- a/libobs/util/bmem.c +++ b/libobs/util/bmem.c @@ -87,19 +87,13 @@ static void a_free(void *ptr) #endif } -static struct base_allocator alloc = {a_malloc, a_realloc, a_free}; static long num_allocs = 0; -void base_set_allocator(struct base_allocator *defs) -{ - memcpy(&alloc, defs, sizeof(struct base_allocator)); -} - void *bmalloc(size_t size) { - void *ptr = alloc.malloc(size); + void *ptr = a_malloc(size); if (!ptr && !size) - ptr = alloc.malloc(1); + ptr = a_malloc(1); if (!ptr) { os_breakpoint(); bcrash("Out of memory while trying to allocate %lu bytes", @@ -115,9 +109,9 @@ void *brealloc(void *ptr, size_t size) if (!ptr) os_atomic_inc_long(&num_allocs); - ptr = alloc.realloc(ptr, size); + ptr = a_realloc(ptr, size); if (!ptr && !size) - ptr = alloc.realloc(ptr, 1); + ptr = a_realloc(ptr, 1); if (!ptr) { os_breakpoint(); bcrash("Out of memory while trying to allocate %lu bytes", @@ -131,7 +125,7 @@ void bfree(void *ptr) { if (ptr) { os_atomic_dec_long(&num_allocs); - alloc.free(ptr); + a_free(ptr); } } @@ -153,3 +147,5 @@ void *bmemdup(const void *ptr, size_t size) return out; } + +OBS_DEPRECATED void base_set_allocator(struct base_allocator *defs) {} diff --git a/libobs/util/bmem.h b/libobs/util/bmem.h index ce0293ef8..c01afd92b 100644 --- a/libobs/util/bmem.h +++ b/libobs/util/bmem.h @@ -31,7 +31,7 @@ struct base_allocator { void (*free)(void *); }; -EXPORT void base_set_allocator(struct base_allocator *defs); +OBS_DEPRECATED EXPORT void base_set_allocator(struct base_allocator *defs); EXPORT void *bmalloc(size_t size); EXPORT void *brealloc(void *ptr, size_t size);