Skip to content

Commit 7f8d390

Browse files
committed
Restore half of Matt's fix.
I don't quite understand why it's needed, but it immediately failed CI.
1 parent 25e5095 commit 7f8d390

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

gc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1810,6 +1810,16 @@ static const rb_data_type_t id_to_obj_tbl_type = {
18101810
.flags = RUBY_TYPED_WB_PROTECTED | RUBY_TYPED_FREE_IMMEDIATELY
18111811
};
18121812

1813+
bool
1814+
rb_gc_update_id_to_obj_table(VALUE obj, VALUE id)
1815+
{
1816+
if (id_to_obj_tbl && !st_lookup(id_to_obj_tbl, id, 0)) {
1817+
st_insert(id_to_obj_tbl, id, obj);
1818+
return true;
1819+
}
1820+
return false;
1821+
}
1822+
18131823
static VALUE
18141824
object_id(VALUE obj)
18151825
{

internal/gc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ void ruby_sized_xfree(void *x, size_t size);
262262
const char *rb_gc_active_gc_name(void);
263263
int rb_gc_modular_gc_loaded_p(void);
264264

265+
bool rb_gc_update_id_to_obj_table(VALUE obj, VALUE id);
266+
265267
RUBY_SYMBOL_EXPORT_END
266268

267269
int rb_ec_stack_check(struct rb_execution_context_struct *ec);

variable.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1590,6 +1590,15 @@ rb_evict_fields_to_hash(VALUE obj)
15901590

15911591
// Evacuate all previous values from shape into id_table
15921592
rb_obj_copy_fields_to_hash_table(obj, table);
1593+
rb_shape_t *shape = rb_shape_get_shape(obj);
1594+
if (rb_shape_has_object_id(shape)) {
1595+
// We need to ensure the object ID is registered in id_to_obj_table
1596+
// before transitioning to too complex.
1597+
rb_shape_t *object_id_shape = rb_shape_object_id_shape(obj);
1598+
VALUE id = rb_field_get(obj, object_id_shape);
1599+
rb_gc_update_id_to_obj_table(obj, id);
1600+
}
1601+
15931602
obj_transition_too_complex(obj, table);
15941603

15951604
RUBY_ASSERT(rb_shape_obj_too_complex(obj));

0 commit comments

Comments
 (0)