Skip to content

Commit

Permalink
refactor: rename TS_REUSE_ALLOCATOR flag
Browse files Browse the repository at this point in the history
TREE_SITTER_REUSE_ALLOCATOR is more consistent
  • Loading branch information
ObserverOfTime committed Feb 27, 2024
1 parent 59d3ea3 commit 6b8531d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion cli/loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}")
Expand Down
2 changes: 1 addition & 1 deletion cli/src/generate/templates/alloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions docs/section-3-creating-parsers.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`).

Expand All @@ -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"

// ...

Expand All @@ -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 {
Expand Down

0 comments on commit 6b8531d

Please sign in to comment.