diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2020-01-29 15:56:00 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2020-01-30 09:33:05 +0100 |
commit | bdd1229c3e1f1d8281e56151b3907c9a6eb07e04 (patch) | |
tree | 2cc682f3c302120df64ac6d174bebf722f365050 | |
parent | f12fc2d07e6f2e9d33ad9350b1f005cbcbe72a18 (diff) |
Revert "SwAutoCompleteClient: SwClient no more"
This reverts commit fa26db1c053a8510ada15fcbaa7e36ae0f6920a5 for now, as it
breaks UBSan builds during e.g. JunitTest_sw_unoapi_1
(<https://ci.libreoffice.org/job/lo_ubsan/1518/>):
> /sw/source/core/doc/acmplwrd.cxx:138:9: runtime error: member access within address 0x607001517be0 which does not point to an object of type 'SwAutoCompleteClient'
> 0x607001517be0: note: object is of type 'SvtListener'
> af 07 80 42 d0 8e 97 f4 84 2b 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00
> ^~~~~~~~~~~~~~~~~~~~~~~
> vptr for 'SvtListener'
> #0 0x2b85787e94b6 in SwAutoCompleteClient::Notify(SfxHint const&) /sw/source/core/doc/acmplwrd.cxx:138:9
> #1 0x2b84f3d5d886 in SvtBroadcaster::Broadcast(SfxHint const&) /svl/source/notify/broadcast.cxx:128:25
> #2 0x2b84f3d5c07a in SvtBroadcaster::~SvtBroadcaster() /svl/source/notify/broadcast.cxx:96:5
> #3 0x2b857812fdc4 in sw::BroadcasterMixin::~BroadcasterMixin() /sw/inc/calbck.hxx:84:24
> #4 0x2b857af251c4 in SwPageDesc::~SwPageDesc() /sw/source/core/layout/pagedesc.cxx:127:1
> #5 0x2b857af25234 in SwPageDesc::~SwPageDesc() /sw/source/core/layout/pagedesc.cxx:126:1
> #6 0x2b8578f2c550 in SwDoc::~SwDoc() /sw/source/core/doc/docnew.cxx:466:9
> #7 0x2b857892a9c3 in SwDoc::release() /sw/source/core/doc/doc.cxx:117:9
> #8 0x2b8579d1efae in rtl::Reference<SwDoc>::clear() /include/rtl/ref.hxx:159:19
> #9 0x2b857e12fd44 in SwDocShell::RemoveLink() /sw/source/uibase/app/docshini.cxx:438:16
> #10 0x2b857e12eac7 in SwDocShell::~SwDocShell() /sw/source/uibase/app/docshini.cxx:366:5
> #11 0x2b857e12ff2b in SwDocShell::~SwDocShell() /sw/source/uibase/app/docshini.cxx:356:1
> #12 0x2b857e130104 in SwDocShell::~SwDocShell() /sw/source/uibase/app/docshini.cxx:356:1
> #13 0x2b84edcb1a4a in SvRefBase::ReleaseRef() /include/tools/ref.hxx:163:29
> #14 0x2b84edcb1020 in tools::SvRef<SfxObjectShell>::~SvRef() /include/tools/ref.hxx:56:36
Change-Id: Iaf1cb698bf898efc66a3abaa1c8bfd3116b389b7
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87715
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r-- | sw/source/core/doc/acmplwrd.cxx | 100 |
1 files changed, 51 insertions, 49 deletions
diff --git a/sw/source/core/doc/acmplwrd.cxx b/sw/source/core/doc/acmplwrd.cxx index fc911a1993cc..619faef05aa4 100644 --- a/sw/source/core/doc/acmplwrd.cxx +++ b/sw/source/core/doc/acmplwrd.cxx @@ -24,7 +24,7 @@ #include <doc.hxx> #include <pagedesc.hxx> #include <poolfmt.hxx> -#include <svl/listener.hxx> +#include <calbck.hxx> #include <IDocumentStylePoolAccess.hxx> #include <editeng/svxacorr.hxx> #include <osl/diagnose.h> @@ -35,12 +35,14 @@ #include <cassert> #include <vector> -#include <atomic> -class SwAutoCompleteClient final: public SvtListener +class SwAutoCompleteClient : public SwClient { SwAutoCompleteWord* m_pAutoCompleteWord; SwDoc* m_pDoc; +#if OSL_DEBUG_LEVEL > 0 + static sal_uLong s_nSwAutoCompleteClientCount; +#endif public: SwAutoCompleteClient(SwAutoCompleteWord& rToTell, SwDoc& rSwDoc); SwAutoCompleteClient(const SwAutoCompleteClient& rClient); @@ -49,44 +51,13 @@ public: SwAutoCompleteClient& operator=(const SwAutoCompleteClient& rClient); const SwDoc& GetDoc() const {return *m_pDoc;} - virtual void Notify(const SfxHint&) override; #if OSL_DEBUG_LEVEL > 0 - static sal_uInt32 GetElementCount() {return s_nSwAutoCompleteClientCount.load();} -private: - static std::atomic<sal_uInt32> s_nSwAutoCompleteClientCount; + static sal_uLong GetElementCount() {return s_nSwAutoCompleteClientCount;} #endif +protected: + virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) override; }; - -SwAutoCompleteClient::SwAutoCompleteClient(SwAutoCompleteWord& rToTell, SwDoc& rSwDoc) - : m_pAutoCompleteWord(&rToTell) - , m_pDoc(&rSwDoc) -{ - StartListening(m_pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier()); -#if OSL_DEBUG_LEVEL > 0 - ++s_nSwAutoCompleteClientCount; -#endif -} - -SwAutoCompleteClient::SwAutoCompleteClient(const SwAutoCompleteClient& rClient) - : SvtListener() - , m_pAutoCompleteWord(rClient.m_pAutoCompleteWord) - , m_pDoc(rClient.m_pDoc) -{ - StartListening(m_pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier()); -#if OSL_DEBUG_LEVEL > 0 - ++s_nSwAutoCompleteClientCount; -#endif -} - -SwAutoCompleteClient::~SwAutoCompleteClient() -{ -#if OSL_DEBUG_LEVEL > 0 - --s_nSwAutoCompleteClientCount; -#endif - (void) this; -} - typedef std::vector<SwAutoCompleteClient> SwAutoCompleteClientVector; class SwAutoCompleteWord_Impl @@ -101,7 +72,6 @@ public: }; typedef std::vector<const SwDoc*> SwDocPtrVector; - class SwAutoCompleteString : public editeng::IAutoCompleteString { @@ -120,22 +90,59 @@ class SwAutoCompleteString static sal_uLong GetElementCount() {return s_nSwAutoCompleteStringCount;} #endif }; +#if OSL_DEBUG_LEVEL > 0 + sal_uLong SwAutoCompleteClient::s_nSwAutoCompleteClientCount = 0; + sal_uLong SwAutoCompleteString::s_nSwAutoCompleteStringCount = 0; +#endif + +SwAutoCompleteClient::SwAutoCompleteClient(SwAutoCompleteWord& rToTell, SwDoc& rSwDoc) : + m_pAutoCompleteWord(&rToTell), + m_pDoc(&rSwDoc) +{ + m_pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->Add(this); +#if OSL_DEBUG_LEVEL > 0 + ++s_nSwAutoCompleteClientCount; +#endif +} + +SwAutoCompleteClient::SwAutoCompleteClient(const SwAutoCompleteClient& rClient) : + SwClient(), + m_pAutoCompleteWord(rClient.m_pAutoCompleteWord), + m_pDoc(rClient.m_pDoc) +{ + m_pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->Add(this); +#if OSL_DEBUG_LEVEL > 0 + ++s_nSwAutoCompleteClientCount; +#endif +} + +SwAutoCompleteClient::~SwAutoCompleteClient() +{ +#if OSL_DEBUG_LEVEL > 0 + --s_nSwAutoCompleteClientCount; +#else + (void) this; +#endif +} SwAutoCompleteClient& SwAutoCompleteClient::operator=(const SwAutoCompleteClient& rClient) { m_pAutoCompleteWord = rClient.m_pAutoCompleteWord; m_pDoc = rClient.m_pDoc; - StartListening(m_pDoc->getIDocumentStylePoolAccess().GetPageDescFromPool(RES_POOLPAGE_STANDARD)->GetNotifier()); + StartListeningToSameModifyAs(rClient); return *this; } -void SwAutoCompleteClient::Notify(const SfxHint& rHint) +void SwAutoCompleteClient::Modify( const SfxPoolItem* pOld, const SfxPoolItem *) { - if(rHint.GetId() == SfxHintId::Dying) + switch( pOld ? pOld->Which() : 0 ) { - EndListeningAll(); + case RES_REMOVE_UNO_OBJECT: + case RES_OBJECTDYING: + if( static_cast<void*>(GetRegisteredIn()) == static_cast<const SwPtrMsgPoolItem *>(pOld)->pObject ) + EndListeningAll(); m_pAutoCompleteWord->DocumentDying(*m_pDoc); - m_pDoc = nullptr; + break; } } @@ -206,7 +213,7 @@ SwAutoCompleteWord::~SwAutoCompleteWord() m_WordList.DeleteAndDestroyAll(); // so the assertion below works #if OSL_DEBUG_LEVEL > 0 sal_uLong nStrings = SwAutoCompleteString::GetElementCount(); - sal_uInt32 nClients = SwAutoCompleteClient::GetElementCount(); + sal_uLong nClients = SwAutoCompleteClient::GetElementCount(); OSL_ENSURE(!nStrings && !nClients, "AutoComplete: clients or string count mismatch"); #endif } @@ -394,9 +401,4 @@ void SwAutoCompleteWord::DocumentDying(const SwDoc& rDoc) } } -#if OSL_DEBUG_LEVEL > 0 -std::atomic<sal_uInt32> SwAutoCompleteClient::s_nSwAutoCompleteClientCount = 0; -sal_uLong SwAutoCompleteString::s_nSwAutoCompleteStringCount = 0; -#endif - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |