diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-22 16:26:30 +0200 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-05-22 16:26:30 +0200 |
commit | 48985bf413bef59778a4e50ba8391938364bae56 (patch) | |
tree | 3d99f7171bbddf8d0b5948b30d7719f7b2bc0229 /src | |
parent | b639c229e3fdef21cec4535284eeabbca361dad6 (diff) | |
download | lanes-48985bf413bef59778a4e50ba8391938364bae56.tar.gz lanes-48985bf413bef59778a4e50ba8391938364bae56.tar.bz2 lanes-48985bf413bef59778a4e50ba8391938364bae56.zip |
Fix __lanesignore
Diffstat (limited to 'src')
-rw-r--r-- | src/intercopycontext.cpp | 15 | ||||
-rw-r--r-- | src/keeper.cpp | 20 | ||||
-rw-r--r-- | src/keeper.h | 1 | ||||
-rw-r--r-- | src/linda.cpp | 13 |
4 files changed, 13 insertions, 36 deletions
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. | |||
28 | 28 | ||
29 | #include "debugspew.h" | 29 | #include "debugspew.h" |
30 | #include "deep.h" | 30 | #include "deep.h" |
31 | #include "keeper.h" | ||
31 | #include "universe.h" | 32 | #include "universe.h" |
32 | 33 | ||
33 | // ################################################################################################# | 34 | // ################################################################################################# |
@@ -887,7 +888,12 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
887 | { | 888 | { |
888 | void* const _p{ lua_touserdata(L1, L1_i) }; | 889 | void* const _p{ lua_touserdata(L1, L1_i) }; |
889 | DEBUGSPEW_CODE(fprintf(stderr, "%p\n", _p)); | 890 | DEBUGSPEW_CODE(fprintf(stderr, "%p\n", _p)); |
890 | lua_pushlightuserdata(L2, _p); | 891 | // when copying a nil sentinel in a non-keeper, write a nil in the destination |
892 | if (mode != LookupMode::ToKeeper && kNilSentinel.equals(L1, L1_i)) { | ||
893 | lua_pushnil(L2); | ||
894 | } else { | ||
895 | lua_pushlightuserdata(L2, _p); | ||
896 | } | ||
891 | return true; | 897 | return true; |
892 | } | 898 | } |
893 | 899 | ||
@@ -898,7 +904,12 @@ void InterCopyContext::inter_copy_keyvaluepair() const | |||
898 | if (vt == VT::KEY) { | 904 | if (vt == VT::KEY) { |
899 | return false; | 905 | return false; |
900 | } | 906 | } |
901 | lua_pushnil(L2); | 907 | // when copying a nil in a keeper, write a nil sentinel in the destination |
908 | if (mode == LookupMode::ToKeeper) { | ||
909 | kNilSentinel.pushKey(L2); | ||
910 | } else { | ||
911 | lua_pushnil(L2); | ||
912 | } | ||
902 | return true; | 913 | return true; |
903 | } | 914 | } |
904 | 915 | ||
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 | |||
569 | 569 | ||
570 | // ################################################################################################# | 570 | // ################################################################################################# |
571 | 571 | ||
572 | void keeper_toggle_nil_sentinels(lua_State* L_, int start_, LookupMode const mode_) | ||
573 | { | ||
574 | int const _n{ lua_gettop(L_) }; | ||
575 | for (int _i = start_; _i <= _n; ++_i) { | ||
576 | if (mode_ == LookupMode::ToKeeper) { | ||
577 | if (lua_isnil(L_, _i)) { | ||
578 | kNilSentinel.pushKey(L_); | ||
579 | lua_replace(L_, _i); | ||
580 | } | ||
581 | } else { | ||
582 | if (kNilSentinel.equals(L_, _i)) { | ||
583 | lua_pushnil(L_); | ||
584 | lua_replace(L_, _i); | ||
585 | } | ||
586 | } | ||
587 | } | ||
588 | } | ||
589 | |||
590 | // ################################################################################################# | ||
591 | |||
592 | /* | 572 | /* |
593 | * Call a function ('func_name') in the keeper state, and pass on the returned | 573 | * Call a function ('func_name') in the keeper state, and pass on the returned |
594 | * values to 'L'. | 574 | * 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 | |||
40 | // xxh64 of string "kNilSentinel" generated at https://www.pelock.com/products/hash-calculator | 40 | // xxh64 of string "kNilSentinel" generated at https://www.pelock.com/products/hash-calculator |
41 | static constexpr UniqueKey kNilSentinel{ 0xC457D4EDDB05B5E4ull, "lanes.null" }; | 41 | static constexpr UniqueKey kNilSentinel{ 0xC457D4EDDB05B5E4ull, "lanes.null" }; |
42 | 42 | ||
43 | void keeper_toggle_nil_sentinels(lua_State* L_, int start_, LookupMode const mode_); | ||
44 | [[nodiscard]] int keeper_push_linda_storage(Linda& linda_, DestState L_); | 43 | [[nodiscard]] int keeper_push_linda_storage(Linda& linda_, DestState L_); |
45 | 44 | ||
46 | using keeper_api_t = lua_CFunction; | 45 | 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) | |||
344 | if (_linda->cancelRequest == CancelRequest::None) { | 344 | if (_linda->cancelRequest == CancelRequest::None) { |
345 | Keeper* const _K{ _linda->whichKeeper() }; | 345 | Keeper* const _K{ _linda->whichKeeper() }; |
346 | _pushed = keeper_call(_K->L, KEEPER_API(get), L_, _linda, 2); | 346 | _pushed = keeper_call(_K->L, KEEPER_API(get), L_, _linda, 2); |
347 | if (_pushed.value_or(0) > 0) { | ||
348 | keeper_toggle_nil_sentinels(L_, lua_gettop(L_) - _pushed.value(), LookupMode::FromKeeper); | ||
349 | } | ||
350 | } else { // linda is cancelled | 347 | } else { // linda is cancelled |
351 | // do nothing and return lanes.cancel_error | 348 | // do nothing and return lanes.cancel_error |
352 | kCancelError.pushKey(L_); | 349 | kCancelError.pushKey(L_); |
@@ -492,10 +489,6 @@ LUAG_FUNC(linda_receive) | |||
492 | } | 489 | } |
493 | if (_pushed.value() > 0) { | 490 | if (_pushed.value() > 0) { |
494 | LUA_ASSERT(L_, _pushed.value() >= _expected_pushed_min && _pushed.value() <= _expected_pushed_max); | 491 | LUA_ASSERT(L_, _pushed.value() >= _expected_pushed_min && _pushed.value() <= _expected_pushed_max); |
495 | // replace sentinels with real nils | ||
496 | keeper_toggle_nil_sentinels(L_, lua_gettop(L_) - _pushed.value(), LookupMode::FromKeeper); | ||
497 | // To be done from within the 'K' locking area | ||
498 | // | ||
499 | _linda->readHappened.notify_all(); | 492 | _linda->readHappened.notify_all(); |
500 | break; | 493 | break; |
501 | } | 494 | } |
@@ -589,8 +582,6 @@ LUAG_FUNC(linda_send) | |||
589 | raise_luaL_error(L_, "no data to send"); | 582 | raise_luaL_error(L_, "no data to send"); |
590 | } | 583 | } |
591 | 584 | ||
592 | // convert nils to some special non-nil sentinel in sent values | ||
593 | keeper_toggle_nil_sentinels(L_, _key_i + 1, LookupMode::ToKeeper); | ||
594 | bool _ret{ false }; | 585 | bool _ret{ false }; |
595 | CancelRequest _cancel{ CancelRequest::None }; | 586 | CancelRequest _cancel{ CancelRequest::None }; |
596 | KeeperCallResult _pushed; | 587 | KeeperCallResult _pushed; |
@@ -701,10 +692,6 @@ LUAG_FUNC(linda_set) | |||
701 | Keeper* const _K{ _linda->whichKeeper() }; | 692 | Keeper* const _K{ _linda->whichKeeper() }; |
702 | KeeperCallResult _pushed; | 693 | KeeperCallResult _pushed; |
703 | if (_linda->cancelRequest == CancelRequest::None) { | 694 | if (_linda->cancelRequest == CancelRequest::None) { |
704 | if (_has_value) { | ||
705 | // convert nils to some special non-nil sentinel in sent values | ||
706 | keeper_toggle_nil_sentinels(L_, 3, LookupMode::ToKeeper); | ||
707 | } | ||
708 | _pushed = keeper_call(_K->L, KEEPER_API(set), L_, _linda, 2); | 695 | _pushed = keeper_call(_K->L, KEEPER_API(set), L_, _linda, 2); |
709 | if (_pushed.has_value()) { // no error? | 696 | if (_pushed.has_value()) { // no error? |
710 | LUA_ASSERT(L_, _pushed.value() == 0 || _pushed.value() == 1); | 697 | LUA_ASSERT(L_, _pushed.value() == 0 || _pushed.value() == 1); |