From fc3f948b02b4b4a50907284645df93fe86bcc1fa Mon Sep 17 00:00:00 2001 From: Kristian Larsson Date: Wed, 13 Mar 2024 10:28:56 +0100 Subject: [PATCH] build.zig: Support ignore_free Add new enable_ignore_free option to build.zig and fix an actual bug related to the implementation of ignore_free. That it was a comment must have been a mistake. --- build.zig | 6 ++++++ malloc.c | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/build.zig b/build.zig index c3ab0e595..5baca8a92 100644 --- a/build.zig +++ b/build.zig @@ -88,6 +88,8 @@ pub fn build(b: *std.Build) void { "Support for atomic uncollectible allocation") orelse true; const enable_redirect_malloc = b.option(bool, "enable_redirect_malloc", "Redirect malloc and friend to GC routines") orelse false; + const enable_ignore_free = b.option(bool, "enable_ignore_free", + "Ignore calls to free") orelse false; const enable_disclaim = b.option(bool, "enable_disclaim", "Support alternative finalization interface") orelse true; const enable_dynamic_pointer_mask = b.option(bool, @@ -303,6 +305,10 @@ pub fn build(b: *std.Build) void { } } + if (enable_ignore_free) { + flags.append("-D IGNORE_FREE") catch unreachable; + } + if (enable_mmap or enable_munmap) { flags.append("-D USE_MMAP") catch unreachable; } diff --git a/malloc.c b/malloc.c index 20a49eda2..e3e17e76a 100644 --- a/malloc.c +++ b/malloc.c @@ -698,7 +698,7 @@ GC_API void GC_CALL GC_free(void * p) void free(void * p) { # ifdef IGNORE_FREE -# UNUSED_ARG(p); + UNUSED_ARG(p); # else # if defined(GC_LINUX_THREADS) && !defined(USE_PROC_FOR_LIBRARIES) /* Don't bother with initialization checks. If nothing */