Skip to content

Commit a7b0ab3

Browse files
committed
Save block argument position in e->cioff; fix #3593
1 parent d9fb8b6 commit a7b0ab3

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/kernel.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,14 @@ mrb_f_block_given_p_m(mrb_state *mrb, mrb_value self)
157157
/* top-level does not have block slot (alway false) */
158158
if (sp == mrb->c->stbase)
159159
return mrb_false_value();
160-
ci = mrb->c->cibase + e->cioff;
161-
bp = ci[1].stackent + 1;
160+
if (e->cioff < 0) {
161+
/* use saved block arg position */
162+
bp = &e->stack[-e->cioff];
163+
}
164+
else {
165+
ci = mrb->c->cibase + e->cioff;
166+
bp = ci[1].stackent + 1;
167+
}
162168
}
163169
}
164170
if (ci->argc > 0) {

src/vm.c

+5
Original file line numberDiff line numberDiff line change
@@ -257,8 +257,13 @@ mrb_env_unshare(mrb_state *mrb, struct REnv *e)
257257
{
258258
size_t len = (size_t)MRB_ENV_STACK_LEN(e);
259259
mrb_value *p = (mrb_value *)mrb_malloc(mrb, sizeof(mrb_value)*len);
260+
ptrdiff_t cioff = e->cioff;
260261

261262
MRB_ENV_UNSHARE_STACK(e);
263+
if (!e->c) {
264+
/* save block argument position (negated) */
265+
e->cioff = -mrb->c->cibase[cioff].argc-1;
266+
}
262267
if (len > 0) {
263268
stack_copy(p, e->stack, len);
264269
}

0 commit comments

Comments
 (0)