diff --git a/configure.ac b/configure.ac index 0a015fe48..90a6d45d5 100644 --- a/configure.ac +++ b/configure.ac @@ -366,7 +366,7 @@ fi AC_ARG_ENABLE(gc, AS_HELP_STRING([--enable-gc],[enable garbage collection in the Nix expression evaluator (requires Boehm GC) [default=yes]]), gc=$enableval, gc=yes) if test "$gc" = yes; then - PKG_CHECK_MODULES([BDW_GC], [bdw-gc >= 8.2.4]) + PKG_CHECK_MODULES([BDW_GC], [bdw-gc]) CXXFLAGS="$BDW_GC_CFLAGS $CXXFLAGS" AC_DEFINE(HAVE_BOEHMGC, 1, [Whether to use the Boehm garbage collector.]) fi diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 30521b072..1eb60a1b8 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -348,14 +348,14 @@ void initGC() GC_set_oom_fn(oomHandler); - // TODO: Comment suggests an implementation that works on darwin and windows - // https://github.com/ivmai/bdwgc/issues/362#issuecomment-1936672196 - #ifndef __APPLE__ - GC_set_sp_corrector(&fixupBoehmStackPointer); - #endif - StackAllocator::defaultAllocator = &boehmGCStackAllocator; + // TODO: Remove __APPLE__ condition. + // Comment suggests an implementation that works on darwin and windows + // https://github.com/ivmai/bdwgc/issues/362#issuecomment-1936672196 + #if GC_VERSION_MAJOR >= 8 && GC_VERSION_MINOR >= 4 && !defined(__APPLE__) + GC_set_sp_corrector(&fixupBoehmStackPointer); + if (!GC_get_sp_corrector()) { printTalkative("BoehmGC on this platform does not support sp_corrector; will disable GC inside coroutines"); /* Used to disable GC when entering coroutines on macOS */ @@ -363,6 +363,10 @@ void initGC() return std::make_shared(); }; } + #else + #warning "BoehmGC version does not support GC while coroutine exists. GC will be disabled inside coroutines. Consider updating bwd-gc to 8.4 or later." + #endif + /* Set the initial heap size to something fairly big (25% of physical RAM, up to a maximum of 384 MiB) so that in most cases