diff options
Diffstat (limited to 'proc.c')
-rw-r--r-- | proc.c | 30 |
1 files changed, 23 insertions, 7 deletions
@@ -507,12 +507,26 @@ proc_call(int argc, VALUE *argv, VALUE procval) } VALUE -rb_proc_call(VALUE self, VALUE args, rb_blockptr blockptr) +rb_proc_call(VALUE self, VALUE args) { rb_proc_t *proc; GetProcPtr(self, proc); return vm_invoke_proc(GET_THREAD(), proc, proc->block.self, - RARRAY_LEN(args), RARRAY_PTR(args), blockptr); + RARRAY_LEN(args), RARRAY_PTR(args), 0); +} + +VALUE +rb_proc_call_with_block(VALUE self, int argc, VALUE *argv, VALUE pass_procval) +{ + rb_proc_t *proc, *pass_proc = 0; + GetProcPtr(self, proc); + + if (!NIL_P(pass_procval)) { + GetProcPtr(pass_procval, pass_proc); + } + + return vm_invoke_proc(GET_THREAD(), proc, proc->block.self, + argc, argv, &pass_proc->block); } /* @@ -1584,7 +1598,7 @@ proc_binding(VALUE self) return bindval; } -static VALUE curry(VALUE dummy, VALUE args, int argc, VALUE *argv, rb_blockptr blockptr); +static VALUE curry(VALUE dummy, VALUE args, int argc, VALUE *argv, VALUE passed_proc); static VALUE make_curry_proc(VALUE proc, VALUE passed, VALUE arity) @@ -1600,7 +1614,7 @@ make_curry_proc(VALUE proc, VALUE passed, VALUE arity) } static VALUE -curry(VALUE dummy, VALUE args, int argc, VALUE *argv, rb_blockptr blockptr) +curry(VALUE dummy, VALUE args, int argc, VALUE *argv, VALUE passed_proc) { VALUE proc, passed, arity; proc = RARRAY_PTR(args)[0]; @@ -1609,15 +1623,17 @@ curry(VALUE dummy, VALUE args, int argc, VALUE *argv, rb_blockptr blockptr) passed = rb_ary_plus(passed, rb_ary_new4(argc, argv)); rb_ary_freeze(passed); + if(RARRAY_LEN(passed) < FIX2INT(arity)) { - if (blockptr) { + if (!NIL_P(passed_proc)) { rb_warn("given block not used"); } arity = make_curry_proc(proc, passed, arity); return arity; } - arity = rb_proc_call(proc, passed, blockptr); - return arity; + else { + return rb_proc_call_with_block(proc, RARRAY_LEN(passed), RARRAY_PTR(passed), passed_proc); + } } /* |