aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Germain <bnt.germain@gmail.com>2025-07-25 12:48:27 +0200
committerBenoit Germain <bnt.germain@gmail.com>2025-07-25 12:48:27 +0200
commitccf4ac6b44a378d8f0e32b8186fdc4d3b25c3bda (patch)
treeb58e3452d09c2a01ef773d26b79f1e78da727eae /src
parentd8acb18ce8bf6e89a042d166f61b2934e8722cf0 (diff)
downloadlanes-ccf4ac6b44a378d8f0e32b8186fdc4d3b25c3bda.tar.gz
lanes-ccf4ac6b44a378d8f0e32b8186fdc4d3b25c3bda.tar.bz2
lanes-ccf4ac6b44a378d8f0e32b8186fdc4d3b25c3bda.zip
Fix crashes in MSVC release builds related to KeeperOperationInProgress
* scope the KeeperOperationInProgress object on linda calls * but since it's not enough, just comment it, it is only debug stuff anyway
Diffstat (limited to 'src')
-rw-r--r--src/lanes.cpp6
-rw-r--r--src/linda.cpp28
-rw-r--r--src/linda.hpp4
3 files changed, 24 insertions, 14 deletions
diff --git a/src/lanes.cpp b/src/lanes.cpp
index d9ac4df..4373aee 100644
--- a/src/lanes.cpp
+++ b/src/lanes.cpp
@@ -178,9 +178,13 @@ LUAG_FUNC(sleep)
178 } else if (lua_isnoneornil(L_, 1)) { 178 } else if (lua_isnoneornil(L_, 1)) {
179 lua_pushnumber(L_, 0); // L_: duration? receive() timerLinda 0 179 lua_pushnumber(L_, 0); // L_: duration? receive() timerLinda 0
180 } else if (!lua_isnumber(L_, 1)) { 180 } else if (!lua_isnumber(L_, 1)) {
181 raise_luaL_argerror(L_, StackIndex{ 1 }, "invalid duration"); 181 raise_luaL_argerror(L_, StackIndex{ 1 }, "duration must be a number");
182 } 182 }
183 else { 183 else {
184 auto const _n{ lua_tonumber(L_, 1) };
185 if (_n < 0) {
186 raise_luaL_argerror(L_, StackIndex{ 1 }, "duration must be >= 0");
187 }
184 lua_pushnumber(L_, lua_tonumber(L_, 1)); // L_: duration? receive() timerLinda duration 188 lua_pushnumber(L_, lua_tonumber(L_, 1)); // L_: duration? receive() timerLinda duration
185 } 189 }
186 luaW_pushstring(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda duration key 190 luaW_pushstring(L_, "ac100de1-a696-4619-b2f0-a26de9d58ab8"); // L_: duration? receive() timerLinda duration key
diff --git a/src/linda.cpp b/src/linda.cpp
index 75d1748..56285f7 100644
--- a/src/linda.cpp
+++ b/src/linda.cpp
@@ -422,17 +422,23 @@ int Linda::ProtectedCall(lua_State* const L_, lua_CFunction const f_)
422 // doing LindaFactory::deleteDeepObjectInternal -> keeper_call(clear) 422 // doing LindaFactory::deleteDeepObjectInternal -> keeper_call(clear)
423 lua_gc(L_, LUA_GCSTOP, 0); 423 lua_gc(L_, LUA_GCSTOP, 0);
424 424
425 LUA_ASSERT_CODE(auto const _koip{ _linda->startKeeperOperation(L_) }); 425 LuaError _rc{};
426 // if we didn't do anything wrong, the keeper stack should be clean 426 {
427 LUA_ASSERT(L_, lua_gettop(_K) == 0); 427 // there is something really strange here: in Release builds, MSVC will invoke _koip destructor on stack unwinding when we raise_lua_error() below
428 428 // even though the variable does not exist in the stack frame because it went out of scope -> comment until we understand why, because it causes a crash
429 // push the function to be called and move it before the arguments 429 //LUA_ASSERT_CODE(auto const _koip{ _linda->startKeeperOperation(L_) });
430 lua_pushcfunction(L_, f_); 430
431 lua_insert(L_, 1); 431 // if we didn't do anything wrong, the keeper stack should be clean
432 // do a protected call 432 LUA_ASSERT(L_, lua_gettop(_K) == 0);
433 LuaError const _rc{ lua_pcall(L_, lua_gettop(L_) - 1, LUA_MULTRET, 0) }; 433
434 // whatever happens, the keeper state stack must be empty when we are done 434 // push the function to be called and move it before the arguments
435 lua_settop(_K, 0); 435 lua_pushcfunction(L_, f_);
436 lua_insert(L_, 1);
437 // do a protected call
438 _rc = ToLuaError(lua_pcall(L_, lua_gettop(L_) - 1, LUA_MULTRET, 0));
439 // whatever happens, the keeper state stack must be empty when we are done
440 lua_settop(_K, 0);
441 }
436 442
437 // restore normal GC operations 443 // restore normal GC operations
438 lua_gc(L_, LUA_GCRESTART, 0); 444 lua_gc(L_, LUA_GCRESTART, 0);
diff --git a/src/linda.hpp b/src/linda.hpp
index cff30e5..9288b38 100644
--- a/src/linda.hpp
+++ b/src/linda.hpp
@@ -21,7 +21,7 @@ class Linda final
21 lua_State* const L{}; // just here for inspection while debugging 21 lua_State* const L{}; // just here for inspection while debugging
22 22
23 public: 23 public:
24 KeeperOperationInProgress(Linda& linda_, lua_State* const L_) 24 KeeperOperationInProgress(Linda& linda_, lua_State* const L_) noexcept
25 : linda{ linda_ } 25 : linda{ linda_ }
26 , L{ L_ } 26 , L{ L_ }
27 { 27 {
@@ -29,7 +29,7 @@ class Linda final
29 } 29 }
30 30
31 public: 31 public:
32 ~KeeperOperationInProgress() 32 ~KeeperOperationInProgress() noexcept
33 { 33 {
34 [[maybe_unused]] UnusedInt const _prev{ linda.keeperOperationCount.fetch_sub(1, std::memory_order_seq_cst) }; 34 [[maybe_unused]] UnusedInt const _prev{ linda.keeperOperationCount.fetch_sub(1, std::memory_order_seq_cst) };
35 } 35 }