@@ -233,25 +233,6 @@ rb_class_new(VALUE super)
233
233
return rb_class_boot (super );
234
234
}
235
235
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
-
255
236
static void
256
237
clone_method (VALUE klass , ID mid , const rb_method_entry_t * me )
257
238
{
@@ -261,7 +242,7 @@ clone_method(VALUE klass, ID mid, const rb_method_entry_t *me)
261
242
NODE * new_cref ;
262
243
newiseqval = rb_iseq_clone (me -> def -> body .iseq -> self , klass );
263
244
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 );
265
246
RB_OBJ_WRITE (iseq -> self , & iseq -> cref_stack , new_cref );
266
247
rb_add_method (klass , mid , VM_METHOD_TYPE_ISEQ , iseq , me -> flag );
267
248
RB_GC_GUARD (newiseqval );
@@ -957,7 +938,7 @@ rb_prepend_module(VALUE klass, VALUE module)
957
938
OBJ_WB_UNPROTECT (origin ); /* TODO: conservertive shading. Need more survery. */
958
939
RCLASS_SET_SUPER (origin , RCLASS_SUPER (klass ));
959
940
RCLASS_SET_SUPER (klass , origin );
960
- RCLASS_ORIGIN (klass ) = origin ;
941
+ RB_OBJ_WRITE ( klass , & RCLASS_ORIGIN (klass ), origin ) ;
961
942
RCLASS_M_TBL_WRAPPER (origin ) = RCLASS_M_TBL_WRAPPER (klass );
962
943
RCLASS_M_TBL_INIT (klass );
963
944
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)
1118
1099
return ins_methods_push ((ID )name , (long )type , (VALUE )ary , NOEX_PUBLIC );
1119
1100
}
1120
1101
1102
+ struct method_entry_arg {
1103
+ st_table * list ;
1104
+ int recur ;
1105
+ };
1106
+
1121
1107
static int
1122
1108
method_entry_i (st_data_t key , st_data_t value , st_data_t data )
1123
1109
{
1124
1110
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 ;
1126
1112
long type ;
1127
1113
1128
1114
if (me && me -> def -> type == VM_METHOD_TYPE_REFINED ) {
1115
+ VALUE klass = me -> klass ;
1129
1116
me = rb_resolve_refined_method (Qnil , me , NULL );
1130
1117
if (!me ) return ST_CONTINUE ;
1118
+ if (!arg -> recur && me -> klass != klass ) return ST_CONTINUE ;
1131
1119
}
1132
- if (!st_lookup (list , key , 0 )) {
1120
+ if (!st_lookup (arg -> list , key , 0 )) {
1133
1121
if (UNDEFINED_METHOD_ENTRY_P (me )) {
1134
1122
type = -1 ; /* none */
1135
1123
}
1136
1124
else {
1137
1125
type = VISI (me -> flag );
1138
1126
}
1139
- st_add_direct (list , key , type );
1127
+ st_add_direct (arg -> list , key , type );
1140
1128
}
1141
1129
return ST_CONTINUE ;
1142
1130
}
@@ -1146,7 +1134,7 @@ class_instance_method_list(int argc, VALUE *argv, VALUE mod, int obj, int (*func
1146
1134
{
1147
1135
VALUE ary ;
1148
1136
int recur , prepended = 0 ;
1149
- st_table * list ;
1137
+ struct method_entry_arg me_arg ;
1150
1138
1151
1139
if (argc == 0 ) {
1152
1140
recur = TRUE;
@@ -1162,16 +1150,17 @@ class_instance_method_list(int argc, VALUE *argv, VALUE mod, int obj, int (*func
1162
1150
prepended = 1 ;
1163
1151
}
1164
1152
1165
- list = st_init_numtable ();
1153
+ me_arg .list = st_init_numtable ();
1154
+ me_arg .recur = recur ;
1166
1155
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 );
1168
1157
if (BUILTIN_TYPE (mod ) == T_ICLASS && !prepended ) continue ;
1169
1158
if (obj && FL_TEST (mod , FL_SINGLETON )) continue ;
1170
1159
if (!recur ) break ;
1171
1160
}
1172
1161
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 );
1175
1164
1176
1165
return ary ;
1177
1166
}
@@ -1393,7 +1382,8 @@ VALUE
1393
1382
rb_obj_singleton_methods (int argc , VALUE * argv , VALUE obj )
1394
1383
{
1395
1384
VALUE recur , ary , klass , origin ;
1396
- st_table * list , * mtbl ;
1385
+ struct method_entry_arg me_arg ;
1386
+ st_table * mtbl ;
1397
1387
1398
1388
if (argc == 0 ) {
1399
1389
recur = Qtrue ;
@@ -1403,22 +1393,23 @@ rb_obj_singleton_methods(int argc, VALUE *argv, VALUE obj)
1403
1393
}
1404
1394
klass = CLASS_OF (obj );
1405
1395
origin = RCLASS_ORIGIN (klass );
1406
- list = st_init_numtable ();
1396
+ me_arg .list = st_init_numtable ();
1397
+ me_arg .recur = recur ;
1407
1398
if (klass && FL_TEST (klass , FL_SINGLETON )) {
1408
1399
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 );
1410
1401
klass = RCLASS_SUPER (klass );
1411
1402
}
1412
1403
if (RTEST (recur )) {
1413
1404
while (klass && (FL_TEST (klass , FL_SINGLETON ) || RB_TYPE_P (klass , T_ICLASS ))) {
1414
1405
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 );
1416
1407
klass = RCLASS_SUPER (klass );
1417
1408
}
1418
1409
}
1419
1410
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 );
1422
1413
1423
1414
return ary ;
1424
1415
}
0 commit comments