From de4f8f9aaf61f0b794f1fcbd24cd6270cfd49ca4 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Tue, 17 Mar 2020 20:53:11 -0500 Subject: [PATCH] Marshal alive fibers in func envs as detached. This will help with marshaling fibers. --- src/core/marsh.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/core/marsh.c b/src/core/marsh.c index b2bb15c2..27394547 100644 --- a/src/core/marsh.c +++ b/src/core/marsh.c @@ -184,16 +184,24 @@ static void marshal_one_env(MarshalState *st, JanetFuncEnv *env, int flags) { } } janet_v_push(st->seen_envs, env); - janet_env_maybe_detach(env); - pushint(st, env->offset); - pushint(st, env->length); - if (env->offset) { - /* On stack variant */ - marshal_one(st, janet_wrap_fiber(env->as.fiber), flags + 1); - } else { - /* Off stack variant */ + if (env->offset && (JANET_STATUS_ALIVE == janet_fiber_status(env->as.fiber))) { + pushint(st, 0); + pushint(st, env->length); + Janet *values = env->as.fiber->data + env->offset; for (int32_t i = 0; i < env->length; i++) - marshal_one(st, env->as.values[i], flags + 1); + marshal_one(st, values[i], flags + 1); + } else { + janet_env_maybe_detach(env); + pushint(st, env->offset); + pushint(st, env->length); + if (env->offset) { + /* On stack variant */ + marshal_one(st, janet_wrap_fiber(env->as.fiber), flags + 1); + } else { + /* Off stack variant */ + for (int32_t i = 0; i < env->length; i++) + marshal_one(st, env->as.values[i], flags + 1); + } } }