From e8521fc95a3d460681ce3c7dbb982cbe28c5a062 Mon Sep 17 00:00:00 2001 From: Oscar Blumberg Date: Fri, 22 May 2015 11:19:18 -0400 Subject: [PATCH] Fix GC not following module parents Also a missing root for new modules. Thanks to @yuyiacho for finding those issues. Fix #11395. --- src/gc.c | 3 +++ src/module.c | 2 ++ src/toplevel.c | 3 +-- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/gc.c b/src/gc.c index ca18e6f25ebc1c..20f62f3808bf64 100644 --- a/src/gc.c +++ b/src/gc.c @@ -1562,6 +1562,9 @@ NOINLINE static int gc_mark_module(jl_module_t *m, int d) verify_parent1("module", m, &m->constant_table, "constant_table"); refyoung |= gc_push_root(m->constant_table, d); } + + refyoung |= gc_push_root(m->parent, d); + return refyoung; } diff --git a/src/module.c b/src/module.c index d4e3b50123b1a8..fb8147763b64ef 100644 --- a/src/module.c +++ b/src/module.c @@ -44,9 +44,11 @@ jl_module_t *jl_new_module(jl_sym_t *name) DLLEXPORT jl_value_t *jl_f_new_module(jl_sym_t *name, uint8_t std_imports) { jl_module_t *m = jl_new_module(name); + JL_GC_PUSH1(&m); m->parent = jl_main_module; gc_wb(m, m->parent); if (std_imports) jl_add_standard_imports(m); + JL_GC_POP(); return (jl_value_t*)m; } diff --git a/src/toplevel.c b/src/toplevel.c index 3abe931dffaeae..453872696c869a 100644 --- a/src/toplevel.c +++ b/src/toplevel.c @@ -116,8 +116,7 @@ jl_value_t *jl_eval_module_expr(jl_expr_t *ex) jl_module_t *newm = jl_new_module(name); newm->parent = parent_module; b->value = (jl_value_t*)newm; - - gc_wb(parent_module, newm); + gc_wb_binding(b, newm); if (parent_module == jl_main_module && name == jl_symbol("Base")) { // pick up Base module during bootstrap