mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
This commit is contained in:
parent
1720a5bac4
commit
62bd8db198
6 changed files with 38 additions and 10 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
Mon Jun 17 21:42:18 2013 Kazuki Tsujimoto <kazuki@callcc.net>
|
||||
|
||||
* 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 <kazuki@callcc.net>
|
||||
|
||||
* include/ruby/intern.h, proc.c (rb_method_call_with_block):
|
||||
|
|
|
@ -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*);
|
||||
|
||||
|
|
4
string.c
4
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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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")
|
||||
|
|
17
vm_eval.c
17
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)
|
||||
{
|
||||
|
|
|
@ -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++;
|
||||
|
|
Loading…
Reference in a new issue