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

ruby-changes:39420

From: nobu <ko1@a...>
Date: Fri, 7 Aug 2015 17:08:16 +0900 (JST)
Subject: [ruby-changes:39420] nobu:r51501 (trunk): proc.c: fix for uncallable method

nobu	2015-08-07 17:07:58 +0900 (Fri, 07 Aug 2015)

  New Revision: 51501

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

  Log:
    proc.c: fix for uncallable method
    
    * proc.c (method_super_method): uncallable method entry does not
      have the defined class, use the owner instead.
      [ruby-core:70254] [Bug #11419]
    * test/ruby/test_method.rb (test_super_method_unbound): add test
      by Akira Matsuda.

  Modified files:
    trunk/ChangeLog
    trunk/proc.c
    trunk/test/ruby/test_method.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51500)
+++ ChangeLog	(revision 51501)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Aug  7 17:07:56 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* proc.c (method_super_method): uncallable method entry does not
+	  have the defined class, use the owner instead.
+	  [ruby-core:70254] [Bug #11419]
+
+	* test/ruby/test_method.rb (test_super_method_unbound): add test
+	  by Akira Matsuda.
+
 Thu Aug  6 10:49:57 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* node.c (rb_alloc_tmp_buffer): round up the size and check the
Index: proc.c
===================================================================
--- proc.c	(revision 51500)
+++ proc.c	(revision 51501)
@@ -1249,6 +1249,12 @@ mnew(VALUE klass, VALUE obj, ID id, VALU https://github.com/ruby/ruby/blob/trunk/proc.c#L1249
     return mnew_from_me(me, klass, obj, id, mclass, scope);
 }
 
+static inline VALUE
+method_entry_defined_class(const rb_method_entry_t *me)
+{
+    VALUE defined_class = me->defined_class;
+    return defined_class ? defined_class : me->owner;
+}
 
 /**********************************************************************
  *
@@ -1299,8 +1305,8 @@ method_eq(VALUE method, VALUE other) https://github.com/ruby/ruby/blob/trunk/proc.c#L1305
     m1 = (struct METHOD *)DATA_PTR(method);
     m2 = (struct METHOD *)DATA_PTR(other);
 
-    klass1 = m1->me->defined_class ? m1->me->defined_class : m1->me->owner;
-    klass2 = m2->me->defined_class ? m2->me->defined_class : m2->me->owner;
+    klass1 = method_entry_defined_class(m1->me);
+    klass2 = method_entry_defined_class(m2->me);
 
     if (!rb_method_entry_eq(m1->me, m2->me) ||
 	klass1 != klass2 ||
@@ -2326,7 +2332,7 @@ method_inspect(VALUE method) https://github.com/ruby/ruby/blob/trunk/proc.c#L2332
 	defined_class = data->me->def->body.alias.original_me->owner;
     }
     else {
-	defined_class = data->me->defined_class ? data->me->defined_class : data->me->owner;
+	defined_class = method_entry_defined_class(data->me);
     }
 
     if (RB_TYPE_P(defined_class, T_ICLASS)) {
@@ -2451,7 +2457,7 @@ method_super_method(VALUE method) https://github.com/ruby/ruby/blob/trunk/proc.c#L2457
     const rb_method_entry_t *me;
 
     TypedData_Get_Struct(method, struct METHOD, &method_data_type, data);
-    super_class = RCLASS_SUPER(data->me->defined_class);
+    super_class = RCLASS_SUPER(method_entry_defined_class(data->me));
     if (!super_class) return Qnil;
     me = (rb_method_entry_t *)rb_callable_method_entry_without_refinements(super_class, data->me->called_id);
     if (!me) return Qnil;
Index: test/ruby/test_method.rb
===================================================================
--- test/ruby/test_method.rb	(revision 51500)
+++ test/ruby/test_method.rb	(revision 51501)
@@ -868,6 +868,11 @@ class TestMethod < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_method.rb#L868
     assert_equal(Base.instance_method(:foo), m, Feature9781)
     m = assert_nothing_raised(NameError, Feature9781) {break m.super_method}
     assert_nil(m, Feature9781)
+
+    bug11419 = '[ruby-core:70254]'
+    m = Object.instance_method(:tap)
+    m = assert_nothing_raised(NameError, bug11419) {break m.super_method}
+    assert_nil(m, bug11419)
   end
 
   def test_super_method_module

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

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