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.
This commit is contained in:
Calvin Rose committed 2026-09-28 16:56:36 -05:00
1 parent ffebf2c497
commit b437ae3feb
2 files changed
+11

No files matched your search

+8
View File
@@ -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;
}
+3
View File
@@ -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);
}