Permalink
Browse files

Revert "Simplify rescue stack management; ref #3683"

This reverts commit eb5a606 and
079f310.
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
  • Loading branch information...
matz committed Jun 3, 2017
1 parent c9a4f8a commit 788cea2b43963a87bf1c4e3c42e30cc2b25ca508
Showing with 15 additions and 13 deletions.
  1. +2 −2 include/mruby.h
  2. +13 −11 src/vm.c
View
@@ -112,7 +112,7 @@ typedef struct {
struct RProc *proc;
mrb_value *stackent;
int nregs;
int rpos;
int ridx;
int epos;
struct REnv *env;
mrb_code *pc; /* return address */
@@ -141,7 +141,7 @@ struct mrb_context {
mrb_callinfo *cibase, *ciend;
mrb_code **rescue; /* exception handler stack */
int rsize, ridx;
int rsize;
struct RProc **ensure; /* ensure handler stack */
int esize, eidx;
View
@@ -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 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
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 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
int a = GETARG_A(i);
while (a--) {
mrb->c->ridx--;
mrb->c->ci->ridx--;
}
NEXT;
}
@@ -1789,11 +1791,11 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
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 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
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,23 +1822,23 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
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;
}
}
}
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;
syms = irep->syms;
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;

0 comments on commit 788cea2

Please sign in to comment.