diff options
| author | kartofen <kartofen.mail.0@protonmail.com> | 2025-07-24 23:43:25 +0300 |
|---|---|---|
| committer | kartofen <kartofen.mail.0@protonmail.com> | 2025-07-24 23:43:25 +0300 |
| commit | 059ee9afcc575572f87f224c93288e2835cd1a52 (patch) | |
| tree | 07c315c5bfa192722e4bfb974b1df651089fbacc /util/arena.h | |
| parent | 1d6f6e7c6a07832b3524871fdec86f5329736598 (diff) | |
actually parsing grammar and generating a def.c file
Diffstat (limited to 'util/arena.h')
| -rw-r--r-- | util/arena.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/util/arena.h b/util/arena.h index 3d82b95..1142321 100644 --- a/util/arena.h +++ b/util/arena.h @@ -9,18 +9,26 @@ struct arena_ctx { size_t offset; }; + #define ARENA_CTX_INIT(buffer, sz) (struct arena_ctx){(buffer), (sz), 0} void *arena_allocate(struct arena_ctx *ctx, size_t sz); void arena_reset(struct arena_ctx *ctx); #ifdef ARENA_IMPLEMENTATION +#define ARENA_ALLIGNMENT 2 +// #include <assert.h> void *arena_allocate(struct arena_ctx *ctx, size_t sz) { + if(sz % ARENA_ALLIGNMENT != 0) + sz += ARENA_ALLIGNMENT - (sz % ARENA_ALLIGNMENT); + if(ctx->offset + sz > ctx->size) return NULL; - void *off = ctx->buffer + ctx->offset; + void *off = (void *)((intptr_t)ctx->buffer + ctx->offset); ctx->offset += sz; + + // assert(((intptr_t)off & 0x1) == 0); return off; } |
