summaryrefslogtreecommitdiff
path: root/prism/defines.h
diff options
context:
space:
mode:
authorHASUMI Hitoshi <[email protected]>2024-02-27 14:25:22 +0900
committergit <[email protected]>2024-03-04 16:40:23 +0000
commitc4bd6da2988ecdf3e6d00be78e58a4eba6192bed (patch)
treef5cc0976ae7ff16bac9913f02ec4d32adef41160 /prism/defines.h
parent61ea202f8b10060e000f79a936e5e608eacb50ee (diff)
[ruby/prism] Make alloc interface replaceable
- Add `x` prefix to malloc, calloc, realloc, and free (eg: malloc -> xmalloc) - By default, they are replaced with stdlib's functions at build - You can use custom functions by defining `PRISM_CUSTOM_ALLOCATOR` macro https://github.com/ruby/prism/commit/7a878af619
Diffstat (limited to 'prism/defines.h')
-rw-r--r--prism/defines.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/prism/defines.h b/prism/defines.h
index 6c09f108c2..00ed80209a 100644
--- a/prism/defines.h
+++ b/prism/defines.h
@@ -125,4 +125,27 @@
# define isinf(x) (sizeof(x) == sizeof(float) ? !_finitef(x) : !_finite(x))
#endif
+/**
+ * If you build prism with a custom allocator, configure it with "-D PRISM_CUSTOM_ALLOCATOR"
+ * to use your own allocator that defines xmalloc, xrealloc, xcalloc, and xfree.
+ * For example, your `custom_allocator.h` file could look like this:
+ * ```
+ * #ifndef PRISM_CUSTOM_ALLOCATOR_H
+ * #define PRISM_CUSTOM_ALLOCATOR_H
+ * #define xmalloc my_malloc
+ * #define xrealloc my_realloc
+ * #define xcalloc my_calloc
+ * #define xfree my_free
+ * #endif
+ * ```
+ */
+#ifdef PRISM_CUSTOM_ALLOCATOR
+# include "custom_allocator.h"
+#else
+# define xmalloc malloc
+# define xrealloc realloc
+# define xcalloc calloc
+# define xfree free
+#endif
+
#endif