From 2c51ab5d78e6417f19010782980bf4102a313098 Mon Sep 17 00:00:00 2001 From: Elaina Claus Date: Thu, 15 Jan 2026 16:43:51 -0500 Subject: [PATCH] malloc shim --- include/ni_alloc/alloc.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/ni_alloc/alloc.h b/include/ni_alloc/alloc.h index 1c62724..be494fc 100644 --- a/include/ni_alloc/alloc.h +++ b/include/ni_alloc/alloc.h @@ -13,6 +13,8 @@ extern "C" { Design goal: easy to use in tools, easy to test, portable across Linux/macOS. */ +//#define ENABLE_NICKEL_ALLOC_SHIM + typedef struct ni_alloc_stats { /* current usage */ size_t bytes_in_use; /* user-visible allocated bytes (approx if desired) */ @@ -115,6 +117,17 @@ size_t ni_align_up(size_t x, size_t align); */ bool ni_alloc_validate(void); + +#ifdef ENABLE_NICKEL_ALLOC_SHIM + /* Allocation functions using the global allocator. + define symbols pointing at our versions + */ + void* malloc(size_t size) { ni_malloc(size); } + void free(void* ptr) { ni_free(ptr); } + void* realloc(void* ptr, size_t new_size) { ni_realloc(ptr, new_size); } + void* calloc(size_t count, size_t elem_size) { ni_calloc(count, elem_size); } +#endif + #ifdef __cplusplus } #endif