Skip to content
Permalink
Browse files
Save block argument position in e->cioff; fix #3593
  • Loading branch information
matz committed Apr 5, 2017
1 parent d9fb8b6 commit a7b0ab3769d9f7f13d47c2c6f23298c87b88eee8
Showing 2 changed files with 13 additions and 2 deletions.
@@ -157,8 +157,14 @@ 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();
ci = mrb->c->cibase + e->cioff;
bp = ci[1].stackent + 1;
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) {
@@ -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);
}

0 comments on commit a7b0ab3

Please sign in to comment.