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

ruby-changes:30645

From: nobu <ko1@a...>
Date: Thu, 29 Aug 2013 17:03:30 +0900 (JST)
Subject: [ruby-changes:30645] nobu:r42724 (trunk): vm_insnhelper.c: fix zsuper in prepended

nobu	2013-08-29 17:03:23 +0900 (Thu, 29 Aug 2013)

  New Revision: 42724

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

  Log:
    vm_insnhelper.c: fix zsuper in prepended
    
    * vm_insnhelper.c (vm_call_method): a method entry refers the based
      class/module, so should search superclass from the origin i-class
      where the entry belongs to, to get rid of infinite loop when zsuper
      in a prepended class/module.  [ruby-core:54105] [Bug #8238]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_module.rb
    trunk/vm_insnhelper.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42723)
+++ ChangeLog	(revision 42724)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Aug 29 17:03:10 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm_insnhelper.c (vm_call_method): a method entry refers the based
+	  class/module, so should search superclass from the origin i-class
+	  where the entry belongs to, to get rid of infinite loop when zsuper
+	  in a prepended class/module.  [ruby-core:54105] [Bug #8238]
+
 Thu Aug 29 05:35:58 2013  Eric Hodel  <drbrain@s...>
 
 	* ext/zlib/zlib.c (zstream_run):  Fix handling of deflate streams that
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 42723)
+++ vm_insnhelper.c	(revision 42724)
@@ -1769,6 +1769,8 @@ vm_call_method(rb_thread_t *th, rb_contr https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1769
   start_method_dispatch:
     if (ci->me != 0) {
 	if ((ci->me->flag == 0)) {
+	    VALUE klass;
+
 	  normal_method_dispatch:
 	    switch (ci->me->def->type) {
 	      case VM_METHOD_TYPE_ISEQ:{
@@ -1801,10 +1803,10 @@ vm_call_method(rb_thread_t *th, rb_contr https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1803
 		return vm_call_bmethod(th, cfp, ci);
 	      }
 	      case VM_METHOD_TYPE_ZSUPER:{
-		VALUE klass;
-
+		klass = ci->me->klass;
+		klass = RCLASS_ORIGIN(klass);
 	      zsuper_method_dispatch:
-		klass = RCLASS_SUPER(ci->me->klass);
+		klass = RCLASS_SUPER(klass);
 		ci_temp = *ci;
 		ci = &ci_temp;
 
@@ -1866,6 +1868,7 @@ vm_call_method(rb_thread_t *th, rb_contr https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L1868
 		    goto normal_method_dispatch;
 		}
 		else {
+		    klass = ci->me->klass;
 		    goto zsuper_method_dispatch;
 		}
 	      }
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 42723)
+++ test/ruby/test_module.rb	(revision 42724)
@@ -1527,6 +1527,21 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1527
     assert_nothing_raised(NoMethodError, bug8005) {a.send :foo}
   end
 
+  def test_prepend_visibility_inherited
+    bug8238 = '[ruby-core:54105] [Bug #8238]'
+    assert_separately [], <<-"end;", timeout: 3
+      class A
+        def foo() A; end
+        private :foo
+      end
+      class B < A
+        public :foo
+        prepend Module.new
+      end
+      assert_equal(A, B.new.foo, "#{bug8238}")
+    end;
+  end
+
   def test_prepend_included_modules
     bug8025 = '[ruby-core:53158] [Bug #8025]'
     mixin = labeled_module("mixin")

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

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