@@ -233,25 +233,6 @@ rb_class_new(VALUE super)
233233 return rb_class_boot (super );
234234}
235235
236- static void
237- rewrite_cref_stack (NODE * node , VALUE old_klass , VALUE new_klass , NODE * * new_cref_ptr )
238- {
239- NODE * new_node ;
240- while (node ) {
241- if (node -> nd_clss == old_klass ) {
242- new_node = NEW_CREF (new_klass );
243- RB_OBJ_WRITE (new_node , & new_node -> nd_next , node -> nd_next );
244- * new_cref_ptr = new_node ;
245- return ;
246- }
247- new_node = NEW_CREF (node -> nd_clss );
248- node = node -> nd_next ;
249- * new_cref_ptr = new_node ;
250- new_cref_ptr = & new_node -> nd_next ;
251- }
252- * new_cref_ptr = NULL ;
253- }
254-
255236static void
256237clone_method (VALUE klass , ID mid , const rb_method_entry_t * me )
257238{
@@ -261,7 +242,7 @@ clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
261242 NODE * new_cref ;
262243 newiseqval = rb_iseq_clone (me -> def -> body .iseq -> self , klass );
263244 GetISeqPtr (newiseqval , iseq );
264- rewrite_cref_stack (me -> def -> body .iseq -> cref_stack , me -> klass , klass , & new_cref );
245+ rb_vm_rewrite_cref_stack (me -> def -> body .iseq -> cref_stack , me -> klass , klass , & new_cref );
265246 RB_OBJ_WRITE (iseq -> self , & iseq -> cref_stack , new_cref );
266247 rb_add_method (klass , mid , VM_METHOD_TYPE_ISEQ , iseq , me -> flag );
267248 RB_GC_GUARD (newiseqval );
@@ -957,7 +938,7 @@ rb_prepend_module(VALUE klass, VALUE module)
957938 OBJ_WB_UNPROTECT (origin ); /* TODO: conservertive shading. Need more survery. */
958939 RCLASS_SET_SUPER (origin , RCLASS_SUPER (klass ));
959940 RCLASS_SET_SUPER (klass , origin );
960- RCLASS_ORIGIN (klass ) = origin ;
941+ RB_OBJ_WRITE ( klass , & RCLASS_ORIGIN (klass ), origin ) ;
961942 RCLASS_M_TBL_WRAPPER (origin ) = RCLASS_M_TBL_WRAPPER (klass );
962943 RCLASS_M_TBL_INIT (klass );
963944 st_foreach (RCLASS_M_TBL (origin ), move_refined_method ,
@@ -1118,25 +1099,32 @@ ins_methods_pub_i(st_data_t name, st_data_t type, st_data_t ary)
11181099 return ins_methods_push ((ID )name , (long )type , (VALUE )ary , NOEX_PUBLIC );
11191100}
11201101
1102+ struct method_entry_arg {
1103+ st_table * list ;
1104+ int recur ;
1105+ };
1106+
11211107static int
11221108method_entry_i (st_data_t key , st_data_t value , st_data_t data )
11231109{
11241110 const rb_method_entry_t * me = (const rb_method_entry_t * )value ;
1125- st_table * list = (st_table * )data ;
1111+ struct method_entry_arg * arg = (struct method_entry_arg * )data ;
11261112 long type ;
11271113
11281114 if (me && me -> def -> type == VM_METHOD_TYPE_REFINED ) {
1115+ VALUE klass = me -> klass ;
11291116 me = rb_resolve_refined_method (Qnil , me , NULL );
11301117 if (!me ) return ST_CONTINUE ;
1118+ if (!arg -> recur && me -> klass != klass ) return ST_CONTINUE ;
11311119 }
1132- if (!st_lookup (list , key , 0 )) {
1120+ if (!st_lookup (arg -> list , key , 0 )) {
11331121 if (UNDEFINED_METHOD_ENTRY_P (me )) {
11341122 type = -1 ; /* none */
11351123 }
11361124 else {
11371125 type = VISI (me -> flag );
11381126 }
1139- st_add_direct (list , key , type );
1127+ st_add_direct (arg -> list , key , type );
11401128 }
11411129 return ST_CONTINUE ;
11421130}
@@ -1146,7 +1134,7 @@ class_instance_method_list(int argc, VALUE *argv, VALUE mod, int obj, int (*func
11461134{
11471135 VALUE ary ;
11481136 int recur , prepended = 0 ;
1149- st_table * list ;
1137+ struct method_entry_arg me_arg ;
11501138
11511139 if (argc == 0 ) {
11521140 recur = TRUE;
@@ -1162,16 +1150,17 @@ class_instance_method_list(int argc, VALUE *argv, VALUE mod, int obj, int (*func
11621150 prepended = 1 ;
11631151 }
11641152
1165- list = st_init_numtable ();
1153+ me_arg .list = st_init_numtable ();
1154+ me_arg .recur = recur ;
11661155 for (; mod ; mod = RCLASS_SUPER (mod )) {
1167- if (RCLASS_M_TBL (mod )) st_foreach (RCLASS_M_TBL (mod ), method_entry_i , (st_data_t )list );
1156+ if (RCLASS_M_TBL (mod )) st_foreach (RCLASS_M_TBL (mod ), method_entry_i , (st_data_t )& me_arg );
11681157 if (BUILTIN_TYPE (mod ) == T_ICLASS && !prepended ) continue ;
11691158 if (obj && FL_TEST (mod , FL_SINGLETON )) continue ;
11701159 if (!recur ) break ;
11711160 }
11721161 ary = rb_ary_new ();
1173- st_foreach (list , func , ary );
1174- st_free_table (list );
1162+ st_foreach (me_arg . list , func , ary );
1163+ st_free_table (me_arg . list );
11751164
11761165 return ary ;
11771166}
@@ -1393,7 +1382,8 @@ VALUE
13931382rb_obj_singleton_methods (int argc , VALUE * argv , VALUE obj )
13941383{
13951384 VALUE recur , ary , klass , origin ;
1396- st_table * list , * mtbl ;
1385+ struct method_entry_arg me_arg ;
1386+ st_table * mtbl ;
13971387
13981388 if (argc == 0 ) {
13991389 recur = Qtrue ;
@@ -1403,22 +1393,23 @@ rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
14031393 }
14041394 klass = CLASS_OF (obj );
14051395 origin = RCLASS_ORIGIN (klass );
1406- list = st_init_numtable ();
1396+ me_arg .list = st_init_numtable ();
1397+ me_arg .recur = recur ;
14071398 if (klass && FL_TEST (klass , FL_SINGLETON )) {
14081399 if ((mtbl = RCLASS_M_TBL (origin )) != 0 )
1409- st_foreach (mtbl , method_entry_i , (st_data_t )list );
1400+ st_foreach (mtbl , method_entry_i , (st_data_t )& me_arg );
14101401 klass = RCLASS_SUPER (klass );
14111402 }
14121403 if (RTEST (recur )) {
14131404 while (klass && (FL_TEST (klass , FL_SINGLETON ) || RB_TYPE_P (klass , T_ICLASS ))) {
14141405 if (klass != origin && (mtbl = RCLASS_M_TBL (klass )) != 0 )
1415- st_foreach (mtbl , method_entry_i , (st_data_t )list );
1406+ st_foreach (mtbl , method_entry_i , (st_data_t )& me_arg );
14161407 klass = RCLASS_SUPER (klass );
14171408 }
14181409 }
14191410 ary = rb_ary_new ();
1420- st_foreach (list , ins_methods_i , ary );
1421- st_free_table (list );
1411+ st_foreach (me_arg . list , ins_methods_i , ary );
1412+ st_free_table (me_arg . list );
14221413
14231414 return ary ;
14241415}
0 commit comments