diff options
author | Benoit Germain <benoit.germain@ubisoft.com> | 2024-03-27 11:09:57 +0100 |
---|---|---|
committer | Benoit Germain <benoit.germain@ubisoft.com> | 2024-03-27 11:09:57 +0100 |
commit | e36bf7059a320d7ea83376d38edc2b5280ae7221 (patch) | |
tree | 3a401161e641bbd9a0d6e0eced168702cfb390ab /src | |
parent | 9e3ca50cfafa0d7dc3e15f3b6a635aef6a938b80 (diff) | |
download | lanes-e36bf7059a320d7ea83376d38edc2b5280ae7221.tar.gz lanes-e36bf7059a320d7ea83376d38edc2b5280ae7221.tar.bz2 lanes-e36bf7059a320d7ea83376d38edc2b5280ae7221.zip |
C++ migration: fix deep userdata refcounting bug introduced by std::atomic usage
Diffstat (limited to 'src')
-rw-r--r-- | src/deep.cpp | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/deep.cpp b/src/deep.cpp index e62ca6d..f59e051 100644 --- a/src/deep.cpp +++ b/src/deep.cpp | |||
@@ -166,9 +166,9 @@ static int deep_userdata_gc( lua_State* L) | |||
166 | 166 | ||
167 | // can work without a universe if creating a deep userdata from some external C module when Lanes isn't loaded | 167 | // can work without a universe if creating a deep userdata from some external C module when Lanes isn't loaded |
168 | // in that case, we are not multithreaded and locking isn't necessary anyway | 168 | // in that case, we are not multithreaded and locking isn't necessary anyway |
169 | int v{ p->m_refcount.fetch_sub(1, std::memory_order_relaxed) }; | 169 | bool const isLastRef{ p->m_refcount.fetch_sub(1, std::memory_order_relaxed) == 1 }; |
170 | 170 | ||
171 | if( v == 0) | 171 | if (isLastRef) |
172 | { | 172 | { |
173 | // retrieve wrapped __gc | 173 | // retrieve wrapped __gc |
174 | lua_pushvalue( L, lua_upvalueindex( 1)); // self __gc? | 174 | lua_pushvalue( L, lua_upvalueindex( 1)); // self __gc? |
@@ -425,7 +425,6 @@ DeepPrelude* luaG_todeep(lua_State* L, luaG_IdFunction idfunc, int index) | |||
425 | STACK_CHECK(L, 0); | 425 | STACK_CHECK(L, 0); |
426 | 426 | ||
427 | DeepPrelude** const proxy{ lua_tofulluserdata<DeepPrelude*>(L, index) }; | 427 | DeepPrelude** const proxy{ lua_tofulluserdata<DeepPrelude*>(L, index) }; |
428 | |||
429 | return *proxy; | 428 | return *proxy; |
430 | } | 429 | } |
431 | 430 | ||