From e36bf7059a320d7ea83376d38edc2b5280ae7221 Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 27 Mar 2024 11:09:57 +0100 Subject: C++ migration: fix deep userdata refcounting bug introduced by std::atomic usage --- src/deep.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src') 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) // can work without a universe if creating a deep userdata from some external C module when Lanes isn't loaded // in that case, we are not multithreaded and locking isn't necessary anyway - int v{ p->m_refcount.fetch_sub(1, std::memory_order_relaxed) }; + bool const isLastRef{ p->m_refcount.fetch_sub(1, std::memory_order_relaxed) == 1 }; - if( v == 0) + if (isLastRef) { // retrieve wrapped __gc lua_pushvalue( L, lua_upvalueindex( 1)); // self __gc? @@ -425,7 +425,6 @@ DeepPrelude* luaG_todeep(lua_State* L, luaG_IdFunction idfunc, int index) STACK_CHECK(L, 0); DeepPrelude** const proxy{ lua_tofulluserdata(L, index) }; - return *proxy; } -- cgit v1.2.3-55-g6feb