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

ruby-changes:29341

From: nagachika <ko1@a...>
Date: Wed, 19 Jun 2013 03:40:51 +0900 (JST)
Subject: [ruby-changes:29341] nagachika:r41393 (ruby_2_0_0): merge revision(s) 41343,41360,41386: [Backport #8531]

nagachika	2013-06-19 03:40:31 +0900 (Wed, 19 Jun 2013)

  New Revision: 41393

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

  Log:
    merge revision(s) 41343,41360,41386: [Backport #8531]
    
    test/ruby/test_symbol.rb: tests for [Bug #8531]
    * include/ruby/ruby.h, vm_eval.c (rb_funcall_with_block):
      new function to invoke a method with a block passed
      as an argument.
    
    * string.c (sym_call): use the above function to avoid
      a block sharing. [ruby-dev:47438] [Bug #8531]
    
    * vm_insnhelper.c (vm_yield_with_cfunc): don't set block
      in the frame.
    
    * test/ruby/test_symbol.rb (TestSymbol#test_block_given_to_proc):
      run related tests.

  Modified directories:
    branches/ruby_2_0_0/
  Modified files:
    branches/ruby_2_0_0/ChangeLog
    branches/ruby_2_0_0/include/ruby/ruby.h
    branches/ruby_2_0_0/string.c
    branches/ruby_2_0_0/test/ruby/test_symbol.rb
    branches/ruby_2_0_0/version.h
    branches/ruby_2_0_0/vm_eval.c
    branches/ruby_2_0_0/vm_insnhelper.c

Index: ruby_2_0_0/include/ruby/ruby.h
===================================================================
--- ruby_2_0_0/include/ruby/ruby.h	(revision 41392)
+++ ruby_2_0_0/include/ruby/ruby.h	(revision 41393)
@@ -1344,6 +1344,7 @@ VALUE rb_funcall(VALUE, ID, int, ...); https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/include/ruby/ruby.h#L1344
 VALUE rb_funcall2(VALUE, ID, int, const VALUE*);
 VALUE rb_funcall3(VALUE, ID, int, const VALUE*);
 VALUE rb_funcall_passing_block(VALUE, ID, int, const VALUE*);
+VALUE rb_funcall_with_block(VALUE, ID, int, const VALUE*, VALUE);
 int rb_scan_args(int, const VALUE*, const char*, ...);
 VALUE rb_call_super(int, const VALUE*);
 
Index: ruby_2_0_0/ChangeLog
===================================================================
--- ruby_2_0_0/ChangeLog	(revision 41392)
+++ ruby_2_0_0/ChangeLog	(revision 41393)
@@ -1,3 +1,18 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1
+Wed Jun 19 03:24:07 2013  Kazuki Tsujimoto  <kazuki@c...>
+
+	* include/ruby/ruby.h, vm_eval.c (rb_funcall_with_block):
+	  new function to invoke a method with a block passed
+	  as an argument.
+
+	* string.c (sym_call): use the above function to avoid
+	  a block sharing. [ruby-dev:47438] [Bug #8531]
+
+	* vm_insnhelper.c (vm_yield_with_cfunc): don't set block
+	  in the frame.
+
+	* test/ruby/test_symbol.rb (TestSymbol#test_block_given_to_proc):
+	  run related tests.
+
 Wed Jun 19 03:06:57 2013  Kazuki Tsujimoto  <kazuki@c...>
 
 	* test/ruby/test_proc.rb (TestProc#test_block_given_method_to_proc):
Index: ruby_2_0_0/string.c
===================================================================
--- ruby_2_0_0/string.c	(revision 41392)
+++ ruby_2_0_0/string.c	(revision 41393)
@@ -7920,7 +7920,7 @@ sym_to_sym(VALUE sym) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/string.c#L7920
 }
 
 static VALUE
-sym_call(VALUE args, VALUE sym, int argc, VALUE *argv)
+sym_call(VALUE args, VALUE sym, int argc, VALUE *argv, VALUE passed_proc)
 {
     VALUE obj;
 
@@ -7928,7 +7928,7 @@ sym_call(VALUE args, VALUE sym, int argc https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/string.c#L7928
 	rb_raise(rb_eArgError, "no receiver given");
     }
     obj = argv[0];
-    return rb_funcall_passing_block(obj, (ID)sym, argc - 1, argv + 1);
+    return rb_funcall_with_block(obj, (ID)sym, argc - 1, argv + 1, passed_proc);
 }
 
 /*
Index: ruby_2_0_0/vm_eval.c
===================================================================
--- ruby_2_0_0/vm_eval.c	(revision 41392)
+++ ruby_2_0_0/vm_eval.c	(revision 41393)
@@ -830,6 +830,23 @@ rb_funcall_passing_block(VALUE recv, ID https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_eval.c#L830
     return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
 }
 
+VALUE
+rb_funcall_with_block(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE pass_procval)
+{
+    if (!NIL_P(pass_procval)) {
+	rb_thread_t *th = GET_THREAD();
+	rb_block_t *block = 0;
+
+	rb_proc_t *pass_proc;
+	GetProcPtr(pass_procval, pass_proc);
+	block = &pass_proc->block;
+
+	th->passed_block = block;
+    }
+
+    return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
+}
+
 static VALUE
 send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope)
 {
Index: ruby_2_0_0/version.h
===================================================================
--- ruby_2_0_0/version.h	(revision 41392)
+++ ruby_2_0_0/version.h	(revision 41393)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1
 #define RUBY_VERSION "2.0.0"
 #define RUBY_RELEASE_DATE "2013-06-19"
-#define RUBY_PATCHLEVEL 230
+#define RUBY_PATCHLEVEL 231
 
 #define RUBY_RELEASE_YEAR 2013
 #define RUBY_RELEASE_MONTH 6
Index: ruby_2_0_0/vm_insnhelper.c
===================================================================
--- ruby_2_0_0/vm_insnhelper.c	(revision 41392)
+++ ruby_2_0_0/vm_insnhelper.c	(revision 41393)
@@ -2053,7 +2053,6 @@ vm_yield_with_cfunc(rb_thread_t *th, con https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L2053
     NODE *ifunc = (NODE *) block->iseq;
     VALUE val, arg, blockarg;
     int lambda = block_proc_is_lambda(block->proc);
-    rb_control_frame_t *cfp;
 
     if (lambda) {
 	arg = rb_ary_new4(argc, argv);
@@ -2077,13 +2076,10 @@ vm_yield_with_cfunc(rb_thread_t *th, con https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/vm_insnhelper.c#L2076
 	blockarg = Qnil;
     }
 
-    cfp = vm_push_frame(th, (rb_iseq_t *)ifunc, VM_FRAME_MAGIC_IFUNC, self,
-			0, VM_ENVVAL_PREV_EP_PTR(block->ep), 0,
-			th->cfp->sp, 1, 0);
+    vm_push_frame(th, (rb_iseq_t *)ifunc, VM_FRAME_MAGIC_IFUNC, self,
+		  0, VM_ENVVAL_PREV_EP_PTR(block->ep), 0,
+		  th->cfp->sp, 1, 0);
 
-    if (blockargptr) {
-	VM_CF_LEP(cfp)[0] = VM_ENVVAL_BLOCK_PTR(blockargptr);
-    }
     val = (*ifunc->nd_cfnc) (arg, ifunc->nd_tval, argc, argv, blockarg);
 
     th->cfp++;
Index: ruby_2_0_0/test/ruby/test_symbol.rb
===================================================================
--- ruby_2_0_0/test/ruby/test_symbol.rb	(revision 41392)
+++ ruby_2_0_0/test/ruby/test_symbol.rb	(revision 41393)
@@ -33,7 +33,7 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_symbol.rb#L33
     assert_inspect_evaled(':foo')
     assert_inspect_evaled(':foo!')
     assert_inspect_evaled(':bar?')
-    assert_inspect_evaled(':<<')
+    assert_inspect_evaled(":<<")
     assert_inspect_evaled(':>>')
     assert_inspect_evaled(':<=')
     assert_inspect_evaled(':>=')
@@ -115,6 +115,33 @@ class TestSymbol < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_symbol.rb#L115
     assert_raise(ArgumentError) { :foo.to_proc.call }
   end
 
+  def m_block_given?
+    block_given?
+  end
+
+  def m2_block_given?(m = nil)
+    if m
+      [block_given?, m.call(self)]
+    else
+      block_given?
+    end
+  end
+
+  def test_block_given_to_proc
+    bug8531 = '[Bug #8531]'
+    m = :m_block_given?.to_proc
+    assert(!m.call(self), "#{bug8531} without block")
+    assert(m.call(self) {}, "#{bug8531} with block")
+    assert(!m.call(self), "#{bug8531} without block second")
+  end
+
+  def test_block_persist_between_calls
+    bug8531 = '[Bug #8531]'
+    m2 = :m2_block_given?.to_proc
+    assert_equal([true, false], m2.call(self, m2) {}, "#{bug8531} nested with block")
+    assert_equal([false, false], m2.call(self, m2), "#{bug8531} nested without block")
+  end
+
   def test_succ
     assert_equal(:fop, :foo.succ)
   end

Property changes on: ruby_2_0_0
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r41343,41360,41386


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

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