From: wanabe Date: 2008-04-09T19:22:20+09:00 Subject: [ruby-dev:34273] patch for [ruby-core:15551] ワナベと申します。 [ruby-core:15551]に対するパッチを書きました。 Proc#curry で作られた Proc オブジェクトにブロックを渡せるようにしました。 proc_call() 中の BUILTIN_TYPE(proc->block.iseq) != T_NODE の意味が よく分からなかったので外してしまいましたが、 何か特別な意図のある式なのでしょうか。 Index: proc.c =================================================================== --- proc.c (revision 15910) +++ proc.c (working copy) @@ -496,8 +496,7 @@ rb_block_t *blockptr = 0; GetProcPtr(procval, proc); - if (BUILTIN_TYPE(proc->block.iseq) != T_NODE && - proc->block.iseq->arg_block != -1) { + if (proc->block.iseq->arg_block != -1) { if (rb_block_given_p()) { rb_proc_t *proc; @@ -1620,7 +1619,7 @@ arity = make_curry_proc(proc, passed, arity); return arity; } - arity = rb_proc_call(proc, passed); + arity = proc_call(RARRAY_LEN(passed), RARRAY_PTR(passed), proc); return arity; } Index: vm.c =================================================================== --- vm.c (revision 15910) +++ vm.c (working copy) @@ -572,7 +572,7 @@ val = vm_eval_body(th); } else { - val = vm_yield_with_cfunc(th, block, self, argc, argv); + val = vm_yield_with_cfunc(th, block, self, argc, argv, blockptr); } return val; } Index: vm_insnhelper.c =================================================================== --- vm_insnhelper.c (revision 15910) +++ vm_insnhelper.c (working copy) @@ -644,7 +644,7 @@ static inline VALUE vm_yield_with_cfunc(rb_thread_t *th, rb_block_t *block, - VALUE self, int argc, VALUE *argv) + VALUE self, int argc, VALUE *argv, rb_block_t *blockptr) { NODE *ifunc = (NODE *) block->iseq; VALUE val; @@ -665,7 +665,15 @@ self, (VALUE)block->dfp, 0, th->cfp->sp, block->lfp, 1); - val = (*ifunc->nd_cfnc) (arg, ifunc->nd_tval, argc, argv); + if (blockptr) { + VALUE store_block = th->cfp->lfp[0]; + th->cfp->lfp[0] = GC_GUARDED_PTR(blockptr); + val = (*ifunc->nd_cfnc) (arg, ifunc->nd_tval, argc, argv); + th->cfp->lfp[0] = store_block; + } + else { + val = (*ifunc->nd_cfnc) (arg, ifunc->nd_tval, argc, argv); + } th->cfp++; return val; @@ -821,7 +829,7 @@ return Qundef; } else { - val = vm_yield_with_cfunc(th, block, block->self, argc, STACK_ADDR_FROM_TOP(argc)); + val = vm_yield_with_cfunc(th, block, block->self, argc, STACK_ADDR_FROM_TOP(argc), 0); POPN(argc); /* TODO: should put before C/yield? */ return val; } -- ワナベ