Avoid allocator from being switched more than once
This commit is contained in:
parent
b9b051e933
commit
486ea2569d
2 changed files with 17 additions and 7 deletions
|
|
@ -70,10 +70,15 @@ TSAllocator *ts_allocator = &ts_default_allocator;
|
|||
|
||||
#endif // defined(TREE_SITTER_ALLOCATION_TRACKING)
|
||||
|
||||
TSAllocator *ts_set_allocator(TSAllocator *new_alloc)
|
||||
bool ts_set_allocator(TSAllocator *new_alloc)
|
||||
{
|
||||
TSAllocator *old = ts_allocator;
|
||||
ts_allocator = new_alloc;
|
||||
return old;
|
||||
static bool using_default_allocator = true;
|
||||
if (!using_default_allocator) {
|
||||
fprintf(stderr, "tree-sitter's allocator can only be set once!");
|
||||
return false;
|
||||
}
|
||||
using_default_allocator = false;
|
||||
ts_allocator = new_alloc;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue