diff options
author | Maxim Nikolenko <maximnproductengine@lindenlab.com> | 2024-04-04 17:43:57 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-04 17:43:57 +0300 |
commit | 3114f674aaef019804803bed50972833f5411f93 (patch) | |
tree | e50ff7417b01403e2a6ea98056b0d368aca04a44 /indra | |
parent | e2d15198bd3d81250850ac7061fdbc7c6153647f (diff) | |
parent | 1507002a4a45c70d25bba7164430607d4224c4e9 (diff) |
Merge pull request #1125 from secondlife/lua-pr-feedback
Introduce LLInstanceTracker::destruct() methods; use in ~LuaState().
Diffstat (limited to 'indra')
-rw-r--r-- | indra/llcommon/llinstancetracker.h | 52 | ||||
-rw-r--r-- | indra/llcommon/lua_function.cpp | 11 |
2 files changed, 54 insertions, 9 deletions
diff --git a/indra/llcommon/llinstancetracker.h b/indra/llcommon/llinstancetracker.h index 27422e1266..921f743ada 100644 --- a/indra/llcommon/llinstancetracker.h +++ b/indra/llcommon/llinstancetracker.h @@ -275,6 +275,35 @@ protected: public: virtual const KEY& getKey() const { return mInstanceKey; } + /// for use ONLY for an object we're sure resides on the heap! + static bool destruct(const KEY& key) + { + return destruct(getInstance(key)); + } + + /// for use ONLY for an object we're sure resides on the heap! + static bool destruct(const weak_t& ptr) + { + return destruct(ptr.lock()); + } + + /// for use ONLY for an object we're sure resides on the heap! + static bool destruct(const ptr_t& ptr) + { + if (! ptr) + { + return false; + } + + // Because we store and return ptr_t instances with no-op deleters, + // merely resetting the last pointer doesn't destroy the referenced + // object. Don't even bother resetting 'ptr'. Just extract its raw + // pointer and delete that. + auto raw{ ptr.get() }; + delete raw; + return true; + } + private: LLInstanceTracker( const LLInstanceTracker& ) = delete; LLInstanceTracker& operator=( const LLInstanceTracker& ) = delete; @@ -479,6 +508,29 @@ public: template <typename SUBCLASS> using key_snapshot_of = instance_snapshot_of<SUBCLASS>; + /// for use ONLY for an object we're sure resides on the heap! + static bool destruct(const weak_t& ptr) + { + return destruct(ptr.lock()); + } + + /// for use ONLY for an object we're sure resides on the heap! + static bool destruct(const ptr_t& ptr) + { + if (! ptr) + { + return false; + } + + // Because we store and return ptr_t instances with no-op deleters, + // merely resetting the last pointer doesn't destroy the referenced + // object. Don't even bother resetting 'ptr'. Just extract its raw + // pointer and delete that. + auto raw{ ptr.get() }; + delete raw; + return true; + } + protected: LLInstanceTracker() { diff --git a/indra/llcommon/lua_function.cpp b/indra/llcommon/lua_function.cpp index 7a5668f384..332a08a444 100644 --- a/indra/llcommon/lua_function.cpp +++ b/indra/llcommon/lua_function.cpp @@ -286,7 +286,7 @@ LLSD lua_tollsd(lua_State* L, int index) popper.disarm(); // Table keys are all integers: are they reasonable integers? // Arbitrary max: may bite us, but more likely to protect us - size_t array_max{ 10000 }; + const size_t array_max{ 10000 }; if (keys.size() > array_max) { return lluau::error(L, "Conversion from Lua to LLSD array limited to %d entries", @@ -459,14 +459,7 @@ LuaState::~LuaState() { // Did somebody call obtainListener() on this LuaState? // That is, is there a LuaListener key in its registry? - auto listener{ getListener() }; - if (listener) - { - // if we got a LuaListener instance, destroy it - auto lptr{ listener.get() }; - listener.reset(); - delete lptr; - } + LuaListener::destruct(getListener()); lua_close(mState); |