diff --git a/cli/src/tests/helpers/allocations.rs b/cli/src/tests/helpers/allocations.rs index ae246c40..c64762bd 100644 --- a/cli/src/tests/helpers/allocations.rs +++ b/cli/src/tests/helpers/allocations.rs @@ -98,7 +98,9 @@ extern "C" fn ts_record_free(ptr: *mut c_void) { } #[no_mangle] -extern "C" fn ts_record_allocations_toggle() { +extern "C" fn ts_toggle_allocation_recording(enabled: bool) -> bool { let mut recorder = RECORDER.lock(); - recorder.enabled = !recorder.enabled; + let was_enabled = recorder.enabled; + recorder.enabled = enabled; + was_enabled } diff --git a/lib/src/alloc.h b/lib/src/alloc.h index 8e027a99..c8fe6c6e 100644 --- a/lib/src/alloc.h +++ b/lib/src/alloc.h @@ -15,7 +15,7 @@ void *ts_record_malloc(size_t); void *ts_record_calloc(size_t, size_t); void *ts_record_realloc(void *, size_t); void ts_record_free(void *); -bool ts_record_allocations_toggle(bool); +bool ts_toggle_allocation_recording(bool); static inline void *ts_malloc(size_t size) { return ts_record_malloc(size); @@ -33,10 +33,6 @@ static inline void ts_free(void *buffer) { ts_record_free(buffer); } -static inline bool ts_toggle_allocation_recording(bool value) { - return ts_record_allocations_toggle(value); -} - #else #include diff --git a/lib/src/stack.c b/lib/src/stack.c index e3a1f22d..9e351d4e 100644 --- a/lib/src/stack.c +++ b/lib/src/stack.c @@ -712,9 +712,9 @@ void ts_stack_clear(Stack *self) { } bool ts_stack_print_dot_graph(Stack *self, const TSLanguage *language, FILE *f) { + array_reserve(&self->iterators, 32); bool was_recording_allocations = ts_toggle_allocation_recording(false); - if (!f) - f = stderr; + if (!f) f = stderr; fprintf(f, "digraph stack {\n"); fprintf(f, "rankdir=\"RL\";\n");