From b437ae3feb3fc8beeb63ccbfe439236375b077a3 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Mon, 28 Sep 2026 16:53:57 -0500 Subject: [PATCH] Apply fix for #1888 from Paolo Marrone Just mark janet_vm.top_dyns during mark phase of collection. It was skipped as it is not part of the usual interpreter flow and was missed in testing. Also add a test case for it. --- src/boot/system_test.c | 8 ++++++++ src/core/gc.c | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/boot/system_test.c b/src/boot/system_test.c index 13e2edef..62846a61 100644 --- a/src/boot/system_test.c +++ b/src/boot/system_test.c @@ -79,5 +79,13 @@ int system_test() { assert(janet_equals(tuple1, tuple2)); + /* System test for GC bug #1888 */ + JanetTable *env = janet_core_env(NULL); + janet_setdyn("probe", janet_wrap_integer(42)); + assert(!janet_dostring(env, "(gccollect)", "gc", NULL)); + Janet value = janet_dyn("probe"); + assert(janet_checktype(value, JANET_NUMBER)); + assert(janet_unwrap_integer(value) == 42); + return 0; } diff --git a/src/core/gc.c b/src/core/gc.c index f609bcc2..cd1ef1b1 100644 --- a/src/core/gc.c +++ b/src/core/gc.c @@ -592,6 +592,9 @@ void janet_collect(void) { #ifdef JANET_EV janet_ev_mark(); #endif + if (janet_vm.top_dyns) { + janet_mark(janet_wrap_table(janet_vm.top_dyns)); + } if (janet_vm.root_fiber != NULL) { /* Can be NULL if janet_collect called outside of interpreter loop */ janet_mark_fiber(janet_vm.root_fiber); }