summaryrefslogtreecommitdiff
path: root/src/tree_sitter_heap.h
blob: 66083be8e19b10368b5762a37cd887c3002e3e59 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
/* Forced into every tree-sitter grammar build ahead of its own source
 * (build.zig passes -include). A few external scanners (bash, markdown,
 * markdown_inline, python, typst) call malloc, calloc, realloc and free
 * themselves rather than tree-sitter's ts_malloc and friends, so they would
 * allocate from libc behind the Zig allocator syntax.zig hands the runtime.
 * stdlib.h comes first so its declarations are made with the real names;
 * from here on the four names are the runtime's current allocator functions,
 * the ones ts_set_allocator sets. The scanners that do use ts_malloc get the
 * same through tree_sitter/alloc.h and TREE_SITTER_REUSE_ALLOCATOR. A scanner
 * frees only what it allocated itself, so none of this memory crosses into
 * the runtime or out of it. */
#ifndef PARDES_TREE_SITTER_HEAP_H
#define PARDES_TREE_SITTER_HEAP_H

#include <stdlib.h>

extern void *(*ts_current_malloc)(size_t size);
extern void *(*ts_current_calloc)(size_t count, size_t size);
extern void *(*ts_current_realloc)(void *ptr, size_t size);
extern void (*ts_current_free)(void *ptr);

#define malloc(size) ts_current_malloc(size)
#define calloc(count, size) ts_current_calloc(count, size)
#define realloc(ptr, size) ts_current_realloc(ptr, size)
#define free(ptr) ts_current_free(ptr)

#endif