5#include <sanitizer/asan_interface.h>
11#define LIST_DEFAULT_CAPACITY 6
23 sz entry_size,
sz capacity) {
27 ls->
data = allocator_alloc(alloc, entry_size * ls->
_capacity);
36#define list_init_ty(ty, ls, alloc) list_init(ls, alloc, sizeof(ty))
38#define list_init_ty_with_capacity(ty, ls, alloc, capacity) \
39 list_init_with_capacity(ls, alloc, sizeof(ty), capacity)
42 sz entry_size,
sz count) {
46 ls->
data = allocator_alloc_copy(alloc, data, count * entry_size);
51#define list_init_copy_ty(ty, ls, alloc, data, count) \
52 list_init_copy(ls, alloc, data, sizeof(ty), count)
79 memcpy(ptr, data, ls->
_entry);
83#define list_push_var(ls, var) \
84 ASSERT(sizeof(var) == (ls)->_entry, \
85 "Attempt to push a variable of size %ld into a list that expects " \
87 sizeof(var), (ls)->_entry); \
94 if (idx == ls->
size) {
101 "Insertion index must be less must be within the list (idx=%d size=%d)",
102 (
int)idx, (
int)ls->
size);
106 sz count_to_move = ls->
size - idx;
107 memmove(&((
char *)ls->
data)[(idx + 1) * ls->
_entry],
115 "Size of a pushed value (%d) must match the entry size defined at "
116 "initilization (%d)",
123 ASSERT(idx < ls->size,
"Index %ld too large (size=%ld)", idx, ls->
size);
125 return (
void *)(&((
char *)ls->
data)[idx * ls->
_entry]);
128#define list_get_ty_ptr(ty, ls, idx) ((ty *)list_get(ls, idx))
130#define list_get_ty(ty, ls, idx) (*list_get_ty_ptr(ty, ls, idx))
152 if (idx == ls->
size) {
153 list_pop_tail(ls, 0);
156 byte *data = (
byte *)ls->
data;
157 byte *tail = data + ls->
_entry * (ls->
size + idx);
#define ASSERT(expr, msg,...)
Definition defs.h:35
int32_t i32
Definition defs.h:47
#define ASSERT__(expr)
Definition defs.h:21
size_t sz
Definition defs.h:51
static void list_init_int(list_t *ls, allocator_t alloc)
Definition list.h:54
static void list_init(list_t *ls, allocator_t alloc, sz entry_size)
Definition list.h:32
static void list_init_copy(list_t *ls, allocator_t alloc, void *data, sz entry_size, sz count)
Definition list.h:41
static void list_init_with_capacity(list_t *ls, allocator_t alloc, sz entry_size, sz capacity)
Definition list.h:22
static void list_cleanup(list_t *ls)
Definition list.h:166
static void list_push(list_t *ls, const void *data)
Definition list.h:72
static void list_insert(list_t *ls, sz idx, const void *data)
Definition list.h:90
#define LIST_DEFAULT_CAPACITY
Definition list.h:11
static void list_grow(list_t *ls)
Definition list.h:60
static void list_push_int(list_t *ls, const i32 value)
Definition list.h:113
static void * list_get(list_t *ls, sz idx)
Definition list.h:122
static void list_clear(list_t *ls)
Definition list.h:161
#define unpoison_memory_region(ptr, sz)
Makes previously poisoned memory safe again. Idemponent. Pair of poison_memory_region....
Definition memory.h:136
#define poison_memory_region(ptr, sz)
If compiled with a memory sanitizer, any write to the brief selected memory will crash the program....
Definition memory.h:128
A generic allocator type passed by value. Contains a fallback allocator and a set of function pointer...
Definition memory.h:30
void * data
Definition list.h:19
allocator_t _alloc
Definition list.h:14
static void list_remove(list_t *ls, sz idx)
Removes an element at index idx. Panics if the index is out of range.
Definition list.h:149
sz size
Definition list.h:17
sz _capacity
Definition list.h:16
sz _entry
Definition list.h:15
static bool list_pop_tail(list_t *ls, void *out)
Removes the last index in the list. Returns true if the element was removed and false if the list was...
Definition list.h:137