diff --git a/lib/src/alloc.c b/lib/src/alloc.c index a6adaf5e..9235d1e4 100644 --- a/lib/src/alloc.c +++ b/lib/src/alloc.c @@ -1,6 +1,12 @@ #include "alloc.h" #include +#ifdef _WIN32 +#define PUBLIC __declspec(dllexport) +#else +#define PUBLIC __attribute__((visibility("default"))) +#endif + static void *ts_malloc_default(size_t size) { void *result = malloc(size); if (size > 0 && !result) { @@ -29,10 +35,10 @@ static void *ts_realloc_default(void *buffer, size_t size) { } // Allow clients to override allocation functions dynamically -void *(*ts_current_malloc)(size_t) = ts_malloc_default; -void *(*ts_current_calloc)(size_t, size_t) = ts_calloc_default; -void *(*ts_current_realloc)(void *, size_t) = ts_realloc_default; -void (*ts_current_free)(void *) = free; +PUBLIC void *(*ts_current_malloc)(size_t) = ts_malloc_default; +PUBLIC void *(*ts_current_calloc)(size_t, size_t) = ts_calloc_default; +PUBLIC void *(*ts_current_realloc)(void *, size_t) = ts_realloc_default; +PUBLIC void (*ts_current_free)(void *) = free; void ts_set_allocator( void *(*new_malloc)(size_t size), diff --git a/lib/src/parser.h b/lib/src/parser.h index 17b4fde9..2703c64f 100644 --- a/lib/src/parser.h +++ b/lib/src/parser.h @@ -20,6 +20,29 @@ typedef uint16_t TSFieldId; typedef struct TSLanguage TSLanguage; #endif +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 consumers to use allocation functions +#ifndef ts_malloc +#define ts_malloc ts_current_malloc +#define malloc ts_current_malloc +#endif +#ifndef ts_calloc +#define ts_calloc ts_current_calloc +#define calloc ts_current_calloc +#endif +#ifndef ts_realloc +#define ts_realloc ts_current_realloc +#define realloc ts_current_realloc +#endif +#ifndef ts_free +#define ts_free ts_current_free +#define free ts_current_free +#endif + typedef struct { TSFieldId field_id; uint8_t child_index;