From 3bddf050230635febc16aabe0ba4f73abeed6663 Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Thu, 6 Jun 2019 10:34:01 +0200 Subject: tree-sitter: vendor tree-sitter runtime tree-sitter/tree-sitter commit 7685b7861ca475664b6ef57e14d1da9acf741275 Included files are: lib/include/tree-sitter/*.h lib/src/*.[ch] LICENSE --- src/tree_sitter/alloc.h | 81 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 src/tree_sitter/alloc.h (limited to 'src/tree_sitter/alloc.h') diff --git a/src/tree_sitter/alloc.h b/src/tree_sitter/alloc.h new file mode 100644 index 0000000000..c8fe6c6e6d --- /dev/null +++ b/src/tree_sitter/alloc.h @@ -0,0 +1,81 @@ +#ifndef TREE_SITTER_ALLOC_H_ +#define TREE_SITTER_ALLOC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#if defined(TREE_SITTER_TEST) + +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_toggle_allocation_recording(bool); + +static inline void *ts_malloc(size_t size) { + return ts_record_malloc(size); +} + +static inline void *ts_calloc(size_t count, size_t size) { + return ts_record_calloc(count, size); +} + +static inline void *ts_realloc(void *buffer, size_t size) { + return ts_record_realloc(buffer, size); +} + +static inline void ts_free(void *buffer) { + ts_record_free(buffer); +} + +#else + +#include + +static inline bool ts_toggle_allocation_recording(bool value) { + return false; +} + +static inline void *ts_malloc(size_t size) { + void *result = malloc(size); + if (size > 0 && !result) { + fprintf(stderr, "tree-sitter failed to allocate %lu bytes", size); + exit(1); + } + return result; +} + +static inline void *ts_calloc(size_t count, size_t size) { + void *result = calloc(count, size); + if (count > 0 && !result) { + fprintf(stderr, "tree-sitter failed to allocate %lu bytes", count * size); + exit(1); + } + return result; +} + +static inline void *ts_realloc(void *buffer, size_t size) { + void *result = realloc(buffer, size); + if (size > 0 && !result) { + fprintf(stderr, "tree-sitter failed to reallocate %lu bytes", size); + exit(1); + } + return result; +} + +static inline void ts_free(void *buffer) { + free(buffer); +} + +#endif + +#ifdef __cplusplus +} +#endif + +#endif // TREE_SITTER_ALLOC_H_ -- cgit From 8ff2f193bb3ed94ee215c83c13431d45d382949b Mon Sep 17 00:00:00 2001 From: Björn Linse Date: Fri, 7 Jun 2019 14:05:26 +0200 Subject: tree-sitter: change vendored tree-sitter to use nvim memory management --- src/tree_sitter/alloc.h | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/tree_sitter/alloc.h') diff --git a/src/tree_sitter/alloc.h b/src/tree_sitter/alloc.h index c8fe6c6e6d..2229995bd1 100644 --- a/src/tree_sitter/alloc.h +++ b/src/tree_sitter/alloc.h @@ -9,7 +9,20 @@ extern "C" { #include #include -#if defined(TREE_SITTER_TEST) +#include "nvim/memory.h" + +#if 1 + +static inline bool ts_toggle_allocation_recording(bool value) { + return false; +} + +#define ts_malloc xmalloc +#define ts_calloc xcalloc +#define ts_realloc xrealloc +#define ts_free xfree + +#elif defined(TREE_SITTER_TEST) void *ts_record_malloc(size_t); void *ts_record_calloc(size_t, size_t); -- cgit From 6b949211a06e21af67bf4cb3a20c6f87c932ef2a Mon Sep 17 00:00:00 2001 From: Thomas Vigouroux Date: Wed, 3 Jun 2020 21:33:34 +0200 Subject: treesitter: update runtime Update to 81d533d2d1b580fdb507accabc91ceddffb5b6f0. --- src/tree_sitter/alloc.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/tree_sitter/alloc.h') diff --git a/src/tree_sitter/alloc.h b/src/tree_sitter/alloc.h index 2229995bd1..d3c6b5eca8 100644 --- a/src/tree_sitter/alloc.h +++ b/src/tree_sitter/alloc.h @@ -51,6 +51,7 @@ static inline void ts_free(void *buffer) { #include static inline bool ts_toggle_allocation_recording(bool value) { + (void)value; return false; } -- cgit