[前][次][番号順一覧][スレッド一覧]

ruby-changes:37511

From: naruse <ko1@a...>
Date: Sat, 14 Feb 2015 08:55:03 +0900 (JST)
Subject: [ruby-changes:37511] naruse:r49592 (ruby_2_2): merge revision(s) 49493: [Backport #10826]

naruse	2015-02-14 08:54:51 +0900 (Sat, 14 Feb 2015)

  New Revision: 49592

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49592

  Log:
    merge revision(s) 49493: [Backport #10826]
    
    * class.c (method_entry_i, class_instance_method_list,
      rb_obj_singleton_methods): should not include methods of
      superclasses if recur is false. [ruby-dev:48854] [Bug #10826]

  Modified directories:
    branches/ruby_2_2/
  Modified files:
    branches/ruby_2_2/ChangeLog
    branches/ruby_2_2/class.c
    branches/ruby_2_2/test/ruby/test_refinement.rb
    branches/ruby_2_2/version.h
Index: ruby_2_2/ChangeLog
===================================================================
--- ruby_2_2/ChangeLog	(revision 49591)
+++ ruby_2_2/ChangeLog	(revision 49592)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1
+Sat Feb 14 08:53:50 2015  Shugo Maeda  <shugo@r...>
+
+	* class.c (method_entry_i, class_instance_method_list,
+	  rb_obj_singleton_methods): should not include methods of
+	  superclasses if recur is false. [ruby-dev:48854] [Bug #10826]
+
 Fri Feb 13 13:59:56 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/mkmf.rb (try_cppflags, try_cflags, try_ldflags): get rid of
Index: ruby_2_2/class.c
===================================================================
--- ruby_2_2/class.c	(revision 49591)
+++ ruby_2_2/class.c	(revision 49592)
@@ -1114,25 +1114,32 @@ ins_methods_pub_i(st_data_t name, st_dat https://github.com/ruby/ruby/blob/trunk/ruby_2_2/class.c#L1114
     return ins_methods_push((ID)name, (long)type, (VALUE)ary, NOEX_PUBLIC);
 }
 
+struct method_entry_arg {
+    st_table *list;
+    int recur;
+};
+
 static int
 method_entry_i(st_data_t key, st_data_t value, st_data_t data)
 {
     const rb_method_entry_t *me = (const rb_method_entry_t *)value;
-    st_table *list = (st_table *)data;
+    struct method_entry_arg *arg = (struct method_entry_arg *)data;
     long type;
 
     if (me && me->def->type == VM_METHOD_TYPE_REFINED) {
+	VALUE klass = me->klass;
 	me = rb_resolve_refined_method(Qnil, me, NULL);
 	if (!me) return ST_CONTINUE;
+	if (!arg->recur && me->klass != klass) return ST_CONTINUE;
     }
-    if (!st_lookup(list, key, 0)) {
+    if (!st_lookup(arg->list, key, 0)) {
 	if (UNDEFINED_METHOD_ENTRY_P(me)) {
 	    type = -1; /* none */
 	}
 	else {
 	    type = VISI(me->flag);
 	}
-	st_add_direct(list, key, type);
+	st_add_direct(arg->list, key, type);
     }
     return ST_CONTINUE;
 }
@@ -1142,7 +1149,7 @@ class_instance_method_list(int argc, con https://github.com/ruby/ruby/blob/trunk/ruby_2_2/class.c#L1149
 {
     VALUE ary;
     int recur, prepended = 0;
-    st_table *list;
+    struct method_entry_arg me_arg;
 
     if (argc == 0) {
 	recur = TRUE;
@@ -1158,16 +1165,17 @@ class_instance_method_list(int argc, con https://github.com/ruby/ruby/blob/trunk/ruby_2_2/class.c#L1165
 	prepended = 1;
     }
 
-    list = st_init_numtable();
+    me_arg.list = st_init_numtable();
+    me_arg.recur = recur;
     for (; mod; mod = RCLASS_SUPER(mod)) {
-	if (RCLASS_M_TBL(mod)) st_foreach(RCLASS_M_TBL(mod), method_entry_i, (st_data_t)list);
+	if (RCLASS_M_TBL(mod)) st_foreach(RCLASS_M_TBL(mod), method_entry_i, (st_data_t)&me_arg);
 	if (BUILTIN_TYPE(mod) == T_ICLASS && !prepended) continue;
 	if (obj && FL_TEST(mod, FL_SINGLETON)) continue;
 	if (!recur) break;
     }
     ary = rb_ary_new();
-    st_foreach(list, func, ary);
-    st_free_table(list);
+    st_foreach(me_arg.list, func, ary);
+    st_free_table(me_arg.list);
 
     return ary;
 }
@@ -1380,7 +1388,8 @@ VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_2/class.c#L1388
 rb_obj_singleton_methods(int argc, const VALUE *argv, VALUE obj)
 {
     VALUE recur, ary, klass, origin;
-    st_table *list, *mtbl;
+    struct method_entry_arg me_arg;
+    st_table *mtbl;
 
     if (argc == 0) {
 	recur = Qtrue;
@@ -1390,22 +1399,23 @@ rb_obj_singleton_methods(int argc, const https://github.com/ruby/ruby/blob/trunk/ruby_2_2/class.c#L1399
     }
     klass = CLASS_OF(obj);
     origin = RCLASS_ORIGIN(klass);
-    list = st_init_numtable();
+    me_arg.list = st_init_numtable();
+    me_arg.recur = recur;
     if (klass && FL_TEST(klass, FL_SINGLETON)) {
 	if ((mtbl = RCLASS_M_TBL(origin)) != 0)
-	    st_foreach(mtbl, method_entry_i, (st_data_t)list);
+	    st_foreach(mtbl, method_entry_i, (st_data_t)&me_arg);
 	klass = RCLASS_SUPER(klass);
     }
     if (RTEST(recur)) {
 	while (klass && (FL_TEST(klass, FL_SINGLETON) || RB_TYPE_P(klass, T_ICLASS))) {
 	    if (klass != origin && (mtbl = RCLASS_M_TBL(klass)) != 0)
-		st_foreach(mtbl, method_entry_i, (st_data_t)list);
+		st_foreach(mtbl, method_entry_i, (st_data_t)&me_arg);
 	    klass = RCLASS_SUPER(klass);
 	}
     }
     ary = rb_ary_new();
-    st_foreach(list, ins_methods_i, ary);
-    st_free_table(list);
+    st_foreach(me_arg.list, ins_methods_i, ary);
+    st_free_table(me_arg.list);
 
     return ary;
 }
Index: ruby_2_2/version.h
===================================================================
--- ruby_2_2/version.h	(revision 49591)
+++ ruby_2_2/version.h	(revision 49592)
@@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1
 #define RUBY_VERSION "2.2.0"
-#define RUBY_RELEASE_DATE "2015-02-13"
-#define RUBY_PATCHLEVEL 46
+#define RUBY_RELEASE_DATE "2015-02-14"
+#define RUBY_PATCHLEVEL 47
 
 #define RUBY_RELEASE_YEAR 2015
 #define RUBY_RELEASE_MONTH 2
-#define RUBY_RELEASE_DAY 13
+#define RUBY_RELEASE_DAY 14
 
 #include "ruby/version.h"
 
Index: ruby_2_2/test/ruby/test_refinement.rb
===================================================================
--- ruby_2_2/test/ruby/test_refinement.rb	(revision 49591)
+++ ruby_2_2/test/ruby/test_refinement.rb	(revision 49592)
@@ -1292,6 +1292,31 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/ruby/test_refinement.rb#L1292
     end;
   end
 
+  module NotIncludeSuperclassMethod
+    class X
+      def foo
+      end
+    end
+
+    class Y < X
+    end
+
+    module Bar
+      refine Y do
+        def foo
+        end
+      end
+    end
+  end
+
+  def test_instance_methods_not_include_superclass_method
+    bug10826 = '[ruby-dev:48854] [Bug #10826]'
+    assert_not_include(NotIncludeSuperclassMethod::Y.instance_methods(false),
+                       :foo, bug10826)
+    assert_include(NotIncludeSuperclassMethod::Y.instance_methods(true),
+                   :foo, bug10826)
+  end
+
   private
 
   def eval_using(mod, s)

Property changes on: ruby_2_2
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r49493


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]