Save block argument position in e->cioff; fix
MODIFY
src/kernel.c
src/kernel.c
@@ -157,10 +157,16 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self)
/* top-level does not have block slot (alway false) */
if (sp == mrb->c->stbase)
return mrb_false_value();
+ if (e->cioff < 0) {
+ /* use saved block arg position */
+ bp = &e->stack[-e->cioff];
+ }
+ else {
ci = mrb->c->cibase + e->cioff;
bp = ci[1].stackent + 1;
}
}
+ }
if (ci->argc > 0) {
bp += ci->argc;
}

MODIFY
src/vm.c
src/vm.c
@@ -257,8 +257,13 @@ mrb_env_unshare(mrb_state *mrb, struct REnv *e)
{
size_t len = (size_t)MRB_ENV_STACK_LEN(e);
mrb_value *p = (mrb_value *)mrb_malloc(mrb, sizeof(mrb_value)*len);
+ ptrdiff_t cioff = e->cioff;
MRB_ENV_UNSHARE_STACK(e);
+ if (!e->c) {
+ /* save block argument position (negated) */
+ e->cioff = -mrb->c->cibase[cioff].argc-1;
+ }
if (len > 0) {
stack_copy(p, e->stack, len);
}

Save block argument position in e->cioff; fix #3593