class_fields_ivar_set: fix multi-ractor mode

We must copy the table before inserting into it if we're in
multi-ractor mode to ensure the table won't be rehashed or
resized.
This commit is contained in:
Jean Boussier 2025-06-30 10:02:19 +02:00
parent 879f4886c9
commit 00357eea31

View file

@ -4704,6 +4704,10 @@ class_fields_ivar_set(VALUE klass, VALUE fields_obj, ID id, VALUE val, bool conc
too_complex: too_complex:
{ {
if (concurrent && fields_obj == original_fields_obj) {
// If we're in the multi-ractor mode, we can't directly insert in the table.
fields_obj = rb_imemo_fields_clone(fields_obj);
}
st_table *table = rb_imemo_fields_complex_tbl(fields_obj); st_table *table = rb_imemo_fields_complex_tbl(fields_obj);
existing = st_insert(table, (st_data_t)id, (st_data_t)val); existing = st_insert(table, (st_data_t)id, (st_data_t)val);
RB_OBJ_WRITTEN(fields_obj, Qundef, val); RB_OBJ_WRITTEN(fields_obj, Qundef, val);