summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-06-03 23:24:12 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-06-03 23:32:15 +0900
commit788cea2b43963a87bf1c4e3c42e30cc2b25ca508 (patch)
treecb820dd8aa57397ef4c1aa13caef9f99009b0030
parentc9a4f8a63bef19c98771c49884ff40126e9b7b33 (diff)
downloadmruby-788cea2b43963a87bf1c4e3c42e30cc2b25ca508.tar.gz
mruby-788cea2b43963a87bf1c4e3c42e30cc2b25ca508.zip
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
-rw-r--r--include/mruby.h4
-rw-r--r--src/vm.c24
2 files changed, 15 insertions, 13 deletions
diff --git a/include/mruby.h b/include/mruby.h
index 3895c4ec3..bd824ea91 100644
--- a/include/mruby.h
+++ b/include/mruby.h
@@ -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;
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;