refactor!: expose the allocator family of functions for consumption in scanners
This commit is contained in:
parent
e6d67ecde0
commit
b66b1a7a92
2 changed files with 33 additions and 4 deletions
|
|
@ -1,6 +1,12 @@
|
|||
#include "alloc.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#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),
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue