Skip to content

Commit

Permalink
fix: segfaults with NULL instances
Browse files Browse the repository at this point in the history
  • Loading branch information
lmichaelis committed Oct 12, 2024
1 parent bd0eb8f commit c0a2559
Show file tree
Hide file tree
Showing 23 changed files with 1,307 additions and 479 deletions.
12 changes: 6 additions & 6 deletions src/DaedalusScript.cc
Original file line number Diff line number Diff line change
Expand Up @@ -88,32 +88,32 @@ ZkDaedalusSymbol* ZkDaedalusScript_getSymbolByName(ZkDaedalusScript* slf, ZkStri

ZkString ZkDaedalusSymbol_getString(ZkDaedalusSymbol const* slf, uint16_t index, ZkDaedalusInstance const* context) {
ZKC_CHECK_NULL(slf);
ZKC_RETURN_CATCH(slf->get_string(index, context->get()).c_str());
ZKC_RETURN_CATCH(slf->get_string(index, context ? context->get() : nullptr).c_str());
}

float ZkDaedalusSymbol_getFloat(ZkDaedalusSymbol const* slf, uint16_t index, ZkDaedalusInstance const* context) {
ZKC_CHECK_NULL(slf);
ZKC_RETURN_CATCH(slf->get_float(index, context->get()));
ZKC_RETURN_CATCH(slf->get_float(index, context ? context->get() : nullptr));
}

int32_t ZkDaedalusSymbol_getInt(ZkDaedalusSymbol const* slf, uint16_t index, ZkDaedalusInstance const* context) {
ZKC_CHECK_NULL(slf);
ZKC_RETURN_CATCH(slf->get_int(index, context->get()));
ZKC_RETURN_CATCH(slf->get_int(index, context ? context->get() : nullptr));
}

void ZkDaedalusSymbol_setString(ZkDaedalusSymbol* slf, ZkString value, uint16_t index, ZkDaedalusInstance* context) {
ZKC_CHECK_NULLV(slf, value);
ZKC_CATCH(slf->set_string(value, index, context->get()));
ZKC_CATCH(slf->set_string(value, index, context ? context->get() : nullptr));
}

void ZkDaedalusSymbol_setFloat(ZkDaedalusSymbol* slf, float value, uint16_t index, ZkDaedalusInstance* context) {
ZKC_CHECK_NULLV(slf);
ZKC_CATCH(slf->set_float(value, index, context->get()));
ZKC_CATCH(slf->set_float(value, index, context ? context->get() : nullptr));
}

void ZkDaedalusSymbol_setInt(ZkDaedalusSymbol* slf, int32_t value, uint16_t index, ZkDaedalusInstance* context) {
ZKC_CHECK_NULLV(slf);
ZKC_CATCH(slf->set_int(value, index, context->get()));
ZKC_CATCH(slf->set_int(value, index, context ? context->get() : nullptr));
}

ZkBool ZkDaedalusSymbol_getIsConst(ZkDaedalusSymbol const* slf) {
Expand Down
34 changes: 27 additions & 7 deletions src/DaedalusVm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,71 +156,91 @@ ZkDaedalusInstance* ZkDaedalusVm_popInstance(ZkDaedalusVm* slf) {
ZKC_TRACE_FN();
ZKC_CHECK_NULL(slf);

auto* instance = new ZkDaedalusInstance(slf->handle.pop_instance());
ZKC_RETURN_CATCH(instance);
auto instance = slf->handle.pop_instance();
if (instance == nullptr) {
return nullptr;
}

ZKC_RETURN_CATCH(new ZkDaedalusInstance(instance));
}

ZkDaedalusInstance* ZkDaedalusVm_getGlobalSelf(ZkDaedalusVm* slf) {
ZKC_TRACE_FN();
ZKC_CHECK_NULL(slf);

auto& instance = slf->handle.global_self()->get_instance();
if (instance == nullptr) {
return nullptr;
}
ZKC_RETURN_CATCH(new ZkDaedalusInstance(instance));
}

ZkDaedalusInstance* ZkDaedalusVm_getGlobalOther(ZkDaedalusVm* slf) {
ZKC_TRACE_FN();
ZKC_CHECK_NULL(slf);
auto& instance = slf->handle.global_other()->get_instance();
if (instance == nullptr) {
return nullptr;
}
ZKC_RETURN_CATCH(new ZkDaedalusInstance(instance));
}

ZkDaedalusInstance* ZkDaedalusVm_getGlobalVictim(ZkDaedalusVm* slf) {
ZKC_TRACE_FN();
ZKC_CHECK_NULL(slf);
auto& instance = slf->handle.global_victim()->get_instance();
if (instance == nullptr) {
return nullptr;
}
ZKC_RETURN_CATCH(new ZkDaedalusInstance(instance));
}

ZkDaedalusInstance* ZkDaedalusVm_getGlobalHero(ZkDaedalusVm* slf) {
ZKC_TRACE_FN();
ZKC_CHECK_NULL(slf);
auto& instance = slf->handle.global_hero()->get_instance();
if (instance == nullptr) {
return nullptr;
}
ZKC_RETURN_CATCH(new ZkDaedalusInstance(instance));
}

ZkDaedalusInstance* ZkDaedalusVm_getGlobalItem(ZkDaedalusVm* slf) {
ZKC_TRACE_FN();
ZKC_CHECK_NULL(slf);
auto& instance = slf->handle.global_item()->get_instance();
if (instance == nullptr) {
return nullptr;
}

ZKC_RETURN_CATCH(new ZkDaedalusInstance(instance));
}

void ZkDaedalusVm_setGlobalSelf(ZkDaedalusVm* slf, ZkDaedalusInstance* value) {
ZKC_TRACE_FN();
ZKC_CHECK_NULLV(slf);

ZKC_CATCH(slf->handle.global_self()->set_instance(*value));
ZKC_CATCH(slf->handle.global_self()->set_instance(value ? *value : nullptr));
}
void ZkDaedalusVm_setGlobalOther(ZkDaedalusVm* slf, ZkDaedalusInstance* value) {
ZKC_TRACE_FN();
ZKC_CHECK_NULLV(slf);
ZKC_CATCH(slf->handle.global_other()->set_instance(*value));
ZKC_CATCH(slf->handle.global_other()->set_instance(value ? *value : nullptr));
}
void ZkDaedalusVm_setGlobalVictim(ZkDaedalusVm* slf, ZkDaedalusInstance* value) {
ZKC_TRACE_FN();
ZKC_CHECK_NULLV(slf);
ZKC_CATCH(slf->handle.global_victim()->set_instance(*value));
ZKC_CATCH(slf->handle.global_victim()->set_instance(value ? *value : nullptr));
}
void ZkDaedalusVm_setGlobalHero(ZkDaedalusVm* slf, ZkDaedalusInstance* value) {
ZKC_TRACE_FN();
ZKC_CHECK_NULLV(slf);
ZKC_CATCH(slf->handle.global_hero()->set_instance(*value));
ZKC_CATCH(slf->handle.global_hero()->set_instance(value ? *value : nullptr));
}
void ZkDaedalusVm_setGlobalItem(ZkDaedalusVm* slf, ZkDaedalusInstance* value) {
ZKC_TRACE_FN();
ZKC_CHECK_NULLV(slf);
ZKC_CATCH(slf->handle.global_item()->set_instance(*value));
ZKC_CATCH(slf->handle.global_item()->set_instance(value ? *value : nullptr));
}

void ZkDaedalusVm_callFunction(ZkDaedalusVm* slf, ZkDaedalusSymbol* sym) {
Expand Down
Loading

0 comments on commit c0a2559

Please sign in to comment.