From c90550c251f0c598458d52dd2cbd5445e8d26c65 Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 1 Oct 2015 10:52:52 +0000 Subject: [PATCH] vm_args.c: fix marking symbol ifunc * vm_args.c (vm_caller_setup_arg_block): store new ifunc for symbol in control frame proc to be marked. * proc.c (proc_new), vm_insnhelper.c (vm_yield_with_cfunc): block->proc may be an ifunc now. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51995 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- proc.c | 7 +++++++ vm_args.c | 22 ++++++++++++++-------- vm_insnhelper.c | 3 +-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/proc.c b/proc.c index 98029d024b..bd4719d00f 100644 --- a/proc.c +++ b/proc.c @@ -596,6 +596,13 @@ proc_new(VALUE klass, int8_t is_lambda) procval = block->proc; if (procval) { + if (RUBY_VM_IFUNC_P(procval)) { + VALUE newprocval = rb_proc_alloc(klass); + rb_proc_t *proc = RTYPEDDATA_DATA(newprocval); + proc->block.iseq = (rb_iseq_t *)procval; + proc->block.proc = newprocval; + return newprocval; + } if (RBASIC(procval)->klass == klass) { return procval; } diff --git a/vm_args.c b/vm_args.c index 1ed98b5a4c..18911b4a5d 100644 --- a/vm_args.c +++ b/vm_args.c @@ -776,12 +776,21 @@ vm_caller_setup_arg_block(const rb_thread_t *th, rb_control_frame_t *reg_cfp, proc = *(--reg_cfp->sp); - if (SYMBOL_P(proc) && rb_method_basic_definition_p(rb_cSymbol, idTo_proc)) { - calling->blockptr = RUBY_VM_GET_BLOCK_PTR_IN_CFP(reg_cfp); - calling->blockptr->iseq = (rb_iseq_t *)IFUNC_NEW(rb_sym_proc_call, SYM2ID(proc), 0); - calling->blockptr->proc = 0; + if (NIL_P(proc)) { + calling->blockptr = NULL; } - else if (!NIL_P(proc)) { + else if (SYMBOL_P(proc) && rb_method_basic_definition_p(rb_cSymbol, idTo_proc)) { + calling->blockptr = RUBY_VM_GET_BLOCK_PTR_IN_CFP(reg_cfp); + blockiseq = (rb_iseq_t *)IFUNC_NEW(rb_sym_proc_call, SYM2ID(proc), 0); + calling->blockptr->iseq = blockiseq; + calling->blockptr->proc = (VALUE)blockiseq; + } + else if (RUBY_VM_IFUNC_P(proc)) { + calling->blockptr = RUBY_VM_GET_BLOCK_PTR_IN_CFP(reg_cfp); + calling->blockptr->iseq = (rb_iseq_t *)proc; + calling->blockptr->proc = proc; + } + else { if (!rb_obj_is_proc(proc)) { VALUE b; b = rb_check_convert_type(proc, T_DATA, "Proc", "to_proc"); @@ -797,9 +806,6 @@ vm_caller_setup_arg_block(const rb_thread_t *th, rb_control_frame_t *reg_cfp, calling->blockptr = &po->block; RUBY_VM_GET_BLOCK_PTR_IN_CFP(reg_cfp)->proc = proc; } - else { - calling->blockptr = NULL; - } } else if (blockiseq != 0) { /* likely */ rb_block_t *blockptr = calling->blockptr = RUBY_VM_GET_BLOCK_PTR_IN_CFP(reg_cfp); diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 59adf8877d..40c208c5bc 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -2297,11 +2297,10 @@ vm_yield_with_cfunc(rb_thread_t *th, const rb_block_t *block, VALUE self, { const struct vm_ifunc *ifunc = (struct vm_ifunc *)block->iseq; VALUE val, arg, blockarg; - int lambda = block_proc_is_lambda(block->proc); const rb_callable_method_entry_t *me = th->passed_bmethod_me; th->passed_bmethod_me = NULL; - if (lambda) { + if (!RUBY_VM_IFUNC_P(block->proc) && block_proc_is_lambda(block->proc)) { arg = rb_ary_new4(argc, argv); } else if (argc == 0) {