Adjust environment when `mrb_exec_irep` happened.
@@ -156,6 +156,18 @@ envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase, size_t size)
e->stack = newbase + off;
}
+
+ if (ci->proc && MRB_PROC_ENV_P(ci->proc) && ci->env != MRB_PROC_ENV(ci->proc)) {
+ e = MRB_PROC_ENV(ci->proc);
+
+ if (e && MRB_ENV_STACK_SHARED_P(e) &&
+ (st = e->stack) && oldbase <= st && st < oldbase+size) {
+ ptrdiff_t off = e->stack - oldbase;
+
+ e->stack = newbase + off;
+ }
+ }
+
ci->stackent = newbase + (ci->stackent - oldbase);
ci++;
}
