Avoid allocator from being switched more than once

This commit is contained in:
Mingkai Dong 2021-12-18 16:45:18 +08:00
parent b9b051e933
commit 486ea2569d
2 changed files with 17 additions and 7 deletions

View file

@ -148,10 +148,15 @@ typedef struct {
/**
* Switch to a new allocator.
*
* Returns the old allocator. The caller needs to take care of any allocated
* memory managed by the old allocator.
* Returns true iff the switch successes.
*
* This function can only be invoked *once*, before tree-sitter has allocated
* any memory via malloc/calloc/realloc. Otherwise, memory bugs could occur
* since some memory is allocated by the old allocator, but freed by the new
* one.
*
*/
TSAllocator *ts_set_allocator(TSAllocator *new_alloc);
bool ts_set_allocator(TSAllocator *new_alloc);
/**
* Create a new parser.