5#if defined(__SANITIZE_ADDRESS__)
6#include <sanitizer/asan_interface.h>
46#define allocator_alloc_ty(ty, allocator, sz) \
47 (ty *)allocator_alloc(allocator, sizeof(ty) * sz)
53 const void *data,
sz size) {
55 memcpy(ptr, data, size);
62#define allocator_alloc_copy_ty(ty, allocator, data, sz) \
63 (ty *)allocator_alloc_copy(allocator, data, sizeof(ty) * sz)
70 ASSERT_(allocator.
realloc,
"This allocator does not implement `realloc`");
84 return malloc(new_size);
88static void *alloc_malloc__realloc(
allocator_ptr allocator,
void *memory,
90 return realloc(memory, new_size);
94static void alloc_malloc__free(
allocator_ptr allocator,
void *memory) {
102 ret.
alloc = alloc_malloc__alloc;
103 ret.
realloc = alloc_malloc__realloc;
104 ret.
free = alloc_malloc__free;
110 return alloca(new_size);
125#if defined(__SANITIZE_ADDRESS__)
126#define poison_memory_region(ptr, sz) __asan_poison_memory_region(ptr, sz)
128#define poison_memory_region(ptr, sz)
133#if defined(__SANITIZE_ADDRESS__)
134#define unpoison_memory_region(ptr, sz) __asan_unpoison_memory_region(ptr, sz)
136#define unpoison_memory_region(ptr, sz)
size_t sz
Definition defs.h:51
#define ASSERT_(expr, msg)
Definition defs.h:29
void() mem_free_f(allocator_ptr allocator, void *memory)
Give up the ownership of the memory within the allocator.
Definition memory.h:25
void *() mem_realloc_f(allocator_ptr allocator, void *memory, sz new_size)
Reallocate the memory at memory to a new location with.
Definition memory.h:21
static allocator_t allocator_new_malloc()
Wrap malloc into an generic allocator interface.
Definition memory.h:99
void * allocator_ptr
Opaque type-erased pointer to an allocator. Carries no value other than marking an argument to the fu...
Definition memory.h:15
static void * alloc_stack_alloc__alloc(allocator_ptr allocator, sz new_size)
Definition memory.h:109
void *() mem_alloc_f(allocator_ptr allocator, sz size)
Allocate size bytes using the allocator
Definition memory.h:18
static allocator_t allocator_new_stack_alloc()
Definition memory.h:113
A generic allocator type passed by value. Contains a fallback allocator and a set of function pointer...
Definition memory.h:30
static void * allocator_alloc_copy(allocator_t allocator, const void *data, sz size)
Copy size bytes of data from data into a freshly allocated slice using the allocator.
Definition memory.h:52
static void * allocator_alloc(allocator_t allocator, sz size)
Proxy the allocation to the actual allocator.
Definition memory.h:40
static void * allocator_realloc(allocator_t allocator, void *memory, sz size)
Move memory to a new memory region with at least size bytes. If an allocator does not implement reall...
Definition memory.h:68
mem_alloc_f * alloc
Definition memory.h:33
mem_free_f * free
Definition memory.h:35
static void allocator_free(allocator_t allocator, void *memory)
Release memory back to the allocator.
Definition memory.h:76
allocator_ptr allocator
A pointer to the actual underyling allocator, type-erased.
Definition memory.h:32
mem_realloc_f * realloc
Definition memory.h:34