@@ -135,46 +135,42 @@ duplicate_classext_id_table(struct rb_id_table *orig, bool init_missing)
135135 return tbl ;
136136}
137137
138- static rb_const_entry_t *
139- duplicate_classext_const_entry (rb_const_entry_t * src , VALUE klass )
138+ static VALUE
139+ duplicate_classext_const_entry (VALUE src_value )
140140{
141+ rb_const_entry_t * src = (rb_const_entry_t * )src_value ;
142+
141143 // See also: setup_const_entry (variable.c)
142- rb_const_entry_t * dst = ZALLOC (rb_const_entry_t );
144+ VALUE dst_value = rb_const_entry_new ();
145+ rb_const_entry_t * dst = (rb_const_entry_t * )dst_value ;
143146
144- dst -> flag = src -> flag ;
145- dst -> line = src -> line ;
146- RB_OBJ_WRITE (klass , & dst -> value , src -> value );
147- RB_OBJ_WRITE (klass , & dst -> file , src -> file );
147+ MEMCPY (dst , src , rb_const_entry_t , 1 );
148+ RB_OBJ_WRITTEN (dst_value , Qundef , src -> value );
149+ RB_OBJ_WRITTEN (dst_value , Qundef , src -> file );
148150
149- return dst ;
151+ return dst_value ;
150152}
151153
152154static enum rb_id_table_iterator_result
153155duplicate_classext_const_tbl_i (ID key , VALUE value , void * data )
154156{
155- struct duplicate_id_tbl_data * arg = (struct duplicate_id_tbl_data * )data ;
156- rb_const_entry_t * entry = duplicate_classext_const_entry ((rb_const_entry_t * )value , arg -> klass );
157+ VALUE dst = (VALUE )data ;
157158
158- rb_id_table_insert (arg -> tbl , key , (VALUE )entry );
159+ VALUE entry = duplicate_classext_const_entry (value );
160+ rb_marked_id_table_insert (dst , key , entry );
159161
160162 return ID_TABLE_CONTINUE ;
161163}
162164
163- static struct rb_id_table *
164- duplicate_classext_const_tbl (struct rb_id_table * src , VALUE klass )
165+ static VALUE
166+ duplicate_classext_const_tbl (VALUE src )
165167{
166- struct rb_id_table * dst ;
167-
168- if (!src )
169- return NULL ;
170-
171- dst = rb_id_table_create (rb_id_table_size (src ));
168+ if (!src ) {
169+ return 0 ;
170+ }
172171
173- struct duplicate_id_tbl_data data = {
174- .tbl = dst ,
175- .klass = klass ,
176- };
177- rb_id_table_foreach (src , duplicate_classext_const_tbl_i , (void * )& data );
172+ VALUE dst = rb_marked_id_table_dup (src );
173+ rb_marked_id_table_foreach (src , duplicate_classext_const_tbl_i , (void * )dst );
178174
179175 return dst ;
180176}
@@ -312,7 +308,7 @@ rb_class_duplicate_classext(rb_classext_t *orig, VALUE klass, const rb_namespace
312308 RCLASSEXT_SHARED_CONST_TBL (ext ) = true;
313309 }
314310 else {
315- RCLASSEXT_CONST_TBL (ext ) = duplicate_classext_const_tbl (RCLASSEXT_CONST_TBL (orig ), klass );
311+ RB_OBJ_WRITE ( klass , & RCLASSEXT_CONST_TBL (ext ), duplicate_classext_const_tbl (RCLASSEXT_CONST_TBL (orig )) );
316312 RCLASSEXT_SHARED_CONST_TBL (ext ) = false;
317313 }
318314 /*
@@ -898,29 +894,22 @@ clone_method_i(ID key, VALUE value, void *data)
898894 return ID_TABLE_CONTINUE ;
899895}
900896
901- struct clone_const_arg {
902- VALUE klass ;
903- struct rb_id_table * tbl ;
904- };
905-
906- static int
907- clone_const (ID key , const rb_const_entry_t * ce , struct clone_const_arg * arg )
897+ static enum rb_id_table_iterator_result
898+ clone_const_i (ID key , VALUE value , void * data )
908899{
909- rb_const_entry_t * nce = ALLOC (rb_const_entry_t );
900+ VALUE new_table = (VALUE )data ;
901+ const rb_const_entry_t * ce = (const rb_const_entry_t * )value ;
902+
903+ VALUE nce_value = rb_const_entry_new ();
904+ rb_const_entry_t * nce = (rb_const_entry_t * )nce_value ;
910905 MEMCPY (nce , ce , rb_const_entry_t , 1 );
911- RB_OBJ_WRITTEN (arg -> klass , Qundef , ce -> value );
912- RB_OBJ_WRITTEN (arg -> klass , Qundef , ce -> file );
906+ RB_OBJ_WRITTEN (nce_value , Qundef , ce -> value );
907+ RB_OBJ_WRITTEN (nce_value , Qundef , ce -> file );
913908
914- rb_id_table_insert ( arg -> tbl , key , (VALUE )nce );
909+ rb_marked_id_table_insert ( new_table , key , (VALUE )nce );
915910 return ID_TABLE_CONTINUE ;
916911}
917912
918- static enum rb_id_table_iterator_result
919- clone_const_i (ID key , VALUE value , void * data )
920- {
921- return clone_const (key , (const rb_const_entry_t * )value , data );
922- }
923-
924913static void
925914class_init_copy_check (VALUE clone , VALUE orig )
926915{
@@ -964,7 +953,6 @@ static void
964953copy_tables (VALUE clone , VALUE orig )
965954{
966955 if (RCLASS_CONST_TBL (clone )) {
967- rb_free_const_table (RCLASS_CONST_TBL (clone ));
968956 RCLASS_WRITE_CONST_TBL (clone , 0 , false);
969957 }
970958 if (RCLASS_CVC_TBL (orig )) {
@@ -982,14 +970,12 @@ copy_tables(VALUE clone, VALUE orig)
982970 if (!RB_TYPE_P (clone , T_ICLASS )) {
983971 rb_fields_tbl_copy (clone , orig );
984972 }
985- if (RCLASS_CONST_TBL (orig )) {
986- struct clone_const_arg arg ;
987- struct rb_id_table * const_tbl ;
988- struct rb_id_table * orig_tbl = RCLASS_CONST_TBL (orig );
989- arg .tbl = const_tbl = rb_id_table_create (rb_id_table_size (orig_tbl ));
990- arg .klass = clone ;
991- rb_id_table_foreach (orig_tbl , clone_const_i , & arg );
992- RCLASS_WRITE_CONST_TBL (clone , const_tbl , false);
973+
974+ VALUE const_table = RCLASS_CONST_TBL (orig );
975+ if (const_table ) {
976+ VALUE new_const_tbl = rb_marked_id_table_new (rb_marked_id_table_size (const_table ));
977+ rb_marked_id_table_foreach (const_table , clone_const_i , (void * )new_const_tbl );
978+ RCLASS_WRITE_CONST_TBL (clone , new_const_tbl , false);
993979 }
994980}
995981
@@ -1177,14 +1163,15 @@ rb_singleton_class_clone_and_attach(VALUE obj, VALUE attach)
11771163
11781164 rb_class_set_super (clone , RCLASS_SUPER (klass ));
11791165 rb_fields_tbl_copy (clone , klass );
1180- if ( RCLASS_CONST_TBL ( klass )) {
1181- struct clone_const_arg arg ;
1182- struct rb_id_table * table ;
1183- arg . tbl = table = rb_id_table_create ( 0 );
1184- arg . klass = clone ;
1185- rb_id_table_foreach ( RCLASS_CONST_TBL ( klass ) , clone_const_i , & arg );
1186- RCLASS_SET_CONST_TBL (clone , table , false);
1166+
1167+
1168+ VALUE const_table = RCLASS_CONST_TBL ( klass ) ;
1169+ if ( const_table ) {
1170+ VALUE new_const_tbl = rb_marked_id_table_new ( rb_marked_id_table_size ( const_table )) ;
1171+ rb_marked_id_table_foreach ( const_table , clone_const_i , ( void * ) new_const_tbl );
1172+ RCLASS_WRITE_CONST_TBL (clone , new_const_tbl , false);
11871173 }
1174+
11881175 if (!UNDEF_P (attach )) {
11891176 rb_singleton_class_attached (clone , attach );
11901177 }
@@ -1669,7 +1656,7 @@ rb_include_class_new(VALUE module, VALUE super)
16691656 RCLASS_SET_CONST_TBL (klass , RCLASS_WRITABLE_CONST_TBL (module ), true);
16701657 }
16711658 else {
1672- RCLASS_WRITE_CONST_TBL (module , rb_id_table_create ( 0 ) , false);
1659+ RCLASS_WRITE_CONST_TBL (module , Qfalse , false);
16731660 RCLASS_SET_CONST_TBL (klass , RCLASS_WRITABLE_CONST_TBL (module ), true);
16741661 }
16751662
@@ -1863,9 +1850,10 @@ do_include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super
18631850 RUBY_ASSERT (BUILTIN_TYPE (c ) == T_MODULE );
18641851 }
18651852
1866- tbl = RCLASS_CONST_TBL (module );
1867- if (tbl && rb_id_table_size (tbl ))
1868- rb_id_table_foreach (tbl , clear_constant_cache_i , NULL );
1853+ VALUE const_table = RCLASS_CONST_TBL (module );
1854+ if (const_table ) {
1855+ rb_marked_id_table_foreach (const_table , clear_constant_cache_i , NULL );
1856+ }
18691857 skip :
18701858 module = RCLASS_SUPER (module );
18711859 }
0 commit comments