diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h index ac11850..df5209f 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 98f2df0..e46d4e1 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 pass_procval) { 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, pass_procval); } /* diff --git a/vm_eval.c b/vm_eval.c index 3895e56..496b605 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 b57cccd..7d849b0 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++;