Fix CI misalignment between Fiber#resume and Fiber.yield

When a fiber switched by `Fiber.yield` is resumed by `Fiber#resume` by C, it is necessary to pop CI with `fiber_switch()`.
Previously, CI misalignment caused inconsistencies, including crashes, on the next `Fiber#resume`.
This commit is contained in:
dearblue
2023-12-04 21:51:10 +09:00
parent 568309b25a
commit 42308c42b5
2 changed files with 2 additions and 1 deletions
+1 -1
View File
@@ -272,6 +272,7 @@ fiber_switch(mrb_state *mrb, mrb_value self, mrb_int len, const mrb_value *a, mr
else {
value = fiber_result(mrb, a, len);
if (vmexec) {
if (c->ci > c->cibase) c->ci--; /* pop dummy callinfo */
c->ci[1].stack[0] = value;
}
}
@@ -412,7 +413,6 @@ mrb_fiber_yield(mrb_state *mrb, mrb_int len, const mrb_value *a)
if (c->vmexec) {
c->vmexec = FALSE;
mrb->c->ci->cci = CINFO_RESUMED;
c->ci--; /* pop callinfo for yield */
}
MARK_CONTEXT_MODIFY(mrb->c);
return fiber_result(mrb, a, len);
+1
View File
@@ -1839,6 +1839,7 @@ RETRY_TRY_BLOCK:
}
recv = MRB_METHOD_FUNC(m)(mrb, recv);
}
mrb_assert(mrb->c->ci > mrb->c->cibase);
mrb_gc_arena_shrink(mrb, ai);
if (mrb->exc) goto L_RAISE;
ci = mrb->c->ci;