summaryrefslogtreecommitdiff
path: root/prism/arena.h
blob: e1fa8fc6ad2c5243676f36753b8682225b3576b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
 * @file arena.h
 *
 * A bump allocator for the prism parser.
 */
#ifndef PRISM_ARENA_H
#define PRISM_ARENA_H

#include "prism/compiler/exported.h"
#include "prism/compiler/nodiscard.h"
#include "prism/compiler/nonnull.h"

#include <stddef.h>

/**
 * An opaque pointer to an arena that is used for allocations.
 */
typedef struct pm_arena_t pm_arena_t;

/**
 * Returns a newly allocated and initialized arena. If the arena cannot be
 * allocated, this function aborts the process.
 *
 * @returns A pointer to the newly allocated arena. It is the responsibility of
 *     the caller to free the arena using pm_arena_free when it is no longer
 *     needed.
 */
PRISM_EXPORTED_FUNCTION PRISM_NODISCARD pm_arena_t * pm_arena_new(void);

/**
 * Frees both the held memory and the arena itself.
 *
 * @param arena The arena to free.
 */
PRISM_EXPORTED_FUNCTION void pm_arena_free(pm_arena_t *arena) PRISM_NONNULL(1);

#endif