Fix crash when user's foreign_method_fn() returns nil.

This commit is contained in:
King_DuckZ 2020-05-02 00:05:36 +02:00
parent 482410356d
commit 3a8285a518

View file

@ -67,10 +67,15 @@ namespace wren {
assert(cb);
assert(cb->foreign_method_fn and cb->config_obj and cb->owner);
foreign_method_t func = cb->foreign_method_fn(*cb->config_obj, cb->owner, module, class_name, is_static, signature);
DynafuncMaker* const dfm = cb->dynafunc;
assert(dfm);
auto retval = reinterpret_cast<WrenForeignMethodFn>(dfm->make(cb->owner, func));
return retval;
if (func) {
DynafuncMaker* const dfm = cb->dynafunc;
assert(dfm);
auto retval = reinterpret_cast<WrenForeignMethodFn>(dfm->make(cb->owner, func));
return retval;
}
else {
return nullptr;
}
}
WrenForeignClassMethods foreign_class_fn (WrenVM* wvm, const char* module, const char* class_name) {
@ -78,10 +83,15 @@ namespace wren {
assert(cb);
assert(cb->foreign_class_fn and cb->config_obj and cb->owner);
foreign_class_t funcs = cb->foreign_class_fn(*cb->config_obj, cb->owner, module, class_name);
DynafuncMaker* const dfm = cb->dynafunc;
assert(dfm);
WrenForeignClassMethods retval;
retval.allocate = reinterpret_cast<WrenForeignMethodFn>(dfm->make(cb->owner, funcs.allocate));
if (funcs.allocate) {
DynafuncMaker* const dfm = cb->dynafunc;
assert(dfm);
retval.allocate = reinterpret_cast<WrenForeignMethodFn>(dfm->make(cb->owner, funcs.allocate));
}
else {
retval.allocate = nullptr;
}
retval.finalize = funcs.finalize;
return retval;
}