|
Ruby 4.1.0dev (2026-03-20 revision eb04ab9117336f2b3613244cfe8a528c52faf6d6)
|
A bump allocator for the prism parser. More...
#include "prism/defines.h"#include <stddef.h>#include <stdio.h>#include <stdlib.h>#include <string.h>

Go to the source code of this file.
Data Structures | |
| struct | pm_arena_block |
| A single block of memory in the arena. More... | |
| struct | pm_arena_t |
| A bump allocator. More... | |
Typedefs | |
| typedef struct pm_arena_block | pm_arena_block_t |
| A single block of memory in the arena. | |
Functions | |
| void | pm_arena_reserve (pm_arena_t *arena, size_t capacity) |
Ensure the arena has at least capacity bytes available in its current block, allocating a new block if necessary. | |
| void * | pm_arena_alloc_slow (pm_arena_t *arena, size_t size) |
Slow path for pm_arena_alloc: allocate a new block and return a pointer to the first size bytes. | |
| static PRISM_FORCE_INLINE void * | pm_arena_alloc (pm_arena_t *arena, size_t size, size_t alignment) |
| Allocate memory from the arena. | |
| static void * | pm_arena_zalloc (pm_arena_t *arena, size_t size, size_t alignment) |
| Allocate zero-initialized memory from the arena. | |
| static void * | pm_arena_memdup (pm_arena_t *arena, const void *src, size_t size, size_t alignment) |
| Allocate memory from the arena and copy the given data into it. | |
| PRISM_EXPORTED_FUNCTION void | pm_arena_free (pm_arena_t *arena) |
| Free all blocks in the arena. | |
A bump allocator for the prism parser.
Definition in file pm_arena.h.
| typedef struct pm_arena_block pm_arena_block_t |
A single block of memory in the arena.
Blocks are linked via prev pointers so they can be freed by walking the chain.
|
static |
Allocate memory from the arena.
The returned memory is NOT zeroed. This function is infallible — it aborts on allocation failure.
The fast path (bump pointer within the current block) is inlined at each call site. The slow path (new block allocation) is out-of-line.
| arena | The arena to allocate from. |
| size | The number of bytes to allocate. |
| alignment | The required alignment (must be a power of 2). |
Definition at line 80 of file pm_arena.h.
Referenced by pm_arena_memdup(), pm_arena_zalloc(), pm_constant_id_list_append(), pm_constant_pool_init(), pm_diagnostic_list_append_format(), pm_line_offset_list_append_slow(), pm_line_offset_list_init(), and pm_parser::pm_parser_init().
| void * pm_arena_alloc_slow | ( | pm_arena_t * | arena, |
| size_t | size | ||
| ) |
Slow path for pm_arena_alloc: allocate a new block and return a pointer to the first size bytes.
Do not call directly — use pm_arena_alloc instead.
| arena | The arena to allocate from. |
| size | The number of bytes to allocate. |
Called when the current block has insufficient space.
Definition at line 74 of file pm_arena.c.
Referenced by pm_arena_alloc().
| PRISM_EXPORTED_FUNCTION void pm_arena_free | ( | pm_arena_t * | arena | ) |
Free all blocks in the arena.
After this call, all pointers returned by pm_arena_alloc and pm_arena_zalloc are invalid.
| arena | The arena to free. |
Definition at line 84 of file pm_arena.c.
|
inlinestatic |
Allocate memory from the arena and copy the given data into it.
This is a convenience wrapper around pm_arena_alloc + memcpy.
| arena | The arena to allocate from. |
| src | The source data to copy. |
| size | The number of bytes to allocate and copy. |
| alignment | The required alignment (must be a power of 2). |
Definition at line 121 of file pm_arena.h.
| void pm_arena_reserve | ( | pm_arena_t * | arena, |
| size_t | capacity | ||
| ) |
Ensure the arena has at least capacity bytes available in its current block, allocating a new block if necessary.
This allows callers to pre-size the arena to avoid repeated small block allocations.
| arena | The arena to pre-size. |
| capacity | The minimum number of bytes to ensure are available. |
This allows callers to pre-size the arena to avoid repeated small block allocations.
Definition at line 63 of file pm_arena.c.
|
inlinestatic |
Allocate zero-initialized memory from the arena.
This function is infallible — it aborts on allocation failure.
| arena | The arena to allocate from. |
| size | The number of bytes to allocate. |
| alignment | The required alignment (must be a power of 2). |
Definition at line 104 of file pm_arena.h.
Referenced by pm_constant_id_list_init_capacity(), pm_constant_pool_init(), pm_diagnostic_list_append(), and pm_diagnostic_list_append_format().