From 7059e4e133b62f5ad3339d51966f226089532710 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Thu, 9 May 2024 15:17:35 +0200 Subject: Try to do better error handling with custom allocators --- lib/alloc/alloc_arena.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'lib/alloc/alloc_arena.c') diff --git a/lib/alloc/alloc_arena.c b/lib/alloc/alloc_arena.c index 9ddc6e2..52d0df9 100644 --- a/lib/alloc/alloc_arena.c +++ b/lib/alloc/alloc_arena.c @@ -1,9 +1,21 @@ #include #include "alloc.h" +#include "errors.h" +#include "macros.h" void * -alloc_arena(void *ctx, void *ptr, size_t old, size_t new, size_t align) +alloc_arena(void *raw_ctx, void *ptr, size_t old, size_t new, size_t align) { - return arena_realloc(ctx, ptr, old, new, 1, align); + struct arena_ctx *ctx = raw_ctx; + ASSUME(ctx != nullptr); + ASSUME(ctx->a != nullptr); + + void *p = arena_realloc(ctx->a, ptr, old, new, 1, align); + if (new == 0 || p != nullptr) + return p; + + if (ctx->jmp != nullptr) + longjmp(*ctx->jmp, 1); + err("arena_realloc:"); } -- cgit v1.2.3