Git commit fddc7d90787827d73f6dee9c3b757c090e289d8f by Frederik Gladhorn. Committed on 07/11/2016 at 22:28. Pushed by gladhorn into branch 'rempt/impex-refactoring'. Add toStrongRef to KisWeakPtr Weak pointers don't hold a strong reference, they may become nullptr at any time. To use them safely, they always have bo be converted to a strong reference. Further commits can then slowly move over to users of weak pointers to first convert them to strong pointers and introduce a check for nullptr at the same time. M +13 -0 libs/global/kis_shared_ptr.h http://commits.kde.org/krita/fddc7d90787827d73f6dee9c3b757c090e289d8f diff --git a/libs/global/kis_shared_ptr.h b/libs/global/kis_shared_ptr.h index 4b35c48..5453bfa 100644 --- a/libs/global/kis_shared_ptr.h +++ b/libs/global/kis_shared_ptr.h @@ -408,6 +408,19 @@ public: = return d && weakReference && isOdd((int)*weakReference); } + + /** + * @brief toStrongRef returns a KisSharedPtr which may be dereferenced. + * + * Weak pointers should only be used to track ownership but never be u= sed as pointers. + * This has historically not been the case, but in new API this functi= on should be used + * instead of directly using a weak pointer as pointer. + * @return a KisSharedPtr, which may be null + */ + inline KisSharedPtr toStrongRef() const { + return KisSharedPtr(*this); + } + private: static const qint32 WEAK_REF =3D 2; static inline bool isOdd(const qint32 &x) {