* string.c (sym_call), vm.c (invoke_block_from_c),
vm_insnhelper.c (vm_yield_with_cfunc): pass given block. [ruby-core:32075] * vm_eval.c (rb_funcall_passing_block): new function to call method with passing given block. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29335 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
08d2e528aa
commit
f5b0cb07e2
@ -1,3 +1,12 @@
|
|||||||
|
Fri Sep 24 23:44:59 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* string.c (sym_call), vm.c (invoke_block_from_c),
|
||||||
|
vm_insnhelper.c (vm_yield_with_cfunc): pass given block.
|
||||||
|
[ruby-core:32075]
|
||||||
|
|
||||||
|
* vm_eval.c (rb_funcall_passing_block): new function to call
|
||||||
|
method with passing given block.
|
||||||
|
|
||||||
Fri Sep 24 15:50:43 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
Fri Sep 24 15:50:43 2010 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* string.c (rb_str_to_i): fix rdoc: String#to_i raises an
|
* string.c (rb_str_to_i): fix rdoc: String#to_i raises an
|
||||||
|
4
string.c
4
string.c
@ -7228,6 +7228,8 @@ sym_to_sym(VALUE sym)
|
|||||||
return sym;
|
return sym;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VALUE rb_funcall_passing_block(VALUE recv, ID mid, int argc, const VALUE *argv);
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
sym_call(VALUE args, VALUE sym, int argc, VALUE *argv)
|
sym_call(VALUE args, VALUE sym, int argc, VALUE *argv)
|
||||||
{
|
{
|
||||||
@ -7237,7 +7239,7 @@ sym_call(VALUE args, VALUE sym, int argc, VALUE *argv)
|
|||||||
rb_raise(rb_eArgError, "no receiver given");
|
rb_raise(rb_eArgError, "no receiver given");
|
||||||
}
|
}
|
||||||
obj = argv[0];
|
obj = argv[0];
|
||||||
return rb_funcall3(obj, (ID)sym, argc - 1, argv + 1);
|
return rb_funcall_passing_block(obj, (ID)sym, argc - 1, argv + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -800,4 +800,22 @@ class TestProc < Test::Unit::TestCase
|
|||||||
ensure
|
ensure
|
||||||
set_trace_func(nil)
|
set_trace_func(nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_block_propagation
|
||||||
|
bug3792 = '[ruby-core:32075]'
|
||||||
|
c = Class.new do
|
||||||
|
def foo
|
||||||
|
yield
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
o = c.new
|
||||||
|
f = :foo.to_proc
|
||||||
|
assert_nothing_raised(LocalJumpError, bug3792) {
|
||||||
|
assert_equal('bar', f.(o) {'bar'}, bug3792)
|
||||||
|
}
|
||||||
|
assert_nothing_raised(LocalJumpError, bug3792) {
|
||||||
|
assert_equal('zot', o.method(:foo).to_proc.() {'zot'}, bug3792)
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
1
vm.c
1
vm.c
@ -549,6 +549,7 @@ invoke_block_from_c(rb_thread_t *th, const rb_block_t *block,
|
|||||||
iseq->local_size - arg_size);
|
iseq->local_size - arg_size);
|
||||||
ncfp->me = th->passed_me;
|
ncfp->me = th->passed_me;
|
||||||
th->passed_me = 0;
|
th->passed_me = 0;
|
||||||
|
th->passed_block = blockptr;
|
||||||
|
|
||||||
if (cref) {
|
if (cref) {
|
||||||
th->cfp->dfp[-1] = (VALUE)cref;
|
th->cfp->dfp[-1] = (VALUE)cref;
|
||||||
|
@ -665,6 +665,14 @@ rb_funcall3(VALUE recv, ID mid, int argc, const VALUE *argv)
|
|||||||
return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
|
return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VALUE
|
||||||
|
rb_funcall_passing_block(VALUE recv, ID mid, int argc, const VALUE *argv)
|
||||||
|
{
|
||||||
|
PASS_PASSED_BLOCK_TH(GET_THREAD());
|
||||||
|
|
||||||
|
return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope)
|
send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope)
|
||||||
{
|
{
|
||||||
|
@ -722,6 +722,9 @@ vm_yield_with_cfunc(rb_thread_t *th, const rb_block_t *block,
|
|||||||
self, (VALUE)block->dfp,
|
self, (VALUE)block->dfp,
|
||||||
0, th->cfp->sp, block->lfp, 1);
|
0, th->cfp->sp, block->lfp, 1);
|
||||||
|
|
||||||
|
if (blockargptr) {
|
||||||
|
th->cfp->lfp[0] = GC_GUARDED_PTR((VALUE)blockargptr);
|
||||||
|
}
|
||||||
val = (*ifunc->nd_cfnc) (arg, ifunc->nd_tval, argc, argv, blockarg);
|
val = (*ifunc->nd_cfnc) (arg, ifunc->nd_tval, argc, argv, blockarg);
|
||||||
|
|
||||||
th->cfp++;
|
th->cfp++;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user