[Libreoffice-commits] core.git: include/vcl package/inc package/source scripting/source vcl/inc vcl/unx

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sat Aug 4 16:50:08 UTC 2018


 include/vcl/threadex.hxx                           |   22 +++++++++------------
 package/inc/ZipOutputEntry.hxx                     |    6 ++---
 package/inc/ZipOutputStream.hxx                    |    2 -
 package/source/zipapi/XBufferedThreadedStream.cxx  |    3 --
 package/source/zipapi/XBufferedThreadedStream.hxx  |    2 -
 package/source/zipapi/ZipOutputStream.cxx          |   10 ++++-----
 package/source/zippackage/ZipPackageStream.cxx     |    4 +--
 scripting/source/protocolhandler/scripthandler.cxx |   10 ++++-----
 vcl/inc/unx/gtk/gtkdata.hxx                        |    4 +--
 vcl/unx/gtk3/gtk3gtkdata.cxx                       |    4 +--
 vcl/unx/gtk3/gtk3gtkframe.cxx                      |   19 +-----------------
 11 files changed, 34 insertions(+), 52 deletions(-)

New commits:
commit ce2792eda318b2760d24d2a744fc89e6a1d87138
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Sat Jul 28 20:00:26 2018 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Sat Aug 4 18:49:48 2018 +0200

    use C++11 exception rethrowing
    
    for those cases where we are doing relatively simple catching and rethrowing
    e.g. catch in one thread and throw in main thread.
    
    Change-Id: I6192017c4ec99dd671a9582f7b004096b0fc4525
    Reviewed-on: https://gerrit.libreoffice.org/58588
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/include/vcl/threadex.hxx b/include/vcl/threadex.hxx
index 5eadc125c748..7879536afc9e 100644
--- a/include/vcl/threadex.hxx
+++ b/include/vcl/threadex.hxx
@@ -61,27 +61,26 @@ public:
         typedef GenericSolarThreadExecutor<FuncT, ResultT> ExecutorT;
         ::std::unique_ptr<ExecutorT> const pExecutor( new ExecutorT(func) );
         pExecutor->execute();
-        if (pExecutor->m_exc.hasValue())
-            ::cppu::throwException( pExecutor->m_exc );
+        if (pExecutor->m_exc)
+            std::rethrow_exception(pExecutor->m_exc);
         return *pExecutor->m_result;
     }
 
 private:
     explicit GenericSolarThreadExecutor( FuncT const& func )
-        : m_exc(), m_func(func), m_result() {}
+        : m_func(func), m_result() {}
 
     virtual void doIt() override
     {
         try {
             m_result.reset( m_func() );
         }
-        catch (css::uno::Exception &) {
-            // only UNO exceptions can be dispatched:
-            m_exc = ::cppu::getCaughtException();
+        catch (...) {
+            m_exc = std::current_exception();
         }
     }
 
-    css::uno::Any m_exc;
+    std::exception_ptr m_exc;
 #ifdef _MSC_VER
     FuncT m_func; // "const" and std::bind() results in Error C3848 expression would lose const-volatile qualifiers
 #else
@@ -97,20 +96,19 @@ class GenericSolarThreadExecutor<FuncT, void> : public SolarThreadExecutor
 {
 private:
     explicit GenericSolarThreadExecutor( FuncT const& func )
-        : m_exc(), m_func(func) {}
+        : m_func(func) {}
 
     virtual void doIt() override
     {
         try {
             m_func();
         }
-        catch (css::uno::Exception &) {
-            // only UNO exceptions can be dispatched:
-            m_exc = ::cppu::getCaughtException();
+        catch (...) {
+            m_exc = std::current_exception();
         }
     }
 
-    css::uno::Any m_exc;
+    std::exception_ptr m_exc;
     FuncT const m_func;
 };
 
diff --git a/package/inc/ZipOutputEntry.hxx b/package/inc/ZipOutputEntry.hxx
index 2e6c11dfa129..d95ffd4969ab 100644
--- a/package/inc/ZipOutputEntry.hxx
+++ b/package/inc/ZipOutputEntry.hxx
@@ -47,7 +47,7 @@ class ZipOutputEntry
 
     css::uno::Reference< css::xml::crypto::XCipherContext > m_xCipherContext;
     css::uno::Reference< css::xml::crypto::XDigestContext > m_xDigestContext;
-    ::css::uno::Any m_aParallelDeflateException;
+    std::exception_ptr m_aParallelDeflateException;
 
     CRC32               m_aCRC;
     ZipEntry            *m_pCurrentEntry;
@@ -70,9 +70,9 @@ public:
         const css::uno::Reference< css::uno::XComponentContext >& rxContext,
         ZipEntry& rEntry, ZipPackageStream* pStream, bool bEncrypt);
     void createBufferFile();
-    void setParallelDeflateException(const ::css::uno::Any &rAny) { m_aParallelDeflateException = rAny; }
+    void setParallelDeflateException(const std::exception_ptr& exception) { m_aParallelDeflateException = exception; }
     css::uno::Reference< css::io::XInputStream > getData() const;
-    const css::uno::Any& getParallelDeflateException() const { return m_aParallelDeflateException; }
+    const std::exception_ptr& getParallelDeflateException() const { return m_aParallelDeflateException; }
     void closeBufferFile();
     void deleteBufferFile();
 
diff --git a/package/inc/ZipOutputStream.hxx b/package/inc/ZipOutputStream.hxx
index 2c3e26fab4ac..3f86f07883ca 100644
--- a/package/inc/ZipOutputStream.hxx
+++ b/package/inc/ZipOutputStream.hxx
@@ -40,7 +40,7 @@ class ZipOutputStream
     ByteChucker         m_aChucker;
     ZipEntry            *m_pCurrentEntry;
     std::vector< ZipOutputEntry* > m_aEntries;
-    ::css::uno::Any m_aDeflateException;
+    std::exception_ptr m_aDeflateException;
 
 public:
     ZipOutputStream(
diff --git a/package/source/zipapi/XBufferedThreadedStream.cxx b/package/source/zipapi/XBufferedThreadedStream.cxx
index 71683cfaf590..e40613d4b66e 100644
--- a/package/source/zipapi/XBufferedThreadedStream.cxx
+++ b/package/source/zipapi/XBufferedThreadedStream.cxx
@@ -29,9 +29,8 @@ private:
         {
             mxStream.produce();
         }
-        catch (const css::uno::Exception &e)
+        catch (...)
         {
-            SAL_WARN("package", "Unexpected " << e );
             mxStream.saveException(std::current_exception());
         }
 
diff --git a/package/source/zipapi/XBufferedThreadedStream.hxx b/package/source/zipapi/XBufferedThreadedStream.hxx
index 5feb6e4252e0..272414c37504 100644
--- a/package/source/zipapi/XBufferedThreadedStream.hxx
+++ b/package/source/zipapi/XBufferedThreadedStream.hxx
@@ -66,7 +66,7 @@ public:
 
     void produce();
     void setTerminateThread();
-    void saveException(std::exception_ptr exception) { maSavedException = exception; }
+    void saveException(const std::exception_ptr& exception) { maSavedException = exception; }
 
     // XInputStream
     virtual sal_Int32 SAL_CALL readBytes( css::uno::Sequence< sal_Int8 >& aData, sal_Int32 nBytesToRead ) override;
diff --git a/package/source/zipapi/ZipOutputStream.cxx b/package/source/zipapi/ZipOutputStream.cxx
index c15fdaee48ef..c98876fdc6c1 100644
--- a/package/source/zipapi/ZipOutputStream.cxx
+++ b/package/source/zipapi/ZipOutputStream.cxx
@@ -94,10 +94,10 @@ void ZipOutputStream::rawCloseEntry( bool bEncrypt )
 void ZipOutputStream::consumeScheduledThreadEntry(ZipOutputEntry* pCandidate)
 {
     //Any exceptions thrown in the threads were caught and stored for now
-    ::css::uno::Any aCaughtException(pCandidate->getParallelDeflateException());
-    if (aCaughtException.hasValue())
+    const std::exception_ptr& rCaughtException(pCandidate->getParallelDeflateException());
+    if (rCaughtException)
     {
-        m_aDeflateException = aCaughtException; // store it for later throwing
+        m_aDeflateException = rCaughtException; // store it for later throwing
         // the exception handler in DeflateThread should have cleaned temp file
         delete pCandidate;
         return;
@@ -184,9 +184,9 @@ void ZipOutputStream::finish()
     m_xStream->flush();
     m_aZipList.clear();
 
-    if (m_aDeflateException.hasValue())
+    if (m_aDeflateException)
     {   // throw once all threads are finished and m_aEntries can be released
-        ::cppu::throwException(m_aDeflateException);
+        std::rethrow_exception(m_aDeflateException);
     }
 }
 
diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx
index 0c780718b251..5fe4d0ef80c5 100644
--- a/package/source/zippackage/ZipPackageStream.cxx
+++ b/package/source/zippackage/ZipPackageStream.cxx
@@ -473,9 +473,9 @@ private:
             mpEntry->closeBufferFile();
             mpEntry->setFinished();
         }
-        catch (const uno::Exception&)
+        catch (...)
         {
-            mpEntry->setParallelDeflateException(::cppu::getCaughtException());
+            mpEntry->setParallelDeflateException(std::current_exception());
             try
             {
                 if (mpEntry->m_xOutStream.is())
diff --git a/scripting/source/protocolhandler/scripthandler.cxx b/scripting/source/protocolhandler/scripthandler.cxx
index 39991b37e6f7..f8ad8c7fd63d 100644
--- a/scripting/source/protocolhandler/scripthandler.cxx
+++ b/scripting/source/protocolhandler/scripthandler.cxx
@@ -210,7 +210,7 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification(
             bSuccess = false;
             while ( !bSuccess )
             {
-                Any aFirstCaughtException;
+                std::exception_ptr aFirstCaughtException;
                 try
                 {
                     invokeResult = xFunc->invoke( inArgs, outIndex, outArgs );
@@ -218,17 +218,17 @@ void SAL_CALL ScriptProtocolHandler::dispatchWithNotification(
                 }
                 catch( const provider::ScriptFrameworkErrorException& se )
                 {
-                    if  ( !aFirstCaughtException.hasValue() )
-                        aFirstCaughtException = ::cppu::getCaughtException();
+                    if  (!aFirstCaughtException)
+                        aFirstCaughtException = std::current_exception();
 
                     if ( se.errorType != provider::ScriptFrameworkErrorType::NO_SUCH_SCRIPT )
                         // the only condition which allows us to retry is if there is no method with the
                         // given name/signature
-                        ::cppu::throwException( aFirstCaughtException );
+                        std::rethrow_exception(aFirstCaughtException);
 
                     if ( inArgs.getLength() == 0 )
                         // no chance to retry if we can't strip more in-args
-                        ::cppu::throwException( aFirstCaughtException );
+                        std::rethrow_exception(aFirstCaughtException);
 
                     // strip one argument, then retry
                     inArgs.realloc( inArgs.getLength() - 1 );
diff --git a/vcl/inc/unx/gtk/gtkdata.hxx b/vcl/inc/unx/gtk/gtkdata.hxx
index 31440f0f3655..14330d70fb9e 100644
--- a/vcl/inc/unx/gtk/gtkdata.hxx
+++ b/vcl/inc/unx/gtk/gtkdata.hxx
@@ -100,7 +100,7 @@ class GtkSalData : public GenericUnixSalData
     GSource*        m_pUserEvent;
     osl::Mutex      m_aDispatchMutex;
     osl::Condition  m_aDispatchCondition;
-    css::uno::Any   m_aException;
+    std::exception_ptr m_aException;
 
     css::uno::Reference<css::accessibility::XAccessibleEventListener> m_xDocumentFocusListener;
     DocumentFocusListener * m_pDocumentFocusListener;
@@ -127,7 +127,7 @@ public:
     virtual bool ErrorTrapPop( bool bIgnoreError = true ) override;
 
     inline GtkSalDisplay *GetGtkDisplay() const;
-    void setException(const css::uno::Any& rException) { m_aException = rException; }
+    void setException(const std::exception_ptr& exception) { m_aException = exception; }
 };
 
 class GtkSalFrame;
diff --git a/vcl/unx/gtk3/gtk3gtkdata.cxx b/vcl/unx/gtk3/gtk3gtkdata.cxx
index 030e922ae101..48047240e643 100644
--- a/vcl/unx/gtk3/gtk3gtkdata.cxx
+++ b/vcl/unx/gtk3/gtk3gtkdata.cxx
@@ -464,8 +464,8 @@ bool GtkSalData::Yield( bool bWait, bool bHandleAllCurrentEvents )
                 if( wasOneEvent )
                     bWasEvent = true;
             }
-            if (m_aException.hasValue())
-                ::cppu::throwException(m_aException);
+            if (m_aException)
+                std::rethrow_exception(m_aException);
         }
         else if( bWait )
         {
diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx
index 1791b82ac4f8..17659c3744fc 100644
--- a/vcl/unx/gtk3/gtk3gtkframe.cxx
+++ b/vcl/unx/gtk3/gtk3gtkframe.cxx
@@ -4482,25 +4482,10 @@ bool GtkSalFrame::CallCallbackExc(SalEvent nEvent, const void* pEvent) const
     {
         nRet = CallCallback(nEvent, pEvent);
     }
-    catch (const css::uno::Exception&)
-    {
-        auto e = cppu::getCaughtException();
-        GtkSalData *pSalData = static_cast<GtkSalData*>(GetSalData());
-        pSalData->setException(e);
-    }
-    catch (std::exception & e)
-    {
-        static_cast<GtkSalData *>(GetSalData())->setException(
-            css::uno::Any(
-                css::uno::RuntimeException(
-                    "wrapped std::exception "
-                    + o3tl::runtimeToOUString(e.what()))));
-    }
     catch (...)
     {
-        static_cast<GtkSalData *>(GetSalData())->setException(
-            css::uno::Any(
-                css::uno::RuntimeException("wrapped unknown exception")));
+        GtkSalData *pSalData = static_cast<GtkSalData*>(GetSalData());
+        pSalData->setException(std::current_exception());
     }
     return nRet;
 }


More information about the Libreoffice-commits mailing list