From 5a879792ccc2cb7b148d4d6055b98edc7c7b7675 Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Fri, 28 Feb 2025 20:16:41 -0500 Subject: have just a single ZONE_BACKEND definition --- zone.h | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'zone.h') diff --git a/zone.h b/zone.h index bce6796..def53d0 100644 --- a/zone.h +++ b/zone.h @@ -3,6 +3,9 @@ #include +#define ZONE_USE_MALLOC 0 +#define ZONE_USE_MMAP 1 + typedef struct ZoneFrame ZoneFrame; struct ZoneFrame { ZoneFrame *prev, *next; @@ -32,11 +35,20 @@ char *zn_strdup(Zone *z, const char *s); #ifdef ZONE_IMPL #include +#include #include #include "zone.h" -#if defined(ZONE_USE_MMAP) +#ifndef ZONE_BACKEND + #ifdef __unix__ + #define ZONE_BACKEND ZONE_USE_MMAP + #else + #define ZONE_BACKEND ZONE_USE_MALLOC + #endif +#endif + +#if ZONE_BACKEND == ZONE_USE_MMAP #include #include @@ -54,9 +66,7 @@ char *zn_strdup(Zone *z, const char *s); munmap(zf, sizeof *zf + zf->capacity * sizeof(uintptr_t)); } -#else - - #include +#elif ZONE_BACKEND == ZONE_USE_MALLOC #define ZONE_CAPACITY 1024 static ZoneFrame *zn_zf_allocate(size_t capacity) { @@ -71,6 +81,10 @@ char *zn_strdup(Zone *z, const char *s); free(zf); } +#else + + #error "unknown or unsupported zone backend" + #endif static ZoneFrame *zn_zf_new(size_t capacity) { -- cgit 1.4.1-2-gfad0