Skip to content

Commit 71bba80

Browse files
committed
ensure bindings handle write barriers for ty and globalref
This has probably been wrong for a long time (since being introduced in 7908246).
1 parent 8d03330 commit 71bba80

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

src/builtins.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,6 +1252,7 @@ JL_CALLABLE(jl_f_set_binding_type)
12521252
jl_errorf("cannot set type for global %s. It already has a value or is already set to a different type.",
12531253
jl_symbol_name(b->name));
12541254
}
1255+
jl_gc_wb_binding(b, ty);
12551256
return jl_nothing;
12561257
}
12571258

src/gc.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3203,8 +3203,17 @@ static void jl_gc_queue_remset(jl_gc_mark_cache_t *gc_cache, jl_gc_mark_sp_t *sp
32033203
jl_binding_t *ptr = (jl_binding_t*)items[i];
32043204
// A null pointer can happen here when the binding is cleaned up
32053205
// as an exception is thrown after it was already queued (#10221)
3206+
int bnd_refyoung = 0;
32063207
jl_value_t *v = jl_atomic_load_relaxed(&ptr->value);
3207-
if (v != NULL && gc_mark_queue_obj(gc_cache, sp, v)) {
3208+
if (v != NULL && gc_mark_queue_obj(gc_cache, sp, v))
3209+
bnd_refyoung = 1;
3210+
jl_value_t *ty = jl_atomic_load_relaxed(&ptr->ty);
3211+
if (ty != NULL && gc_mark_queue_obj(gc_cache, sp, ty))
3212+
bnd_refyoung = 1;
3213+
jl_value_t *globalref = jl_atomic_load_relaxed(&ptr->globalref);
3214+
if (globalref != NULL && gc_mark_queue_obj(gc_cache, sp, globalref))
3215+
bnd_refyoung = 1;
3216+
if (bnd_refyoung) {
32083217
items[n_bnd_refyoung] = ptr;
32093218
n_bnd_refyoung++;
32103219
}

src/module.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ JL_DLLEXPORT jl_value_t *jl_module_globalref(jl_module_t *m, jl_sym_t *var)
449449
if (jl_atomic_cmpswap_relaxed(&b->globalref, &globalref, newref)) {
450450
JL_GC_PROMISE_ROOTED(newref);
451451
globalref = newref;
452-
jl_gc_wb(m, globalref);
452+
jl_gc_wb_binding(b, globalref);
453453
}
454454
}
455455
JL_UNLOCK(&m->lock); // may GC

0 commit comments

Comments
 (0)