forked from smacker/go-tree-sitter
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
941 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include "alloc.h" | ||
#include <stdlib.h> | ||
|
||
static void *ts_malloc_default(size_t size) { | ||
void *result = malloc(size); | ||
if (size > 0 && !result) { | ||
fprintf(stderr, "tree-sitter failed to allocate %zu bytes", size); | ||
exit(1); | ||
} | ||
return result; | ||
} | ||
|
||
static void *ts_calloc_default(size_t count, size_t size) { | ||
void *result = calloc(count, size); | ||
if (count > 0 && !result) { | ||
fprintf(stderr, "tree-sitter failed to allocate %zu bytes", count * size); | ||
exit(1); | ||
} | ||
return result; | ||
} | ||
|
||
static void *ts_realloc_default(void *buffer, size_t size) { | ||
void *result = realloc(buffer, size); | ||
if (size > 0 && !result) { | ||
fprintf(stderr, "tree-sitter failed to reallocate %zu bytes", size); | ||
exit(1); | ||
} | ||
return result; | ||
} | ||
|
||
// Allow clients to override allocation functions dynamically | ||
void *(*ts_current_malloc)(size_t) = ts_malloc_default; | ||
void *(*ts_current_calloc)(size_t, size_t) = ts_calloc_default; | ||
void *(*ts_current_realloc)(void *, size_t) = ts_realloc_default; | ||
void (*ts_current_free)(void *) = free; | ||
|
||
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 *) | ||
) { | ||
ts_current_malloc = new_malloc ? new_malloc : ts_malloc_default; | ||
ts_current_calloc = new_calloc ? new_calloc : ts_calloc_default; | ||
ts_current_realloc = new_realloc ? new_realloc : ts_realloc_default; | ||
ts_current_free = new_free ? new_free : free; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
// Determine endian and pointer size based on known defines. | ||
// TS_BIG_ENDIAN and TS_PTR_SIZE can be set as -D compiler arguments | ||
// to override this. | ||
|
||
#if !defined(TS_BIG_ENDIAN) | ||
#if (defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) \ | ||
|| (defined( __APPLE_CC__) && (defined(__ppc__) || defined(__ppc64__))) | ||
#define TS_BIG_ENDIAN 1 | ||
#else | ||
#define TS_BIG_ENDIAN 0 | ||
#endif | ||
#endif | ||
|
||
#if !defined(TS_PTR_SIZE) | ||
#if UINTPTR_MAX == 0xFFFFFFFF | ||
#define TS_PTR_SIZE 32 | ||
#else | ||
#define TS_PTR_SIZE 64 | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.