Revert to old behavior of janet_fiber returning NULL.

When there is a bad arity function passed in to the fiber
constructor, return NULL so the runtime can choose what to do.
This is not the prettiest API but does work, and gives better error
messages for instance in the compiler.
This commit is contained in:
Calvin Rose 2023-06-04 11:21:52 -05:00
parent 67f375bea2
commit 4b3c813f5a
2 changed files with 6 additions and 7 deletions

View File

@ -93,9 +93,7 @@ JanetFiber *janet_fiber_reset(JanetFiber *fiber, JanetFunction *callee, int32_t
/* Create a new fiber with argn values on the stack. */
JanetFiber *janet_fiber(JanetFunction *callee, int32_t capacity, int32_t argc, const Janet *argv) {
JanetFiber *result = janet_fiber_reset(fiber_alloc(capacity), callee, argc, argv);
if (NULL == result) janet_panic("cannot create fiber");
return result;
return janet_fiber_reset(fiber_alloc(capacity), callee, argc, argv);
}
#ifdef JANET_DEBUG
@ -512,6 +510,7 @@ JANET_CORE_FN(cfun_fiber_new,
janet_panicf("fiber function must accept 0 or 1 arguments");
}
fiber = janet_fiber(func, 64, func->def->min_arity, NULL);
janet_assert(fiber != NULL, "bad fiber arity check");
if (argc == 2) {
int32_t i;
JanetByteView view = janet_getbytes(argv, 1);

View File

@ -1513,14 +1513,14 @@ JanetSignal janet_pcall(
JanetFiber *fiber;
if (f && *f) {
fiber = janet_fiber_reset(*f, fun, argc, argv);
if (NULL == fiber) {
*out = janet_cstringv("arity mismatch");
return JANET_SIGNAL_ERROR;
}
} else {
fiber = janet_fiber(fun, 64, argc, argv);
}
if (f) *f = fiber;
if (NULL == fiber) {
*out = janet_cstringv("arity mismatch");
return JANET_SIGNAL_ERROR;
}
return janet_continue(fiber, janet_wrap_nil(), out);
}