summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--proc.c44
-rw-r--r--vm.c2
-rw-r--r--vm_args.c10
-rw-r--r--vm_dump.c6
-rw-r--r--vm_insnhelper.c16
5 files changed, 49 insertions, 29 deletions
diff --git a/proc.c b/proc.c
index 8ede200..818853e 100644
--- a/proc.c
+++ b/proc.c
@@ -579,6 +579,20 @@ bind_receiver(VALUE bindval)
return env->block.self;
}
+static VALUE
+sym_proc_new(VALUE klass, VALUE sym)
+{
+ rb_proc_t *proc;
+ sym_proc_t *symproc;
+ VALUE procval = TypedData_Make_Struct(klass, sym_proc_t, &proc_data_type, symproc);
+ symproc->env[0] = VM_ENVVAL_BLOCK_PTR(0);
+ proc = &symproc->basic;
+ proc->block.ep = symproc->env;
+ proc->block.iseq = (rb_iseq_t *)sym;
+ proc->block.proc = procval;
+ return procval;
+}
+
static const char proc_without_block[] = "tried to create Proc object without a block";
static VALUE
@@ -609,13 +623,9 @@ 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 = *block;
- proc->block.iseq = (rb_iseq_t *)procval;
- proc->block.proc = newprocval;
- return newprocval;
+ if (SYMBOL_P(procval)) {
+ if (klass != rb_cProc) return sym_proc_new(klass, procval);
+ return rb_sym_to_proc(procval);
}
if (RBASIC(procval)->klass == klass) {
return procval;
@@ -952,6 +962,7 @@ rb_proc_get_iseq(VALUE self, int *is_proc)
const rb_proc_t *proc;
const rb_iseq_t *iseq;
+ again:
GetProcPtr(self, proc);
iseq = proc->block.iseq;
if (is_proc) *is_proc = !proc->is_lambda;
@@ -964,6 +975,10 @@ rb_proc_get_iseq(VALUE self, int *is_proc)
if (is_proc) *is_proc = 0;
}
}
+ else if (SYMBOL_P(iseq)) {
+ self = rb_sym_to_proc((VALUE)iseq);
+ goto again;
+ }
return iseq;
}
@@ -1070,15 +1085,7 @@ rb_sym_to_proc(VALUE sym)
return aryp[index + 1];
}
else {
- rb_proc_t *ptr;
- sym_proc_t *symproc;
- VALUE ifunc = (VALUE)IFUNC_NEW(rb_sym_proc_call, (VALUE)id, 0);
- proc = TypedData_Make_Struct(rb_cProc, sym_proc_t, &proc_data_type, symproc);
- symproc->env[0] = VM_ENVVAL_BLOCK_PTR(0);
- ptr = &symproc->basic;
- ptr->block.ep = symproc->env;
- ptr->block.iseq = (rb_iseq_t *)ifunc;
- ptr->block.proc = ifunc;
+ proc = sym_proc_new(rb_cProc, ID2SYM(id));
aryp[index] = sym;
aryp[index + 1] = proc;
return proc;
@@ -1120,7 +1127,6 @@ proc_to_s(VALUE self)
const char *cname = rb_obj_classname(self);
const rb_iseq_t *iseq;
const char *is_lambda;
- const struct vm_ifunc *ifunc;
GetProcPtr(self, proc);
iseq = proc->block.iseq;
@@ -1135,9 +1141,9 @@ proc_to_s(VALUE self)
str = rb_sprintf("#<%s:%p@%"PRIsVALUE":%d%s>", cname, (void *)self,
iseq->body->location.path, first_lineno, is_lambda);
}
- else if ((ifunc = (struct vm_ifunc *)iseq)->func == rb_sym_proc_call) {
+ else if (SYMBOL_P(iseq)) {
str = rb_sprintf("#<%s:%p(&%+"PRIsVALUE")%s>", cname, (void *)self,
- ID2SYM((ID)ifunc->data), is_lambda);
+ (VALUE)iseq, is_lambda);
}
else {
str = rb_sprintf("#<%s:%p%s>", cname, (void *)proc->block.iseq,
diff --git a/vm.c b/vm.c
index 93a816d..755c28f 100644
--- a/vm.c
+++ b/vm.c
@@ -839,7 +839,7 @@ invoke_block_from_c_0(rb_thread_t *th, const rb_block_t *block,
VALUE self, int argc, const VALUE *argv, const rb_block_t *blockptr,
const rb_cref_t *cref, const int splattable)
{
- if (UNLIKELY(SPECIAL_CONST_P(block->iseq))) {
+ if (UNLIKELY(!RTEST(block->iseq))) {
return Qnil;
}
else if (LIKELY(RUBY_VM_NORMAL_ISEQ_P(block->iseq))) {
diff --git a/vm_args.c b/vm_args.c
index cb20f23..e0c7448 100644
--- a/vm_args.c
+++ b/vm_args.c
@@ -477,9 +477,8 @@ args_setup_block_parameter(rb_thread_t *th, struct rb_calling_info *calling, VAL
GetProcPtr(blockval, proc);
calling->blockptr = &proc->block;
}
- else if (RUBY_VM_IFUNC_P(blockptr->proc)) {
- const ID mid = (ID)((struct vm_ifunc *)blockptr->proc)->data;
- blockval = rb_sym_to_proc(ID2SYM(mid));
+ else if (SYMBOL_P(blockptr->proc)) {
+ blockval = rb_sym_to_proc(blockptr->proc);
}
else {
blockval = blockptr->proc;
@@ -783,9 +782,8 @@ vm_caller_setup_arg_block(const rb_thread_t *th, rb_control_frame_t *reg_cfp,
}
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;
+ calling->blockptr->iseq = (rb_iseq_t *)proc;
+ calling->blockptr->proc = proc;
}
else if (RUBY_VM_IFUNC_P(proc)) {
calling->blockptr = RUBY_VM_GET_BLOCK_PTR_IN_CFP(reg_cfp);
diff --git a/vm_dump.c b/vm_dump.c
index 311f1e8..1f9c5ba 100644
--- a/vm_dump.c
+++ b/vm_dump.c
@@ -98,6 +98,12 @@ control_frame_dump(rb_thread_t *th, rb_control_frame_t *cfp)
if (RUBY_VM_IFUNC_P(cfp->iseq)) {
iseq_name = "<ifunc>";
}
+ else if (SYMBOL_P(cfp->iseq)) {
+ tmp = rb_sym2str((VALUE)cfp->iseq);
+ iseq_name = RSTRING_PTR(tmp);
+ snprintf(posbuf, MAX_POSBUF, ":%s", iseq_name);
+ line = -1;
+ }
else {
pc = cfp->pc - cfp->iseq->body->iseq_encoded;
iseq_name = RSTRING_PTR(cfp->iseq->body->location.label);
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 850ef8b..7fbdb0e 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -2283,11 +2283,13 @@ vm_yield_with_cfunc(rb_thread_t *th, const rb_block_t *block, VALUE self,
const rb_block_t *blockargptr)
{
const struct vm_ifunc *ifunc = (struct vm_ifunc *)block->iseq;
- VALUE val, arg, blockarg;
+ VALUE val, arg, blockarg, data;
+ rb_block_call_func *func;
const rb_callable_method_entry_t *me = th->passed_bmethod_me;
th->passed_bmethod_me = NULL;
- if (!RUBY_VM_IFUNC_P(block->proc) && block_proc_is_lambda(block->proc)) {
+ if (!RUBY_VM_IFUNC_P(block->proc) && !SYMBOL_P(block->proc) &&
+ block_proc_is_lambda(block->proc)) {
arg = rb_ary_new4(argc, argv);
}
else if (argc == 0) {
@@ -2313,7 +2315,15 @@ vm_yield_with_cfunc(rb_thread_t *th, const rb_block_t *block, VALUE self,
self, VM_ENVVAL_PREV_EP_PTR(block->ep), (VALUE)me,
0, th->cfp->sp, 1, 0);
- val = (*ifunc->func) (arg, ifunc->data, argc, argv, blockarg);
+ if (SYMBOL_P(ifunc)) {
+ func = rb_sym_proc_call;
+ data = SYM2ID((VALUE)ifunc);
+ }
+ else {
+ func = ifunc->func;
+ data = (VALUE)ifunc->data;
+ }
+ val = (*func)(arg, data, argc, argv, blockarg);
th->cfp++;
return val;