From ca3a6156bf0d15031ad946a67e9a88b4fb288d38 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Wed, 6 Jan 2021 14:16:56 +0900 Subject: Allow context switch from C using `mrb_fiber_resume()`. But you still cannot cross C function boundary. --- src/vm.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src') 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) { -- cgit v1.2.3