diff options
| author | @syxhe <https://t.me/syxhe> | 2025-03-28 17:23:55 -0500 |
|---|---|---|
| committer | @syxhe <https://t.me/syxhe> | 2025-03-28 17:23:55 -0500 |
| commit | 97713275dc87ea1d0afa4fd6bc49f695ad40efc0 (patch) | |
| tree | 3bd1d8c14639808a66b3a5b6e7a27f6a7261cce5 /src/arena.c | |
| parent | cfdd25cdd8efabaa43446036e0ff0c326c001f8f (diff) | |
Create xalloc function and wrappers, fix XALLOC_EXIT usages to comply with ISO C99
Diffstat (limited to 'src/arena.c')
| -rw-r--r-- | src/arena.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/arena.c b/src/arena.c index 36a9ce7..62dbbf8 100644 --- a/src/arena.c +++ b/src/arena.c | |||
| @@ -23,6 +23,7 @@ typedef struct arena { | |||
| 23 | arenanode *current; | 23 | arenanode *current; |
| 24 | 24 | ||
| 25 | // For keeping track of the largest possible thing that can be allocated to one node | 25 | // For keeping track of the largest possible thing that can be allocated to one node |
| 26 | // I don't know if I care to keep this or remove it. I'll see if it becomes a problem / is useful | ||
| 26 | size_t node_memspace; | 27 | size_t node_memspace; |
| 27 | } arena; | 28 | } arena; |
| 28 | 29 | ||
| @@ -49,7 +50,7 @@ arenanode * arenanode_init(size_t bytes) { | |||
| 49 | 50 | ||
| 50 | arena * arena_init(size_t bytes) { | 51 | arena * arena_init(size_t bytes) { |
| 51 | if(!ISPOWOF2(MEM_ALIGN_BYTES)) | 52 | if(!ISPOWOF2(MEM_ALIGN_BYTES)) |
| 52 | XALLOC_EXIT("<arena_init> \"MEM_ALIGN_BYTES\" is not a power of 2. Refusing to create a new arena"); | 53 | XALLOC_EXIT("<arena_init> \"MEM_ALIGN_BYTES\" is not a power of 2. Refusing to create a new arena", ); |
| 53 | 54 | ||
| 54 | arena *a = VALLOC(1, sizeof(arena)); | 55 | arena *a = VALLOC(1, sizeof(arena)); |
| 55 | if(!a) | 56 | if(!a) |
| @@ -73,7 +74,7 @@ arena * arena_init(size_t bytes) { | |||
| 73 | 74 | ||
| 74 | void * arena_alloc(arena * const arena, size_t bytes) { | 75 | void * arena_alloc(arena * const arena, size_t bytes) { |
| 75 | if(!ISPOWOF2(MEM_ALIGN_BYTES)) | 76 | if(!ISPOWOF2(MEM_ALIGN_BYTES)) |
| 76 | XALLOC_EXIT("<arena_alloc> \"MEM_ALIGN_BYTES\" is not a power of 2. Refusing to allocate any memory"); | 77 | XALLOC_EXIT("<arena_alloc> \"MEM_ALIGN_BYTES\" is not a power of 2. Refusing to allocate any memory", ); |
| 77 | if(!arena) | 78 | if(!arena) |
| 78 | RETURNWERR(EINVAL, NULL); | 79 | RETURNWERR(EINVAL, NULL); |
| 79 | if(bytes > arena->node_memspace) | 80 | if(bytes > arena->node_memspace) |
