summaryrefslogtreecommitdiff
path: root/src/tree_sitter_heap.h
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 17:35:06 -0300
committerGabriel Schneider <[email protected]>2026-10-30 17:35:06 -0300
commit6d8da8721141284cf33bb901168b26135893eb86 (patch)
tree791d63401d4e85fbca1d597a8ce0326e70efd545 /src/tree_sitter_heap.h
parentefd43a3a2cf03bb741366331158b368abf9ac583 (diff)
parentbf6810a8f9d6cc82050e7d9c0cfb06358301b574 (diff)
downloadpardes-6d8da8721141284cf33bb901168b26135893eb86.tar.gz
pardes-6d8da8721141284cf33bb901168b26135893eb86.zip
Merge latest upstream into the macOS branch for Zig 0.17
Retain the macOS branch history and local Acme selection color while adopting upstream's current core and platform changes. Pin Zig and ZLS to 0.17.0, and fetch the existing zstbi compatibility commit through upstream after its original fork was removed.
Diffstat (limited to 'src/tree_sitter_heap.h')
-rw-r--r--src/tree_sitter_heap.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/tree_sitter_heap.h b/src/tree_sitter_heap.h
new file mode 100644
index 00000000..66083be8
--- /dev/null
+++ b/src/tree_sitter_heap.h
@@ -0,0 +1,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