diff options
author | Jan Holesovsky <kendy@collabora.com> | 2019-11-29 16:03:27 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2019-12-05 11:02:01 +0100 |
commit | eb15ac837e06087fb8148330e9171d6697d89ee6 (patch) | |
tree | 5accb155a2a778db3ce6872685b0f86e1231e37d /cppuhelper | |
parent | a8cd98c437f2c3b5c4f7c139aa7223c5cfb74d1a (diff) |
android: Avoid throwing exceptions through the bridges.
From some reason it does not work, so let's do the same we are doing on
iOS; at least for now.
Change-Id: I915f8683a112548fc3defc1114f9dce3aa7be30e
Reviewed-on: https://gerrit.libreoffice.org/84067
Reviewed-by: Tor Lillqvist <tml@collabora.com>
Tested-by: Tor Lillqvist <tml@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/84204
Tested-by: Jenkins
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Diffstat (limited to 'cppuhelper')
-rw-r--r-- | cppuhelper/Library_cppuhelper.mk | 1 | ||||
-rw-r--r-- | cppuhelper/source/exc_thrower.cxx | 57 |
2 files changed, 52 insertions, 6 deletions
diff --git a/cppuhelper/Library_cppuhelper.mk b/cppuhelper/Library_cppuhelper.mk index 67413f711cd2..5741eea6476f 100644 --- a/cppuhelper/Library_cppuhelper.mk +++ b/cppuhelper/Library_cppuhelper.mk @@ -15,6 +15,7 @@ $(eval $(call gb_Library_set_soversion_script,cppuhelper,$(SRCDIR)/cppuhelper/so $(eval $(call gb_Library_use_internal_comprehensive_api,cppuhelper,\ cppuhelper \ udkapi \ + offapi \ )) $(eval $(call gb_Library_add_defs,cppuhelper,\ diff --git a/cppuhelper/source/exc_thrower.cxx b/cppuhelper/source/exc_thrower.cxx index 5e029feae982..a0e7fb32b046 100644 --- a/cppuhelper/source/exc_thrower.cxx +++ b/cppuhelper/source/exc_thrower.cxx @@ -17,21 +17,22 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <config_features.h> #include <rtl/instance.hxx> #include <osl/diagnose.h> +#include <osl/doublecheckedlocking.h> +#include <sal/log.hxx> #include <uno/dispatcher.hxx> #include <uno/lbnames.h> #include <uno/mapping.hxx> #include <cppuhelper/detail/XExceptionThrower.hpp> +#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp> +#include <com/sun/star/ucb/NameClashException.hpp> #include <com/sun/star/uno/RuntimeException.hpp> #include <cppuhelper/exc_hlp.hxx> -#ifdef IOS -#include <ios/ios.hxx> -#endif - using namespace ::osl; using namespace ::cppu; using namespace ::com::sun::star; @@ -172,6 +173,46 @@ ExceptionThrower::ExceptionThrower() class theExceptionThrower : public rtl::Static<ExceptionThrower, theExceptionThrower> {}; +#if defined(IOS) || HAVE_FEATURE_ANDROID_LOK +// In the native iOS / Android app, where we don't have any Java, Python, +// BASIC, or other scripting, the only thing that would use the C++/UNO bridge +// functionality that invokes codeSnippet() was cppu::throwException(). +// +// codeSnippet() is part of what corresponds to the code that uses +// run-time-generated machine code on other platforms. We can't generate code +// at run-time on iOS, that has been known forever. +// +// Instead of digging in and trying to understand what is wrong, another +// solution was chosen. It turns out that the number of types of exception +// objects thrown by cppu::throwException() is fairly small. During startup of +// the LibreOffice code, and loading of an .odt document, only one kind of +// exception is thrown this way... (The lovely +// css::ucb:InteractiveAugmentedIOException.) +// +// So we can simply have code that checks what the type of object being thrown +// is, and explicitgly throws such an object then with a normal C++ throw +// statement. Seems to work. +template <class E> void tryThrow(css::uno::Any const& aException) +{ + E aSpecificException; + if (aException >>= aSpecificException) + throw aSpecificException; +} + +void lo_mobile_throwException(css::uno::Any const& aException) +{ + assert(aException.getValueTypeClass() == css::uno::TypeClass_EXCEPTION); + + tryThrow<css::ucb::InteractiveAugmentedIOException>(aException); + tryThrow<css::ucb::NameClashException>(aException); + tryThrow<css::uno::RuntimeException>(aException); + + SAL_WARN("cppuhelper", "lo_mobile_throwException: Unhandled exception type: " << aException.getValueTypeName()); + + assert(false); +} +#endif // defined(IOS) || HAVE_FEATURE_ANDROID_LOK + } // anonymous namespace @@ -188,8 +229,8 @@ void SAL_CALL throwException( Any const & exc ) "(must be derived from com::sun::star::uno::Exception)!" ); } -#ifdef IOS - lo_ios_throwException(exc); +#if defined(IOS) || HAVE_FEATURE_ANDROID_LOK + lo_mobile_throwException(exc); #else Mapping uno2cpp(Environment(UNO_LB_UNO), Environment::getCurrent()); if (! uno2cpp.is()) @@ -211,6 +252,9 @@ void SAL_CALL throwException( Any const & exc ) Any SAL_CALL getCaughtException() { +#if HAVE_FEATURE_ANDROID_LOK + return Any(); +#else Mapping cpp2uno(Environment::getCurrent(), Environment(UNO_LB_UNO)); if (! cpp2uno.is()) { @@ -258,6 +302,7 @@ Any SAL_CALL getCaughtException() &ret, exc->pData, exc->pType, uno2cpp.get() ); uno_any_destruct( exc, nullptr ); return ret; +#endif } } |