[Libreoffice-commits] core.git: 5 commits - sfx2/source sw/CppunitTest_sw_odfexport.mk sw/qa sw/source

Michael Stahl mstahl at redhat.com
Fri Feb 12 17:58:03 UTC 2016


 sfx2/source/doc/objstor.cxx                  |    8 ++
 sw/CppunitTest_sw_odfexport.mk               |    1 
 sw/qa/extras/htmlexport/htmlexport.cxx       |   18 ++---
 sw/qa/extras/inc/swmodeltestbase.hxx         |   34 +++++++++--
 sw/qa/extras/odfexport/data/2_MathType3.docx |binary
 sw/qa/extras/odfexport/odfexport.cxx         |   46 ++++++++++++---
 sw/qa/extras/ooxmlimport/ooxmlimport.cxx     |   15 ++--
 sw/qa/extras/rtfimport/rtfimport.cxx         |   19 +++---
 sw/source/core/ole/ndole.cxx                 |   82 +++++++++++++--------------
 9 files changed, 147 insertions(+), 76 deletions(-)

New commits:
commit f705570c8180d855130096604dd2eff61a6e9585
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Feb 12 18:35:53 2016 +0100

    sw,sfx2: assert that embedded object supports XEmbedPersist
    
    Change-Id: Ibdeec746e9664f8bfe4e2af9afb8e5ec0142bd08

diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index c1c6455..07a3c6d 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -2278,14 +2278,9 @@ bool SfxObjectShell::ImportFrom(SfxMedium& rMedium,
                     if (xModifiable.is() && xModifiable->isModified())
                     {
                         uno::Reference<embed::XEmbedPersist> const xPers(xObj, uno::UNO_QUERY);
-                        if (xPers.is())
-                        {   // store it before resetting modified!
-                            xPers->storeOwn();
-                        }
-                        else
-                        {
-                            SAL_WARN("sfx.doc", "Modified object without persistence!");
-                        }
+                        assert(xPers.is() && "Modified object without persistence!");
+                        // store it before resetting modified!
+                        xPers->storeOwn();
                         xModifiable->setModified(sal_False);
                     }
                 }
diff --git a/sw/source/core/ole/ndole.cxx b/sw/source/core/ole/ndole.cxx
index f3f53c1..2f3b75a 100644
--- a/sw/source/core/ole/ndole.cxx
+++ b/sw/source/core/ole/ndole.cxx
@@ -864,11 +864,8 @@ bool SwOLEObj::UnloadObject( uno::Reference< embed::XEmbeddedObject > xObj, cons
                     if( xMod.is() && xMod->isModified() )
                     {
                         uno::Reference < embed::XEmbedPersist > xPers( xObj, uno::UNO_QUERY );
-                        if ( xPers.is() )
-                            xPers->storeOwn();
-                        else {
-                            OSL_FAIL("Modified object without persistence in cache!");
-                        }
+                        assert(xPers.is() && "Modified object without persistence in cache!");
+                        xPers->storeOwn();
                     }
 
                     // setting object to loaded state will remove it from cache
commit d81d104833f0ee9349ebcd0d79d2de84ba9a7262
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Feb 12 18:22:51 2016 +0100

    sfx2: related tdf#56270: loss of embedded objects imported from DOCX
    
    After the import some of these are kept in RUNNING state.  For Math
    objects imported from MathType3 OLEs in particular, first a new
    Math object is created and stored to the XStorage, only then is the
    MathType3 stream imported.  This means the Math object is modified and
    contains data that must be stored.
    
    The problem is then that SfxObjectShell::ImportFrom() simply calls
    setModified(false), clearing the flag without storing the object.
    
    For Flat ODF export we lose all the objects that are cached in sw's
    SwOLELRUCache; for the bugdoc something more inexplicable happens for
    ODT export where we lose "Object 214" (which is the first one in the
    cache) but no other ones.
    
    (The main difference is that for ODF there is an optimization to copy the
    embedded object's storage without loading the object, but for Flat ODF
    every object must be loaded and exported.)
    
    (regression from 83777cd6e0f3f1a4458af896fd13344c696ecb1e)
    
    Change-Id: Id1474fba9f4da2d5247c7ff4dc6819ddb9829fe8

diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index c6fc52a..c1c6455 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -2275,8 +2275,19 @@ bool SfxObjectShell::ImportFrom(SfxMedium& rMedium,
                 if ( nState == embed::EmbedStates::LOADED || nState == embed::EmbedStates::RUNNING )    // means that the object is not active
                 {
                     uno::Reference< util::XModifiable > xModifiable( xObj->getComponent(), uno::UNO_QUERY );
-                    if ( xModifiable.is() )
+                    if (xModifiable.is() && xModifiable->isModified())
+                    {
+                        uno::Reference<embed::XEmbedPersist> const xPers(xObj, uno::UNO_QUERY);
+                        if (xPers.is())
+                        {   // store it before resetting modified!
+                            xPers->storeOwn();
+                        }
+                        else
+                        {
+                            SAL_WARN("sfx.doc", "Modified object without persistence!");
+                        }
                         xModifiable->setModified(sal_False);
+                    }
                 }
             }
         }
diff --git a/sw/CppunitTest_sw_odfexport.mk b/sw/CppunitTest_sw_odfexport.mk
index c6434ac..3757e01 100644
--- a/sw/CppunitTest_sw_odfexport.mk
+++ b/sw/CppunitTest_sw_odfexport.mk
@@ -87,6 +87,7 @@ $(eval $(call gb_CppunitTest_use_components,sw_odfexport,\
     sd/util/sd \
     svx/util/svxcore \
     xmloff/source/transform/xof \
+    xmlscript/util/xmlscript \
 ))
 
 $(eval $(call gb_CppunitTest_use_custom_headers,sw_odfexport,\
diff --git a/sw/qa/extras/odfexport/data/2_MathType3.docx b/sw/qa/extras/odfexport/data/2_MathType3.docx
new file mode 100644
index 0000000..0694921
Binary files /dev/null and b/sw/qa/extras/odfexport/data/2_MathType3.docx differ
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index 4b713cd..3d805ba 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -73,10 +73,40 @@ public:
             pBatch->commit();
             return pResetter;
         }
+        if (OString(pFilename) == "2_MathType3.docx")
+        {
+            std::unique_ptr<Resetter> pResetter(new Resetter(
+                [this] () {
+                    mpFilter = "writer8";
+                    std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
+                            comphelper::ConfigurationChanges::create());
+                    officecfg::Office::Common::Cache::Writer::OLE_Objects::set(20, pBatch);
+                    return pBatch->commit();
+                }));
+            mpFilter = "OpenDocument Text Flat XML"; // doesn't happen with ODF package
+            std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
+                    comphelper::ConfigurationChanges::create());
+            officecfg::Office::Common::Cache::Writer::OLE_Objects::set(1, pBatch);
+            pBatch->commit();
+            return pResetter;
+        }
         return nullptr;
     }
 };
 
+DECLARE_ODFEXPORT_TEST(testMathObjectFlatExport, "2_MathType3.docx")
+{
+    uno::Reference<util::XModifiable> xModifiable(mxComponent, uno::UNO_QUERY);
+    CPPUNIT_ASSERT(!xModifiable->isModified());
+    // see preTest(), set the OLE cache to 1 for this test
+    // and the problem was that the formulas that were in the cache
+    // (the second one) were lost
+    OUString formula1(getFormula(getRun(getParagraph(1), 1)));
+    CPPUNIT_ASSERT_EQUAL(OUString(" size 12{1+1=2} {}"), formula1);
+    OUString formula2(getFormula(getRun(getParagraph(2), 1)));
+    CPPUNIT_ASSERT_EQUAL(OUString(" size 12{2+2=4} {}"), formula2);
+}
+
 DECLARE_ODFEXPORT_TEST(testFramebackgrounds, "framebackgrounds.odt")
 {
    //Counting the Number of Frames and checking with the expected count
commit e2bfae9006e6adc4de17d0167dac6661b002f126
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Feb 12 15:47:05 2016 +0100

    sw: ensure that configuration change in odfexporttest.cxx ...
    
    ... is reverted in case the test function throws an exception, so that
    subsequent^Wfollowing tests don't inherit the changed configuration.
    
    Change-Id: I748f9edf15a7f860607ae4cce891450db254c73e

diff --git a/sw/qa/extras/htmlexport/htmlexport.cxx b/sw/qa/extras/htmlexport/htmlexport.cxx
index 64bc4cf..f951a0a 100644
--- a/sw/qa/extras/htmlexport/htmlexport.cxx
+++ b/sw/qa/extras/htmlexport/htmlexport.cxx
@@ -41,7 +41,7 @@ private:
         return OString(filename) != "fdo62336.docx";
     }
 
-    void preTest(const char* filename) override
+    virtual std::unique_ptr<Resetter> preTest(const char* filename) override
     {
         if (getTestName().indexOf("SkipImage") != -1)
             setFilterOptions("SkipImages");
@@ -50,22 +50,22 @@ private:
 
         if (OString(filename) == "charborder.odt")
         {
+
             // FIXME if padding-top gets exported as inches, not cms, we get rounding errors.
             SwGlobals::ensure(); // make sure that SW_MOD() is not 0
+            std::unique_ptr<Resetter> pResetter(new Resetter(
+                [this] () {
+                    SwMasterUsrPref* pPref = const_cast<SwMasterUsrPref*>(SW_MOD()->GetUsrPref(false));
+                    pPref->SetMetric(this->m_eUnit);
+                }));
             SwMasterUsrPref* pPref = const_cast<SwMasterUsrPref*>(SW_MOD()->GetUsrPref(false));
             m_eUnit = pPref->GetMetric();
             pPref->SetMetric(FUNIT_CM);
+            return pResetter;
         }
+        return nullptr;
     }
 
-    void postTest(const char* filename) override
-    {
-        if (OString(filename) == "charborder.odt")
-        {
-            SwMasterUsrPref* pPref = const_cast<SwMasterUsrPref*>(SW_MOD()->GetUsrPref(false));
-            pPref->SetMetric(m_eUnit);
-        }
-    }
 };
 
 #define DECLARE_HTMLEXPORT_ROUNDTRIP_TEST(TestName, filename) DECLARE_SW_ROUNDTRIP_TEST(TestName, filename, HtmlExportTest)
diff --git a/sw/qa/extras/inc/swmodeltestbase.hxx b/sw/qa/extras/inc/swmodeltestbase.hxx
index b154efe..95eee35 100644
--- a/sw/qa/extras/inc/swmodeltestbase.hxx
+++ b/sw/qa/extras/inc/swmodeltestbase.hxx
@@ -149,6 +149,31 @@ protected:
     bool mbExported; ///< Does maTempFile already contain something useful?
 
 protected:
+
+    class Resetter
+    {
+    private:
+        std::function<void ()> m_Func;
+
+    public:
+        Resetter(std::function<void ()> const& rFunc)
+            : m_Func(rFunc)
+        {
+        }
+        ~Resetter()
+        {
+            try
+            {
+                m_Func();
+            }
+            catch (...) // has to be reliable
+            {
+                fprintf(stderr, "resetter failed with exception\n");
+                abort();
+            }
+        }
+    };
+
     virtual OUString getTestName() { return OUString(); }
 
 public:
@@ -197,7 +222,7 @@ protected:
         {
             maTempFile.EnableKillingFile(false);
             header();
-            preTest(filename);
+            std::unique_ptr<Resetter> const pChanges(preTest(filename));
             load(mpTestDocumentPath, filename);
             postTest(filename);
             verify();
@@ -215,7 +240,7 @@ protected:
     {
         maTempFile.EnableKillingFile(false);
         header();
-        preTest(filename);
+        std::unique_ptr<Resetter> const pChanges(preTest(filename));
         load(mpTestDocumentPath, filename);
         postLoad(filename);
         reload(mpFilter, filename);
@@ -235,7 +260,7 @@ protected:
     {
         maTempFile.EnableKillingFile(false);
         header();
-        preTest(filename);
+        std::unique_ptr<Resetter> const pChanges(preTest(filename));
         load(mpTestDocumentPath, filename);
         save(OUString::createFromAscii(mpFilter), maTempFile);
         maTempFile.EnableKillingFile(false);
@@ -263,8 +288,9 @@ protected:
     /**
      * Override this function if some special filename-specific setup is needed
      */
-    virtual void preTest(const char* /*filename*/)
+    virtual std::unique_ptr<Resetter> preTest(const char* /*filename*/)
     {
+        return nullptr;
     }
 
     /// Override this function if some special file-specific setup is needed during export test: after load, but before save.
diff --git a/sw/qa/extras/odfexport/odfexport.cxx b/sw/qa/extras/odfexport/odfexport.cxx
index a5b1847..4b713cd 100644
--- a/sw/qa/extras/odfexport/odfexport.cxx
+++ b/sw/qa/extras/odfexport/odfexport.cxx
@@ -56,24 +56,24 @@ public:
         return std::find(aBlacklist.begin(), aBlacklist.end(), filename) == aBlacklist.end();
     }
 
-    virtual void preTest(const char* pFilename) override
+    virtual std::unique_ptr<Resetter> preTest(const char* pFilename) override
     {
         if (OString(pFilename) == "fdo58949.docx")
         {
-            std::shared_ptr<comphelper::ConfigurationChanges> pBatch(comphelper::ConfigurationChanges::create());
-            officecfg::Office::Common::Filter::Microsoft::Import::MathTypeToMath::set(false, pBatch);
-            pBatch->commit();
-        }
-    }
+            std::unique_ptr<Resetter> pResetter(new Resetter(
+                [] () {
+                    std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
+                            comphelper::ConfigurationChanges::create());
+                    officecfg::Office::Common::Filter::Microsoft::Import::MathTypeToMath::set(true, pBatch);
+                    return pBatch->commit();
+                }));
 
-    virtual void postTest(const char* pFilename) override
-    {
-        if (OString(pFilename) == "fdo58949.docx")
-        {
             std::shared_ptr<comphelper::ConfigurationChanges> pBatch(comphelper::ConfigurationChanges::create());
-            officecfg::Office::Common::Filter::Microsoft::Import::MathTypeToMath::set(true, pBatch);
+            officecfg::Office::Common::Filter::Microsoft::Import::MathTypeToMath::set(false, pBatch);
             pBatch->commit();
+            return pResetter;
         }
+        return nullptr;
     }
 };
 
diff --git a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
index f210370..df0f695 100644
--- a/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
+++ b/sw/qa/extras/ooxmlimport/ooxmlimport.cxx
@@ -91,17 +91,20 @@ public:
     {
     }
 
-    virtual void preTest(const char* filename) override
+    virtual std::unique_ptr<Resetter> preTest(const char* filename) override
     {
         if (OString(filename) == "smartart.docx" || OString(filename) == "strict-smartart.docx" || OString(filename) == "fdo87488.docx")
+        {
+            std::unique_ptr<Resetter> pResetter(new Resetter(
+                [] () {
+                    SvtFilterOptions::Get().SetSmartArt2Shape(false);
+                }));
             SvtFilterOptions::Get().SetSmartArt2Shape(true);
+            return pResetter;
+        }
+        return nullptr;
     }
 
-    virtual void postTest(const char* filename) override
-    {
-        if (OString(filename) == "smartart.docx" || OString(filename) == "strict-smartart.docx" || OString(filename) == "fdo87488.docx")
-            SvtFilterOptions::Get().SetSmartArt2Shape(false);
-    }
 protected:
     /// Copy&paste helper.
     bool paste(const OUString& rFilename, const uno::Reference<text::XTextRange>& xTextRange)
diff --git a/sw/qa/extras/rtfimport/rtfimport.cxx b/sw/qa/extras/rtfimport/rtfimport.cxx
index b5216c9..a5264d3 100644
--- a/sw/qa/extras/rtfimport/rtfimport.cxx
+++ b/sw/qa/extras/rtfimport/rtfimport.cxx
@@ -66,27 +66,32 @@ public:
     {
     }
 
-    virtual void preTest(const char* filename) override
+    virtual std::unique_ptr<Resetter> preTest(const char* filename) override
     {
         m_aSavedSettings = Application::GetSettings();
         if (OString(filename) == "fdo48023.rtf" || OString(filename) == "fdo72031.rtf")
         {
+            std::unique_ptr<Resetter> pResetter(new Resetter(
+                [this] () {
+                    Application::SetSettings(this->m_aSavedSettings);
+                }));
             AllSettings aSettings(m_aSavedSettings);
             aSettings.SetLanguageTag(LanguageTag("ru"));
             Application::SetSettings(aSettings);
+            return pResetter;
         }
         else if (OString(filename) == "fdo44211.rtf")
         {
+            std::unique_ptr<Resetter> pResetter(new Resetter(
+                [this] () {
+                    Application::SetSettings(this->m_aSavedSettings);
+                }));
             AllSettings aSettings(m_aSavedSettings);
             aSettings.SetLanguageTag(LanguageTag("lt"));
             Application::SetSettings(aSettings);
+            return pResetter;
         }
-    }
-
-    virtual void postTest(const char* filename) override
-    {
-        if (OString(filename) == "fdo48023.rtf" || OString(filename) == "fdo72031.rtf" || OString(filename) == "fdo44211.rtf")
-            Application::SetSettings(m_aSavedSettings);
+        return nullptr;
     }
 
 protected:
commit 2edfb8d9b4da733a2d825cd5fc791fea5352dffe
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Feb 12 13:47:42 2016 +0100

    sw: unindent SwOLELRUCache::Load()
    
    Change-Id: If1a83fd4716b7a8ebfb09a7118e760fcca3a61b4

diff --git a/sw/source/core/ole/ndole.cxx b/sw/source/core/ole/ndole.cxx
index 5573942..f3f53c1 100644
--- a/sw/source/core/ole/ndole.cxx
+++ b/sw/source/core/ole/ndole.cxx
@@ -932,33 +932,31 @@ void SwOLELRUCache::Load()
     Sequence< Any > aValues = GetProperties( aNames );
     const Any* pValues = aValues.getConstArray();
     OSL_ENSURE( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
-    if( aValues.getLength() == aNames.getLength() && pValues->hasValue() )
+    if (aValues.getLength() != aNames.getLength() || !pValues->hasValue())
+        return;
+
+    sal_Int32 nVal = 0;
+    *pValues >>= nVal;
+
+    if (nVal < m_nLRU_InitSize)
     {
-        sal_Int32 nVal = 0;
-        *pValues >>= nVal;
+        std::shared_ptr<SwOLELRUCache> tmp(g_pOLELRU_Cache); // prevent delete this
+        // size of cache has been changed
+        sal_Int32 nCount = m_OleObjects.size();
+        sal_Int32 nPos = nCount;
 
+        // try to remove the last entries until new maximum size is reached
+        while( nCount > nVal )
         {
-            if (nVal < m_nLRU_InitSize)
-            {
-                std::shared_ptr<SwOLELRUCache> tmp(g_pOLELRU_Cache); // prevent delete this
-                // size of cache has been changed
-                sal_Int32 nCount = m_OleObjects.size();
-                sal_Int32 nPos = nCount;
-
-                // try to remove the last entries until new maximum size is reached
-                while( nCount > nVal )
-                {
-                    SwOLEObj *const pObj = m_OleObjects[ --nPos ];
-                    if ( pObj->UnloadObject() )
-                        nCount--;
-                    if ( !nPos )
-                        break;
-                }
-            }
+            SwOLEObj *const pObj = m_OleObjects[ --nPos ];
+            if ( pObj->UnloadObject() )
+                nCount--;
+            if ( !nPos )
+                break;
         }
-
-        m_nLRU_InitSize = nVal;
     }
+
+    m_nLRU_InitSize = nVal;
 }
 
 void SwOLELRUCache::InsertObj( SwOLEObj& rObj )
commit 60d4dd0a6c44b45ed424ca6a0ddcf857ec089b24
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Feb 12 13:40:46 2016 +0100

    sw: don't crash if Office.Common/Cache/Writer/OLE_Objects set to 1
    
    (possibly regression from b717bda1f6484905aebc571c4538165a1fbfd2bb)
    
    Change-Id: I9113fe2e769cd6ba56bdccc629ac63241b238553

diff --git a/sw/source/core/ole/ndole.cxx b/sw/source/core/ole/ndole.cxx
index 99b3f77..5573942 100644
--- a/sw/source/core/ole/ndole.cxx
+++ b/sw/source/core/ole/ndole.cxx
@@ -85,7 +85,7 @@ public:
     void RemoveObj( SwOLEObj& rObj );
 };
 
-SwOLELRUCache* pOLELRU_Cache = nullptr;
+std::shared_ptr<SwOLELRUCache> g_pOLELRU_Cache;
 
 class SwOLEListener_Impl : public ::cppu::WeakImplHelper< embed::XStateChangeListener >
 {
@@ -103,7 +103,7 @@ SwOLEListener_Impl::SwOLEListener_Impl( SwOLEObj* pObj )
 {
     if ( mpObj->IsOleRef() && mpObj->GetOleRef()->getCurrentState() == embed::EmbedStates::RUNNING )
     {
-        pOLELRU_Cache->InsertObj( *mpObj );
+        g_pOLELRU_Cache->InsertObj( *mpObj );
     }
 }
 
@@ -115,29 +115,29 @@ void SAL_CALL SwOLEListener_Impl::stateChanged( const lang::EventObject&, ::sal_
 {
     if ( mpObj && nOldState == embed::EmbedStates::LOADED && nNewState == embed::EmbedStates::RUNNING )
     {
-        if( !pOLELRU_Cache )
-            pOLELRU_Cache = new SwOLELRUCache;
-        pOLELRU_Cache->InsertObj( *mpObj );
+        if (!g_pOLELRU_Cache)
+            g_pOLELRU_Cache.reset(new SwOLELRUCache);
+        g_pOLELRU_Cache->InsertObj( *mpObj );
     }
     else if ( mpObj && nNewState == embed::EmbedStates::LOADED && nOldState == embed::EmbedStates::RUNNING )
     {
-        if ( pOLELRU_Cache )
-            pOLELRU_Cache->RemoveObj( *mpObj );
+        if (g_pOLELRU_Cache)
+            g_pOLELRU_Cache->RemoveObj( *mpObj );
     }
 }
 
 void SwOLEListener_Impl::Release()
 {
-    if ( mpObj && pOLELRU_Cache )
-        pOLELRU_Cache->RemoveObj( *mpObj );
+    if (mpObj && g_pOLELRU_Cache)
+        g_pOLELRU_Cache->RemoveObj( *mpObj );
     mpObj=nullptr;
     release();
 }
 
 void SAL_CALL SwOLEListener_Impl::disposing( const lang::EventObject& ) throw (uno::RuntimeException, std::exception)
 {
-    if ( mpObj && pOLELRU_Cache )
-        pOLELRU_Cache->RemoveObj( *mpObj );
+    if (mpObj && g_pOLELRU_Cache)
+        g_pOLELRU_Cache->RemoveObj( *mpObj );
 }
 
 // TODO/LATER: actually SwEmbedObjectLink should be used here, but because different objects are used to control
@@ -813,9 +813,9 @@ const uno::Reference < embed::XEmbeddedObject > SwOLEObj::GetOleRef()
     else if ( xOLERef->getCurrentState() == embed::EmbedStates::RUNNING )
     {
         // move object to first position in cache
-        if( !pOLELRU_Cache )
-            pOLELRU_Cache = new SwOLELRUCache;
-        pOLELRU_Cache->InsertObj( *this );
+        if (!g_pOLELRU_Cache)
+            g_pOLELRU_Cache.reset(new SwOLELRUCache);
+        g_pOLELRU_Cache->InsertObj( *this );
     }
 
     return xOLERef.GetObject();
@@ -940,6 +940,7 @@ void SwOLELRUCache::Load()
         {
             if (nVal < m_nLRU_InitSize)
             {
+                std::shared_ptr<SwOLELRUCache> tmp(g_pOLELRU_Cache); // prevent delete this
                 // size of cache has been changed
                 sal_Int32 nCount = m_OleObjects.size();
                 sal_Int32 nPos = nCount;
@@ -973,6 +974,7 @@ void SwOLELRUCache::InsertObj( SwOLEObj& rObj )
     }
     if (it == m_OleObjects.end())
     {
+        std::shared_ptr<SwOLELRUCache> tmp(g_pOLELRU_Cache); // prevent delete this
         // try to remove objects if necessary
         sal_Int32 nCount = m_OleObjects.size();
         sal_Int32 nPos = nCount-1;
@@ -996,7 +998,10 @@ void SwOLELRUCache::RemoveObj( SwOLEObj& rObj )
     }
     if (m_OleObjects.empty())
     {
-        DELETEZ( pOLELRU_Cache );
+        if (g_pOLELRU_Cache.unique()) // test that we're not in InsertObj()
+        {
+            g_pOLELRU_Cache.reset();
+        }
     }
 }
 


More information about the Libreoffice-commits mailing list