Skip to content

Commit

Permalink
Avoid duplicated envadjust() of env stacks; fix #3637
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Apr 25, 2017
1 parent a3d80e8 commit cef523c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,17 @@ stack_init(mrb_state *mrb)
}

static inline void
envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase)
envadjust(mrb_state *mrb, mrb_value *oldbase, mrb_value *newbase, size_t size)
{
mrb_callinfo *ci = mrb->c->cibase;

if (newbase == oldbase) return;
while (ci <= mrb->c->ci) {
struct REnv *e = ci->env;
if (e && MRB_ENV_STACK_SHARED_P(e)) {
mrb_value *st;

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;
Expand Down Expand Up @@ -164,7 +167,7 @@ stack_extend_alloc(mrb_state *mrb, int room)
mrb_exc_raise(mrb, mrb_obj_value(mrb->stack_err));
}
stack_clear(&(newstack[oldsize]), size - oldsize);
envadjust(mrb, oldbase, newstack);
envadjust(mrb, oldbase, newstack, size);
mrb->c->stbase = newstack;
mrb->c->stack = mrb->c->stbase + off;
mrb->c->stend = mrb->c->stbase + size;
Expand Down Expand Up @@ -297,7 +300,7 @@ ecall(mrb_state *mrb, int i)
mrb_callinfo *ci = mrb->c->ci;
mrb_value *self = mrb->c->stack;
struct RObject *exc;
int cioff;
ptrdiff_t cioff;

if (i<0) return;
if (ci - mrb->c->cibase > MRB_FUNCALL_DEPTH_MAX) {
Expand Down

0 comments on commit cef523c

Please sign in to comment.