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

ruby-changes:32100

From: nobu <ko1@a...>
Date: Sat, 14 Dec 2013 00:18:23 +0900 (JST)
Subject: [ruby-changes:32100] nobu:r44179 (trunk): proc.c: fix inherited owner

nobu	2013-12-14 00:18:12 +0900 (Sat, 14 Dec 2013)

  New Revision: 44179

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

  Log:
    proc.c: fix inherited owner
    
    * proc.c (mnew_from_me): achieve the original defined_class from
      prepended iclass, to fix inherited owner.
    * proc.c (method_owner): return the defined class, but not the
      class which the method object is created from.

  Modified files:
    trunk/ChangeLog
    trunk/proc.c
    trunk/test/ruby/test_method.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44178)
+++ ChangeLog	(revision 44179)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Dec 14 00:18:08 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* proc.c (mnew_from_me): achieve the original defined_class from
+	  prepended iclass, to fix inherited owner.
+
+	* proc.c (method_owner): return the defined class, but not the
+	  class which the method object is created from.
+
 Fri Dec 13 22:29:21 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* proc.c (method_owner): return the class where alias is defined, not
Index: proc.c
===================================================================
--- proc.c	(revision 44178)
+++ proc.c	(revision 44179)
@@ -1168,6 +1168,10 @@ mnew_from_me(rb_method_entry_t *me, VALU https://github.com/ruby/ruby/blob/trunk/proc.c#L1168
 	goto again;
     }
 
+    if (RB_TYPE_P(defined_class, T_ICLASS)) {
+	defined_class = RBASIC_CLASS(defined_class);
+    }
+
     klass = defined_class;
 
     while (rclass != klass &&
@@ -1175,10 +1179,6 @@ mnew_from_me(rb_method_entry_t *me, VALU https://github.com/ruby/ruby/blob/trunk/proc.c#L1179
 	rclass = RCLASS_SUPER(rclass);
     }
 
-    if (RB_TYPE_P(klass, T_ICLASS)) {
-	klass = RBASIC(klass)->klass;
-    }
-
   gen_method:
     method = TypedData_Make_Struct(mclass, struct METHOD, &method_data_type, data);
 
@@ -1395,7 +1395,7 @@ method_owner(VALUE obj) https://github.com/ruby/ruby/blob/trunk/proc.c#L1395
     struct METHOD *data;
 
     TypedData_Get_Struct(obj, struct METHOD, &method_data_type, data);
-    return data->rclass;
+    return data->defined_class;
 }
 
 void
Index: test/ruby/test_method.rb
===================================================================
--- test/ruby/test_method.rb	(revision 44178)
+++ test/ruby/test_method.rb	(revision 44179)
@@ -180,6 +180,15 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L180
     assert_equal(Array.instance_method(:map).hash, Array.instance_method(:collect).hash)
   end
 
+  def test_owner
+    c = Class.new do
+      def foo; end
+    end
+    assert_equal(c, c.instance_method(:foo).owner)
+    c2 = Class.new(c)
+    assert_equal(c, c2.instance_method(:foo).owner)
+  end
+
   def test_receiver_name_owner
     o = Object.new
     def o.foo; end

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

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