summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zone.h22
1 files changed, 18 insertions, 4 deletions
diff --git a/zone.h b/zone.h
index bce6796..def53d0 100644
--- a/zone.h
+++ b/zone.h
@@ -3,6 +3,9 @@
#include <stdint.h>
+#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 <stdio.h>
+#include <stdlib.h>
#include <string.h>
#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 <sys/mman.h>
#include <unistd.h>
@@ -54,9 +66,7 @@ char *zn_strdup(Zone *z, const char *s);
munmap(zf, sizeof *zf + zf->capacity * sizeof(uintptr_t));
}
-#else
-
- #include <stdlib.h>
+#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) {