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

ruby-changes:41069

From: ko1 <ko1@a...>
Date: Wed, 16 Dec 2015 15:39:22 +0900 (JST)
Subject: [ruby-changes:41069] ko1:r53144 (trunk): * vm.c: fix mark miss for proc given as passed block.

ko1	2015-12-16 15:38:52 +0900 (Wed, 16 Dec 2015)

  New Revision: 53144

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

  Log:
    * vm.c: fix mark miss for proc given as passed block.
      [Bug #11750]
    
    * vm.c (vm_make_proc_from_block): should return a Proc object
      if block is given. Previous implementation returns
      a Proc object only when corresponding Proc object is not
      available.
    
    * vm.c (vm_make_env_each): ditto.
    
    * test/ruby/test_proc.rb: add a test for this bug.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_proc.rb
    trunk/vm.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53143)
+++ ChangeLog	(revision 53144)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Dec 16 15:35:13 2015  Koichi Sasada  <ko1@a...>
+
+	* vm.c: fix mark miss for proc given as passed block.
+	  [Bug #11750]
+
+	* vm.c (vm_make_proc_from_block): should return a Proc object
+	  if block is given. Previous implementation returns
+	  a Proc object only when corresponding Proc object is not
+	  available.
+
+	* vm.c (vm_make_env_each): ditto.
+
+	* test/ruby/test_proc.rb: add a test for this bug.
+
 Wed Dec 16 12:24:59 2015  Marc-Andre Lafortune  <ruby-core@m...>
 
 	* test_struct.rb: Test that initialize is overridable [#11708]
Index: vm.c
===================================================================
--- vm.c	(revision 53143)
+++ vm.c	(revision 53144)
@@ -559,16 +559,17 @@ check_env_value(VALUE envval) https://github.com/ruby/ruby/blob/trunk/vm.c#L559
     return Qnil;		/* unreachable */
 }
 
-/* return Qfalse if proc was already created */
-static VALUE
-vm_make_proc_from_block(rb_thread_t *th, rb_block_t *block)
+/* return FALSE if proc was already created */
+static int
+vm_make_proc_from_block(rb_thread_t *th, rb_block_t *block, VALUE *procptr)
 {
     if (!block->proc) {
-	block->proc = rb_vm_make_proc(th, block, rb_cProc);
-	return block->proc;
+	*procptr = block->proc = rb_vm_make_proc(th, block, rb_cProc);
+	return TRUE;
     }
     else {
-	return Qfalse;
+	*procptr = block->proc;
+	return FALSE;
     }
 }
 
@@ -603,7 +604,7 @@ vm_make_env_each(rb_thread_t *const th, https://github.com/ruby/ruby/blob/trunk/vm.c#L604
     else {
 	rb_block_t *block = VM_EP_BLOCK_PTR(ep);
 
-	if (block && (blockprocval = vm_make_proc_from_block(th, block)) != Qfalse) {
+	if (block && (vm_make_proc_from_block(th, block, &blockprocval)) != Qfalse) {
 	    rb_proc_t *p;
 	    GetProcPtr(blockprocval, p);
 	    *ep = VM_ENVVAL_BLOCK_PTR(&p->block);
Index: test/ruby/test_proc.rb
===================================================================
--- test/ruby/test_proc.rb	(revision 53143)
+++ test/ruby/test_proc.rb	(revision 53144)
@@ -1321,4 +1321,24 @@ class TestProc < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_proc.rb#L1321
     def obj.b; binding; end
     assert_same(obj, obj.b.receiver, feature8779)
   end
+
+  def test_proc_mark
+    assert_normal_exit(<<-'EOS')
+      def f
+        Enumerator.new{
+          100000.times {|i|
+            yield
+            s = "#{i}"
+          }
+        }
+      end
+
+      def g
+        x = proc{}
+        f(&x)
+      end
+      e = g
+      e.each {}
+    EOS
+  end
 end

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

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