Ruby 4.1.0dev (2026-08-28 revision 5eb9a6925b805a17dced976d5b741afe5086aab1)
allocator.h
1#ifndef PRISM_INTERNAL_ALLOCATOR_H
2#define PRISM_INTERNAL_ALLOCATOR_H
3
4/* If you build Prism with a custom allocator, configure it with
5 * "-D PRISM_XALLOCATOR" to use your own allocator that defines xmalloc,
6 * xrealloc, xcalloc, and xfree.
7 *
8 * For example, your `prism_xallocator.h` file could look like this:
9 *
10 * ```
11 * #ifndef PRISM_XALLOCATOR_H
12 * #define PRISM_XALLOCATOR_H
13 * #define xmalloc my_malloc
14 * #define xrealloc my_realloc
15 * #define xcalloc my_calloc
16 * #define xfree my_free
17 * #define xrealloc_sized my_realloc_sized // (optional)
18 * #define xfree_sized my_free_sized // (optional)
19 * #endif
20 * ```
21 */
22#ifdef PRISM_XALLOCATOR
23 #include "prism_xallocator.h"
24#else
25 #ifndef xmalloc
26 /* The malloc function that should be used. This can be overridden with
27 * the PRISM_XALLOCATOR define. */
28 #define xmalloc malloc
29 #endif
30
31 #ifndef xrealloc
32 /* The realloc function that should be used. This can be overridden with
33 * the PRISM_XALLOCATOR define. */
34 #define xrealloc realloc
35 #endif
36
37 #ifndef xcalloc
38 /* The calloc function that should be used. This can be overridden with
39 * the PRISM_XALLOCATOR define. */
40 #define xcalloc calloc
41 #endif
42
43 #ifndef xfree
44 /* The free function that should be used. This can be overridden with
45 * the PRISM_XALLOCATOR define. */
46 #define xfree free
47 #endif
48#endif
49
50#ifndef xfree_sized
51 /* The free_sized function that should be used. This can be overridden with
52 * the PRISM_XALLOCATOR define. If not defined, defaults to calling xfree.
53 */
54 #define xfree_sized(p, s) xfree(((void)(s), (p)))
55#endif
56
57#ifndef xrealloc_sized
58 /* The xrealloc_sized function that should be used. This can be overridden
59 * with the PRISM_XALLOCATOR define. If not defined, defaults to calling
60 * xrealloc. */
61 #define xrealloc_sized(p, ns, os) xrealloc((p), ((void)(os), (ns)))
62#endif
63
64#ifdef PRISM_BUILD_DEBUG
65 #include "prism/internal/allocator_debug.h"
66#endif
67
68#endif