From 48985bf413bef59778a4e50ba8391938364bae56 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 22 May 2024 16:26:30 +0200 Subject: Fix __lanesignore --- src/intercopycontext.cpp | 15 +++++++++++++-- src/keeper.cpp | 20 -------------------- src/keeper.h | 1 - src/linda.cpp | 13 ------------- 4 files changed, 13 insertions(+), 36 deletions(-) (limited to 'src') diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 0301382..6ebbbb0 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp @@ -28,6 +28,7 @@ THE SOFTWARE. #include "debugspew.h" #include "deep.h" +#include "keeper.h" #include "universe.h" // ################################################################################################# @@ -887,7 +888,12 @@ void InterCopyContext::inter_copy_keyvaluepair() const { void* const _p{ lua_touserdata(L1, L1_i) }; DEBUGSPEW_CODE(fprintf(stderr, "%p\n", _p)); - lua_pushlightuserdata(L2, _p); + // when copying a nil sentinel in a non-keeper, write a nil in the destination + if (mode != LookupMode::ToKeeper && kNilSentinel.equals(L1, L1_i)) { + lua_pushnil(L2); + } else { + lua_pushlightuserdata(L2, _p); + } return true; } @@ -898,7 +904,12 @@ void InterCopyContext::inter_copy_keyvaluepair() const if (vt == VT::KEY) { return false; } - lua_pushnil(L2); + // when copying a nil in a keeper, write a nil sentinel in the destination + if (mode == LookupMode::ToKeeper) { + kNilSentinel.pushKey(L2); + } else { + lua_pushnil(L2); + } return true; } diff --git a/src/keeper.cpp b/src/keeper.cpp index 9bde2d5..b0ed062 100644 --- a/src/keeper.cpp +++ b/src/keeper.cpp @@ -569,26 +569,6 @@ void Linda::releaseKeeper(Keeper* K_) const // ################################################################################################# -void keeper_toggle_nil_sentinels(lua_State* L_, int start_, LookupMode const mode_) -{ - int const _n{ lua_gettop(L_) }; - for (int _i = start_; _i <= _n; ++_i) { - if (mode_ == LookupMode::ToKeeper) { - if (lua_isnil(L_, _i)) { - kNilSentinel.pushKey(L_); - lua_replace(L_, _i); - } - } else { - if (kNilSentinel.equals(L_, _i)) { - lua_pushnil(L_); - lua_replace(L_, _i); - } - } - } -} - -// ################################################################################################# - /* * Call a function ('func_name') in the keeper state, and pass on the returned * values to 'L'. diff --git a/src/keeper.h b/src/keeper.h index 62d9ec8..a902caa 100644 --- a/src/keeper.h +++ b/src/keeper.h @@ -40,7 +40,6 @@ struct Keepers // xxh64 of string "kNilSentinel" generated at https://www.pelock.com/products/hash-calculator static constexpr UniqueKey kNilSentinel{ 0xC457D4EDDB05B5E4ull, "lanes.null" }; -void keeper_toggle_nil_sentinels(lua_State* L_, int start_, LookupMode const mode_); [[nodiscard]] int keeper_push_linda_storage(Linda& linda_, DestState L_); using keeper_api_t = lua_CFunction; diff --git a/src/linda.cpp b/src/linda.cpp index 1916629..4bd4553 100644 --- a/src/linda.cpp +++ b/src/linda.cpp @@ -344,9 +344,6 @@ LUAG_FUNC(linda_get) if (_linda->cancelRequest == CancelRequest::None) { Keeper* const _K{ _linda->whichKeeper() }; _pushed = keeper_call(_K->L, KEEPER_API(get), L_, _linda, 2); - if (_pushed.value_or(0) > 0) { - keeper_toggle_nil_sentinels(L_, lua_gettop(L_) - _pushed.value(), LookupMode::FromKeeper); - } } else { // linda is cancelled // do nothing and return lanes.cancel_error kCancelError.pushKey(L_); @@ -492,10 +489,6 @@ LUAG_FUNC(linda_receive) } if (_pushed.value() > 0) { LUA_ASSERT(L_, _pushed.value() >= _expected_pushed_min && _pushed.value() <= _expected_pushed_max); - // replace sentinels with real nils - keeper_toggle_nil_sentinels(L_, lua_gettop(L_) - _pushed.value(), LookupMode::FromKeeper); - // To be done from within the 'K' locking area - // _linda->readHappened.notify_all(); break; } @@ -589,8 +582,6 @@ LUAG_FUNC(linda_send) raise_luaL_error(L_, "no data to send"); } - // convert nils to some special non-nil sentinel in sent values - keeper_toggle_nil_sentinels(L_, _key_i + 1, LookupMode::ToKeeper); bool _ret{ false }; CancelRequest _cancel{ CancelRequest::None }; KeeperCallResult _pushed; @@ -701,10 +692,6 @@ LUAG_FUNC(linda_set) Keeper* const _K{ _linda->whichKeeper() }; KeeperCallResult _pushed; if (_linda->cancelRequest == CancelRequest::None) { - if (_has_value) { - // convert nils to some special non-nil sentinel in sent values - keeper_toggle_nil_sentinels(L_, 3, LookupMode::ToKeeper); - } _pushed = keeper_call(_K->L, KEEPER_API(set), L_, _linda, 2); if (_pushed.has_value()) { // no error? LUA_ASSERT(L_, _pushed.value() == 0 || _pushed.value() == 1); -- cgit v1.2.3-55-g6feb