1919// . under single thread
2020// . so eg after MtInQueue.mt_push(), shall NOT touch pushed SafePtr
2121// . only HID is MT safe that can be used here
22- // . no exception
2322// . T's duty to ensure it's inner safety (eg no exception from T's constructor)
2423// . loop-ref: out-duty, usr issue than SafePtr
2524// . safe ptr array: no need since std::array
@@ -185,7 +184,7 @@ template<typename U, typename... ConstructArgs>
185184SafePtr<U> make_safe (ConstructArgs&&... aArgs) noexcept
186185{
187186 SafePtr<U> safeU;
188- try {
187+ try { // bad_alloc, or except from U's constructor
189188 safeU.pT_ = std::make_shared<U>(std::forward<ConstructArgs>(aArgs)...); // std::make_shared, not boost's
190189 // HID("new ptr=" << (void*)(safeU.pT_.get())); // too many print; void* print addr rather than content(dangeous)
191190 } catch (...) {
@@ -259,14 +258,9 @@ SafeWeak<T>::SafeWeak(const SafePtr<T>& aSafeFrom) noexcept
259258template <typename T>
260259SafePtr<T> SafeWeak<T>::lock() const noexcept
261260{
262- SafePtr<T> ret;
263- if (pT_.expired ())
264- return ret;
265-
266- ret.pT_ = pT_.lock ();
267- ret.realType_ = realType_;
268- ret.lastType_ = lastType_;
269- return ret;
261+ return (pT_.expired ())
262+ ? nullptr
263+ : SafePtr<T>(pT_.lock (), realType_, lastType_); // constructor is faster
270264}
271265} // namespace
272266
@@ -289,7 +283,7 @@ struct std::hash<rlib::SafePtr<T>>
289283// 2024-06-28 CSZ - dynamic_pointer_cast ok or ret null
290284// 2024-10-16 CSZ - dynamic_pointer_cast to safe_cast since std not allowed
291285// 2025-02-13 CSZ 4)SafeWeak
292- // 2025-03-24 CSZ 5)enable exception, tolerate except is safer
286+ // 2025-03-24 CSZ 5)enable exception: tolerate except is safer; can't recover except->terminate
293287// ***********************************************************************************************
294288// - Q&A
295289// . How to solve safety issue:
0 commit comments