[Libreoffice-commits] core.git: compilerplugins/clang include/sfx2 sfx2/source sw/source
Noel Grandin
noel.grandin at collabora.co.uk
Mon May 15 06:46:03 UTC 2017
compilerplugins/clang/useuniqueptr.cxx | 18 ++++++++++++++++--
include/sfx2/sfxhtml.hxx | 3 ++-
sfx2/source/bastyp/sfxhtml.cxx | 6 ++----
sw/source/core/inc/laycache.hxx | 7 ++++---
sw/source/core/layout/laycache.cxx | 11 +++++------
5 files changed, 29 insertions(+), 16 deletions(-)
New commits:
commit 5e7583fe864c4491c5a19d2896b6555448146ad8
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date: Fri May 12 15:32:36 2017 +0200
loplugin:useuniqueptr
ignore SAL_LOG type stuff in the destructor
Change-Id: If014382ca0c96edd3f2b325a28451d83b3d1f278
Reviewed-on: https://gerrit.libreoffice.org/37539
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx
index 4d9d159e11fb..24f6007ca2af 100644
--- a/compilerplugins/clang/useuniqueptr.cxx
+++ b/compilerplugins/clang/useuniqueptr.cxx
@@ -50,10 +50,21 @@ bool UseUniquePtr::VisitCXXDestructorDecl(const CXXDestructorDecl* destructorDec
if (compoundStmt == nullptr) {
return true;
}
- if (compoundStmt->size() != 1) {
+
+ const CXXDeleteExpr* deleteExpr;
+ if (compoundStmt->size() == 1) {
+ deleteExpr = dyn_cast<CXXDeleteExpr>(compoundStmt->body_front());
+ }
+ else if (compoundStmt->size() == 2) {
+ // ignore SAL_INFO type stuff
+ // TODO should probably be a little more specific here
+ if (!isa<DoStmt>(compoundStmt->body_front())) {
+ return true;
+ }
+ deleteExpr = dyn_cast<CXXDeleteExpr>(compoundStmt->body_back());
+ } else {
return true;
}
- const CXXDeleteExpr* deleteExpr = dyn_cast<CXXDeleteExpr>(compoundStmt->body_front());
if (deleteExpr == nullptr) {
return true;
}
@@ -104,6 +115,9 @@ bool UseUniquePtr::VisitCXXDestructorDecl(const CXXDestructorDecl* destructorDec
// @TODO SwDoc has some weird ref-counting going on
if (aFileName.startswith(SRCDIR "/sw/inc/shellio.hxx"))
return true;
+ // @TODO it's sharing pointers with another class
+ if (aFileName.startswith(SRCDIR "/sc/inc/formulacell.hxx"))
+ return true;
report(
DiagnosticsEngine::Warning,
diff --git a/include/sfx2/sfxhtml.hxx b/include/sfx2/sfxhtml.hxx
index 90031e4471cf..2796c950cad4 100644
--- a/include/sfx2/sfxhtml.hxx
+++ b/include/sfx2/sfxhtml.hxx
@@ -26,6 +26,7 @@
#include <i18nlangtag/lang.h>
#include <svtools/parhtml.hxx>
#include <svl/macitem.hxx>
+#include <memory>
class ImageMap;
@@ -37,7 +38,7 @@ class SFX2_DLLPUBLIC SfxHTMLParser : public HTMLParser
OUString aScriptType;
SfxMedium* pMedium;
- SfxMedium *pDLMedium; // Medium for Download Files
+ std::unique_ptr<SfxMedium> pDLMedium; // Medium for Download Files
ScriptType eScriptType;
diff --git a/sfx2/source/bastyp/sfxhtml.cxx b/sfx2/source/bastyp/sfxhtml.cxx
index 70c2741d408e..6499f58430ad 100644
--- a/sfx2/source/bastyp/sfxhtml.cxx
+++ b/sfx2/source/bastyp/sfxhtml.cxx
@@ -78,7 +78,6 @@ SfxHTMLParser::SfxHTMLParser( SvStream& rStream, bool bIsNewDoc,
SfxHTMLParser::~SfxHTMLParser()
{
DBG_ASSERT( !pDLMedium, "Here is a File Download that has got stuck" );
- delete pDLMedium;
}
bool SfxHTMLParser::ParseMapOptions(
@@ -227,7 +226,7 @@ void SfxHTMLParser::StartFileDownload(const OUString& rURL)
if( pDLMedium )
return;
- pDLMedium = new SfxMedium( rURL, SFX_STREAM_READONLY );
+ pDLMedium.reset( new SfxMedium( rURL, SFX_STREAM_READONLY ) );
pDLMedium->Download();
}
@@ -250,8 +249,7 @@ bool SfxHTMLParser::FinishFileDownload( OUString& rStr )
rStr = OStringToOUString( sBuffer, RTL_TEXTENCODING_UTF8 );
}
- delete pDLMedium;
- pDLMedium = nullptr;
+ pDLMedium.reset();
return bOK;
}
diff --git a/sw/source/core/inc/laycache.hxx b/sw/source/core/inc/laycache.hxx
index 53dd324d4dac..38f464794615 100644
--- a/sw/source/core/inc/laycache.hxx
+++ b/sw/source/core/inc/laycache.hxx
@@ -21,6 +21,7 @@
#define INCLUDED_SW_SOURCE_CORE_INC_LAYCACHE_HXX
#include <tools/solar.h>
+#include <memory>
class SwDoc;
class SwLayCacheImpl;
@@ -39,11 +40,11 @@ class SvStream;
*/
class SwLayoutCache
{
- SwLayCacheImpl *pImpl;
+ std::unique_ptr<SwLayCacheImpl> pImpl;
sal_uInt16 nLockCount;
public:
- SwLayoutCache() : pImpl( nullptr ), nLockCount( 0 ) {}
+ SwLayoutCache();
~SwLayoutCache();
void Read( SvStream &rStream );
@@ -56,7 +57,7 @@ public:
{ if( nLockCount & 0x8000 ) return nullptr;
if ( pImpl )
++nLockCount;
- return pImpl; }
+ return pImpl.get(); }
void UnlockImpl() { --nLockCount; }
#ifdef DBG_UTIL
diff --git a/sw/source/core/layout/laycache.cxx b/sw/source/core/layout/laycache.cxx
index 251651fdbbe4..ab8f0e361841 100644
--- a/sw/source/core/layout/laycache.cxx
+++ b/sw/source/core/layout/laycache.cxx
@@ -47,6 +47,8 @@
using namespace ::com::sun::star;
+SwLayoutCache::SwLayoutCache() : nLockCount( 0 ) {}
+
/*
* Reading and writing of the layout cache.
* The layout cache is not necessary, but it improves
@@ -62,11 +64,10 @@ void SwLayoutCache::Read( SvStream &rStream )
{
if( !pImpl )
{
- pImpl = new SwLayCacheImpl;
+ pImpl.reset( new SwLayCacheImpl );
if( !pImpl->Read( rStream ) )
{
- delete pImpl;
- pImpl = nullptr;
+ pImpl.reset();
}
}
}
@@ -429,15 +430,13 @@ void SwLayoutCache::ClearImpl()
{
if( !IsLocked() )
{
- delete pImpl;
- pImpl = nullptr;
+ pImpl.reset();
}
}
SwLayoutCache::~SwLayoutCache()
{
OSL_ENSURE( !nLockCount, "Deleting a locked SwLayoutCache!?" );
- delete pImpl;
}
/// helper class to create not nested section frames for nested sections.
More information about the Libreoffice-commits
mailing list