aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Germain <benoit.germain@ubisoft.com>2024-04-15 12:21:27 +0200
committerBenoit Germain <benoit.germain@ubisoft.com>2024-04-15 12:21:27 +0200
commite79953ff093c0518975111c69d16e97ccf966e20 (patch)
tree2644e1fd7b0b5f88359c42499945f8aedbe30f1c /src
parentadaa36dbec1ce9aaafd61873b9d3d898a8c240cf (diff)
downloadlanes-e79953ff093c0518975111c69d16e97ccf966e20.tar.gz
lanes-e79953ff093c0518975111c69d16e97ccf966e20.tar.bz2
lanes-e79953ff093c0518975111c69d16e97ccf966e20.zip
fix keeper state stack accumulating garbage in case of transfer errors
Diffstat (limited to 'src')
-rw-r--r--src/keeper.c4
-rw-r--r--src/linda.c4
2 files changed, 7 insertions, 1 deletions
diff --git a/src/keeper.c b/src/keeper.c
index a1505b7..1522718 100644
--- a/src/keeper.c
+++ b/src/keeper.c
@@ -810,7 +810,9 @@ int keeper_call( Universe* U, lua_State* K, keeper_api_t func_, lua_State* L, vo
810 int const Ktos = lua_gettop( K); 810 int const Ktos = lua_gettop( K);
811 int retvals = -1; 811 int retvals = -1;
812 812
813 STACK_GROW( K, 2); 813 // if we didn't do anything wrong, the keeper stack should be clean
814 ASSERT_L(Ktos == 0);
815 STACK_GROW(K, 2);
814 816
815 PUSH_KEEPER_FUNC( K, func_); 817 PUSH_KEEPER_FUNC( K, func_);
816 818
diff --git a/src/linda.c b/src/linda.c
index 2128520..d92f5f2 100644
--- a/src/linda.c
+++ b/src/linda.c
@@ -90,12 +90,16 @@ LUAG_FUNC( linda_protected_call)
90 Keeper* K = keeper_acquire( linda->U->keepers, LINDA_KEEPER_HASHSEED(linda)); 90 Keeper* K = keeper_acquire( linda->U->keepers, LINDA_KEEPER_HASHSEED(linda));
91 lua_State* KL = K ? K->L : NULL; // need to do this for 'STACK_CHECK' 91 lua_State* KL = K ? K->L : NULL; // need to do this for 'STACK_CHECK'
92 if( KL == NULL) return 0; 92 if( KL == NULL) return 0;
93 // if we didn't do anything wrong, the keeper stack should be clean
94 ASSERT_L(lua_gettop(KL) == 0);
93 95
94 // retrieve the actual function to be called and move it before the arguments 96 // retrieve the actual function to be called and move it before the arguments
95 lua_pushvalue( L, lua_upvalueindex( 1)); 97 lua_pushvalue( L, lua_upvalueindex( 1));
96 lua_insert( L, 1); 98 lua_insert( L, 1);
97 // do a protected call 99 // do a protected call
98 rc = lua_pcall( L, lua_gettop( L) - 1, LUA_MULTRET, 0); 100 rc = lua_pcall( L, lua_gettop( L) - 1, LUA_MULTRET, 0);
101 // whatever happens, the keeper state stack must be empty when we are done
102 lua_settop(KL, 0);
99 103
100 // release the keeper 104 // release the keeper
101 keeper_release( K); 105 keeper_release( K);