From dc259b9f8e18e2b80ebcb51c6bf1134b60c5acfa Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Fri, 3 Jul 2020 15:20:19 -0500 Subject: [PATCH] Set fiber env for heavyweight threads. Since you already incur the cost of creating the core environment, this is probably what you want anyways. This will make eval and other reflective code work as expected. --- src/core/thread.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/thread.c b/src/core/thread.c index d1d6cbab..336ce09a 100644 --- a/src/core/thread.c +++ b/src/core/thread.c @@ -499,6 +499,10 @@ static int thread_worker(JanetMailboxPair *pair) { /* Call function */ Janet argv[1] = { parentv }; fiber = janet_fiber(func, 64, 1, argv); + if (pair->flags & JANET_THREAD_HEAVYWEIGHT) { + fiber->env = janet_table(0); + fiber->env->proto = janet_core_env(NULL); + } JanetSignal sig = janet_continue(fiber, janet_wrap_nil(), &out); if (sig != JANET_SIGNAL_OK && sig < JANET_SIGNAL_USER0) { janet_eprintf("in thread %v: ", janet_wrap_abstract(janet_make_thread(pair->newbox, encode)));