From eec3543c093fe65d8b625faa117fa1f3eec13083 Mon Sep 17 00:00:00 2001 From: Hongze Cheng Date: Mon, 27 Sep 2021 17:08:02 +0800 Subject: [PATCH] refact --- include/util/amalloc.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/include/util/amalloc.h b/include/util/amalloc.h index 944d27513e..6d2869f719 100644 --- a/include/util/amalloc.h +++ b/include/util/amalloc.h @@ -35,10 +35,14 @@ typedef struct { SMemAllocatorIf interface; } SMemAllocator; -#define amalloc(allocator, size) (*((allocator)->interface.malloc))((allocator)->impl, size) -#define acalloc(allocator, nmemb, size) (*((allocator)->interface.calloc))((allocator)->impl, nmemb, size) -#define arealloc(allocator, ptr, size) (*((allocator)->interface.realloc))((allocator)->impl, ptr, size) -#define afree(allocator, ptr, size) (*((allocator)->interface.free))((allocator)->impl, ptr, size) +#define amalloc(allocator, size) \ + ((allocator) ? (*((allocator)->interface.malloc))((allocator)->impl, (size)) : malloc(size)) +#define acalloc(allocator, nmemb, size) \ + ((allocator) ? (*((allocator)->interface.calloc))((allocator)->impl, (nmemb), (size)) : calloc((nmemb), (size))) +#define arealloc(allocator, ptr, size) \ + ((allocator) ? (*((allocator)->interface.realloc))((allocator)->impl, (ptr), (size)) : realloc((ptr), (size))) +#define afree(allocator, ptr, size) \ + ((allocator) ? (*((allocator)->interface.free))((allocator)->impl, (ptr), (size)) : free(ptr)) #ifdef __cplusplus }