Skip to content

Commit 4f1d6a0

Browse files
committed
Fix ractor copy of structs
1 parent a0b2dcd commit 4f1d6a0

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

ractor.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,16 @@ obj_traverse_i(VALUE obj, struct obj_traverse_data *data)
12611261
for (long i=0; i<len; i++) {
12621262
if (obj_traverse_i(ptr[i], data)) return 1;
12631263
}
1264+
1265+
if (RSTRUCT_EMBED_LEN(obj)) {
1266+
if (!FL_TEST_RAW(obj, RSTRUCT_GEN_IVAR_FLAG)) {
1267+
if (obj_traverse_i(ptr[len], data)) return 1;
1268+
}
1269+
}
1270+
else {
1271+
if (obj_traverse_i(RSTRUCT(obj)->as.heap.fields_obj, data)) return 1;
1272+
}
1273+
12641274
}
12651275
break;
12661276

@@ -1681,6 +1691,7 @@ obj_traverse_replace_i(VALUE obj, struct obj_traverse_replace_data *data)
16811691
if (UNLIKELY(rb_obj_exivar_p(obj))) {
16821692
VALUE fields_obj = 0;
16831693
rb_ivar_generic_fields_tbl_lookup(obj, &fields_obj);
1694+
RUBY_ASSERT(fields_obj);
16841695

16851696
if (UNLIKELY(rb_shape_obj_too_complex_p(obj))) {
16861697
struct obj_traverse_replace_callback_data d = {

variable.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,8 +1278,10 @@ rb_free_generic_ivar(VALUE obj)
12781278

12791279
RB_VM_LOCKING() {
12801280
st_delete(generic_fields_tbl_no_ractor_check(obj), &key, &value);
1281+
RBASIC_SET_SHAPE_ID(obj, ROOT_SHAPE_ID);
12811282
}
12821283
}
1284+
RUBY_ASSERT(!rb_obj_exivar_p(obj));
12831285
}
12841286

12851287
VALUE
@@ -2440,11 +2442,7 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj)
24402442

24412443
rb_check_frozen(dest);
24422444

2443-
if (!rb_obj_exivar_p(obj)) {
2444-
return;
2445-
}
2446-
2447-
if (rb_gen_fields_tbl_get(obj, 0, &fields_obj)) {
2445+
if (rb_obj_exivar_p(obj) && rb_gen_fields_tbl_get(obj, 0, &fields_obj)) {
24482446
VALUE new_fields_obj = copy_imemo_fields_ivar(obj, fields_obj, dest);
24492447
if (new_fields_obj) {
24502448
RB_VM_LOCKING() {
@@ -2454,9 +2452,9 @@ rb_copy_generic_ivar(VALUE dest, VALUE obj)
24542452
RBASIC_SET_SHAPE_ID(dest, RBASIC_SHAPE_ID(new_fields_obj));
24552453
}
24562454
}
2457-
else {
2458-
rb_free_generic_ivar(dest);
2459-
}
2455+
}
2456+
else {
2457+
rb_free_generic_ivar(dest);
24602458
}
24612459
}
24622460

0 commit comments

Comments
 (0)