1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-24 17:27:18 +00:00

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

View File

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