From 649977aae7e5922f992cd69eb84da0a2db368580 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Wed, 24 Dec 2025 12:45:29 -0500 Subject: Split out new()/gc logic from stdlib/util.h --- src/stdlib/util.h | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/stdlib/util.h') diff --git a/src/stdlib/util.h b/src/stdlib/util.h index db667ccf..3ab025f4 100644 --- a/src/stdlib/util.h +++ b/src/stdlib/util.h @@ -4,7 +4,6 @@ #include #include -#include #include #include @@ -12,9 +11,6 @@ #define starts_with(line, prefix) (strncmp(line, prefix, strlen(prefix)) == 0) #define ends_with(line, suffix) \ (strlen(line) >= strlen(suffix) && strcmp(line + strlen(line) - strlen(suffix), suffix) == 0) -#define new(t, ...) ((t *)memcpy(GC_MALLOC(sizeof(t)), &(t){__VA_ARGS__}, sizeof(t))) -#define heap(x) (__typeof(x) *)memcpy(GC_MALLOC(sizeof(x)), (__typeof(x)[1]){x}, sizeof(x)) -#define stack(x) (__typeof(x) *)((__typeof(x)[1]){x}) #define check_initialized(var, init_var, name) \ *({ \ if (!init_var) fail("The variable " name " is being accessed before it has been initialized!"); \ @@ -61,3 +57,10 @@ #define MACROLIKE extern inline __attribute__((gnu_inline, always_inline)) #endif #endif + +#ifndef GC_MALLOC +extern void *GC_malloc(size_t); +#define GC_MALLOC GC_malloc +#define heap(x) (__typeof(x) *)memcpy(GC_malloc(sizeof(x)), (__typeof(x)[1]){x}, sizeof(x)) +#define stack(x) (__typeof(x) *)((__typeof(x)[1]){x}) +#endif -- cgit v1.2.3