Simplify allocation-recording in test suite using new ts_set_allocator API
This commit is contained in:
parent
e01ea9ff51
commit
622359b400
19 changed files with 245 additions and 254 deletions
|
|
@ -138,22 +138,6 @@ typedef enum {
|
|||
/* Section - Parser */
|
||||
/********************/
|
||||
|
||||
/**
|
||||
* Switch to a new allocator.
|
||||
*
|
||||
* This function can be invoked more than once. However, the application needs
|
||||
* to pay attention to the memory allocated by the old allocator but might be
|
||||
* freed by the new one.
|
||||
*
|
||||
* Specifically, the application either,
|
||||
* 1. ensures all parsers and trees are freed before calling it;
|
||||
* 2. provides an allocator that shares its state with the old allocator.
|
||||
*/
|
||||
void ts_set_allocator(void *(*new_malloc)(size_t),
|
||||
void *(*new_calloc)(size_t, size_t),
|
||||
void *(*new_realloc)(void *, size_t),
|
||||
void (*new_free)(void *));
|
||||
|
||||
/**
|
||||
* Create a new parser.
|
||||
*/
|
||||
|
|
@ -912,6 +896,33 @@ TSSymbolType ts_language_symbol_type(const TSLanguage *, TSSymbol);
|
|||
*/
|
||||
uint32_t ts_language_version(const TSLanguage *);
|
||||
|
||||
/**********************************/
|
||||
/* Section - Global Configuration */
|
||||
/**********************************/
|
||||
|
||||
/**
|
||||
* Set the allocation functions used by the library.
|
||||
*
|
||||
* By default, Tree-sitter uses the standard libc allocation functions,
|
||||
* but aborts the process when an allocation fails. This function lets
|
||||
* you supply alternative allocation functions at runtime.
|
||||
*
|
||||
* If you pass `NULL` for any parameter, Tree-sitter will switch back to
|
||||
* its default implementation of that function.
|
||||
*
|
||||
* If you call this function after the library has already been used, then
|
||||
* you must ensure that either:
|
||||
* 1. All the existing objects have been freed.
|
||||
* 2. The new allocator shares its state with the old one, so it is capable
|
||||
* of freeing memory that was allocated by the old allocator.
|
||||
*/
|
||||
void ts_set_allocator(
|
||||
void *(*new_malloc)(size_t),
|
||||
void *(*new_calloc)(size_t, size_t),
|
||||
void *(*new_realloc)(void *, size_t),
|
||||
void (*new_free)(void *)
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue