From 502dacf220b75f23b882222d826d4b0afb465885 Mon Sep 17 00:00:00 2001 From: ObserverOfTime Date: Tue, 27 Feb 2024 21:41:11 +0200 Subject: [PATCH] refactor: rename TS_REUSE_ALLOCATOR flag TREE_SITTER_REUSE_ALLOCATOR is more consistent --- cli/loader/src/lib.rs | 2 +- cli/src/generate/templates/alloc.h | 2 +- docs/section-3-creating-parsers.md | 4 +--- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/cli/loader/src/lib.rs b/cli/loader/src/lib.rs index 8abc419c..cbc8d21c 100644 --- a/cli/loader/src/lib.rs +++ b/cli/loader/src/lib.rs @@ -603,7 +603,7 @@ impl Loader { // Always use the same allocator in the CLI as any scanner, useful for debugging and // tracking memory leaks in tests. #[cfg(not(any(target_os = "macos", target_os = "ios")))] - command.arg("-DTS_REUSE_ALLOCATOR"); + command.arg("-DTREE_SITTER_REUSE_ALLOCATOR"); let output = command.output().with_context(|| { format!("Failed to execute the C compiler with the following command:\n{command:?}") diff --git a/cli/src/generate/templates/alloc.h b/cli/src/generate/templates/alloc.h index 1f7610a3..4cb7e187 100644 --- a/cli/src/generate/templates/alloc.h +++ b/cli/src/generate/templates/alloc.h @@ -21,7 +21,7 @@ TS_PUBLIC extern void *(*ts_current_realloc)(void *, size_t); TS_PUBLIC extern void (*ts_current_free)(void *); // Allow clients to override allocation functions -#ifdef TS_REUSE_ALLOCATOR +#ifdef TREE_SITTER_REUSE_ALLOCATOR #ifndef ts_malloc #define ts_malloc ts_current_malloc diff --git a/docs/section-3-creating-parsers.md b/docs/section-3-creating-parsers.md index 2b42c6e7..f5636ec9 100644 --- a/docs/section-3-creating-parsers.md +++ b/docs/section-3-creating-parsers.md @@ -801,7 +801,7 @@ Instead of using libc's `malloc`, `calloc`, `realloc`, and `free`, you should us These macros can allow a potential consumer to override the default allocator with their own implementation, but by default will use the libc functions. As a consumer of the tree-sitter core library as well as any parser libraries that might use allocations, you can enable overriding the default allocator and have it use the same one as the library allocator, of which you can set with `ts_set_allocator`. -To enable this overriding in scanners, you must compile them with the `TS_REUSE_ALLOCATOR` macro defined, and tree-sitter the library must be linked into your final app dynamically, since it needs to resolve the internal functions at runtime. If you are compiling +To enable this overriding in scanners, you must compile them with the `TREE_SITTER_REUSE_ALLOCATOR` macro defined, and tree-sitter the library must be linked into your final app dynamically, since it needs to resolve the internal functions at runtime. If you are compiling an executable binary that uses the core library, but want to load parsers dynamically at runtime, then you will have to use a special linker flag on Unix. For non-Darwin systems, that would be `--dynamic-list` and for Darwin systems, that would be `-exported_symbols_list`. The CLI does exactly this, so you can use it as a reference (check out `cli/build.rs`). @@ -810,7 +810,6 @@ For example, assuming you wanted to allocate 100 bytes for your scanner, you'd d ```c #include "tree_sitter/parser.h" #include "tree_sitter/alloc.h" -#include "tree_sitter/array.h" // ... @@ -833,7 +832,6 @@ These are internal functions used as helpers by other macros that are public. Th ```c #include "tree_sitter/parser.h" -#include "tree_sitter/alloc.h" #include "tree_sitter/array.h" enum TokenType {