@@ -42,7 +42,20 @@ static inline bool ts_toggle_allocation_recording(bool value) {
4242 return false;
4343}
4444
45- static inline void * ts_malloc (size_t size ) {
45+ #ifndef ts_malloc
46+ #define ts_malloc (_sz ) ts_malloc_dflt(_sz)
47+ #endif
48+ #ifndef ts_calloc
49+ #define ts_calloc (_cnt ,_sz ) ts_calloc_dflt(_cnt,_sz)
50+ #endif
51+ #ifndef ts_realloc
52+ #define ts_realloc (_ptr ,_sz ) ts_realloc_dflt(_ptr,_sz)
53+ #endif
54+ #ifndef ts_free
55+ #define ts_free (_ptr ) ts_free_dflt(_ptr)
56+ #endif
57+
58+ static inline void * ts_malloc_dflt (size_t size ) {
4659 void * result = malloc (size );
4760 if (size > 0 && !result ) {
4861 fprintf (stderr , "tree-sitter failed to allocate %zu bytes" , size );
@@ -51,7 +64,7 @@ static inline void *ts_malloc(size_t size) {
5164 return result ;
5265}
5366
54- static inline void * ts_calloc (size_t count , size_t size ) {
67+ static inline void * ts_calloc_dflt (size_t count , size_t size ) {
5568 void * result = calloc (count , size );
5669 if (count > 0 && !result ) {
5770 fprintf (stderr , "tree-sitter failed to allocate %zu bytes" , count * size );
@@ -60,7 +73,7 @@ static inline void *ts_calloc(size_t count, size_t size) {
6073 return result ;
6174}
6275
63- static inline void * ts_realloc (void * buffer , size_t size ) {
76+ static inline void * ts_realloc_dflt (void * buffer , size_t size ) {
6477 void * result = realloc (buffer , size );
6578 if (size > 0 && !result ) {
6679 fprintf (stderr , "tree-sitter failed to reallocate %zu bytes" , size );
@@ -69,7 +82,7 @@ static inline void *ts_realloc(void *buffer, size_t size) {
6982 return result ;
7083}
7184
72- static inline void ts_free (void * buffer ) {
85+ static inline void ts_free_dflt (void * buffer ) {
7386 free (buffer );
7487}
7588
0 commit comments