Wrap all calls to malloc and friends

This commit is contained in:
Max Brunsfeld 2016-01-15 15:08:42 -08:00
parent 19b776e74d
commit 87316f22f3
9 changed files with 79 additions and 22 deletions

View file

@ -4,6 +4,7 @@
#include <stdbool.h>
#include <stdio.h>
#include "tree_sitter/parser.h"
#include "runtime/alloc.h"
#include "runtime/tree.h"
#include "runtime/length.h"
@ -12,7 +13,7 @@ TSStateId TS_TREE_STATE_ERROR = USHRT_MAX - 1;
TSTree *ts_tree_make_leaf(TSSymbol sym, TSLength padding, TSLength size,
TSSymbolMetadata metadata) {
TSTree *result = malloc(sizeof(TSTree));
TSTree *result = ts_malloc(sizeof(TSTree));
*result = (TSTree){
.ref_count = 1,
.symbol = sym,
@ -46,7 +47,7 @@ TSTree *ts_tree_make_error(TSLength size, TSLength padding, char lookahead_char)
}
TSTree *ts_tree_make_copy(TSTree *self) {
TSTree *result = malloc(sizeof(TSTree));
TSTree *result = ts_malloc(sizeof(TSTree));
*result = *self;
return result;
}
@ -125,8 +126,8 @@ void ts_tree_release(TSTree *self) {
for (size_t i = 0; i < self->child_count; i++)
ts_tree_release(self->children[i]);
if (self->child_count > 0)
free(self->children);
free(self);
ts_free(self->children);
ts_free(self);
}
}
@ -252,7 +253,7 @@ char *ts_tree_string(const TSTree *self, const char **symbol_names,
static char SCRATCH[1];
size_t size = 1 + ts_tree__write_to_string(self, symbol_names, SCRATCH, 0,
true, include_anonymous);
char *result = malloc(size * sizeof(char));
char *result = ts_malloc(size * sizeof(char));
ts_tree__write_to_string(self, symbol_names, result, size, true,
include_anonymous);
return result;