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:
parent
67f375bea2
commit
4b3c813f5a
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user