summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-01-06 14:16:56 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-01-06 14:16:56 +0900
commitca3a6156bf0d15031ad946a67e9a88b4fb288d38 (patch)
treebc8b9d044704dd79e6f67e312457d9568f127895 /src
parent4585c360e4e2548c143042d45c7f5bf1dfc5fb9e (diff)
downloadmruby-ca3a6156bf0d15031ad946a67e9a88b4fb288d38.tar.gz
mruby-ca3a6156bf0d15031ad946a67e9a88b4fb288d38.zip
Allow context switch from C using `mrb_fiber_resume()`.
But you still cannot cross C function boundary.
Diffstat (limited to 'src')
-rw-r--r--src/vm.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/vm.c b/src/vm.c
index 7a93eeac3..57b38ee39 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -2074,7 +2074,7 @@ RETRY_TRY_BLOCK:
regs[irep->nlocals] = v;
goto CHECKPOINT_LABEL_MAKE(RBREAK_TAG_STOP);
}
- if (c->prev->ci == c->prev->cibase) {
+ if (!c->vmexec && c->prev->ci == c->prev->cibase) {
mrb_value exc = mrb_exc_new_lit(mrb, E_FIBER_ERROR, "double resume");
mrb_exc_set(mrb, exc);
goto L_RAISE;
@@ -2089,8 +2089,14 @@ RETRY_TRY_BLOCK:
/* automatic yield at the end */
c->status = MRB_FIBER_TERMINATED;
mrb->c = c->prev;
- c->prev = NULL;
mrb->c->status = MRB_FIBER_RUNNING;
+ c->prev = NULL;
+ if (c->vmexec) {
+ mrb_gc_arena_restore(mrb, ai);
+ c->vmexec = FALSE;
+ mrb->jmp = prev_jmp;
+ return v;
+ }
ci = mrb->c->ci;
}
CHECKPOINT_RESTORE(RBREAK_TAG_RETURN) {