From 44c29e88aeaf241915b3d10a44d4a3748d1a6328 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Thu, 11 Dec 2014 00:36:18 +0900 Subject: block_given did not work with nested block invocation for some cases; fix #2665 --- src/kernel.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/kernel.c') diff --git a/src/kernel.c b/src/kernel.c index 22fe40218..cb938f152 100644 --- a/src/kernel.c +++ b/src/kernel.c @@ -187,15 +187,19 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self) else { /* block_given? called within block; check upper scope */ if (ci->proc->env && ci->proc->env->stack) { - given_p = !(ci->proc->env->stack == mrb->c->stbase || - mrb_nil_p(ci->proc->env->stack[1])); - } - else { - if (ci->argc > 0) { - bp += ci->argc; + mrb_value *sp = ci->proc->env->stack; + + while (mrb->c->cibase < ci) { + if (ci->stackent == sp) { + break; + } + ci--; } - given_p = !mrb_nil_p(*bp); } + if (ci->argc > 0) { + bp += ci->argc; + } + given_p = !mrb_nil_p(*bp); } return mrb_bool_value(given_p); -- cgit v1.2.3