diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-05-27 10:27:46 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2022-08-29 13:44:02 +0200 |
commit | 8611f6e259b807b4f19c8dc0eab86ca648891ce3 (patch) | |
tree | fa2b0e463aafb51df754768f916ca9104969a557 /compilerplugins | |
parent | 25a997c15d39fb30676a375df8ea4ce1ed2e1acd (diff) |
ref-count SdrObject
Which means we can get rid of the majestic hack of ScCaptionPtr
Previously, SdrObject was manually managed, and the ownership
passed around in very complicated fashion.
Notes:
(*) SvxShape has a strong reference to SdrObject, where
previously it had a weak reference. It is now strong
since otherwise the SdrObject will go away very eagerly.
(*) SdrObject still has a weak reference to SvxShape
(*) In the existing places that an SdrObject is being
deleted, we now just clear the reference
(*) instead of SwVirtFlyDrawObj removing itself from the
page that contains inside it's destructor, make the call site
do the removing from the page.
(*) Needed to take the SolarMutex in UndoManagerHelper_Impl::impl_clear
because this can be called from UNO (e.g. sfx2_complex JUnit test)
and the SdrObjects need the SolarMutex when destructing.
(*) handle a tricky situation with SwDrawVirtObj in the SwDrawModel
destructor because the existing code wants mpDrawObj in
SwAnchoredObject to be sometimes owning, sometimes not, which
results in a cycle with the new code.
Change-Id: I4d79df1660e386388e5d51030653755bca02a163
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138837
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'compilerplugins')
-rw-r--r-- | compilerplugins/clang/refcounting.cxx | 13 | ||||
-rw-r--r-- | compilerplugins/clang/test/refcounting.cxx | 17 | ||||
-rw-r--r-- | compilerplugins/clang/weakobject.cxx | 1 |
3 files changed, 21 insertions, 10 deletions
diff --git a/compilerplugins/clang/refcounting.cxx b/compilerplugins/clang/refcounting.cxx index 61204b67a470..e65772f71e7d 100644 --- a/compilerplugins/clang/refcounting.cxx +++ b/compilerplugins/clang/refcounting.cxx @@ -505,6 +505,10 @@ bool RefCounting::VisitCXXDeleteExpr(const CXXDeleteExpr * cxxDeleteExpr) compiler.getSourceManager().getSpellingLoc(cxxDeleteExpr->getBeginLoc())); if (loplugin::isSamePathname(aFileName, SRCDIR "/cppuhelper/source/weak.cxx")) return true; + if (loplugin::isSamePathname(aFileName, SRCDIR "/include/svx/svdobj.hxx")) + return true; + if (loplugin::isSamePathname(aFileName, SRCDIR "/svx/source/svdraw/svdobj.cxx")) + return true; if (!cxxDeleteExpr->getArgument()) return true; @@ -746,6 +750,15 @@ bool RefCounting::isCastingReference(const Expr* expr) if (callMethod->getReturnType()->isReferenceType()) return false; } + // Ignore + // WeakReference x; + // if (x.get.get()) + // and similar stuff + if (auto memberCall2 = dyn_cast<CXXMemberCallExpr>(obj)) + { + if (loplugin::TypeCheck(memberCall2->getImplicitObjectArgument()->getType()).Class("WeakReference")) + return false; + } return true; } diff --git a/compilerplugins/clang/test/refcounting.cxx b/compilerplugins/clang/test/refcounting.cxx index 7ab830fc913b..2b8ce94b42e6 100644 --- a/compilerplugins/clang/test/refcounting.cxx +++ b/compilerplugins/clang/test/refcounting.cxx @@ -13,16 +13,8 @@ #include <rtl/ref.hxx> #include <boost/intrusive_ptr.hpp> #include <com/sun/star/uno/XInterface.hpp> - -namespace cppu -{ -class OWeakObject -{ -public: - void acquire(); - void release(); -}; -} +#include <cppuhelper/weak.hxx> +#include <unotools/weakref.hxx> struct UnoObject : public cppu::OWeakObject { @@ -115,6 +107,11 @@ void foo7() UnoSubObject* p3 = static_cast<UnoSubObject*>(getConstRef().get()); (void)p3; p3 = static_cast<UnoSubObject*>(getConstRef().get()); + + // no warning expected, although, arguably, we should be assigning to a rtl::Reference temporary + unotools::WeakReference<UnoObject> weak1; + auto pTextObj = dynamic_cast<UnoSubObject*>(weak1.get().get()); + (void)pTextObj; } /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/weakobject.cxx b/compilerplugins/clang/weakobject.cxx index d021dd419d89..7f1a2986faa5 100644 --- a/compilerplugins/clang/weakobject.cxx +++ b/compilerplugins/clang/weakobject.cxx @@ -1,3 +1,4 @@ + /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. |