1
0

alloc.h 985 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef TREE_SITTER_ALLOC_H_
  2. #define TREE_SITTER_ALLOC_H_
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <stdbool.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. // Allow clients to override allocation functions
  10. #ifdef TREE_SITTER_REUSE_ALLOCATOR
  11. extern void *(*ts_current_malloc)(size_t size);
  12. extern void *(*ts_current_calloc)(size_t count, size_t size);
  13. extern void *(*ts_current_realloc)(void *ptr, size_t size);
  14. extern void (*ts_current_free)(void *ptr);
  15. #ifndef ts_malloc
  16. #define ts_malloc ts_current_malloc
  17. #endif
  18. #ifndef ts_calloc
  19. #define ts_calloc ts_current_calloc
  20. #endif
  21. #ifndef ts_realloc
  22. #define ts_realloc ts_current_realloc
  23. #endif
  24. #ifndef ts_free
  25. #define ts_free ts_current_free
  26. #endif
  27. #else
  28. #ifndef ts_malloc
  29. #define ts_malloc malloc
  30. #endif
  31. #ifndef ts_calloc
  32. #define ts_calloc calloc
  33. #endif
  34. #ifndef ts_realloc
  35. #define ts_realloc realloc
  36. #endif
  37. #ifndef ts_free
  38. #define ts_free free
  39. #endif
  40. #endif
  41. #ifdef __cplusplus
  42. }
  43. #endif
  44. #endif // TREE_SITTER_ALLOC_H_