clear all stack everytime to prevent GC crash; ref #2109

parent 29f6cdcd
......@@ -160,14 +160,14 @@ stack_extend_alloc(mrb_state *mrb, int room)
}
static inline void
stack_extend(mrb_state *mrb, int room, int init, int keep)
stack_extend(mrb_state *mrb, int room, int keep)
{
if (mrb->c->stack + room >= mrb->c->stend) {
stack_extend_alloc(mrb, room);
}
if (init > keep) {
if (room > keep) {
/* do not leave uninitialized malloc region */
stack_clear(&(mrb->c->stack[keep]), init - keep);
stack_clear(&(mrb->c->stack[keep]), room - keep);
}
}
......@@ -381,11 +381,11 @@ mrb_funcall_with_block(mrb_state *mrb, mrb_value self, mrb_sym mid, mrb_int argc
mrb->c->stack = mrb->c->stack + n;
if (MRB_PROC_CFUNC_P(p)) {
ci->nregs = argc + 2;
stack_extend(mrb, ci->nregs, 0, 0);
stack_extend(mrb, ci->nregs, 0);
}
else {
ci->nregs = p->body.irep->nregs + n;
stack_extend(mrb, ci->nregs, p->body.irep->nlocals, argc+2);
stack_extend(mrb, ci->nregs, argc+2);
}
mrb->c->stack[0] = self;
if (undef) {
......@@ -514,11 +514,11 @@ mrb_yield_with_class(mrb_state *mrb, mrb_value b, mrb_int argc, const mrb_value
mrb->c->stack = mrb->c->stack + n;
if (MRB_PROC_CFUNC_P(p)) {
ci->nregs = argc + 2;
stack_extend(mrb, ci->nregs, 0, 0);
stack_extend(mrb, ci->nregs, 0);
}
else {
ci->nregs = p->body.irep->nregs + 1;
stack_extend(mrb, ci->nregs, p->body.irep->nlocals, argc+2);
stack_extend(mrb, ci->nregs, argc+2);
}
mrb->c->stack[0] = self;
......@@ -683,7 +683,7 @@ RETRY_TRY_BLOCK:
if (!mrb->c->stack) {
stack_init(mrb);
}
stack_extend(mrb, irep->nregs, irep->nlocals, stack_keep);
stack_extend(mrb, irep->nregs, stack_keep);
mrb->c->ci->proc = proc;
mrb->c->ci->nregs = irep->nregs + 1;
regs = mrb->c->stack;
......@@ -1048,11 +1048,11 @@ RETRY_TRY_BLOCK:
ci->nregs = irep->nregs;
if (n == CALL_MAXARGS) {
ci->argc = -1;
stack_extend(mrb, (irep->nregs < 3) ? 3 : irep->nregs, irep->nlocals, 3);
stack_extend(mrb, (irep->nregs < 3) ? 3 : irep->nregs, 3);
}
else {
ci->argc = n;
stack_extend(mrb, irep->nregs, irep->nlocals, n+2);
stack_extend(mrb, irep->nregs, n+2);
}
regs = mrb->c->stack;
pc = irep->iseq;
......@@ -1112,10 +1112,10 @@ RETRY_TRY_BLOCK:
syms = irep->syms;
ci->nregs = irep->nregs;
if (ci->argc < 0) {
stack_extend(mrb, (irep->nregs < 3) ? 3 : irep->nregs, irep->nlocals, 3);
stack_extend(mrb, (irep->nregs < 3) ? 3 : irep->nregs, 3);
}
else {
stack_extend(mrb, irep->nregs, irep->nlocals, ci->argc+2);
stack_extend(mrb, irep->nregs, ci->argc+2);
}
regs = mrb->c->stack;
regs[0] = m->env->stack[0];
......@@ -1187,10 +1187,10 @@ RETRY_TRY_BLOCK:
syms = irep->syms;
ci->nregs = irep->nregs;
if (n == CALL_MAXARGS) {
stack_extend(mrb, (irep->nregs < 3) ? 3 : irep->nregs, irep->nlocals, 3);
stack_extend(mrb, (irep->nregs < 3) ? 3 : irep->nregs, 3);
}
else {
stack_extend(mrb, irep->nregs, irep->nlocals, ci->argc+2);
stack_extend(mrb, irep->nregs, ci->argc+2);
}
regs = mrb->c->stack;
pc = irep->iseq;
......@@ -1533,10 +1533,10 @@ RETRY_TRY_BLOCK:
pool = irep->pool;
syms = irep->syms;
if (ci->argc < 0) {
stack_extend(mrb, (irep->nregs < 3) ? 3 : irep->nregs, irep->nlocals, 3);
stack_extend(mrb, (irep->nregs < 3) ? 3 : irep->nregs, 3);
}
else {
stack_extend(mrb, irep->nregs, irep->nlocals, ci->argc+2);
stack_extend(mrb, irep->nregs, ci->argc+2);
}
regs = mrb->c->stack;
pc = irep->iseq;
......@@ -2173,7 +2173,7 @@ RETRY_TRY_BLOCK:
irep = p->body.irep;
pool = irep->pool;
syms = irep->syms;
stack_extend(mrb, irep->nregs, irep->nlocals, 1);
stack_extend(mrb, irep->nregs, 1);
ci->nregs = irep->nregs;
regs = mrb->c->stack;
pc = irep->iseq;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment