瀏覽代碼

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.
Richard Stanway 3 年之前
父節點
當前提交
dbdbfe79d2
共有 2 個文件被更改,包括 8 次插入12 次删除
  1. 7 11
      libobs/util/bmem.c
  2. 1 1
      libobs/util/bmem.h

+ 7 - 11
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) {}

+ 1 - 1
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);