compilerplugins/clang/test/useuniqueptr.cxx | 11 ++ compilerplugins/clang/useuniqueptr.cxx | 9 ++ include/svtools/asynclink.hxx | 5 - include/svtools/embedtransfer.hxx | 3 include/svtools/grfmgr.hxx | 2 include/toolkit/awt/vclxgraphics.hxx | 3 include/toolkit/awt/vclxwindow.hxx | 3 include/vcl/ppdparser.hxx | 3 svtools/source/contnr/imivctl.hxx | 6 - svtools/source/contnr/imivctl1.cxx | 17 ++-- svtools/source/control/asynclink.cxx | 6 - svtools/source/graphic/grfmgr2.cxx | 2 svtools/source/hatchwindow/documentcloser.cxx | 14 --- svtools/source/misc/embedtransfer.cxx | 7 - svtools/source/misc/transfer2.cxx | 15 +--- toolkit/source/awt/vclxgraphics.cxx | 9 +- toolkit/source/awt/vclxwindow.cxx | 4 - vcl/inc/openglgdiimpl.hxx | 2 vcl/inc/unx/genprn.h | 2 vcl/inc/unx/printerjob.hxx | 10 +- vcl/inc/unx/saldisp.hxx | 4 - vcl/inc/unx/salvd.h | 2 vcl/opengl/gdiimpl.cxx | 2 vcl/unx/generic/app/saldata.cxx | 4 - vcl/unx/generic/gdi/salvd.cxx | 5 - vcl/unx/generic/print/genprnpsp.cxx | 14 +-- vcl/unx/generic/print/printerjob.cxx | 96 +++++++++++--------------- vcl/unx/generic/printer/ppdparser.cxx | 2 28 files changed, 122 insertions(+), 140 deletions(-)
New commits: commit 6492ae184c9cea9bba10e8986eff4d6469d7d578 Author: Noel Grandin <[email protected]> Date: Mon Jan 15 16:23:14 2018 +0200 loplugin:useuniqueptr in TransferDataContainer_Impl Change-Id: I605e2d8ab97c74bfc00928921cddab513ac8c23d diff --git a/svtools/source/misc/transfer2.cxx b/svtools/source/misc/transfer2.cxx index 680cb5fa60c9..936ccb2301fe 100644 --- a/svtools/source/misc/transfer2.cxx +++ b/svtools/source/misc/transfer2.cxx @@ -320,19 +320,12 @@ struct TransferDataContainer_Impl { TDataCntnrEntryList aFmtList; Link<sal_Int8,void> aFinshedLnk; - INetBookmark* pBookmk; - Graphic* pGrf; + std::unique_ptr<INetBookmark> pBookmk; + std::unique_ptr<Graphic> pGrf; TransferDataContainer_Impl() - : pBookmk( nullptr ), pGrf( nullptr ) { } - - ~TransferDataContainer_Impl() - { - delete pBookmk; - delete pGrf; - } }; @@ -402,7 +395,7 @@ bool TransferDataContainer::GetData( void TransferDataContainer::CopyINetBookmark( const INetBookmark& rBkmk ) { if( !pImpl->pBookmk ) - pImpl->pBookmk = new INetBookmark( rBkmk ); + pImpl->pBookmk.reset( new INetBookmark( rBkmk ) ); else *pImpl->pBookmk = rBkmk; @@ -466,7 +459,7 @@ void TransferDataContainer::CopyGraphic( const Graphic& rGrf ) return; if( !pImpl->pGrf ) - pImpl->pGrf = new Graphic( rGrf ); + pImpl->pGrf.reset( new Graphic( rGrf ) ); else *pImpl->pGrf = rGrf; commit e16655d3790f500e28c845e31ef6ef5fda7a7c57 Author: Noel Grandin <[email protected]> Date: Mon Jan 15 16:22:06 2018 +0200 loplugin:useuniqueptr in SvEmbedTransferHelper Change-Id: Ie01e783fea160fba0041ae43a82ad3f4a7c961f9 diff --git a/include/svtools/embedtransfer.hxx b/include/svtools/embedtransfer.hxx index 35a45987607f..6cd0a407093d 100644 --- a/include/svtools/embedtransfer.hxx +++ b/include/svtools/embedtransfer.hxx @@ -23,6 +23,7 @@ #include <svtools/svtdllapi.h> #include <com/sun/star/embed/XEmbeddedObject.hpp> #include <svtools/transfer.hxx> +#include <memory> class Graphic; class SVT_DLLPUBLIC SvEmbedTransferHelper : public TransferableHelper @@ -30,7 +31,7 @@ class SVT_DLLPUBLIC SvEmbedTransferHelper : public TransferableHelper private: css::uno::Reference< css::embed::XEmbeddedObject > m_xObj; - Graphic* m_pGraphic; + std::unique_ptr<Graphic> m_pGraphic; sal_Int64 m_nAspect; OUString maParentShellID; diff --git a/svtools/source/misc/embedtransfer.cxx b/svtools/source/misc/embedtransfer.cxx index dc168ce5dfed..5d642c7a513f 100644 --- a/svtools/source/misc/embedtransfer.cxx +++ b/svtools/source/misc/embedtransfer.cxx @@ -59,11 +59,6 @@ SvEmbedTransferHelper::SvEmbedTransferHelper( const uno::Reference< embed::XEmbe SvEmbedTransferHelper::~SvEmbedTransferHelper() { - if ( m_pGraphic ) - { - delete m_pGraphic; - m_pGraphic = nullptr; - } } void SvEmbedTransferHelper::SetParentShellID( const OUString& rShellID ) @@ -95,7 +90,7 @@ bool SvEmbedTransferHelper::GetData( const css::datatransfer::DataFlavor& rFlavo if( nFormat == SotClipboardFormatId::OBJECTDESCRIPTOR ) { TransferableObjectDescriptor aDesc; - FillTransferableObjectDescriptor( aDesc, m_xObj, m_pGraphic, m_nAspect ); + FillTransferableObjectDescriptor( aDesc, m_xObj, m_pGraphic.get(), m_nAspect ); bRet = SetTransferableObjectDescriptor( aDesc ); } else if( nFormat == SotClipboardFormatId::EMBED_SOURCE ) commit 219e73b43cb173379cc402c90530e479c9376c7f Author: Noel Grandin <[email protected]> Date: Mon Jan 15 16:20:58 2018 +0200 loplugin:useuniqueptr in ODocumentCloser Change-Id: I7f985e4f63631909365560b8409a33180738043f diff --git a/svtools/source/hatchwindow/documentcloser.cxx b/svtools/source/hatchwindow/documentcloser.cxx index 9840cab38cdc..2285da9a3d63 100644 --- a/svtools/source/hatchwindow/documentcloser.cxx +++ b/svtools/source/hatchwindow/documentcloser.cxx @@ -49,13 +49,12 @@ class ODocumentCloser : public ::cppu::WeakImplHelper< css::lang::XComponent, { ::osl::Mutex m_aMutex; css::uno::Reference< css::frame::XFrame > m_xFrame; - ::comphelper::OInterfaceContainerHelper2* m_pListenersContainer; // list of listeners + std::unique_ptr<::comphelper::OInterfaceContainerHelper2> m_pListenersContainer; // list of listeners bool m_bDisposed; public: explicit ODocumentCloser(const css::uno::Sequence< css::uno::Any >& aArguments); - virtual ~ODocumentCloser() override; // XComponent virtual void SAL_CALL dispose() override; @@ -165,15 +164,6 @@ ODocumentCloser::ODocumentCloser(const css::uno::Sequence< css::uno::Any >& aArg } -ODocumentCloser::~ODocumentCloser() -{ - if ( m_pListenersContainer ) - { - delete m_pListenersContainer; - m_pListenersContainer = nullptr; - } -} - // XComponent void SAL_CALL ODocumentCloser::dispose() @@ -206,7 +196,7 @@ void SAL_CALL ODocumentCloser::addEventListener( const uno::Reference< lang::XEv throw lang::DisposedException(); // TODO if ( !m_pListenersContainer ) - m_pListenersContainer = new ::comphelper::OInterfaceContainerHelper2( m_aMutex ); + m_pListenersContainer.reset( new ::comphelper::OInterfaceContainerHelper2( m_aMutex ) ); m_pListenersContainer->addInterface( xListener ); } commit a9dc29d76e9a358d3f02524e0874c70b2884127e Author: Noel Grandin <[email protected]> Date: Mon Jan 15 16:19:32 2018 +0200 loplugin:useuniqueptr in GraphicManager Change-Id: I46f2e6a0ef2e2d19b0af0238a46462efe6e2c068 diff --git a/include/svtools/grfmgr.hxx b/include/svtools/grfmgr.hxx index 993d13dd117a..84e60975891f 100644 --- a/include/svtools/grfmgr.hxx +++ b/include/svtools/grfmgr.hxx @@ -498,7 +498,7 @@ private: std::unordered_set< GraphicObject* > maObjList; sal_uLong mnUsedSize; // currently used memory footprint of all swapped in graphics - GraphicCache* mpCache; + std::unique_ptr<GraphicCache> mpCache; GraphicManager( const GraphicManager& ) = delete; GraphicManager& operator=( const GraphicManager& ) = delete; diff --git a/svtools/source/graphic/grfmgr2.cxx b/svtools/source/graphic/grfmgr2.cxx index 0fc929a76610..976c1be508c8 100644 --- a/svtools/source/graphic/grfmgr2.cxx +++ b/svtools/source/graphic/grfmgr2.cxx @@ -56,7 +56,7 @@ GraphicManager::GraphicManager( sal_uLong nCacheSize, sal_uLong nMaxObjCacheSize GraphicManager::~GraphicManager() { assert(maObjList.empty()); - delete mpCache; + mpCache.reset(); } void GraphicManager::SetMaxCacheSize( sal_uLong nNewCacheSize ) commit ff90c1beb95f61db22022b944305453660c7e5a1 Author: Noel Grandin <[email protected]> Date: Mon Jan 15 16:18:18 2018 +0200 loplugin:useuniqueptr in SvxIconChoiceCtrl_Impl Change-Id: I42538502dd9cdd86739f56b7bd668038daf696a8 diff --git a/svtools/source/contnr/imivctl.hxx b/svtools/source/contnr/imivctl.hxx index 5ba8627ed6e8..2920288c91bc 100644 --- a/svtools/source/contnr/imivctl.hxx +++ b/svtools/source/contnr/imivctl.hxx @@ -168,11 +168,11 @@ class SvxIconChoiceCtrl_Impl Size aDefaultTextSize; Size aOutputSize; // Pixel VclPtr<SvtIconChoiceCtrl> pView; - IcnCursor_Impl* pImpCursor; - IcnGridMap_Impl* pGridMap; + std::unique_ptr<IcnCursor_Impl> pImpCursor; + std::unique_ptr<IcnGridMap_Impl> pGridMap; long nMaxVirtWidth; // max. width aVirtOutputSize for ALIGN_TOP long nMaxVirtHeight; // max. height aVirtOutputSize for ALIGN_LEFT - SvxIconChoiceCtrlEntryList_impl* pZOrderList; + std::unique_ptr<SvxIconChoiceCtrlEntryList_impl> pZOrderList; SvxIconChoiceCtrlColumnInfoMap* m_pColumns; VclPtr<IcnViewEdit_Impl> pEdit; WinBits nWinBits; diff --git a/svtools/source/contnr/imivctl1.cxx b/svtools/source/contnr/imivctl1.cxx index 3686ac96bba0..266941dcf6d8 100644 --- a/svtools/source/contnr/imivctl1.cxx +++ b/svtools/source/contnr/imivctl1.cxx @@ -116,7 +116,7 @@ SvxIconChoiceCtrl_Impl::SvxIconChoiceCtrl_Impl( bHighlightFramePressed = false; eSelectionMode = SelectionMode::Multiple; pView = pCurView; - pZOrderList = new SvxIconChoiceCtrlEntryList_impl; + pZOrderList.reset( new SvxIconChoiceCtrlEntryList_impl ); ePositionMode = SvxIconChoiceCtrlPositionMode::Free; SetStyle( nWinStyle ); nFlags = IconChoiceFlags::NONE; @@ -128,8 +128,8 @@ SvxIconChoiceCtrl_Impl::SvxIconChoiceCtrl_Impl( pDDBufDev = nullptr; pDDTempDev = nullptr; eTextMode = SvxIconChoiceCtrlTextMode::Short; - pImpCursor = new IcnCursor_Impl( this ); - pGridMap = new IcnGridMap_Impl( this ); + pImpCursor.reset( new IcnCursor_Impl( this ) ); + pGridMap.reset( new IcnGridMap_Impl( this ) ); aVerSBar->SetScrollHdl( LINK( this, SvxIconChoiceCtrl_Impl, ScrollUpDownHdl ) ); aHorSBar->SetScrollHdl( LINK( this, SvxIconChoiceCtrl_Impl, ScrollLeftRightHdl ) ); @@ -173,9 +173,9 @@ SvxIconChoiceCtrl_Impl::~SvxIconChoiceCtrl_Impl() Clear(false); StopEditTimer(); CancelUserEvents(); - delete pZOrderList; - delete pImpCursor; - delete pGridMap; + pZOrderList.reset(); + pImpCursor.reset(); + pGridMap.reset(); pDDDev.disposeAndClear(); pDDBufDev.disposeAndClear(); pDDTempDev.disposeAndClear(); @@ -658,7 +658,7 @@ void SvxIconChoiceCtrl_Impl::Paint(vcl::RenderContext& rRenderContext, const too rRenderContext.Push(PushFlags::CLIPREGION); rRenderContext.SetClipRegion(vcl::Region(rRect)); - SvxIconChoiceCtrlEntryList_impl* pNewZOrderList = new SvxIconChoiceCtrlEntryList_impl; + std::unique_ptr<SvxIconChoiceCtrlEntryList_impl> pNewZOrderList( new SvxIconChoiceCtrlEntryList_impl ); std::unique_ptr<SvxIconChoiceCtrlEntryList_impl> pPaintedEntries(new SvxIconChoiceCtrlEntryList_impl); size_t nPos = 0; @@ -678,8 +678,7 @@ void SvxIconChoiceCtrl_Impl::Paint(vcl::RenderContext& rRenderContext, const too nCount--; nPos++; } - delete pZOrderList; - pZOrderList = pNewZOrderList; + pZOrderList = std::move( pNewZOrderList ); nCount = pPaintedEntries->size(); if (nCount) { commit 70fcc41234907e434ebdc5883483248922f610ed Author: Noel Grandin <[email protected]> Date: Mon Jan 15 16:15:48 2018 +0200 loplugin:useuniqueptr in AsynchronLink Change-Id: I911bb1f8ca98e368f8275083936a8eb9013f462c diff --git a/include/svtools/asynclink.hxx b/include/svtools/asynclink.hxx index d037504b0464..c229b25f3d1c 100644 --- a/include/svtools/asynclink.hxx +++ b/include/svtools/asynclink.hxx @@ -24,6 +24,7 @@ #include <tools/solar.h> #include <tools/link.hxx> #include <osl/mutex.hxx> +#include <memory> class Idle; class Timer; @@ -35,11 +36,11 @@ class SVT_DLLPUBLIC AsynchronLink { Link<void*,void> _aLink; ImplSVEvent* _nEventId; - Idle* _pIdle; + std::unique_ptr<Idle> _pIdle; bool _bInCall; bool* _pDeleted; void* _pArg; - ::osl::Mutex* _pMutex; + std::unique_ptr<::osl::Mutex> _pMutex; DECL_DLLPRIVATE_LINK( HandleCall_Idle, Timer*, void ); DECL_DLLPRIVATE_LINK( HandleCall_PostUserEvent, void*, void ); diff --git a/svtools/source/control/asynclink.cxx b/svtools/source/control/asynclink.cxx index 16bccb92a2b6..5778b291ef86 100644 --- a/svtools/source/control/asynclink.cxx +++ b/svtools/source/control/asynclink.cxx @@ -30,7 +30,7 @@ namespace svtools { void AsynchronLink::CreateMutex() { - if( !_pMutex ) _pMutex = new osl::Mutex; + if( !_pMutex ) _pMutex.reset( new osl::Mutex ); } void AsynchronLink::Call( void* pObj, bool bAllowDoubles ) @@ -55,9 +55,9 @@ AsynchronLink::~AsynchronLink() { Application::RemoveUserEvent( _nEventId ); } - delete _pIdle; + _pIdle.reset(); if( _pDeleted ) *_pDeleted = true; - delete _pMutex; + _pMutex.reset(); } IMPL_LINK_NOARG( AsynchronLink, HandleCall_Idle, Timer*, void ) commit c4e8e59fd8b30447aac861884963e4e28a788db9 Author: Noel Grandin <[email protected]> Date: Mon Jan 15 16:13:27 2018 +0200 loplugin:useuniqueptr in VCLXWindow Change-Id: Iefec174c7dc3dbd52bdb9f6d7ebe6c8c42c031e9 diff --git a/include/toolkit/awt/vclxwindow.hxx b/include/toolkit/awt/vclxwindow.hxx index 18cd3f0392ca..27be3e102d32 100644 --- a/include/toolkit/awt/vclxwindow.hxx +++ b/include/toolkit/awt/vclxwindow.hxx @@ -44,6 +44,7 @@ #include <tools/link.hxx> #include <stdarg.h> +#include <memory> #include <vector> #include <functional> @@ -76,7 +77,7 @@ typedef cppu::ImplInheritanceHelper< VCLXDevice, class TOOLKIT_DLLPUBLIC VCLXWindow : public VCLXWindow_Base { private: - VCLXWindowImpl* mpImpl; + std::unique_ptr<VCLXWindowImpl> mpImpl; UnoPropertyArrayHelper *GetPropHelper(); diff --git a/toolkit/source/awt/vclxwindow.cxx b/toolkit/source/awt/vclxwindow.cxx index 6142b15140a3..7d1a70a23515 100644 --- a/toolkit/source/awt/vclxwindow.cxx +++ b/toolkit/source/awt/vclxwindow.cxx @@ -328,12 +328,12 @@ void ImplInitWindowEvent( css::awt::WindowEvent& rEvent, vcl::Window const * pWi VCLXWindow::VCLXWindow( bool _bWithDefaultProps ) :mpImpl( nullptr ) { - mpImpl = new VCLXWindowImpl( *this, _bWithDefaultProps ); + mpImpl.reset( new VCLXWindowImpl( *this, _bWithDefaultProps ) ); } VCLXWindow::~VCLXWindow() { - delete mpImpl; + mpImpl.reset(); if ( GetWindow() ) { commit 0e4ebf7fe413eb3bf827edaa27b91f97cd0ee5fe Author: Noel Grandin <[email protected]> Date: Mon Jan 15 16:12:24 2018 +0200 loplugin:useuniqueptr in VCLXGraphics Change-Id: If753b871831a9954048becd0aca73769e23163ec diff --git a/include/toolkit/awt/vclxgraphics.hxx b/include/toolkit/awt/vclxgraphics.hxx index 3818977d4ba0..8fc980a731de 100644 --- a/include/toolkit/awt/vclxgraphics.hxx +++ b/include/toolkit/awt/vclxgraphics.hxx @@ -32,6 +32,7 @@ #include <vcl/vclenum.hxx> #include <vcl/vclptr.hxx> #include <o3tl/typed_flags_set.hxx> +#include <memory> class OutputDevice; namespace vcl { class Region; } @@ -68,7 +69,7 @@ private: Color maLineColor; Color maFillColor; RasterOp meRasterOp; - vcl::Region* mpClipRegion; + std::unique_ptr<vcl::Region> mpClipRegion; void initAttrs(); diff --git a/toolkit/source/awt/vclxgraphics.cxx b/toolkit/source/awt/vclxgraphics.cxx index fac87df6f571..e8496a105b6f 100644 --- a/toolkit/source/awt/vclxgraphics.cxx +++ b/toolkit/source/awt/vclxgraphics.cxx @@ -79,7 +79,7 @@ VCLXGraphics::~VCLXGraphics() } } - delete mpClipRegion; + mpClipRegion.reset(); SolarMutexGuard g; mpOutputDevice.reset(); @@ -227,11 +227,10 @@ void VCLXGraphics::setClipRegion( const uno::Reference< awt::XRegion >& rxRegion { SolarMutexGuard aGuard; - delete mpClipRegion; if ( rxRegion.is() ) - mpClipRegion = new vcl::Region( VCLUnoHelper::GetRegion( rxRegion ) ); + mpClipRegion.reset( new vcl::Region( VCLUnoHelper::GetRegion( rxRegion ) ) ); else - mpClipRegion = nullptr; + mpClipRegion.reset(); } void VCLXGraphics::intersectClipRegion( const uno::Reference< awt::XRegion >& rxRegion ) @@ -242,7 +241,7 @@ void VCLXGraphics::intersectClipRegion( const uno::Reference< awt::XRegion >& rx { vcl::Region aRegion( VCLUnoHelper::GetRegion( rxRegion ) ); if ( !mpClipRegion ) - mpClipRegion = new vcl::Region( aRegion ); + mpClipRegion.reset( new vcl::Region( aRegion ) ); else mpClipRegion->Intersect( aRegion ); } commit 88ec67151faf70934577a3b355c7048a15adc937 Author: Noel Grandin <[email protected]> Date: Mon Jan 15 16:10:47 2018 +0200 loplugin:useuniqueptr in OpenGLSalGraphicsImpl Change-Id: I0d0e4da9c081c890ffd7dcaf051e3a3900345c35 diff --git a/vcl/inc/openglgdiimpl.hxx b/vcl/inc/openglgdiimpl.hxx index 7bc6644fdc48..aa55b970e64c 100644 --- a/vcl/inc/openglgdiimpl.hxx +++ b/vcl/inc/openglgdiimpl.hxx @@ -74,7 +74,7 @@ protected: OpenGLProgram* mpProgram; /// This idle handler is used to swap buffers after rendering. - OpenGLFlushIdle *mpFlush; + std::unique_ptr<OpenGLFlushIdle> mpFlush; // clipping vcl::Region maClipRegion; diff --git a/vcl/opengl/gdiimpl.cxx b/vcl/opengl/gdiimpl.cxx index 608b28dbb927..afe0157c520a 100644 --- a/vcl/opengl/gdiimpl.cxx +++ b/vcl/opengl/gdiimpl.cxx @@ -94,7 +94,7 @@ OpenGLSalGraphicsImpl::~OpenGLSalGraphicsImpl() if( !IsOffscreen() && mnDrawCountAtFlush != mnDrawCount ) VCL_GL_INFO( "Destroying un-flushed on-screen graphics" ); - delete mpFlush; + mpFlush.reset(); ReleaseContext(); } commit 0101ab807c409dced5d1acf9e38b887e9c878c02 Author: Noel Grandin <[email protected]> Date: Mon Jan 15 16:08:53 2018 +0200 loplugin:useuniqueptr in SalXLib Change-Id: Id3f8cf95479aa4e03bc6dcb05c5475ae462cfe5a diff --git a/vcl/inc/unx/saldisp.hxx b/vcl/inc/unx/saldisp.hxx index 546d6d7a6664..259af28e63a8 100644 --- a/vcl/inc/unx/saldisp.hxx +++ b/vcl/inc/unx/saldisp.hxx @@ -159,7 +159,7 @@ protected: fd_set aExceptionFDS_; Display *m_pDisplay; - SalI18N_InputMethod *m_pInputMethod; + std::unique_ptr<SalI18N_InputMethod> m_pInputMethod; public: SalXLib(); @@ -181,7 +181,7 @@ public: virtual bool CheckTimeout( bool bExecuteTimers = true ); - SalI18N_InputMethod* GetInputMethod() const { return m_pInputMethod; } + SalI18N_InputMethod* GetInputMethod() const { return m_pInputMethod.get(); } Display* GetDisplay() const { return m_pDisplay; } }; diff --git a/vcl/unx/generic/app/saldata.cxx b/vcl/unx/generic/app/saldata.cxx index 29b434eb6be8..a424dc5e05ef 100644 --- a/vcl/unx/generic/app/saldata.cxx +++ b/vcl/unx/generic/app/saldata.cxx @@ -376,7 +376,7 @@ SalXLib::~SalXLib() close (m_pTimeoutFDS[0]); close (m_pTimeoutFDS[1]); - delete m_pInputMethod; + m_pInputMethod.reset(); } static Display *OpenX11Display(OString& rDisplay) @@ -433,7 +433,7 @@ static Display *OpenX11Display(OString& rDisplay) void SalXLib::Init() { - m_pInputMethod = new SalI18N_InputMethod; + m_pInputMethod.reset( new SalI18N_InputMethod ); m_pInputMethod->SetLocale(); XrmInitialize(); commit a9a1ca1351694bf0fbad3fdb7c128bdfe1291d07 Author: Noel Grandin <[email protected]> Date: Mon Jan 15 16:06:59 2018 +0200 loplugin:useuniqueptr in X11SalVirtualDevice Change-Id: I812fb31ec802d2c20e2e82693be127d42df73a69 diff --git a/vcl/inc/unx/salvd.h b/vcl/inc/unx/salvd.h index 49b3ddff2d02..dbc489f63aab 100644 --- a/vcl/inc/unx/salvd.h +++ b/vcl/inc/unx/salvd.h @@ -32,7 +32,7 @@ class X11SalGraphics; class X11SalVirtualDevice : public SalVirtualDevice { SalDisplay *pDisplay_; - X11SalGraphics *pGraphics_; + std::unique_ptr<X11SalGraphics> pGraphics_; Pixmap hDrawable_; SalX11Screen m_nXScreen; diff --git a/vcl/unx/generic/gdi/salvd.cxx b/vcl/unx/generic/gdi/salvd.cxx index 09367e1e8a25..3be1449de90f 100644 --- a/vcl/unx/generic/gdi/salvd.cxx +++ b/vcl/unx/generic/gdi/salvd.cxx @@ -171,8 +171,7 @@ X11SalVirtualDevice::X11SalVirtualDevice(SalGraphics const * pGraphics, long &nD X11SalVirtualDevice::~X11SalVirtualDevice() { - delete pGraphics_; - pGraphics_ = nullptr; + pGraphics_.reset(); if( GetDrawable() && !bExternPixmap_ ) XFreePixmap( GetXDisplay(), GetDrawable() ); @@ -186,7 +185,7 @@ SalGraphics* X11SalVirtualDevice::AcquireGraphics() if( pGraphics_ ) bGraphics_ = true; - return pGraphics_; + return pGraphics_.get(); } void X11SalVirtualDevice::ReleaseGraphics( SalGraphics* ) commit 2e30f449f382dd163819eb18655d6473fe89de85 Author: Noel Grandin <[email protected]> Date: Mon Jan 15 16:03:34 2018 +0200 loplugin:useuniqueptr in PspSalInfoPrinter Change-Id: I77494fca8f0c326aa35872640b99596597116ef2 diff --git a/vcl/inc/unx/genprn.h b/vcl/inc/unx/genprn.h index 4a1c2db0a538..f741ca03effb 100644 --- a/vcl/inc/unx/genprn.h +++ b/vcl/inc/unx/genprn.h @@ -30,7 +30,7 @@ class GenPspGraphics; class VCL_DLLPUBLIC PspSalInfoPrinter : public SalInfoPrinter { public: - GenPspGraphics* m_pGraphics; + std::unique_ptr<GenPspGraphics> m_pGraphics; psp::JobData m_aJobData; psp::PrinterGfx m_aPrinterGfx; diff --git a/vcl/unx/generic/print/genprnpsp.cxx b/vcl/unx/generic/print/genprnpsp.cxx index 77abd94f6cbf..617eedc46eb6 100644 --- a/vcl/unx/generic/print/genprnpsp.cxx +++ b/vcl/unx/generic/print/genprnpsp.cxx @@ -480,11 +480,6 @@ PspSalInfoPrinter::PspSalInfoPrinter() PspSalInfoPrinter::~PspSalInfoPrinter() { - if( m_pGraphics ) - { - delete m_pGraphics; - m_pGraphics = nullptr; - } } void PspSalInfoPrinter::InitPaperFormats( const ImplJobSetup* ) @@ -524,19 +519,18 @@ SalGraphics* PspSalInfoPrinter::AcquireGraphics() SalGraphics* pRet = nullptr; if( ! m_pGraphics ) { - m_pGraphics = GetGenericInstance()->CreatePrintGraphics(); + m_pGraphics.reset( GetGenericInstance()->CreatePrintGraphics() ); m_pGraphics->Init(&m_aJobData, &m_aPrinterGfx); - pRet = m_pGraphics; + pRet = m_pGraphics.get(); } return pRet; } void PspSalInfoPrinter::ReleaseGraphics( SalGraphics* pGraphics ) { - if( pGraphics == m_pGraphics ) + if( m_pGraphics.get() == pGraphics ) { - delete pGraphics; - m_pGraphics = nullptr; + m_pGraphics.reset(); } } commit f0e304f55f271aecbdc3de174b73d3a646ce1433 Author: Noel Grandin <[email protected]> Date: Mon Jan 15 16:00:11 2018 +0200 loplugin:useuniqueptr in PPDParser Change-Id: Iafd63c276d430ea2a08286921f593bc56587e71c diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx index 24992685df43..62d462d2d66d 100644 --- a/compilerplugins/clang/useuniqueptr.cxx +++ b/compilerplugins/clang/useuniqueptr.cxx @@ -290,6 +290,9 @@ void UseUniquePtr::CheckForRangedLoopDelete(const CXXDestructorDecl* destructorD auto tc = loplugin::TypeCheck(fieldDecl->getType()); if (tc.Class("map").StdNamespace() || tc.Class("unordered_map").StdNamespace()) continue; + // there is a loop in ~ImplPrnQueueList deleting stuff on a global data structure + if (loplugin::hasPathnamePrefix(aFileName, SRCDIR "/vcl/inc/print.h")) + return; report( DiagnosticsEngine::Warning, diff --git a/include/vcl/ppdparser.hxx b/include/vcl/ppdparser.hxx index a3a04b86fdff..7cffed146ea7 100644 --- a/include/vcl/ppdparser.hxx +++ b/include/vcl/ppdparser.hxx @@ -19,6 +19,7 @@ #ifndef INCLUDED_VCL_PPDPARSER_HXX #define INCLUDED_VCL_PPDPARSER_HXX +#include <memory> #include <unordered_map> #include <vector> @@ -172,7 +173,7 @@ private: const PPDKey* m_pFontList; // translations - PPDTranslator* m_pTranslator; + std::unique_ptr<PPDTranslator> m_pTranslator; PPDParser( const OUString& rFile ); PPDParser( const OUString& rFile, std::vector<PPDKey*> keys ); diff --git a/vcl/unx/generic/printer/ppdparser.cxx b/vcl/unx/generic/printer/ppdparser.cxx index 335b72db59de..8de510de902b 100644 --- a/vcl/unx/generic/printer/ppdparser.cxx +++ b/vcl/unx/generic/printer/ppdparser.cxx @@ -885,7 +885,7 @@ PPDParser::~PPDParser() { for( PPDParser::hash_type::iterator it = m_aKeys.begin(); it != m_aKeys.end(); ++it ) delete it->second; - delete m_pTranslator; + m_pTranslator.reset(); } void PPDParser::insertKey( const OUString& rKey, PPDKey* pKey ) commit 883b4a7e4662752e8ea08c96b41180ddc75a4df8 Author: Noel Grandin <[email protected]> Date: Mon Jan 15 14:56:29 2018 +0200 loplugin:useuniqueptr expand search for ranged-loop-delete Change-Id: I78955f4db9b4da2858dfb25e69a5502eb0280418 diff --git a/compilerplugins/clang/test/useuniqueptr.cxx b/compilerplugins/clang/test/useuniqueptr.cxx index ddd30c73ae62..7495a9ec192d 100644 --- a/compilerplugins/clang/test/useuniqueptr.cxx +++ b/compilerplugins/clang/test/useuniqueptr.cxx @@ -8,6 +8,7 @@ */ #include <array> +#include <vector> #include <unordered_map> struct XXX { @@ -124,4 +125,14 @@ class Foo10 { } XXX* getOther() { return nullptr; } }; +class Foo11 { + std::vector<XXX*> m_pbar1; // expected-note {{member is here [loplugin:useuniqueptr]}} + ~Foo11() + { + for (const auto & p : m_pbar1) + { + delete p; // expected-error {{rather manage with std::some_container<std::unique_ptr<T>> [loplugin:useuniqueptr]}} + } + } +}; /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/compilerplugins/clang/useuniqueptr.cxx b/compilerplugins/clang/useuniqueptr.cxx index c14d5fc5a57b..24992685df43 100644 --- a/compilerplugins/clang/useuniqueptr.cxx +++ b/compilerplugins/clang/useuniqueptr.cxx @@ -256,7 +256,11 @@ void UseUniquePtr::CheckForRangedLoopDelete(const CXXDestructorDecl* destructorD auto cxxForRangeStmt = dyn_cast<CXXForRangeStmt>(*i); if (!cxxForRangeStmt) continue; - auto deleteExpr = dyn_cast<CXXDeleteExpr>(cxxForRangeStmt->getBody()); + CXXDeleteExpr const * deleteExpr = nullptr; + if (auto compoundStmt = dyn_cast<CompoundStmt>(cxxForRangeStmt->getBody())) + deleteExpr = dyn_cast<CXXDeleteExpr>(*compoundStmt->body_begin()); + else + deleteExpr = dyn_cast<CXXDeleteExpr>(cxxForRangeStmt->getBody()); if (!deleteExpr) continue; auto memberExpr = dyn_cast<MemberExpr>(cxxForRangeStmt->getRangeInit()); commit 8cfd56ba779ad23677dc22a4c4724ce666aff2a5 Author: Noel Grandin <[email protected]> Date: Mon Jan 15 14:52:07 2018 +0200 loplugin:useuniqueptr in PrinterJob Change-Id: I029cb5e5c117ea1c337509420b11589aa29cb383 diff --git a/vcl/inc/unx/printerjob.hxx b/vcl/inc/unx/printerjob.hxx index c744122b444a..d1de1f02f1c3 100644 --- a/vcl/inc/unx/printerjob.hxx +++ b/vcl/inc/unx/printerjob.hxx @@ -38,11 +38,11 @@ private: OUString maJobTitle; int mnFileMode; - osl::File* mpJobHeader; - osl::File* mpJobTrailer; + std::unique_ptr<osl::File> mpJobHeader; + std::unique_ptr<osl::File> mpJobTrailer; - std::vector< osl::File* > maPageVector; - std::vector< osl::File* > maHeaderVector; + std::vector< std::unique_ptr<osl::File> > maPageVector; + std::vector< std::unique_ptr<osl::File> > maHeaderVector; JobData m_aDocumentJobData; JobData m_aLastJobData; @@ -69,7 +69,7 @@ private: bool m_bQuickJob; private: - osl::File* CreateSpoolFile (const OUString& rName, + std::unique_ptr<osl::File> CreateSpoolFile (const OUString& rName, const OUString& rExtension); void InitPaperSize (const JobData& rJobSetup); diff --git a/vcl/unx/generic/print/printerjob.cxx b/vcl/unx/generic/print/printerjob.cxx index 76ed433834d3..4aaa737d12e4 100644 --- a/vcl/unx/generic/print/printerjob.cxx +++ b/vcl/unx/generic/print/printerjob.cxx @@ -80,11 +80,9 @@ AppendPS (FILE* pDst, osl::File* pSrc, unsigned char* pBuffer) * private convenience routines for file handling */ -osl::File* +std::unique_ptr<osl::File> PrinterJob::CreateSpoolFile (const OUString& rName, const OUString& rExtension) { - osl::File* pFile = nullptr; - OUString aFile = rName + rExtension; OUString aFileURL; osl::File::RC nError = osl::File::getFileURLFromSystemPath( aFile, aFileURL ); @@ -92,11 +90,10 @@ PrinterJob::CreateSpoolFile (const OUString& rName, const OUString& rExtension) return nullptr; aFileURL = maSpoolDirName + "/" + aFileURL; - pFile = new osl::File (aFileURL); + std::unique_ptr<osl::File> pFile( new osl::File (aFileURL) ); nError = pFile->open (osl_File_OpenFlag_Read | osl_File_OpenFlag_Write | osl_File_OpenFlag_Create); if (nError != osl::File::E_None) { - delete pFile; return nullptr; } @@ -158,7 +155,7 @@ PrinterJob::IsColorPrinter () const osl::File* PrinterJob::GetCurrentPageBody () { - return maPageVector.back(); + return maPageVector.back().get(); } /* @@ -166,8 +163,6 @@ PrinterJob::GetCurrentPageBody () */ PrinterJob::PrinterJob() : mnFileMode(0) - , mpJobHeader(nullptr) - , mpJobTrailer(nullptr) , m_pGraphics(nullptr) , mnResolution(96) , mnWidthPt(0) @@ -239,18 +234,13 @@ createSpoolDir () PrinterJob::~PrinterJob () { - for (auto const& page : maPageVector) - { - delete page; - } - for (auto const& header : maHeaderVector) - { - delete header; - } + maPageVector.clear(); + maHeaderVector.clear(); + // mpJobHeader->remove(); - delete mpJobHeader; + mpJobHeader.reset(); // mpJobTrailer->remove(); - delete mpJobTrailer; + mpJobTrailer.reset(); // XXX should really call osl::remove routines if( !maSpoolDirName.isEmpty() ) @@ -318,7 +308,7 @@ PrinterJob::StartJob ( return false; // write document header according to Document Structuring Conventions (DSC) - WritePS (mpJobHeader, + WritePS (mpJobHeader.get(), "%!PS-Adobe-3.0\n" "%%BoundingBox: (atend)\n" ); @@ -326,24 +316,24 @@ PrinterJob::StartJob ( // Creator (this application) aFilterWS = WhitespaceToSpace( rAppName, false ); - WritePS (mpJobHeader, "%%Creator: ("); - WritePS (mpJobHeader, aFilterWS); - WritePS (mpJobHeader, ")\n"); + WritePS (mpJobHeader.get(), "%%Creator: ("); + WritePS (mpJobHeader.get(), aFilterWS); + WritePS (mpJobHeader.get(), ")\n"); // For (user name) osl::Security aSecurity; OUString aUserName; if( aSecurity.getUserName( aUserName ) ) { - WritePS (mpJobHeader, "%%For: ("); - WritePS (mpJobHeader, aUserName); - WritePS (mpJobHeader, ")\n"); + WritePS (mpJobHeader.get(), "%%For: ("); + WritePS (mpJobHeader.get(), aUserName); + WritePS (mpJobHeader.get(), ")\n"); } // Creation Date (locale independent local time) - WritePS (mpJobHeader, "%%CreationDate: ("); - WriteLocalTimePS (mpJobHeader); - WritePS (mpJobHeader, ")\n"); + WritePS (mpJobHeader.get(), "%%CreationDate: ("); + WriteLocalTimePS (mpJobHeader.get()); + WritePS (mpJobHeader.get(), ")\n"); // Document Title /* #i74335# @@ -369,9 +359,9 @@ PrinterJob::StartJob ( maJobTitle = aFilterWS; if( !aTitle.isEmpty() ) { - WritePS (mpJobHeader, "%%Title: ("); - WritePS (mpJobHeader, aTitle); - WritePS (mpJobHeader, ")\n"); + WritePS (mpJobHeader.get(), "%%Title: ("); + WritePS (mpJobHeader.get(), aTitle); + WritePS (mpJobHeader.get(), ")\n"); } // Language Level @@ -379,18 +369,18 @@ PrinterJob::StartJob ( sal_Int32 nSz = getValueOf(GetPostscriptLevel(&rSetupData), pLevel); pLevel[nSz++] = '\n'; pLevel[nSz ] = '\0'; - WritePS (mpJobHeader, "%%LanguageLevel: "); - WritePS (mpJobHeader, pLevel); + WritePS (mpJobHeader.get(), "%%LanguageLevel: "); + WritePS (mpJobHeader.get(), pLevel); // Other - WritePS (mpJobHeader, "%%DocumentData: Clean7Bit\n"); - WritePS (mpJobHeader, "%%Pages: (atend)\n"); - WritePS (mpJobHeader, "%%Orientation: (atend)\n"); - WritePS (mpJobHeader, "%%PageOrder: Ascend\n"); - WritePS (mpJobHeader, "%%EndComments\n"); + WritePS (mpJobHeader.get(), "%%DocumentData: Clean7Bit\n"); + WritePS (mpJobHeader.get(), "%%Pages: (atend)\n"); + WritePS (mpJobHeader.get(), "%%Orientation: (atend)\n"); + WritePS (mpJobHeader.get(), "%%PageOrder: Ascend\n"); + WritePS (mpJobHeader.get(), "%%EndComments\n"); // write Prolog - writeProlog (mpJobHeader, rSetupData); + writeProlog (mpJobHeader.get(), rSetupData); // mark last job setup as not set m_aLastJobData.m_pParser = nullptr; @@ -409,7 +399,7 @@ PrinterJob::EndJob() // write document setup (done here because it // includes the accumulated fonts if( mpJobHeader ) - writeSetup( mpJobHeader, m_aDocumentJobData ); + writeSetup( mpJobHeader.get(), m_aDocumentJobData ); m_pGraphics->OnEndJob(); if( ! (mpJobHeader && mpJobTrailer) ) return false; @@ -428,7 +418,7 @@ PrinterJob::EndJob() aTrailer.append( "\n%%Pages: " ); aTrailer.append( static_cast<sal_Int32>(maPageVector.size()) ); aTrailer.append( "\n%%EOF\n" ); - WritePS (mpJobTrailer, aTrailer.getStr()); + WritePS (mpJobTrailer.get(), aTrailer.getStr()); /* * spool the set of files to their final destination, this is U**X dependent @@ -478,12 +468,12 @@ PrinterJob::EndJob() unsigned char pBuffer[ nBLOCKSIZE ]; - AppendPS (pDestFILE, mpJobHeader, pBuffer); + AppendPS (pDestFILE, mpJobHeader.get(), pBuffer); mpJobHeader->close(); bool bSuccess = true; - std::vector< osl::File* >::iterator pPageBody; - std::vector< osl::File* >::iterator pPageHead; + std::vector< std::unique_ptr<osl::File> >::iterator pPageBody; + std::vector< std::unique_ptr<osl::File> >::iterator pPageHead; for (pPageBody = maPageVector.begin(), pPageHead = maHeaderVector.begin(); pPageBody != maPageVector.end() && pPageHead != maHeaderVector.end(); ++pPageBody, ++pPageHead) @@ -493,7 +483,7 @@ PrinterJob::EndJob() osl::File::RC nError = (*pPageHead)->open(osl_File_OpenFlag_Read); if (nError == osl::File::E_None) { - AppendPS (pDestFILE, *pPageHead, pBuffer); + AppendPS (pDestFILE, pPageHead->get(), pBuffer); (*pPageHead)->close(); } } @@ -504,7 +494,7 @@ PrinterJob::EndJob() osl::File::RC nError = (*pPageBody)->open(osl_File_OpenFlag_Read); if (nError == osl::File::E_None) { - AppendPS (pDestFILE, *pPageBody, pBuffer); + AppendPS (pDestFILE, pPageBody->get(), pBuffer); (*pPageBody)->close(); } } @@ -512,7 +502,7 @@ PrinterJob::EndJob() bSuccess = false; } - AppendPS (pDestFILE, mpJobTrailer, pBuffer); + AppendPS (pDestFILE, mpJobTrailer.get(), pBuffer); mpJobTrailer->close(); /* well done */ @@ -573,11 +563,11 @@ PrinterJob::StartPage (const JobData& rJobSetup) OUString aPageNo = OUString::number (static_cast<sal_Int32>(maPageVector.size())+1); // sequential page number must start with 1 OUString aExt = aPageNo + ".ps"; - osl::File* pPageHeader = CreateSpoolFile ( "psp_pghead", aExt); - osl::File* pPageBody = CreateSpoolFile ( "psp_pgbody", aExt); + maHeaderVector.push_back( CreateSpoolFile ( "psp_pghead", aExt) ); + maPageVector.push_back( CreateSpoolFile ( "psp_pgbody", aExt) ); - maHeaderVector.push_back (pPageHeader); - maPageVector.push_back (pPageBody); + osl::File* pPageHeader = maHeaderVector.back().get(); + osl::File* pPageBody = maPageVector.back().get(); if( ! (pPageHeader && pPageBody) ) return; @@ -636,8 +626,8 @@ PrinterJob::StartPage (const JobData& rJobSetup) bool PrinterJob::EndPage () { - osl::File* pPageHeader = maHeaderVector.back(); - osl::File* pPageBody = maPageVector.back(); + osl::File* pPageHeader = maHeaderVector.back().get(); + osl::File* pPageBody = maPageVector.back().get(); if( ! (pPageBody && pPageHeader) ) return false; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
