From 62bd8db1985736d23d68608c70c32d56432a84fd Mon Sep 17 00:00:00 2001 From: ktsj Date: Mon, 17 Jun 2013 12:47:26 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41360 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 15 +++++++++++++++ include/ruby/ruby.h | 1 + string.c | 4 ++-- test/ruby/test_symbol.rb | 1 - vm_eval.c | 17 +++++++++++++++++ vm_insnhelper.c | 10 +++------- 6 files changed, 38 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3ed7df09c5..72c2333e31 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +Mon Jun 17 21:42:18 2013 Kazuki Tsujimoto + + * 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. + Mon Jun 17 21:33:27 2013 Kazuki Tsujimoto * include/ruby/intern.h, proc.c (rb_method_call_with_block): diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index ac11850d69..df5209f0bb 100644 --- a/include/ruby/ruby.h +++ b/include/ruby/ruby.h @@ -1480,6 +1480,7 @@ VALUE rb_funcallv_public(VALUE, ID, int, const VALUE*); #define rb_funcall2 rb_funcallv #define rb_funcall3 rb_funcallv_public 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*); diff --git a/string.c b/string.c index 98f2df04f0..9cc8e1e54e 100644 --- a/string.c +++ b/string.c @@ -8213,7 +8213,7 @@ sym_to_sym(VALUE sym) } 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; @@ -8221,7 +8221,7 @@ sym_call(VALUE args, VALUE sym, int argc, VALUE *argv) 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); } /* diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb index f3c1b99a6d..3a4f68cdd5 100644 --- a/test/ruby/test_symbol.rb +++ b/test/ruby/test_symbol.rb @@ -128,7 +128,6 @@ class TestSymbol < Test::Unit::TestCase def test_block_given_to_proc bug8531 = '[Bug #8531]' - skip bug8531 m = :m_block_given?.to_proc assert(!m.call(self), "#{bug8531} without block") assert(m.call(self) {}, "#{bug8531} with block") diff --git a/vm_eval.c b/vm_eval.c index 80ed1bd0be..ec949fa7d0 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -830,6 +830,23 @@ rb_funcall_passing_block(VALUE recv, ID mid, int argc, const VALUE *argv) 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) { diff --git a/vm_insnhelper.c b/vm_insnhelper.c index b57cccd0fa..7d849b0081 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -2076,7 +2076,6 @@ vm_yield_with_cfunc(rb_thread_t *th, const rb_block_t *block, 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); @@ -2100,13 +2099,10 @@ vm_yield_with_cfunc(rb_thread_t *th, const rb_block_t *block, 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++;