Replace allocator struct with function pointers

This commit is contained in:
Mingkai Dong 2021-12-24 09:28:23 +08:00
parent 486ea2569d
commit 8e4d4ef8b9
3 changed files with 34 additions and 43 deletions

View file

@ -11,20 +11,23 @@ extern "C" {
#include <stdbool.h>
#include <stdio.h>
extern TSAllocator *ts_allocator;
extern void *(*ts_current_malloc)(size_t);
extern void *(*ts_current_calloc)(size_t, size_t);
extern void *(*ts_current_realloc)(void *, size_t);
extern void (*ts_current_free)(void *);
// Allow clients to override allocation functions
#ifndef ts_malloc
#define ts_malloc ts_allocator->malloc
#define ts_malloc ts_current_malloc
#endif
#ifndef ts_calloc
#define ts_calloc ts_allocator->calloc
#define ts_calloc ts_current_calloc
#endif
#ifndef ts_realloc
#define ts_realloc ts_allocator->realloc
#define ts_realloc ts_current_realloc
#endif
#ifndef ts_free
#define ts_free ts_allocator->free
#define ts_free ts_current_free
#endif
bool ts_toggle_allocation_recording(bool);