From f67c54eb50b488ecd2e92ae4c495e89bd3da5663 Mon Sep 17 00:00:00 2001 From: Thomas Schmucker Date: Sun, 21 Jun 2026 17:12:55 +0200 Subject: cleanup allocator interface --- src/allocator.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'src/allocator.c') diff --git a/src/allocator.c b/src/allocator.c index d6aeea9..1627089 100644 --- a/src/allocator.c +++ b/src/allocator.c @@ -1,23 +1,31 @@ #include "allocator.h" +#include #include /* malloc */ +#ifndef UNUSED +# define UNUSED(var) (void) (var) +#endif + /* Interface Code */ static void * default_allocate(struct allocator *allocator, size_t n) { - (void) allocator; + UNUSED(allocator); return malloc(n); } static void default_deallocate(struct allocator *allocator, void *ptr) { - (void) allocator; + UNUSED(allocator); free(ptr); } struct allocator allocator_default_allocator = { +#ifndef NDEBUG + .self = &allocator_default_allocator, +#endif .allocate = &default_allocate, .deallocate = &default_deallocate }; @@ -32,6 +40,8 @@ allocator_malloc(struct allocator *allocator, size_t n) allocator = &allocator_default_allocator; } + assert(allocator->self == allocator); + return allocator->allocate(allocator, n); } @@ -42,6 +52,8 @@ allocator_free(struct allocator *allocator, void *ptr) allocator = &allocator_default_allocator; } + assert(allocator->self == allocator); + allocator->deallocate(allocator, ptr); } -- cgit v1.3