X-Git-Url: https://git.draconx.ca/gitweb/cdecl99.git/blobdiff_plain/0c3d696d84c1d76482d83e76e4c2b4218b028f1f..beac10d6593fee948759c05d956b83db6803f2ec:/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