diff options
author | Nat Goodspeed <nat@lindenlab.com> | 2024-04-03 15:52:46 -0400 |
---|---|---|
committer | Nat Goodspeed <nat@lindenlab.com> | 2024-04-03 15:52:46 -0400 |
commit | 81d7fae644b759dd7b5620c7469b2941743dced8 (patch) | |
tree | a7b81da33404dc5eb00d2abf53123be00c581250 /indra/llcommon | |
parent | f069543328efc441673db9877c97ae2201b86e91 (diff) |
Introduce LLInstanceTracker::destroy() methods; use in ~LuaState().
Diffstat (limited to 'indra/llcommon')
-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..22e5d9c7a7 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 destroy(const KEY& key) + { + return destroy(getInstance(key)); + } + + /// for use ONLY for an object we're sure resides on the heap! + static bool destroy(const weak_t& ptr) + { + return destroy(ptr.lock()); + } + + /// for use ONLY for an object we're sure resides on the heap! + static bool destroy(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 destroy(const weak_t& ptr) + { + return destroy(ptr.lock()); + } + + /// for use ONLY for an object we're sure resides on the heap! + static bool destroy(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..c86faf1ae2 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::destroy(getListener()); lua_close(mState); |