Restore the value of ci->cci with fiber_switch()

If `mrb_fiber_resume()` was called from a C function as a method definition, the mruby VM was not processed afterwards.

    Called Fiber.yield
    mrb_vm_exec()       <<-- returns from the function by CINFO_RESUMED
    fiber_switch()      <<-- this patch causes the value to return to its pre-call state
    mrb_fiber_resume()
    mrb_vm_exec()       <<-- previously, returns from the function immediately as it was CINFO_RESUMED
    ...
    main()
This commit is contained in:
dearblue
2023-12-04 21:48:56 +09:00
parent ef8b0b7ed8
commit aaa0f124c3
+2
View File
@@ -277,9 +277,11 @@ fiber_switch(mrb_state *mrb, mrb_value self, mrb_int len, const mrb_value *a, mr
}
if (vmexec) {
int cci = old_c->ci->cci;
c->vmexec = TRUE;
value = mrb_vm_exec(mrb, c->ci->proc, c->ci->pc);
mrb->c = old_c;
old_c->ci->cci = cci; /* restore values as they may have changed in Fiber.yield */
}
else {
MARK_CONTEXT_MODIFY(c);