Graphviz 13.1.3~dev.20250813.2319
Loading...
Searching...
No Matches
arena.c File Reference

Implementation of the arena.h API. More...

#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <util/alloc.h>
#include <util/arena.h>
#include <util/asan.h>
#include <util/unused.h>
Include dependency graph for arena.c:

Go to the source code of this file.

Data Structures

struct  arena_chunk
 

Functions

static UNUSED bool is_power_of_2 (size_t value)
 popcount(value) == 1?
 
static void more_core (arena_t *arena, size_t req_alignment, size_t req_size)
 
static void * alloc (arena_t *arena, size_t alignment, size_t size)
 
void * gv_arena_alloc (arena_t *arena, size_t alignment, size_t size)
 
char * gv_arena_strdup (arena_t *arena, const char *s)
 
void gv_arena_free (arena_t *arena, void *ptr, size_t size)
 
void gv_arena_reset (arena_t *arena)
 

Function Documentation

◆ alloc()

static void * alloc ( arena_t arena,
size_t  alignment,
size_t  size 
)
static

allocate new dynamic memory

Parameters
arenaArena to allocate from
alignmentRequested alignment
sizeRequested size in bytes
Returns
Pointer to allocated memory or NULL on failure

Definition at line 71 of file arena.c.

References ASAN_UNPOISON, is_power_of_2(), NULL, arena_t::remaining, and arena_t::source.

Referenced by gv_arena_alloc().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gv_arena_alloc()

void * gv_arena_alloc ( arena_t arena,
size_t  alignment,
size_t  size 
)

allocate new memory

The requested alignment must be a power of two. The returned memory is zero initialized.

Parameters
arenaArena to allocate from
alignmentRequired pointer alignment for the resulting allocation
sizeNumber of bytes requested
Returns
Pointer to allocated memory

Definition at line 116 of file arena.c.

References alloc(), more_core(), and NULL.

Referenced by eval(), exprintf(), exsplit(), exstralloc(), exsubstr(), extoken_fn(), extokens(), getdyn(), gv_arena_strdup(), prformat(), scformat(), str_add(), str_and(), str_ior(), str_mod(), str_mpy(), and str_xor().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gv_arena_free()

void gv_arena_free ( arena_t arena,
void *  ptr,
size_t  size 
)

deallocate memory

Parameters
arenaArena that was previously used to allocate this memory
ptrPointer to memory to release
sizeNumber of bytes of the original allocation

Definition at line 147 of file arena.c.

References ASAN_POISON, and NULL.

Referenced by prformat(), and scformat().

Here is the caller graph for this function:

◆ gv_arena_reset()

void gv_arena_reset ( arena_t arena)

deallocate all memory

Calling this restores the arena to an empty state from which it can be used for more allocations.

Parameters
arenaArena to reset

Definition at line 162 of file arena.c.

References free(), NULL, arena_chunk::previous, and arena_t::source.

Referenced by ELcleanup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ gv_arena_strdup()

char * gv_arena_strdup ( arena_t arena,
const char *  s 
)

copy a string into new dynamic memory

Parameters
arenaArena to allocate from
sSource string to copy
Returns
A copy of the string, hosted in arena-allocated memory

Definition at line 134 of file arena.c.

References gv_arena_alloc(), len(), and NULL.

Referenced by eval(), exstring(), exsub(), extoken_fn(), and prformat().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_power_of_2()

static UNUSED bool is_power_of_2 ( size_t  value)
static

Definition at line 23 of file arena.c.

Referenced by alloc().

Here is the caller graph for this function:

◆ more_core()

static void more_core ( arena_t arena,
size_t  req_alignment,
size_t  req_size 
)
static

get some more memory from the system allocator

Parameters
arenaArena to install the new memory into
req_alignmentAlignment request that led to this call
req_sizeSize request that led to this call

Definition at line 38 of file arena.c.

References ASAN_POISON, gv_alloc(), NULL, arena_chunk::previous, arena_t::remaining, and arena_t::source.

Referenced by gv_arena_alloc().

Here is the call graph for this function:
Here is the caller graph for this function: