Skip to content

Commit

Permalink
should adjust stack size when irep->nregs is larger than allocate size;
Browse files Browse the repository at this point in the history
close #835
  • Loading branch information
matz committed Feb 10, 2013
1 parent 06c06d5 commit 75ae568
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/vm.c
Expand Up @@ -108,6 +108,9 @@ stack_extend(mrb_state *mrb, int room, int keep)
size = mrb->stend - mrb->stbase;
off = mrb->stack - mrb->stbase;

/* do not leave uninitialized malloc region */
if (keep > size) keep = size;

/* Use linear stack growth.
It is slightly slower than doubling thestack space,
but it saves memory on small devices. */
Expand Down Expand Up @@ -554,6 +557,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
if (!mrb->stack) {
stack_init(mrb);
}
stack_extend(mrb, irep->nregs, irep->nregs);
mrb->ci->proc = proc;
mrb->ci->nregs = irep->nregs + 2;
regs = mrb->stack;
Expand Down

0 comments on commit 75ae568

Please sign in to comment.