Ruby 4.1.0dev (2026-03-07 revision fd9448bc87a51482564ac997e0c1c6e5f36e7927)
Data Structures | Typedefs | Functions
pm_arena.h File Reference

(fd9448bc87a51482564ac997e0c1c6e5f36e7927)

A bump allocator for the prism parser. More...

#include "prism/defines.h"
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for pm_arena.h:
This graph shows which files directly or indirectly include this file:

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_alloc (pm_arena_t *arena, size_t size, size_t alignment)
 Allocate memory from the arena.
 
void * pm_arena_zalloc (pm_arena_t *arena, size_t size, size_t alignment)
 Allocate zero-initialized memory from the arena.
 
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.
 

Detailed Description

A bump allocator for the prism parser.

Definition in file pm_arena.h.

Typedef Documentation

◆ 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.

Function Documentation

◆ pm_arena_alloc()

void * pm_arena_alloc ( pm_arena_t arena,
size_t  size,
size_t  alignment 
)

Allocate memory from the arena.

The returned memory is NOT zeroed. This function is infallible — it aborts on allocation failure.

Parameters
arenaThe arena to allocate from.
sizeThe number of bytes to allocate.
alignmentThe required alignment (must be a power of 2).
Returns
A pointer to the allocated memory.

The returned memory is NOT zeroed. This function is infallible — it aborts on allocation failure.

Definition at line 37 of file pm_arena.c.

◆ pm_arena_free()

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.

Parameters
arenaThe arena to free.

Definition at line 95 of file pm_arena.c.

◆ pm_arena_memdup()

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.

This is a convenience wrapper around pm_arena_alloc + memcpy.

Parameters
arenaThe arena to allocate from.
srcThe source data to copy.
sizeThe number of bytes to allocate and copy.
alignmentThe required alignment (must be a power of 2).
Returns
A pointer to the allocated copy.

Definition at line 85 of file pm_arena.c.

◆ pm_arena_zalloc()

void * pm_arena_zalloc ( pm_arena_t arena,
size_t  size,
size_t  alignment 
)

Allocate zero-initialized memory from the arena.

This function is infallible — it aborts on allocation failure.

Parameters
arenaThe arena to allocate from.
sizeThe number of bytes to allocate.
alignmentThe required alignment (must be a power of 2).
Returns
A pointer to the allocated, zero-initialized memory.

This function is infallible — it aborts on allocation failure.

Definition at line 75 of file pm_arena.c.