X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/486349a83f783742b9d148447c6119eb76d4ead0..da87235fd91665373a44dbc75b1750deaaf81abe:/src/cdecl-internal.h diff --git a/src/cdecl-internal.h b/src/cdecl-internal.h index dc8d1f0..335094c 100644 --- a/src/cdecl-internal.h +++ b/src/cdecl-internal.h @@ -134,4 +134,28 @@ struct parse_item *cdecl__alloc_item(size_t s_sz); # endif #endif +/* + * Build-time hook for white-box testing of memory allocation behaviour. + */ +#if TEST_MALLOC_HOOK +void *test_realloc_hook(void *, size_t); + +static inline void *test_wrap_malloc(size_t n) +{ + return test_realloc_hook(0, n); +} + +static inline void test_wrap_free(void *p) +{ + test_realloc_hook(p, 0); +} + +#undef realloc +#define realloc test_realloc_hook +#undef malloc +#define malloc test_wrap_malloc +#undef free +#define free test_wrap_free +#endif + #endif