aboutsummaryrefslogtreecommitdiff
path: root/lib/alloc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/alloc')
-rw-r--r--lib/alloc/alloc_arena.c9
-rw-r--r--lib/alloc/alloc_heap.c (renamed from lib/alloc/heapalloc.c)2
-rw-r--r--lib/alloc/arena_realloc.c7
3 files changed, 14 insertions, 4 deletions
diff --git a/lib/alloc/alloc_arena.c b/lib/alloc/alloc_arena.c
new file mode 100644
index 0000000..9ddc6e2
--- /dev/null
+++ b/lib/alloc/alloc_arena.c
@@ -0,0 +1,9 @@
+#include <stdlib.h>
+
+#include "alloc.h"
+
+void *
+alloc_arena(void *ctx, void *ptr, size_t old, size_t new, size_t align)
+{
+ return arena_realloc(ctx, ptr, old, new, 1, align);
+}
diff --git a/lib/alloc/heapalloc.c b/lib/alloc/alloc_heap.c
index 0a698f0..72cd7ad 100644
--- a/lib/alloc/heapalloc.c
+++ b/lib/alloc/alloc_heap.c
@@ -3,7 +3,7 @@
#include "alloc.h"
void *
-heapalloc(void *, void *ptr, size_t, size_t new)
+alloc_heap(void *, void *ptr, size_t, size_t new, size_t)
{
if (new > 0)
return realloc(ptr, new);
diff --git a/lib/alloc/arena_realloc.c b/lib/alloc/arena_realloc.c
index f13ce17..b30c1b2 100644
--- a/lib/alloc/arena_realloc.c
+++ b/lib/alloc/arena_realloc.c
@@ -11,6 +11,9 @@ arena_realloc(arena *a, void *ptr, size_t old, size_t new, size_t elemsz,
{
ASSUME(a != nullptr);
+ if (ptr == nullptr)
+ return arena_alloc(a, new, elemsz, align);
+
if (old == new)
return ptr;
@@ -55,7 +58,5 @@ arena_realloc(arena *a, void *ptr, size_t old, size_t new, size_t elemsz,
/* At this point we just make a new allocation and copy the data over */
void *dst = arena_alloc(a, new, elemsz, align);
- if (dst == nullptr || ptr == nullptr)
- return nullptr;
- return memcpy(dst, ptr, new * elemsz);
+ return dst == nullptr ? nullptr : memcpy(dst, ptr, new * elemsz);
}