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

ruby-changes:39570

From: ko1 <ko1@a...>
Date: Fri, 21 Aug 2015 17:38:15 +0900 (JST)
Subject: [ruby-changes:39570] ko1:r51651 (trunk): * vm_insnhelper.c (vm_invoke_block): we should not expect ci->argc is

ko1	2015-08-21 17:37:46 +0900 (Fri, 21 Aug 2015)

  New Revision: 51651

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

  Log:
    * vm_insnhelper.c (vm_invoke_block): we should not expect ci->argc is
      stable after invoking a block. [Bug #11451]
    * test/ruby/test_yield.rb: add a test. This test script is given by
      Alex Dowad.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_yield.rb
    trunk/vm_insnhelper.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51650)
+++ ChangeLog	(revision 51651)
@@ -1,3 +1,11 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Aug 21 17:32:42 2015  Koichi Sasada  <ko1@a...>
+
+	* vm_insnhelper.c (vm_invoke_block): we should not expect ci->argc is
+	  stable after invoking a block. [Bug #11451]
+
+	* test/ruby/test_yield.rb: add a test. This test script is given by
+	  Alex Dowad.
+
 Fri Aug 21 06:35:50 2015  Aaron Patterson <tenderlove@r...>
 
 	* test/openssl/test_ssl_session.rb: Fix tests so that they take in to
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 51650)
+++ vm_insnhelper.c	(revision 51651)
@@ -2336,10 +2336,11 @@ vm_invoke_block(rb_thread_t *th, rb_cont https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2336
     }
     else {
 	VALUE val;
+	int argc = ci->argc;
 	CALLER_SETUP_ARG(th->cfp, ci);
-	val = vm_yield_with_cfunc(th, block, block->self,
-				  ci->argc, STACK_ADDR_FROM_TOP(ci->argc), 0);
-	POPN(ci->argc); /* TODO: should put before C/yield? */
+
+	val = vm_yield_with_cfunc(th, block, block->self, argc, STACK_ADDR_FROM_TOP(argc), 0);
+	POPN(argc); /* TODO: should put before C/yield? */
 	return val;
     }
 }
Index: test/ruby/test_yield.rb
===================================================================
--- test/ruby/test_yield.rb	(revision 51650)
+++ test/ruby/test_yield.rb	(revision 51651)
@@ -401,4 +401,28 @@ class TestRubyYieldGen < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/ruby/test_yield.rb#L401
     end
     assert_equal [m, nil], y.s(m){|a,b|[a,b]}
   end
+
+  def test_block_cached_argc
+    # [Bug #11451]
+    assert_separately([], <<-"end;")
+      class Yielder
+        def each
+          yield :x, :y, :z
+        end
+      end
+      class Getter1
+        include Enumerable
+        def each(&block)
+          Yielder.new.each(&block)
+        end
+      end
+      class Getter2
+        include Enumerable
+        def each
+          Yielder.new.each { |a, b, c, d| yield(a) }
+        end
+      end
+      Getter1.new.map{Getter2.new.each{|x|}}
+    end;
+  end
 end

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

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