1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-05 16:26:17 +00:00

Avoid panicking when calling :missing-symbol lookup function

This commit is contained in:
Michael Camilleri 2022-01-23 17:29:52 +09:00
parent ed5c1dfc3c
commit d396180939
No known key found for this signature in database
GPG Key ID: 7EB218A48DF8B572

View File

@ -608,10 +608,17 @@ JanetBinding janet_resolve_ext(JanetTable *env, const uint8_t *sym) {
/* Check environment for entry */
if (!janet_checktype(entry, JANET_TABLE)) {
Janet fn_entry = janet_table_get(env, janet_ckeywordv("missing-symbol"));
if (janet_checktype(fn_entry, JANET_FUNCTION)) {
Janet lookup_entry = janet_table_get(env, janet_ckeywordv("missing-symbol"));
if (janet_checktype(lookup_entry, JANET_FUNCTION)) {
JanetFunction *lookup = janet_unwrap_function(lookup_entry);
Janet args[2] = { janet_wrap_symbol(sym), janet_wrap_table(env) };
entry = janet_call(janet_unwrap_function(fn_entry), 2, args);
JanetFiber *fiberp = janet_fiber(lookup, 64, 2, args);
if (NULL == fiberp) return binding;
fiberp->env = env;
int lock = janet_gclock();
JanetSignal status = janet_continue(fiberp, janet_wrap_nil(), &entry);
janet_gcunlock(lock);
if (status != JANET_SIGNAL_OK) return binding;
}
if (!janet_checktype(entry, JANET_TABLE)) return binding;
}