From 788cea2b43963a87bf1c4e3c42e30cc2b25ca508 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 3 Jun 2017 23:24:12 +0900 Subject: Revert "Simplify rescue stack management; ref #3683" This reverts commit eb5a606fe209944d0757301edb331ed7ff0fd31f and 079f310fbc9c23b97f062230c32bd91ac65e4835. The rescue stack works differently from ensure stack, so the change caused #3686 and #3688. It might take long to solve the problems, so that I would revert the changes for now. Fix #3688 --- src/vm.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'src/vm.c') diff --git a/src/vm.c b/src/vm.c index 3a5df91a2..10ec5acdc 100644 --- a/src/vm.c +++ b/src/vm.c @@ -234,6 +234,8 @@ cipush(mrb_state *mrb) struct mrb_context *c = mrb->c; mrb_callinfo *ci = c->ci; + int ridx = ci->ridx; + if (ci + 1 == c->ciend) { ptrdiff_t size = ci - c->cibase; @@ -243,7 +245,7 @@ cipush(mrb_state *mrb) } ci = ++c->ci; ci->epos = mrb->c->eidx; - ci->rpos = mrb->c->ridx; + ci->ridx = ridx; ci->env = 0; ci->pc = 0; ci->err = 0; @@ -283,8 +285,8 @@ cipop(mrb_state *mrb) struct mrb_context *c = mrb->c; struct REnv *env = c->ci->env; - c->ridx = c->ci->rpos; c->ci--; + if (env) { mrb_env_unshare(mrb, env); } @@ -1123,12 +1125,12 @@ RETRY_TRY_BLOCK: CASE(OP_ONERR) { /* sBx pc+=sBx on exception */ - if (mrb->c->rsize <= mrb->c->ridx) { + if (mrb->c->rsize <= mrb->c->ci->ridx) { if (mrb->c->rsize == 0) mrb->c->rsize = RESCUE_STACK_INIT_SIZE; else mrb->c->rsize *= 2; mrb->c->rescue = (mrb_code **)mrb_realloc(mrb, mrb->c->rescue, sizeof(mrb_code*) * mrb->c->rsize); } - mrb->c->rescue[mrb->c->ridx++] = pc + GETARG_sBx(i); + mrb->c->rescue[mrb->c->ci->ridx++] = pc + GETARG_sBx(i); NEXT; } @@ -1178,7 +1180,7 @@ RETRY_TRY_BLOCK: int a = GETARG_A(i); while (a--) { - mrb->c->ridx--; + mrb->c->ci->ridx--; } NEXT; } @@ -1789,11 +1791,11 @@ RETRY_TRY_BLOCK: L_RAISE: ci0 = ci = mrb->c->ci; if (ci == mrb->c->cibase) { - if (mrb->c->ridx == 0) goto L_FTOP; + if (ci->ridx == 0) goto L_FTOP; goto L_RESCUE; } stk = mrb->c->stack; - while (mrb->c->ridx == ci->rpos) { + while (ci[0].ridx == ci[-1].ridx) { cipop(mrb); mrb->c->stack = ci->stackent; if (ci->acc == CI_ACC_SKIP && prev_jmp) { @@ -1803,7 +1805,7 @@ RETRY_TRY_BLOCK: ci = mrb->c->ci; if (ci == mrb->c->cibase) { mrb->c->stack = stk; - if (mrb->c->ridx == 0) { + if (ci->ridx == 0) { L_FTOP: /* fiber top */ if (mrb->c == mrb->root_c) { mrb->c->stack = mrb->c->stbase; @@ -1820,7 +1822,7 @@ RETRY_TRY_BLOCK: break; } /* call ensure only when we skip this callinfo */ - if (mrb->c->ridx == ci->rpos) { + if (ci[0].ridx == ci[-1].ridx) { while (mrb->c->eidx > ci->epos) { ecall(mrb, --mrb->c->eidx); ci = mrb->c->ci; @@ -1828,7 +1830,7 @@ RETRY_TRY_BLOCK: } } L_RESCUE: - if (mrb->c->ridx == 0) goto L_STOP; + if (ci->ridx == 0) goto L_STOP; proc = ci->proc; irep = proc->body.irep; pool = irep->pool; @@ -1836,7 +1838,7 @@ RETRY_TRY_BLOCK: if (ci != ci0) { mrb->c->stack = ci[1].stackent; } - pc = mrb->c->rescue[--mrb->c->ridx]; + pc = mrb->c->rescue[--ci->ridx]; } else { int acc; -- cgit v1.2.3