From 7d65cec0385b6dcaf3346d3f862efb5eb07ad14a Mon Sep 17 00:00:00 2001 From: Benoit Germain <benoit.germain@ubisoft.com> Date: Fri, 14 Jun 2024 17:00:01 +0200 Subject: Handle std::ignore cases that should not be ignored --- src/cancel.cpp | 10 +++++----- src/intercopycontext.cpp | 5 ++++- src/state.cpp | 7 +++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/cancel.cpp b/src/cancel.cpp index 4f04857..a62fa96 100644 --- a/src/cancel.cpp +++ b/src/cancel.cpp @@ -176,17 +176,17 @@ LUAG_FUNC(thread_cancel) STACK_CHECK_START_REL(L_, 0); switch (_lane->cancel(_op, _hook_count, _until, _wake_lane)) { default: // should never happen unless we added a case and forgot to handle it - LUA_ASSERT(L_, false); + raise_luaL_error(L_, "should not get here!"); break; case CancelResult::Timeout: - lua_pushboolean(L_, 0); // false - lua_pushstring(L_, "timeout"); // false "timeout" + lua_pushboolean(L_, 0); // false + lua_pushstring(L_, "timeout"); // false "timeout" break; case CancelResult::Cancelled: - lua_pushboolean(L_, 1); // true - std::ignore = _lane->pushThreadStatus(L_); // true status + lua_pushboolean(L_, 1); // true + std::ignore = _lane->pushThreadStatus(L_); // true "<status>" break; } STACK_CHECK(L_, 2); diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 285ca9b..34a1c95 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp @@ -913,7 +913,10 @@ LuaType InterCopyContext::processConversion() const // perform the custom cloning part lua_insert(L2, -2); // L2: ... u mt // __lanesclone should always exist because we wouldn't be restoring data from a userdata_clone_sentinel closure to begin with - std::ignore = luaG_getfield(L2, -1, "__lanesclone"); // L2: ... u mt __lanesclone + LuaType const _funcType{ luaG_getfield(L2, -1, "__lanesclone") }; // L2: ... u mt __lanesclone + if (_funcType != LuaType::FUNCTION) { + raise_luaL_error(getErrL(), "INTERNAL ERROR: __lanesclone is a %s, not a function", luaG_typename(L2, _funcType).data()); + } lua_remove(L2, -2); // L2: ... u __lanesclone lua_pushlightuserdata(L2, _clone); // L2: ... u __lanesclone clone lua_pushlightuserdata(L2, _source); // L2: ... u __lanesclone clone source diff --git a/src/state.cpp b/src/state.cpp index 18c5ae2..267554e 100644 --- a/src/state.cpp +++ b/src/state.cpp @@ -167,7 +167,7 @@ namespace state { DEBUGSPEW_CODE(DebugSpew(U_) << "calling on_state_create()" << std::endl); if (U_->onStateCreateFunc != reinterpret_cast<lua_CFunction>(InitializeOnStateCreate)) { // C function: recreate a closure in the new state, bypassing the lookup scheme - lua_pushcfunction(L_, U_->onStateCreateFunc); // on_state_create() + lua_pushcfunction(L_, U_->onStateCreateFunc); // on_state_create() } else { // Lua function located in the config table, copied when we opened "lanes.core" if (mode_ != LookupMode::LaneBody) { // if attempting to call in a keeper state, do nothing because the function doesn't exist there @@ -177,7 +177,10 @@ namespace state { } kConfigRegKey.pushValue(L_); // L_: {} STACK_CHECK(L_, 1); - std::ignore = luaG_getfield(L_, -1, kOnStateCreate); // L_: {} on_state_create() + LuaType const _funcType{ luaG_getfield(L_, -1, kOnStateCreate) }; // L_: {} on_state_create() + if (_funcType != LuaType::FUNCTION) { + raise_luaL_error(L_, "INTERNAL ERROR: %s is a %s, not a function", kOnStateCreate.data(), luaG_typename(L_, _funcType).data()); + } lua_remove(L_, -2); // L_: on_state_create() } STACK_CHECK(L_, 1); -- cgit v1.2.3-55-g6feb