[Libreoffice-commits] core.git: 2 commits - include/o3tl include/xmloff sw/qa xmloff/source

Caolán McNamara caolanm at redhat.com
Tue Oct 4 11:31:30 UTC 2016


 include/o3tl/stack.hxx                  |   78 ++++++++++++++++++++++++++++++++
 include/xmloff/xmlimp.hxx               |    5 +-
 sw/qa/core/data/xml/fail/ooo71273-1.sxw |binary
 xmloff/source/core/xmlimp.cxx           |   36 +++++++-------
 4 files changed, 99 insertions(+), 20 deletions(-)

New commits:
commit fd79f88272d13c36e88199d276fea94f6b567a13
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Oct 4 12:08:11 2016 +0100

    crashtesting: use a stack with the expected dtor order for its elements
    
    contains test document which crashes if it doesn't
    
    Change-Id: Ieeee6cc7007a90d37225fffd636c9648289f04d7

diff --git a/include/o3tl/stack.hxx b/include/o3tl/stack.hxx
new file mode 100644
index 0000000..1fa7934
--- /dev/null
+++ b/include/o3tl/stack.hxx
@@ -0,0 +1,78 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_O3TL_STACK_HXX
+#define INCLUDED_O3TL_STACK_HXX
+
+#include <stack>
+
+namespace o3tl
+{
+
+/**
+ *
+ * Same as std::stack (it just wraps it) except at destruction time the
+ * container elements are destroyed in order starting from the top of the stack
+ * which is the order one would rather assume a stack uses, but doesn't have to
+ *
+ * https://connect.microsoft.com/VisualStudio/feedback/details/765649/std-vector-does-not-destruct-in-reverse-order-of-construction
+ *
+ **/
+
+template<class T> class stack final
+{
+private:
+    typedef std::stack<T> stack_t;
+
+    stack_t mStack;
+public:
+
+    T& top()
+    {
+        return mStack.top();
+    }
+
+    const T& top() const
+    {
+        return mStack.top();
+    }
+
+    void push(const T& val)
+    {
+        mStack.push(val);
+    }
+
+    void push(T&& val)
+    {
+        mStack.push(val);
+    }
+
+    void pop()
+    {
+        mStack.pop();
+    }
+
+    bool empty() const
+    {
+        return mStack.empty();
+    }
+
+    ~stack()
+    {
+        while (!mStack.empty())
+            mStack.pop();
+    }
+};
+
+}
+
+#endif /* INCLUDED_O3TL_STACK_HXX */
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
index 07168bc..0aedd5b 100644
--- a/include/xmloff/xmlimp.hxx
+++ b/include/xmloff/xmlimp.hxx
@@ -23,7 +23,7 @@
 #include <sal/config.h>
 
 #include <set>
-#include <stack>
+#include <o3tl/stack.hxx>
 
 #include <xmloff/dllapi.h>
 #include <sal/types.h>
@@ -86,8 +86,8 @@ class XMLErrors;
 class StyleMap;
 enum class SvXMLErrorFlags;
 
-typedef std::stack<SvXMLImportContextRef> SvXMLImportContexts_Impl;
-typedef std::stack<css::uno::Reference<css::xml::sax::XFastContextHandler>>
+typedef o3tl::stack<SvXMLImportContextRef> SvXMLImportContexts_Impl;
+typedef o3tl::stack<css::uno::Reference<css::xml::sax::XFastContextHandler>>
             FastSvXMLImportContexts_Impl;
 
 namespace xmloff {
diff --git a/sw/qa/core/data/xml/fail/ooo71273-1.sxw b/sw/qa/core/data/xml/fail/ooo71273-1.sxw
new file mode 100644
index 0000000..5208512
Binary files /dev/null and b/sw/qa/core/data/xml/fail/ooo71273-1.sxw differ
commit 22cea99518af0358ddabab95f68fedcb94a7d923
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue Oct 4 11:28:21 2016 +0100

    this is used as a stack, so convert to std::stack
    
    Change-Id: I248617ccbb985615f936ecd607ab7c8246ff8e71

diff --git a/include/xmloff/xmlimp.hxx b/include/xmloff/xmlimp.hxx
index 93c5f25..07168bc 100644
--- a/include/xmloff/xmlimp.hxx
+++ b/include/xmloff/xmlimp.hxx
@@ -23,6 +23,7 @@
 #include <sal/config.h>
 
 #include <set>
+#include <stack>
 
 #include <xmloff/dllapi.h>
 #include <sal/types.h>
@@ -85,8 +86,8 @@ class XMLErrors;
 class StyleMap;
 enum class SvXMLErrorFlags;
 
-typedef std::vector<SvXMLImportContextRef> SvXMLImportContexts_Impl;
-typedef std::vector< ::css::uno::Reference< ::css::xml::sax::XFastContextHandler>>
+typedef std::stack<SvXMLImportContextRef> SvXMLImportContexts_Impl;
+typedef std::stack<css::uno::Reference<css::xml::sax::XFastContextHandler>>
             FastSvXMLImportContexts_Impl;
 
 namespace xmloff {
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index d528a17..c061d8e 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -736,7 +736,7 @@ void SAL_CALL SvXMLImport::startElement( const OUString& rName,
     SvXMLImportContextRef xContext;
     if(!maContexts.empty())
     {
-        xContext.set(maContexts.back()->CreateChildContext(nPrefix, aLocalName, xAttrList));
+        xContext.set(maContexts.top()->CreateChildContext(nPrefix, aLocalName, xAttrList));
         SAL_WARN_IF( !xContext.is() || (xContext->GetPrefix() != nPrefix), "xmloff.core",
                 "SvXMLImport::startElement: created context has wrong prefix" );
     }
@@ -767,7 +767,7 @@ void SAL_CALL SvXMLImport::startElement( const OUString& rName,
     xContext->StartElement( xAttrList );
 
     // Push context on stack.
-    maContexts.push_back( xContext );
+    maContexts.push(xContext);
 }
 
 void SAL_CALL SvXMLImport::endElement( const OUString&
@@ -787,8 +787,8 @@ rName
 
     {
         // Get topmost context and remove it from the stack.
-        SvXMLImportContextRef xContext = maContexts.back();
-        maContexts.pop_back();
+        SvXMLImportContextRef xContext = maContexts.top();
+        maContexts.pop();
 
 #ifdef DBG_UTIL
         // Non product only: check if endElement call matches startELement call.
@@ -819,11 +819,11 @@ void SAL_CALL SvXMLImport::characters( const OUString& rChars )
 {
     if ( !maFastContexts.empty() )
     {
-        maFastContexts.back()->characters( rChars );
+        maFastContexts.top()->characters( rChars );
     }
     else if( !maContexts.empty() )
     {
-        maContexts.back()->Characters( rChars );
+        maContexts.top()->Characters( rChars );
     }
 }
 
@@ -831,7 +831,7 @@ void SvXMLImport::Characters( const OUString& rChars )
 {
     if( !maContexts.empty() )
     {
-        maContexts.back()->Characters( rChars );
+        maContexts.top()->Characters( rChars );
     }
 }
 
@@ -861,7 +861,7 @@ void SAL_CALL SvXMLImport::startFastElement (sal_Int32 Element,
     uno::Reference<XFastContextHandler> xContext;
     if (!maFastContexts.empty())
     {
-        uno::Reference< XFastContextHandler > pHandler = maFastContexts.back();
+        uno::Reference<XFastContextHandler> pHandler = maFastContexts.top();
         xContext = pHandler->createFastChildContext( Element, Attribs );
     }
     else
@@ -884,11 +884,11 @@ void SAL_CALL SvXMLImport::startFastElement (sal_Int32 Element,
         SvXMLImportContext *pContext = dynamic_cast<SvXMLImportContext*>( xContext.get() );
         if( pContext && pRewindMap )
             pContext->PutRewindMap(std::move(pRewindMap));
-        maContexts.push_back( pContext );
+        maContexts.push(pContext);
     }
 
     // Push context on stack.
-    maFastContexts.push_back( xContext );
+    maFastContexts.push(xContext);
 }
 
 void SAL_CALL SvXMLImport::startUnknownElement (const OUString & rPrefix, const OUString & rLocalName,
@@ -898,7 +898,7 @@ void SAL_CALL SvXMLImport::startUnknownElement (const OUString & rPrefix, const
     uno::Reference<XFastContextHandler> xContext;
     if (!maFastContexts.empty())
     {
-        uno::Reference< XFastContextHandler > pHandler = maFastContexts.back();
+        uno::Reference<XFastContextHandler> pHandler = maFastContexts.top();
         xContext = pHandler->createUnknownChildContext( rPrefix, rLocalName, Attribs );
     }
     else
@@ -908,7 +908,7 @@ void SAL_CALL SvXMLImport::startUnknownElement (const OUString & rPrefix, const
         xContext.set( new SvXMLImportContext( *this ) );
 
     xContext->startUnknownElement( rPrefix, rLocalName, Attribs );
-    maFastContexts.push_back( xContext );
+    maFastContexts.push(xContext);
 }
 
 void SAL_CALL SvXMLImport::endFastElement (sal_Int32 Element)
@@ -916,12 +916,12 @@ void SAL_CALL SvXMLImport::endFastElement (sal_Int32 Element)
 {
     if (!maFastContexts.empty())
     {
-        uno::Reference< XFastContextHandler > xContext = maFastContexts.back();
-        maFastContexts.pop_back();
+        uno::Reference<XFastContextHandler> xContext = maFastContexts.top();
+        maFastContexts.pop();
         isFastContext = true;
         xContext->endFastElement( Element );
-        if ( isFastContext )
-            maContexts.pop_back();
+        if (isFastContext)
+            maContexts.pop();
 
         xContext = nullptr;
     }
@@ -932,8 +932,8 @@ void SAL_CALL SvXMLImport::endUnknownElement (const OUString & rPrefix, const OU
 {
     if (!maFastContexts.empty())
     {
-        uno::Reference< XFastContextHandler > xContext = maFastContexts.back();
-        maFastContexts.pop_back();
+        uno::Reference<XFastContextHandler> xContext = maFastContexts.top();
+        maFastContexts.pop();
         xContext->endUnknownElement( rPrefix, rLocalName );
         xContext = nullptr;
     }


More information about the Libreoffice-commits mailing list