diff --git a/src/core/ev.c b/src/core/ev.c index e5576fcc..8b1abe6d 100644 --- a/src/core/ev.c +++ b/src/core/ev.c @@ -2031,33 +2031,35 @@ void janet_ev_default_threaded_callback(JanetEVGenericMessage return_value) { if (return_value.fiber == NULL) { return; } - switch (return_value.tag) { - default: - case JANET_EV_TCTAG_NIL: - janet_schedule(return_value.fiber, janet_wrap_nil()); - break; - case JANET_EV_TCTAG_INTEGER: - janet_schedule(return_value.fiber, janet_wrap_integer(return_value.argi)); - break; - case JANET_EV_TCTAG_STRING: - case JANET_EV_TCTAG_STRINGF: - janet_schedule(return_value.fiber, janet_cstringv((const char *) return_value.argp)); - if (return_value.tag == JANET_EV_TCTAG_STRINGF) janet_free(return_value.argp); - break; - case JANET_EV_TCTAG_KEYWORD: - janet_schedule(return_value.fiber, janet_ckeywordv((const char *) return_value.argp)); - break; - case JANET_EV_TCTAG_ERR_STRING: - case JANET_EV_TCTAG_ERR_STRINGF: - janet_cancel(return_value.fiber, janet_cstringv((const char *) return_value.argp)); - if (return_value.tag == JANET_EV_TCTAG_STRINGF) janet_free(return_value.argp); - break; - case JANET_EV_TCTAG_ERR_KEYWORD: - janet_cancel(return_value.fiber, janet_ckeywordv((const char *) return_value.argp)); - break; - case JANET_EV_TCTAG_BOOLEAN: - janet_schedule(return_value.fiber, janet_wrap_boolean(return_value.argi)); - break; + if (janet_fiber_can_resume(return_value.fiber)) { + switch (return_value.tag) { + default: + case JANET_EV_TCTAG_NIL: + janet_schedule(return_value.fiber, janet_wrap_nil()); + break; + case JANET_EV_TCTAG_INTEGER: + janet_schedule(return_value.fiber, janet_wrap_integer(return_value.argi)); + break; + case JANET_EV_TCTAG_STRING: + case JANET_EV_TCTAG_STRINGF: + janet_schedule(return_value.fiber, janet_cstringv((const char *) return_value.argp)); + if (return_value.tag == JANET_EV_TCTAG_STRINGF) janet_free(return_value.argp); + break; + case JANET_EV_TCTAG_KEYWORD: + janet_schedule(return_value.fiber, janet_ckeywordv((const char *) return_value.argp)); + break; + case JANET_EV_TCTAG_ERR_STRING: + case JANET_EV_TCTAG_ERR_STRINGF: + janet_cancel(return_value.fiber, janet_cstringv((const char *) return_value.argp)); + if (return_value.tag == JANET_EV_TCTAG_STRINGF) janet_free(return_value.argp); + break; + case JANET_EV_TCTAG_ERR_KEYWORD: + janet_cancel(return_value.fiber, janet_ckeywordv((const char *) return_value.argp)); + break; + case JANET_EV_TCTAG_BOOLEAN: + janet_schedule(return_value.fiber, janet_wrap_boolean(return_value.argi)); + break; + } } janet_gcunroot(janet_wrap_fiber(return_value.fiber)); } diff --git a/src/core/os.c b/src/core/os.c index a3ee2fe2..488001ee 100644 --- a/src/core/os.c +++ b/src/core/os.c @@ -529,7 +529,9 @@ static void janet_proc_wait_cb(JanetEVGenericMessage args) { JanetString s = janet_formatc("command failed with non-zero exit code %d", status); janet_cancel(args.fiber, janet_wrap_string(s)); } else { - janet_schedule(args.fiber, janet_wrap_integer(status)); + if (janet_fiber_can_resume(args.fiber)) { + janet_schedule(args.fiber, janet_wrap_integer(status)); + } } } } diff --git a/src/core/symcache.c b/src/core/symcache.c index e1d9aeab..841bfbd9 100644 --- a/src/core/symcache.c +++ b/src/core/symcache.c @@ -233,6 +233,7 @@ const uint8_t *janet_symbol_gen(void) { head->length = sizeof(janet_vm.gensym_counter) - 1; head->hash = hash; sym = (uint8_t *)(head->data); + sym[head->length] = 0; memcpy(sym, janet_vm.gensym_counter, sizeof(janet_vm.gensym_counter)); janet_symcache_put((const uint8_t *)sym, bucket); return (const uint8_t *)sym;