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

ruby-changes:20179

From: nagachika <ko1@a...>
Date: Sun, 26 Jun 2011 00:05:48 +0900 (JST)
Subject: [ruby-changes:20179] nagachika:r32227 (trunk): * vm_insnhelper.c (vm_search_superclass): avoid control frame

nagachika	2011-06-26 00:05:37 +0900 (Sun, 26 Jun 2011)

  New Revision: 32227

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

  Log:
    * vm_insnhelper.c (vm_search_superclass): avoid control frame
      stack overrun. currently super() in Proc created in a method
      defined by Module#define_method raise NoMethodError. [Bug #4881]
    * test/ruby/test_method.rb t_super_in_proc_from_define_method):
      add test for it.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_method.rb
    trunk/vm_insnhelper.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32226)
+++ ChangeLog	(revision 32227)
@@ -1,3 +1,11 @@
+Sat Jun 25 23:45:30 2011  CHIKANAGA Tomoyuki  <nagachika00@g...>
+
+	* vm_insnhelper.c (vm_search_superclass): avoid control frame
+	  stack overrun. currently super() in Proc created in a method
+	  defined by Module#define_method raise NoMethodError. [Bug #4881]
+	* test/ruby/test_method.rb t_super_in_proc_from_define_method):
+	  add test for it.
+
 Sat Jun 25 23:23:14 2011  CHIKANAGA Tomoyuki  <nagachika00@g...>
 
 	* thread.c (sleep_forever): now Kernel#sleep don't wakeup by
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 32226)
+++ vm_insnhelper.c	(revision 32227)
@@ -1410,9 +1410,14 @@
 	}
 
 	while (lcfp->iseq != iseq) {
+	    rb_thread_t *th = GET_THREAD();
 	    VALUE *tdfp = GET_PREV_DFP(lcfp->dfp);
 	    while (1) {
 		lcfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(lcfp);
+		if (RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, lcfp)) {
+		    rb_raise(rb_eNoMethodError,
+			     "super called outside of method");
+		}
 		if (lcfp->dfp == tdfp) {
 		    break;
 		}
Index: test/ruby/test_method.rb
===================================================================
--- test/ruby/test_method.rb	(revision 32226)
+++ test/ruby/test_method.rb	(revision 32227)
@@ -233,6 +233,20 @@
     end
   end
 
+  def test_super_in_proc_from_define_method
+    c1 = Class.new {
+      def m
+        :m1
+      end
+    }
+    c2 = Class.new(c1) { define_method(:m) { Proc.new { super() } } }
+    # c2.new.m.call should return :m1, but currently it raise NoMethodError.
+    # see [Bug #4881] and [Bug #3136]
+    assert_raise(NoMethodError) {
+      c2.new.m.call
+    }
+  end
+
   def test_clone
     o = Object.new
     def o.foo; :foo; end

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

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