From c6ea22c967819ce5276169edc20686a096bbf757 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Sat, 14 Mar 2026 17:01:33 -0700 Subject: Fix writebarrier on rb_class_set_box_classext --- class.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/class.c b/class.c index 86686a9fa8..c9fbe14be2 100644 --- a/class.c +++ b/class.c @@ -205,13 +205,13 @@ rb_class_set_box_classext(VALUE obj, const rb_box_t *box, rb_classext_t *ext) VM_ASSERT(BOX_USER_P(box)); st_update(RCLASS_CLASSEXT_TBL(obj), (st_data_t)box->box_object, set_box_classext_update, (st_data_t)&args); - st_insert(box->classext_cow_classes, (st_data_t)rb_obj_id(obj), obj); - // FIXME: This is done here because this is the first time the objects in - // the classext are exposed via this class. It's likely that if GC - // compaction occurred between the VALUEs being copied in and this - // writebarrier trigger the values will be stale. + // The classext references are now visible via the classext table, + // so we must issue the write barrier before any further allocations + // (e.g. st_insert below) that could trigger GC. rb_gc_writebarrier_remember(obj); + + st_insert(box->classext_cow_classes, (st_data_t)rb_obj_id(obj), obj); } RUBY_EXTERN rb_serial_t ruby_vm_global_cvar_state; -- cgit v1.2.3