Skip to content

Commit 97db70f

Browse files
committed
gc.c: Add more assertions around object_id
1 parent 7119139 commit 97db70f

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

gc.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,7 @@ rb_gc_update_id_to_obj_table(VALUE obj, VALUE id)
18231823
static VALUE
18241824
object_id(VALUE obj)
18251825
{
1826-
VALUE id;
1826+
VALUE id = Qfalse;
18271827
rb_shape_t *shape = rb_shape_get_shape(obj);
18281828
unsigned int lock_lev;
18291829

@@ -1836,6 +1836,8 @@ object_id(VALUE obj)
18361836
st_table *table = ROBJECT_FIELDS_HASH(obj);
18371837
if (rb_shape_has_object_id(shape)) {
18381838
st_lookup(table, (st_data_t)internal_object_id, (st_data_t *)&id);
1839+
RUBY_ASSERT(id, "object_id missing");
1840+
18391841
rb_gc_vm_unlock(lock_lev);
18401842
return id;
18411843
}
@@ -1914,11 +1916,11 @@ obj_free_object_id(VALUE obj)
19141916
{
19151917
if (RB_UNLIKELY(id_to_obj_tbl)) {
19161918
if (rb_shape_obj_has_id(obj)) {
1917-
st_data_t id = (st_data_t)rb_obj_id(obj);
1918-
GC_ASSERT(id);
1919+
VALUE obj_id = rb_obj_id(obj);
1920+
RUBY_ASSERT(FIXNUM_P(obj_id) || RB_TYPE_P(obj, T_BIGNUM));
19191921

1920-
if (!st_delete(id_to_obj_tbl, &id, NULL)) {
1921-
rb_bug("Object ID seen, but not in id_to_obj table: object_id=%llu object=%s", NUM2ULL((VALUE)id), rb_obj_info(obj));
1922+
if (!st_delete(id_to_obj_tbl, (st_data_t *)&obj_id, NULL)) {
1923+
rb_bug("Object ID seen, but not in id_to_obj table: object_id=%llu object=%s", NUM2ULL(obj_id), rb_obj_info(obj));
19221924
}
19231925
}
19241926
}
@@ -3690,6 +3692,7 @@ vm_weak_table_id_to_obj_foreach(st_data_t key, st_data_t value, st_data_t data)
36903692
{
36913693
st_insert(id_to_obj_tbl, key, (st_data_t)new_value);
36923694
}
3695+
DURING_GC_COULD_MALLOC_REGION_END();
36933696
}
36943697
return ST_CONTINUE;
36953698
}

0 commit comments

Comments
 (0)