Skip to content

Commit faa6750

Browse files
committed
Ensure CC entries always marked, add missing WB
Previously we were issuing writebarriers for each cc, but were missing the cme. We also need to avoid it being possible to run GC after we've copied the values into the allocated array, but before they're visible in the object.
1 parent bc789ca commit faa6750

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

vm_method.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,19 @@ rb_vm_cc_table_create(size_t capa)
136136
static enum rb_id_table_iterator_result
137137
vm_cc_table_dup_i(ID key, VALUE old_ccs_ptr, void *data)
138138
{
139+
VALUE new_table = (VALUE)data;
139140
struct rb_class_cc_entries *old_ccs = (struct rb_class_cc_entries *)old_ccs_ptr;
140141
size_t memsize = vm_ccs_alloc_size(old_ccs->capa);
141-
struct rb_class_cc_entries *new_ccs = ruby_xmalloc(memsize);
142+
struct rb_class_cc_entries *new_ccs = ruby_xcalloc(1, memsize);
143+
rb_managed_id_table_insert(new_table, key, (VALUE)new_ccs);
144+
142145
memcpy(new_ccs, old_ccs, memsize);
143146

144147
#if VM_CHECK_MODE > 0
145148
new_ccs->debug_sig = ~(VALUE)new_ccs;
146149
#endif
147150

148-
VALUE new_table = (VALUE)data;
149-
rb_managed_id_table_insert(new_table, key, (VALUE)new_ccs);
151+
RB_OBJ_WRITTEN(new_table, Qundef, (VALUE)new_ccs->cme);
150152
for (int index = 0; index < new_ccs->len; index++) {
151153
RB_OBJ_WRITTEN(new_table, Qundef, new_ccs->entries[index].cc);
152154
}

0 commit comments

Comments
 (0)