mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-13 05:10:07 +08:00
be6584e2b9
When using libtcc it's reasonable to be able to use the application's memory allocator for all allocations, including tcc_new(), and including #define MEM_DEBUG Ideally the allocator would be stored in the TCCState, like TCCErrorFunc. That would imply a new API tcc_new_with_allocator(), but more importantly would require all uses of tcc_malloc(x) to be changed to s->tcc_malloc(x). That's a non-starter in my book. Instead I refactored the memory management code so that all allocations flow through tcc_realloc(). Which simply calls a function pointer, the default value of which is the previous tcc_realloc(). It then becomess trivial to install a new allocator with the new function: LIBTCCAPI void tcc_set_realloc(TCCReallocFunc realloc); The resulting code adds the trivial cost of an additional function call per allocation/free. It also doesn't distinguish between malloc failure and realloc failure, but since both just fprintf then exit() that seems unimportant to me. On the plus side the preprocessor magic is much more clear. The diffs don't hightlight that, but take a look at the result to see if you agree. All tests passed on my x86 linux box. |
||
---|---|---|
.. | ||
pp | ||
tests2 | ||
42test.h | ||
abitest.c | ||
arm-asm-testsuite.sh | ||
asm-c-connect-1.c | ||
asm-c-connect-2.c | ||
asmtest.S | ||
boundtest.c | ||
bug.c | ||
gcctestsuite.sh | ||
libtcc_test_mt.c | ||
libtcc_test.c | ||
Makefile | ||
tcctest.c | ||
tcctest.h | ||
testfp.c | ||
vla_test.c |