| 33 | } |
| 34 | |
| 35 | void *cbm_arena_alloc(CBMArena *a, size_t n) { |
| 36 | if (!a || n == 0) { |
| 37 | return NULL; |
| 38 | } |
| 39 | // 8-byte alignment |
| 40 | n = (n + 7) & ~(size_t)7; |
| 41 | |
| 42 | if (a->nblocks == 0) { |
| 43 | return NULL; |
| 44 | } |
| 45 | |
| 46 | if (a->used + n > a->block_size) { |
| 47 | if (!arena_grow(a, n)) { |
| 48 | return NULL; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | char *ptr = a->blocks[a->nblocks - SKIP_ONE] + a->used; |
| 53 | a->used += n; |
| 54 | return ptr; |
| 55 | } |
| 56 | |
| 57 | char *cbm_arena_strdup(CBMArena *a, const char *s) { |
| 58 | if (!s) |
no test coverage detected