From 19235b7127bcf5597fb0436deb45c2e6af5843c6 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 14 Sep 2021 17:19:12 -0400 Subject: Make ZixAllocator a single flat struct I can never decide between these two patterns for polymorphic objects in C, but this one seems more appropriate here since it's more conducive to inheritance. --- src/allocator.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/allocator.c') diff --git a/src/allocator.c b/src/allocator.c index e4a9f83..c998463 100644 --- a/src/allocator.c +++ b/src/allocator.c @@ -7,43 +7,42 @@ ZIX_MALLOC_FUNC static void* -zix_default_malloc(ZixAllocatorHandle* const handle, const size_t size) +zix_default_malloc(ZixAllocator* const allocator, const size_t size) { - (void)handle; + (void)allocator; return malloc(size); } ZIX_MALLOC_FUNC static void* -zix_default_calloc(ZixAllocatorHandle* const handle, - const size_t nmemb, - const size_t size) +zix_default_calloc(ZixAllocator* const allocator, + const size_t nmemb, + const size_t size) { - (void)handle; + (void)allocator; return calloc(nmemb, size); } static void* -zix_default_realloc(ZixAllocatorHandle* const handle, - void* const ptr, - const size_t size) +zix_default_realloc(ZixAllocator* const allocator, + void* const ptr, + const size_t size) { - (void)handle; + (void)allocator; return realloc(ptr, size); } static void -zix_default_free(ZixAllocatorHandle* const handle, void* const ptr) +zix_default_free(ZixAllocator* const allocator, void* const ptr) { - (void)handle; + (void)allocator; free(ptr); } -const ZixAllocator* +ZixAllocator* zix_default_allocator(void) { - static const ZixAllocator default_allocator = { - NULL, + static ZixAllocator default_allocator = { zix_default_malloc, zix_default_calloc, zix_default_realloc, -- cgit v1.2.1