@@ -1234,6 +1234,23 @@ rb_shape_verify_consistency(VALUE obj, shape_id_t shape_id)
12341234 }
12351235 }
12361236
1237+ // Make sure SHAPE_ID_HAS_IVAR_MASK is valid.
1238+ if (rb_shape_too_complex_p (shape_id )) {
1239+ RUBY_ASSERT (shape_id & SHAPE_ID_HAS_IVAR_MASK );
1240+ }
1241+ else {
1242+ attr_index_t ivar_count = RSHAPE_LEN (shape_id );
1243+ if (has_object_id ) {
1244+ ivar_count -- ;
1245+ }
1246+ if (ivar_count ) {
1247+ RUBY_ASSERT (shape_id & SHAPE_ID_HAS_IVAR_MASK );
1248+ }
1249+ else {
1250+ RUBY_ASSERT (!(shape_id & SHAPE_ID_HAS_IVAR_MASK ));
1251+ }
1252+ }
1253+
12371254 uint8_t flags_heap_index = rb_shape_heap_index (shape_id );
12381255 if (RB_TYPE_P (obj , T_OBJECT )) {
12391256 size_t shape_id_slot_size = rb_shape_tree .capacities [flags_heap_index - 1 ] * sizeof (VALUE ) + sizeof (struct RBasic );
@@ -1524,14 +1541,15 @@ Init_default_shapes(void)
15241541 root -> type = SHAPE_ROOT ;
15251542 rb_shape_tree .root_shape = root ;
15261543 RUBY_ASSERT (raw_shape_id (rb_shape_tree .root_shape ) == ROOT_SHAPE_ID );
1544+ RUBY_ASSERT (!(raw_shape_id (rb_shape_tree .root_shape ) & SHAPE_ID_HAS_IVAR_MASK ));
15271545
15281546 bool dontcare ;
15291547 rb_shape_t * root_with_obj_id = get_next_shape_internal (root , id_object_id , SHAPE_OBJ_ID , & dontcare , true);
15301548 RUBY_ASSERT (raw_shape_id (root_with_obj_id ) == ROOT_SHAPE_WITH_OBJ_ID );
15311549 RUBY_ASSERT (root_with_obj_id -> type == SHAPE_OBJ_ID );
15321550 RUBY_ASSERT (root_with_obj_id -> edge_name == id_object_id );
15331551 RUBY_ASSERT (root_with_obj_id -> next_field_index == 1 );
1534- ( void ) root_with_obj_id ;
1552+ RUBY_ASSERT (!( raw_shape_id ( root_with_obj_id ) & SHAPE_ID_HAS_IVAR_MASK )) ;
15351553}
15361554
15371555void
0 commit comments