8000 Add missing write barriers in `rb_imemo_fields_clone`. · ruby/ruby@0eceb37 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0eceb37

Browse files
committed
Add missing write barriers in rb_imemo_fields_clone.
1 parent 12a5d57 commit 0eceb37

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

imemo.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,13 @@ imemo_fields_trigger_wb_i(st_data_t key, st_data_t value, st_data_t arg)
155155
return ST_CONTINUE;
156156
}
157157

158+
static int
159+
imemo_fields_complex_wb_i(st_data_t key, st_data_t value, st_data_t arg)
160+
{
161+
RB_OBJ_WRITTEN((VALUE)arg, Qundef, (VALUE)value);
162+
return ST_CONTINUE;
163+
}
164+
158165
VALUE
159166
rb_imemo_fields_new_complex_tbl(VALUE klass, st_table *tbl)
160167
{
@@ -174,12 +181,19 @@ rb_imemo_fields_clone(VALUE fields_obj)
174181
clone = rb_imemo_fields_new_complex(CLASS_OF(fields_obj), 0);
175182
RBASIC_SET_SHAPE_ID(clone, shape_id);
176183
st_table *src_table = rb_imemo_fields_complex_tbl(fields_obj);
177-
st_replace(rb_imemo_fields_complex_tbl(clone), src_table);
184+
st_table *dest_table = rb_imemo_fields_complex_tbl(clone);
185+
st_replace(dest_table, src_table);
186+
st_foreach(dest_table, imemo_fields_complex_wb_i, (st_data_t)clone);
178187
}
179188
else {
180189
clone = imemo_fields_new(CLASS_OF(fields_obj), RSHAPE_CAPACITY(shape_id));
181190
RBASIC_SET_SHAPE_ID(clone, shape_id);
182-
MEMCPY(rb_imemo_fields_ptr(clone), rb_imemo_fields_ptr(fields_obj), VALUE, RSHAPE_LEN(shape_id));
191+
VALUE *fields = rb_imemo_fields_ptr(clone);
192+
attr_index_t fields_count = RSHAPE_LEN(shape_id);
193+
MEMCPY(fields, rb_imemo_fields_ptr(fields_obj), VALUE, fields_count);
194+
for (attr_index_t i = 0; i < fields_count; i++) {
195+
RB_OBJ_WRITTEN(clone, Qundef, fields[i]);
196+
}
183197
}
184198

185199
return clone;

variable.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4774,13 +4774,14 @@ rb_class_ivar_set(VALUE obj, ID id, VALUE val)
47744774

47754775
if (new_fields_obj != original_fields_obj) {
47764776
RCLASS_WRITABLE_SET_FIELDS_OBJ(obj, new_fields_obj);
4777-
4778-
// TODO: What should we set as the T_CLASS shape_id?
4779-
// In most case we can replicate the single `fields_obj` shape
4780-
// but in namespaced case?
4781-
// Perhaps INVALID_SHAPE_ID?
4782-
RBASIC_SET_SHAPE_ID(obj, RBASIC_SHAPE_ID(new_fields_obj));
47834777
}
4778+
4779+
// TODO: What should we set as the T_CLASS shape_id?
4780+
// In most case we can replicate the single `fields_obj` shape
4781+
// but in namespaced case?
4782+
// Perhaps INVALID_SHAPE_ID?
4783+
RBASIC_SET_SHAPE_ID(obj, RBASIC_SHAPE_ID(new_fields_obj));
4784+
47844785
return existing;
47854786
}
47864787

0 commit comments

Comments
 (0)
0