[Libreoffice-commits] core.git: Branch 'feature/vclptr' - 14 commits - basctl/source canvas/source framework/source include/sfx2 include/vcl sd/source sfx2/source starmath/source svtools/source sw/source vcl/qa vcl/README.lifecycle vcl/source

Michael Meeks michael.meeks at collabora.com
Fri Apr 10 05:05:17 PDT 2015


 basctl/source/basicide/basdoc.cxx                     |    4 ++-
 canvas/source/vcl/bitmapbackbuffer.cxx                |    3 --
 framework/source/uielement/fontsizemenucontroller.cxx |    2 -
 include/sfx2/printer.hxx                              |    1 
 include/sfx2/viewsh.hxx                               |    2 -
 include/vcl/lazydelete.hxx                            |   11 +++++----
 include/vcl/outdev.hxx                                |    2 +
 include/vcl/vclptr.hxx                                |    1 
 include/vcl/window.hxx                                |    8 +-----
 sd/source/ui/presenter/PresenterTextView.cxx          |    7 ++----
 sfx2/source/view/printer.cxx                          |    6 +++++
 sfx2/source/view/viewprn.cxx                          |   13 +++++------
 starmath/source/unomodel.cxx                          |    2 -
 svtools/source/dialogs/prnsetup.cxx                   |   10 +++++---
 sw/source/core/doc/DocumentDeviceManager.cxx          |    7 ++++++
 sw/source/ui/dialog/ascfldlg.cxx                      |    4 +--
 sw/source/uibase/uno/SwXDocumentSettings.cxx          |    5 ++--
 vcl/README.lifecycle                                  |    6 ++++-
 vcl/qa/cppunit/lifecycle.cxx                          |   17 ++++++++++++++
 vcl/source/control/button.cxx                         |    5 +---
 vcl/source/gdi/print.cxx                              |    4 +--
 vcl/source/outdev/font.cxx                            |    5 ++++
 vcl/source/outdev/map.cxx                             |    3 ++
 vcl/source/window/dialog.cxx                          |    2 -
 vcl/source/window/layout.cxx                          |    8 +++---
 vcl/source/window/window.cxx                          |   21 +++++++++++++-----
 vcl/source/window/window2.cxx                         |   16 ++++++-------
 27 files changed, 115 insertions(+), 60 deletions(-)

New commits:
commit 23eada8dbbf10de29b85e9d965f5c0ed11942efc
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Fri Mar 27 14:12:28 2015 +0000

    repair dialog related lifecycle bits.
    
    Change-Id: I33ec0318a257929583aa4bb0d107f16d1f8edbcd

diff --git a/vcl/source/window/dialog.cxx b/vcl/source/window/dialog.cxx
index 9ca9c30..56c5dd4 100644
--- a/vcl/source/window/dialog.cxx
+++ b/vcl/source/window/dialog.cxx
@@ -488,7 +488,7 @@ OUString VclBuilderContainer::getUIRootDir()
 //do the init. Find the real parent stashed in mpDialogParent.
 void Dialog::doDeferredInit(WinBits nBits)
 {
-    vcl::Window *pParent = mpDialogParent;
+    VclPtr<vcl::Window> pParent = mpDialogParent;
     mpDialogParent = NULL;
     ImplInit(pParent, nBits);
     mbIsDefferedInit = false;
commit dc60f2a95552ab440dcdacca8969eb3bcc2758c1
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Thu Mar 26 22:38:03 2015 +0000

    get messagebox dispose ordering right.
    
    Change-Id: Ia7085cf98141fdbd50cf9cc9ed45e2e0c09e448e

diff --git a/vcl/source/window/layout.cxx b/vcl/source/window/layout.cxx
index 34de14a..3bc1a63 100644
--- a/vcl/source/window/layout.cxx
+++ b/vcl/source/window/layout.cxx
@@ -2034,13 +2034,13 @@ void MessageDialog::dispose()
         m_aOwnedButtons[i].disposeAndClear();
     m_aOwnedButtons.clear();
 
-    m_pSecondaryMessage.clear();
-    m_pSecondaryMessage.clear();
-    m_pImage.clear();
+    m_pPrimaryMessage.disposeAndClear();
+    m_pSecondaryMessage.disposeAndClear();
+    m_pSecondaryMessage.disposeAndClear();
+    m_pImage.disposeAndClear();
     m_pGrid.disposeAndClear();
     m_pOwnedActionArea.disposeAndClear();
     m_pOwnedContentArea.disposeAndClear();
-    m_pPrimaryMessage.clear();
     Dialog::dispose();
 }
 
commit 1757fb4a49050ecef14c0c71b81cee9a0759e36b
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Thu Mar 26 22:29:54 2015 +0000

    no need to free mpButtonData in dispose.
    
    Change-Id: Ie6f135d9e91d0831717c2a0726161825d0a06665

diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx
index 7bcea27..09a6ee5 100644
--- a/vcl/source/control/button.cxx
+++ b/vcl/source/control/button.cxx
@@ -96,12 +96,11 @@ Button::Button( WindowType nType ) :
 Button::~Button()
 {
     disposeOnce();
+    delete mpButtonData;
 }
 
 void Button::dispose()
 {
-    delete mpButtonData;
-    mpButtonData = NULL;
     Control::dispose();
 }
 
@@ -542,7 +541,7 @@ sal_uInt16& Button::ImplGetButtonState()
 
 sal_uInt16 Button::ImplGetButtonState() const
 {
-    return mpButtonData ? mpButtonData->mnButtonState : 0;
+    return mpButtonData->mnButtonState;
 }
 
 void Button::ImplSetSymbolAlign( SymbolAlign eAlign )
commit 8dd74ea0862170c7705a6b9468dc16ee5e8c419b
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Thu Mar 26 22:14:24 2015 +0000

    Fix unintended destruction of adjacent printers.
    
    also audit commit: "start wrapping OutputDevice in VclPtr"
    
    Change-Id: I6e018d7c3e3c8f941c184ad1aaa8593f7750c620

diff --git a/vcl/source/gdi/print.cxx b/vcl/source/gdi/print.cxx
index 7c48a7f..3cbc34d 100644
--- a/vcl/source/gdi/print.cxx
+++ b/vcl/source/gdi/print.cxx
@@ -1067,8 +1067,8 @@ void Printer::dispose()
     else
         pSVData->maGDIData.mpLastPrinter = mpPrev;
 
-    mpPrev.disposeAndClear();
-    mpNext.disposeAndClear();
+    mpPrev.clear();
+    mpNext.clear();
     OutputDevice::dispose();
 }
 
commit 5c91c9fed51bf10387a7673cb8c1ccd95e0469d0
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Thu Mar 26 21:45:50 2015 +0000

    Fix LazyDelete crasher, and add & test more post-dispose robustness.
    
    Change-Id: I0e9460cb33b7cb5da9ddb950ff27bac8cbf7fed8

diff --git a/vcl/qa/cppunit/lifecycle.cxx b/vcl/qa/cppunit/lifecycle.cxx
index 8be94a5..12b0a51 100644
--- a/vcl/qa/cppunit/lifecycle.cxx
+++ b/vcl/qa/cppunit/lifecycle.cxx
@@ -30,6 +30,7 @@ public:
     void testIsolatedWidgets();
     void testParentedWidgets();
     void testChildDispose();
+    void testPostDispose();
 
     CPPUNIT_TEST_SUITE(LifecycleTest);
     CPPUNIT_TEST(testCast);
@@ -38,6 +39,7 @@ public:
     CPPUNIT_TEST(testIsolatedWidgets);
     CPPUNIT_TEST(testParentedWidgets);
     CPPUNIT_TEST(testChildDispose);
+    CPPUNIT_TEST(testPostDispose);
     CPPUNIT_TEST_SUITE_END();
 };
 
@@ -125,6 +127,21 @@ void LifecycleTest::testChildDispose()
     xWin->disposeOnce();
 }
 
+void LifecycleTest::testPostDispose()
+{
+    VclPtr<WorkWindow> xWin(new WorkWindow((vcl::Window *)NULL, WB_STDWORK));
+    xWin->disposeOnce();
+
+    // check selected methods continue to work post-dispose
+    CPPUNIT_ASSERT(!xWin->GetParent());
+    xWin->Show();
+    CPPUNIT_ASSERT(!xWin->IsReallyShown());
+    CPPUNIT_ASSERT(!xWin->IsEnabled());
+    CPPUNIT_ASSERT(!xWin->IsInputEnabled());
+    CPPUNIT_ASSERT(!xWin->GetChild(0));
+    CPPUNIT_ASSERT(!xWin->GetWindow(0));
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(LifecycleTest);
 
 CPPUNIT_PLUGIN_IMPLEMENT();
diff --git a/vcl/source/window/window2.cxx b/vcl/source/window/window2.cxx
index 95468f3..cf8fd3f 100644
--- a/vcl/source/window/window2.cxx
+++ b/vcl/source/window/window2.cxx
@@ -975,27 +975,27 @@ vcl::Window* Window::ImplGetWindow()
 
 ImplFrameData* Window::ImplGetFrameData()
 {
-    return mpWindowImpl->mpFrameData;
+    return mpWindowImpl ? mpWindowImpl->mpFrameData : NULL;
 }
 
 SalFrame* Window::ImplGetFrame() const
 {
-    return mpWindowImpl->mpFrame;
+    return mpWindowImpl ? mpWindowImpl->mpFrame : NULL;
 }
 
 vcl::Window* Window::ImplGetParent() const
 {
-    return mpWindowImpl->mpParent;
+    return mpWindowImpl ? mpWindowImpl->mpParent.get() : NULL;
 }
 
 vcl::Window* Window::ImplGetClientWindow() const
 {
-    return mpWindowImpl->mpClientWindow;
+    return mpWindowImpl ? mpWindowImpl->mpClientWindow.get() : NULL;
 }
 
 vcl::Window* Window::ImplGetBorderWindow() const
 {
-    return mpWindowImpl->mpBorderWindow;
+    return mpWindowImpl ? mpWindowImpl->mpBorderWindow.get() : NULL;
 }
 
 vcl::Window* Window::ImplGetFirstOverlapWindow()
@@ -1237,7 +1237,7 @@ bool Window::IsReallyVisible() const
 
 bool Window::IsReallyShown() const
 {
-    return mpWindowImpl->mbReallyShown;
+    return mpWindowImpl ? mpWindowImpl->mbReallyShown : false;
 }
 
 bool Window::IsInInitShow() const
@@ -1247,12 +1247,12 @@ bool Window::IsInInitShow() const
 
 bool Window::IsEnabled() const
 {
-    return !mpWindowImpl->mbDisabled;
+    return mpWindowImpl ? !mpWindowImpl->mbDisabled : false;
 }
 
 bool Window::IsInputEnabled() const
 {
-    return !mpWindowImpl->mbInputDisabled;
+    return mpWindowImpl ? !mpWindowImpl->mbInputDisabled : false;
 }
 
 bool Window::IsAlwaysEnableInput() const
commit 7acf94a7cfca389e73016ec337708498bc12cc3c
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Mar 24 17:52:38 2015 +0000

    vcl: remove curious self referential OutputDevice ptr.
    
    No need to pay a per-instance cost for this, also avoid a self
    reference for every Window sub-class.
    
    Change-Id: I040a0ede9481229e43a39bc23297969e90b95f5e

diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx
index 0ee581a..a9ee87d 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -416,10 +416,6 @@ private:
 
     WindowImpl* mpWindowImpl;
 
-    // This is a first attempt to start to remove the dependency of Window on
-    // OutputDevice
-    VclPtr<::OutputDevice> mpOutputDevice;
-
 #ifdef DBG_UTIL
     friend const char* ::ImplDbgCheckWindow( const void* pObj );
 #endif
@@ -695,8 +691,8 @@ public:
                                         Window( vcl::Window* pParent, const ResId& rResId );
     virtual                             ~Window();
 
-    ::OutputDevice const*               GetOutDev() const { return mpOutputDevice; };
-    ::OutputDevice*                     GetOutDev()       { return mpOutputDevice; };
+    ::OutputDevice const*               GetOutDev() const;
+    ::OutputDevice*                     GetOutDev();
 
     virtual void                        EnableRTL ( bool bEnable = true ) SAL_OVERRIDE;
     virtual void                        MouseMove( const MouseEvent& rMEvt );
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index b04bad1..89679ba 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -581,6 +581,22 @@ Window::~Window()
     disposeOnce();
 }
 
+// We will eventually being removing the inheritance of OutputDevice
+// from Window. It will be replaced with a transient relationship such
+// that the OutputDevice is only live for the scope of the Paint method.
+// In the meantime this can help move us towards a Window use an
+// OutputDevice, not being one.
+
+::OutputDevice const* Window::GetOutDev() const
+{
+    return this;
+}
+
+::OutputDevice* Window::GetOutDev()
+{
+    return this;
+}
+
 } /* namespace vcl */
 
 WindowImpl::WindowImpl( WindowType nType )
@@ -1195,11 +1211,6 @@ void Window::ImplInitAppFontData( vcl::Window* pWindow )
 
 void Window::ImplInitWindowData( WindowType nType )
 {
-    // We will eventually being removing the inheritance of OutputDevice from Window.
-    // It will be replaced with a composition relationship. A Window will use an OutputDevice,
-    // it will not *be* an OutputDevice
-    mpOutputDevice = (OutputDevice*)this;
-
     mnRefCnt = 0;
     mpWindowImpl = new WindowImpl( nType );
 
commit baf676996b8187e5300672b8e381ab7f86ce6fd0
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Mar 24 17:43:20 2015 +0000

    unwind LazyDelete issues - deleting VclPtr types.
    
    Change-Id: Iffdc9f73520a97ccc284ecba1b2468dc229506c1

diff --git a/include/vcl/lazydelete.hxx b/include/vcl/lazydelete.hxx
index 531d640..811829f 100644
--- a/include/vcl/lazydelete.hxx
+++ b/include/vcl/lazydelete.hxx
@@ -21,6 +21,7 @@
 #define INCLUDED_VCL_LAZYDELETE_HXX
 
 #include <vcl/dllapi.h>
+#include <vcl/vclptr.hxx>
 
 #include <unordered_map>
 #include <vector>
@@ -101,8 +102,8 @@ namespace vcl
 
         struct DeleteObjectEntry
         {
-            T*      m_pObject;
-            bool    m_bDeleted;
+            VclPtr<T> m_pObject;
+            bool      m_bDeleted;
 
             DeleteObjectEntry() :
                 m_pObject( NULL ),
@@ -136,7 +137,7 @@ namespace vcl
 
             // do the actual work
             unsigned int nCount = m_aObjects.size();
-            std::vector<T*> aRealDelete;
+            std::vector< VclPtr < T > > aRealDelete;
             aRealDelete.reserve( nCount );
             for( unsigned int i = 0; i < nCount; i++ )
             {
@@ -158,8 +159,8 @@ namespace vcl
                 #endif
                 // check if the object to be deleted is not already destroyed
                 // as a side effect of a previous lazily destroyed object
-                if( ! m_aObjects[ m_aPtrToIndex[ reinterpret_cast<sal_IntPtr>(aRealDelete[n]) ] ].m_bDeleted )
-                    delete aRealDelete[n];
+                if( ! m_aObjects[ m_aPtrToIndex[ reinterpret_cast<sal_IntPtr>(aRealDelete[n].get()) ] ].m_bDeleted )
+                    aRealDelete[n].disposeAndClear();
             }
         }
 
diff --git a/vcl/README.lifecycle b/vcl/README.lifecycle
index 0edd0c8..26e7a34 100644
--- a/vcl/README.lifecycle
+++ b/vcl/README.lifecycle
@@ -137,6 +137,8 @@ or:
 
 ---------- What remains to be done ? ----------
 
+	* Cleanup DogTags and LazyDelete.
+
 	* Expand the VclPtr pattern to many other less
 	  than safe VCL types.
 
commit 554be83e0f30d7c47f84195b1677ee1304fe2a34
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Mar 24 12:01:07 2015 +0000

    correct debugging assertions.
    
    Change-Id: I2437b4d3c532be6cbb31dccfa9e267498111c183

diff --git a/sw/source/core/doc/DocumentDeviceManager.cxx b/sw/source/core/doc/DocumentDeviceManager.cxx
index a8ef613..b8b0438 100644
--- a/sw/source/core/doc/DocumentDeviceManager.cxx
+++ b/sw/source/core/doc/DocumentDeviceManager.cxx
@@ -65,7 +65,7 @@ SfxPrinter* DocumentDeviceManager::getPrinter(/*[in]*/ bool bCreate ) const
 
 void DocumentDeviceManager::setPrinter(/*[in]*/ SfxPrinter *pP,/*[in]*/ bool bDeleteOld,/*[in]*/ bool bCallPrtDataChanged )
 {
-    assert ( !pP->isDisposed() );
+    assert ( !!pP && !pP->isDisposed() );
     if ( pP != mpPrt )
     {
         if ( bDeleteOld )
@@ -101,7 +101,7 @@ VirtualDevice* DocumentDeviceManager::getVirtualDevice(/*[in]*/ bool bCreate ) c
     else
         pRet = &CreateVirtualDevice_();
 
-    assert ( !pRet->isDisposed() );
+    assert ( !pRet || !pRet->isDisposed() );
 
     return pRet;
 }
@@ -138,7 +138,7 @@ OutputDevice* DocumentDeviceManager::getReferenceDevice(/*[in]*/ bool bCreate )
         pRet = getVirtualDevice( bCreate );
     }
 
-    assert ( !pRet->isDisposed() );
+    assert ( !pRet || !pRet->isDisposed() );
 
     return pRet;
 }
commit 9d35e6df6693eba3d23036028fc3f3621e40822a
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Mar 24 12:00:07 2015 +0000

    Nothing really that wrong with acquiring a disposed reference, for now.
    
    Emitting events acquires and passes references conservatively, and the
    VCLEVENT_OBJECT_DYING event hit this hard.
    
    Change-Id: If86991ead63b05425a237bf213583c020ba4e582

diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index 4e2341a..7066df4 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -274,7 +274,6 @@ private:
 
     inline void acquire() const
     {
-        assert(!mbDisposed);
         mnRefCnt++;
     }
 
commit 385bae4bbac02eb3633af5e2085f70ce0391b262
Author: Noel Grandin <noel at peralex.com>
Date:   Mon Mar 23 13:47:50 2015 +0200

    vclwidget: some small fixes
    
    Change-Id: I094163c894ff9accf70050d5a4fab83e905a282b

diff --git a/framework/source/uielement/fontsizemenucontroller.cxx b/framework/source/uielement/fontsizemenucontroller.cxx
index 3e09765..1c0af14 100644
--- a/framework/source/uielement/fontsizemenucontroller.cxx
+++ b/framework/source/uielement/fontsizemenucontroller.cxx
@@ -135,7 +135,7 @@ void FontSizeMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& r
     if ( pVCLPopupMenu )
     {
         boost::scoped_ptr<FontList> pFontList;
-        boost::scoped_ptr<Printer>  pInfoPrinter;
+        ScopedVclPtr<Printer>  pInfoPrinter;
         OUString   aPrinterName;
 
         SolarMutexGuard aSolarMutexGuard;
diff --git a/include/sfx2/printer.hxx b/include/sfx2/printer.hxx
index f07a135..694e2e8 100644
--- a/include/sfx2/printer.hxx
+++ b/include/sfx2/printer.hxx
@@ -51,6 +51,7 @@ public:
                                         const JobSetup &rTheOrigJobSetup );
                             SfxPrinter( const SfxPrinter &rPrinter );
                             virtual ~SfxPrinter();
+    virtual void            dispose() SAL_OVERRIDE;
 
     SfxPrinter*             Clone() const;
 
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index bb7379d..b1a00c8 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -290,7 +290,7 @@ public:
     SAL_DLLPRIVATE void ResetAllClients_Impl( SfxInPlaceClient *pIP );
     SAL_DLLPRIVATE void DiscardClients_Impl();
 
-    SAL_DLLPRIVATE SfxPrinter* SetPrinter_Impl( SfxPrinter *pNewPrinter );
+    SAL_DLLPRIVATE SfxPrinter* SetPrinter_Impl( VclPtr<SfxPrinter>& pNewPrinter );
     SAL_DLLPRIVATE bool IsShowView_Impl() const;
 
     SAL_DLLPRIVATE bool HandleNotifyEvent_Impl( NotifyEvent& rEvent );
diff --git a/sd/source/ui/presenter/PresenterTextView.cxx b/sd/source/ui/presenter/PresenterTextView.cxx
index a9c746f..91c1e2d 100644
--- a/sd/source/ui/presenter/PresenterTextView.cxx
+++ b/sd/source/ui/presenter/PresenterTextView.cxx
@@ -82,7 +82,7 @@ public:
 private:
     Reference<rendering::XBitmap> mxBitmap;
     cppcanvas::CanvasSharedPtr mpCanvas;
-    VirtualDevice* mpOutputDevice;
+    VclPtr<VirtualDevice> mpOutputDevice;
     EditEngine* mpEditEngine;
     SfxItemPool* mpEditEngineItemPool;
     Size maSize;
@@ -261,7 +261,7 @@ PresenterTextView::Implementation::~Implementation (void)
 {
     delete mpEditEngine;
     SfxItemPool::Free(mpEditEngineItemPool);
-    delete mpOutputDevice;
+    mpOutputDevice.disposeAndClear();
 }
 
 EditEngine * PresenterTextView::Implementation::GetEditEngine (void)
@@ -453,8 +453,7 @@ Reference<rendering::XBitmap> PresenterTextView::Implementation::GetBitmap (void
 
     if ( ! mxBitmap.is())
     {
-        if (mpOutputDevice != NULL)
-            delete mpOutputDevice;
+        mpOutputDevice.disposeAndClear();
         mpOutputDevice = new VirtualDevice(*Application::GetDefaultDevice(), 0, 0);
         mpOutputDevice->SetMapMode(MAP_PIXEL);
         mpOutputDevice->SetOutputSizePixel(maSize, true);
diff --git a/sfx2/source/view/printer.cxx b/sfx2/source/view/printer.cxx
index ee08f4d..add92b0 100644
--- a/sfx2/source/view/printer.cxx
+++ b/sfx2/source/view/printer.cxx
@@ -189,8 +189,14 @@ SfxPrinter* SfxPrinter::Clone() const
 
 SfxPrinter::~SfxPrinter()
 {
+    disposeOnce();
+}
+
+void SfxPrinter::dispose()
+{
     delete pOptions;
     delete pImpl;
+    Printer::dispose();
 }
 
 
diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx
index 909c3d8..8877eb1 100644
--- a/sfx2/source/view/viewprn.cxx
+++ b/sfx2/source/view/viewprn.cxx
@@ -469,7 +469,7 @@ IMPL_LINK_NOARG(SfxDialogExecutor_Impl, Execute)
    Internal method for setting the differences between 'pNewPrinter' to the
    current printer. pNewPrinter is either taken over or deleted.
 */
-SfxPrinter* SfxViewShell::SetPrinter_Impl( SfxPrinter *pNewPrinter )
+SfxPrinter* SfxViewShell::SetPrinter_Impl( VclPtr<SfxPrinter>& pNewPrinter )
 {
     // get current Printer
     SfxPrinter *pDocPrinter = GetPrinter();
@@ -558,7 +558,7 @@ SfxPrinter* SfxViewShell::SetPrinter_Impl( SfxPrinter *pNewPrinter )
 
         // Keep old changed Printer.
         pDocPrinter->SetPrinterProps( pNewPrinter );
-        delete pNewPrinter;
+        pNewPrinter.disposeAndClear();
     }
 
     if ( SfxPrinterChangeFlags::NONE != nChangedFlags )
diff --git a/sw/source/ui/dialog/ascfldlg.cxx b/sw/source/ui/dialog/ascfldlg.cxx
index d1b6472..fa41047 100644
--- a/sw/source/ui/dialog/ascfldlg.cxx
+++ b/sw/source/ui/dialog/ascfldlg.cxx
@@ -174,7 +174,7 @@ SwAsciiFilterDlg::SwAsciiFilterDlg( vcl::Window* pParent, SwDocShell& rDocSh,
 
         {
             bool bDelPrinter = false;
-            SfxPrinter* pPrt = pDoc ? pDoc->getIDocumentDeviceAccess().getPrinter(false) : 0;
+            VclPtr<SfxPrinter> pPrt = pDoc ? pDoc->getIDocumentDeviceAccess().getPrinter(false) : 0;
             if( !pPrt )
             {
                 SfxItemSet* pSet = new SfxItemSet( rDocSh.GetPool(),
@@ -211,7 +211,7 @@ SwAsciiFilterDlg::SwAsciiFilterDlg( vcl::Window* pParent, SwDocShell& rDocSh,
             m_pFontLB->SelectEntry( aOpt.GetFontName() );
 
             if( bDelPrinter )
-                delete pPrt;
+                pPrt.disposeAndClear();
         }
 
     }
commit a6e5ac3be1398aa63fab1d751d6238daeb3a2b2f
Author: Noel Grandin <noel at peralex.com>
Date:   Mon Mar 23 10:25:26 2015 +0200

    vclwidget: add some safety net asserts
    
    Change-Id: I5fa19ec6161ab97eb7df8b52a268917f41ae2205

diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index f5875b7..4e2341a 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -274,11 +274,13 @@ private:
 
     inline void acquire() const
     {
+        assert(!mbDisposed);
         mnRefCnt++;
     }
 
     inline void release() const
     {
+        assert(mnRefCnt>0);
         if (!--mnRefCnt)
             delete const_cast<OutputDevice*>(this);
     }
diff --git a/include/vcl/vclptr.hxx b/include/vcl/vclptr.hxx
index 3e0de76..6ab6373 100644
--- a/include/vcl/vclptr.hxx
+++ b/include/vcl/vclptr.hxx
@@ -270,6 +270,7 @@ public:
     ~ScopedVclPtr()
     {
         VclPtr<reference_type>::disposeAndClear();
+        assert(VclPtr<reference_type>::get() == nullptr); // make sure there are no lingering references
     }
 private:
     // Most likely we don't want this default copy-construtor.
commit 489a4fb3a00cf7e6c32ecfe7e50538d6c8eb075b
Author: Noel Grandin <noel at peralex.com>
Date:   Mon Mar 23 10:24:57 2015 +0200

    calling delete on VclPtr
    
    Change-Id: I25346435d2129086281783636624b1bb430d0096

diff --git a/canvas/source/vcl/bitmapbackbuffer.cxx b/canvas/source/vcl/bitmapbackbuffer.cxx
index d140ea0..1bbf73c 100644
--- a/canvas/source/vcl/bitmapbackbuffer.cxx
+++ b/canvas/source/vcl/bitmapbackbuffer.cxx
@@ -45,8 +45,7 @@ namespace vclcanvas
         // are supposed to be called with already locked solar mutex)
         SolarMutexGuard aGuard;
 
-        if( mpVDev )
-            delete mpVDev;
+        mpVDev.disposeAndClear();
     }
 
     OutputDevice& BitmapBackBuffer::getOutDev()
commit 0e491a7a2affbb08071e6378dacc1995cb301655
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Mon Mar 23 09:14:13 2015 +0000

    vclptr: add isDisposed method - and assert for it here & there.
    
    Change-Id: I2b154e0ed9eee0a45900ada7f805a1d444a31bc0

diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index b9d542f..f5875b7 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -390,6 +390,7 @@ protected:
 public:
     /// call the dispose() method if we have not already been disposed.
     void                                disposeOnce();
+    bool                                isDisposed() const { return mbDisposed; }
 
 public:
 
diff --git a/sw/source/core/doc/DocumentDeviceManager.cxx b/sw/source/core/doc/DocumentDeviceManager.cxx
index 5d38a93..a8ef613 100644
--- a/sw/source/core/doc/DocumentDeviceManager.cxx
+++ b/sw/source/core/doc/DocumentDeviceManager.cxx
@@ -65,6 +65,7 @@ SfxPrinter* DocumentDeviceManager::getPrinter(/*[in]*/ bool bCreate ) const
 
 void DocumentDeviceManager::setPrinter(/*[in]*/ SfxPrinter *pP,/*[in]*/ bool bDeleteOld,/*[in]*/ bool bCallPrtDataChanged )
 {
+    assert ( !pP->isDisposed() );
     if ( pP != mpPrt )
     {
         if ( bDeleteOld )
@@ -100,11 +101,15 @@ VirtualDevice* DocumentDeviceManager::getVirtualDevice(/*[in]*/ bool bCreate ) c
     else
         pRet = &CreateVirtualDevice_();
 
+    assert ( !pRet->isDisposed() );
+
     return pRet;
 }
 
 void DocumentDeviceManager::setVirtualDevice(/*[in]*/ VirtualDevice* pVd,/*[in]*/ bool bDeleteOld, /*[in]*/ bool )
 {
+    assert ( !pVd->isDisposed() );
+
     if ( mpVirDev.get() != pVd )
     {
         if ( bDeleteOld )
@@ -133,6 +138,8 @@ OutputDevice* DocumentDeviceManager::getReferenceDevice(/*[in]*/ bool bCreate )
         pRet = getVirtualDevice( bCreate );
     }
 
+    assert ( !pRet->isDisposed() );
+
     return pRet;
 }
 
diff --git a/sw/source/uibase/uno/SwXDocumentSettings.cxx b/sw/source/uibase/uno/SwXDocumentSettings.cxx
index 6b94722..9ae2d42 100644
--- a/sw/source/uibase/uno/SwXDocumentSettings.cxx
+++ b/sw/source/uibase/uno/SwXDocumentSettings.cxx
@@ -389,6 +389,7 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf
                     if ( OUString ( pPrinter->GetName()) != sPrinterName )
                     {
                         VclPtr<SfxPrinter> pNewPrinter = new SfxPrinter ( pPrinter->GetOptions().Clone(), sPrinterName );
+                        assert (! pNewPrinter->isDisposed() );
                         if( pNewPrinter->IsKnown() )
                         {
                             // set printer only once; in _postSetValues
@@ -426,7 +427,7 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf
                     };
                     SfxItemSet *pItemSet = new SfxItemSet( mpDoc->GetAttrPool(), nRange );
                     VclPtr<SfxPrinter> pPrinter = SfxPrinter::Create ( aStream, pItemSet );
-
+                    assert (! pPrinter->isDisposed() );
                     // set printer only once; in _postSetValues
                     mpPrinter.disposeAndClear();
                     mpPrinter = pPrinter;
diff --git a/vcl/README.lifecycle b/vcl/README.lifecycle
index 1ee7eab..0edd0c8 100644
--- a/vcl/README.lifecycle
+++ b/vcl/README.lifecycle
@@ -144,11 +144,13 @@ or:
 	  their constructors.
 
 	* Pass 'const VclPtr<> &' instead of pointers everywhere
+		+ add 'explicit' keywords to VclPtr constructors to
+		  accelerate compilation etc.
 
 	* Cleanup common existing methods such that they continue to
 	  work post-dispose.
 
-	* Dispose functions shoudl be audited to:
+	* Dispose functions should be audited to:
 		+ not leave dangling pointsr
 		+ shrink them - some work should incrementally
 		  migrate back to destructors.
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index 1bf2df8..27810d4 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -91,7 +91,12 @@ vcl::FontInfo OutputDevice::GetDevFont( int nDevFontIndex ) const
 int OutputDevice::GetDevFontCount() const
 {
     if( !mpGetDevFontList )
+    {
+        if (!mpFontCollection)
+            return 0;
+
         mpGetDevFontList = mpFontCollection->GetDevFontList();
+    }
     return mpGetDevFontList->Count();
 }
 
commit c612c3b0aed9ad7f7f42b4313f821b71995ead15
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Fri Mar 20 23:08:41 2015 +0000

    protect more printer code-paths.
    
    Change-Id: Ic5bc5c3325b460cba0d95484454c9bb826684890

diff --git a/basctl/source/basicide/basdoc.cxx b/basctl/source/basicide/basdoc.cxx
index ee96c23..41b6dd7 100644
--- a/basctl/source/basicide/basdoc.cxx
+++ b/basctl/source/basicide/basdoc.cxx
@@ -51,7 +51,9 @@ DocShell::DocShell()
 }
 
 DocShell::~DocShell()
-{ }
+{
+    pPrinter.disposeAndClear();
+}
 
 SfxPrinter* DocShell::GetPrinter( bool bCreate )
 {
diff --git a/sfx2/source/view/viewprn.cxx b/sfx2/source/view/viewprn.cxx
index 739ce7d..909c3d8 100644
--- a/sfx2/source/view/viewprn.cxx
+++ b/sfx2/source/view/viewprn.cxx
@@ -637,7 +637,7 @@ Printer* SfxViewShell::GetActivePrinter() const
 void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
 {
     sal_uInt16              nDialogRet = RET_CANCEL;
-    SfxPrinter*             pPrinter = 0;
+    VclPtr<SfxPrinter>      pPrinter;
     bool                    bSilent = false;
 
     // does the function have been called by the user interface or by an API call
@@ -774,7 +774,7 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
 
                 // if printer is unknown, it can't be used - now printer from document will be used
                 if ( !pPrinter->IsKnown() )
-                    DELETEZ(pPrinter);
+                    pPrinter.disposeAndClear();
             }
 
             if ( SID_PRINTER_NAME == nId )
@@ -816,7 +816,7 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
             if ( !bIsAPI )
             {
                 // PrinterDialog needs a temporary printer
-                SfxPrinter* pDlgPrinter = pPrinter->Clone();
+                VclPtr<SfxPrinter> pDlgPrinter = pPrinter->Clone();
                 nDialogRet = 0;
 
                 // execute PrinterSetupDialog
@@ -868,13 +868,12 @@ void SfxViewShell::ExecPrint_Impl( SfxRequest &rReq )
 
                     // forget new printer, it was taken over (as pPrinter) or deleted
                     pDlgPrinter = NULL;
-
                 }
                 else
                 {
                     // PrinterDialog is used to transfer information on printing,
                     // so it will only be deleted here if dialog was cancelled
-                    DELETEZ( pDlgPrinter );
+                    pDlgPrinter.disposeAndClear();
                     rReq.Ignore();
                 }
             }
diff --git a/starmath/source/unomodel.cxx b/starmath/source/unomodel.cxx
index 7956ce2..f9752e8 100644
--- a/starmath/source/unomodel.cxx
+++ b/starmath/source/unomodel.cxx
@@ -642,7 +642,7 @@ void SmModel::_setPropertyValues(const PropertyMapEntry** ppEntries, const Any*
                     SfxItemSet *pItemSet = new SfxItemSet( pDocSh->GetPool(), nRange );
                     SmModule *pp = SM_MOD();
                     pp->GetConfig()->ConfigToItemSet(*pItemSet);
-                    SfxPrinter *pPrinter = SfxPrinter::Create ( aStream, pItemSet );
+                    VclPtr<SfxPrinter> pPrinter = SfxPrinter::Create ( aStream, pItemSet );
 
                     pDocSh->SetPrinter( pPrinter );
                 }
diff --git a/svtools/source/dialogs/prnsetup.cxx b/svtools/source/dialogs/prnsetup.cxx
index d6f35ef..a841a59 100644
--- a/svtools/source/dialogs/prnsetup.cxx
+++ b/svtools/source/dialogs/prnsetup.cxx
@@ -53,8 +53,9 @@ void ImplFreePrnDlgListBox( ListBox* pBox, bool bClear )
 
 
 Printer* ImplPrnDlgListBoxSelect( ListBox* pBox, PushButton* pPropBtn,
-                                  Printer* pPrinter, Printer* pTempPrinter )
+                                  Printer* pPrinter, Printer* pTempPrinterIn )
 {
+    VclPtr<Printer> pTempPrinter( pTempPrinterIn );
     if ( pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND )
     {
         const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), true );
@@ -73,7 +74,7 @@ Printer* ImplPrnDlgListBoxSelect( ListBox* pBox, PushButton* pPropBtn,
                 if ( (pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
                      (pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
                 {
-                    VclPtr<Printer>(pTempPrinter).disposeAndClear();
+                    pTempPrinter.disposeAndClear();
                     pTempPrinter = new Printer( *pInfo );
                 }
             }
@@ -91,8 +92,9 @@ Printer* ImplPrnDlgListBoxSelect( ListBox* pBox, PushButton* pPropBtn,
 
 
 
-Printer* ImplPrnDlgUpdatePrinter( Printer* pPrinter, Printer* pTempPrinter )
+Printer* ImplPrnDlgUpdatePrinter( Printer* pPrinter, Printer* pTempPrinterIn )
 {
+    VclPtr<Printer> pTempPrinter( pTempPrinterIn );
     OUString aPrnName;
     if ( pTempPrinter )
         aPrnName = pTempPrinter->GetName();
@@ -101,7 +103,7 @@ Printer* ImplPrnDlgUpdatePrinter( Printer* pPrinter, Printer* pTempPrinter )
 
     if ( ! Printer::GetQueueInfo( aPrnName, false ) )
     {
-        VclPtr<Printer>(pTempPrinter).disposeAndClear();
+        pTempPrinter.disposeAndClear();
         pTempPrinter = new Printer;
     }
 
diff --git a/sw/source/uibase/uno/SwXDocumentSettings.cxx b/sw/source/uibase/uno/SwXDocumentSettings.cxx
index ce19d65..6b94722 100644
--- a/sw/source/uibase/uno/SwXDocumentSettings.cxx
+++ b/sw/source/uibase/uno/SwXDocumentSettings.cxx
@@ -425,7 +425,7 @@ void SwXDocumentSettings::_setSingleValue( const comphelper::PropertyInfo & rInf
                         0
                     };
                     SfxItemSet *pItemSet = new SfxItemSet( mpDoc->GetAttrPool(), nRange );
-                    SfxPrinter *pPrinter = SfxPrinter::Create ( aStream, pItemSet );
+                    VclPtr<SfxPrinter> pPrinter = SfxPrinter::Create ( aStream, pItemSet );
 
                     // set printer only once; in _postSetValues
                     mpPrinter.disposeAndClear();
diff --git a/vcl/source/outdev/map.cxx b/vcl/source/outdev/map.cxx
index a1aa6c1..753e297 100644
--- a/vcl/source/outdev/map.cxx
+++ b/vcl/source/outdev/map.cxx
@@ -343,6 +343,9 @@ inline void ImplCalcMapResolution( const MapMode& rMapMode,
 // #i75163#
 void OutputDevice::ImplInvalidateViewTransform()
 {
+    if(!mpOutDevData)
+        return;
+
     if(mpOutDevData->mpViewTransform)
     {
         delete mpOutDevData->mpViewTransform;


More information about the Libreoffice-commits mailing list