Kaydet (Commit) 7d6be61a authored tarafından Tor Lillqvist's avatar Tor Lillqvist Kaydeden (comit) Tor Lillqvist

Re-think cppu::throwException() and the C++/UNO bridge on iOS

It seems that on iOS, 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 we have
used some manually written assembler to handle it instead. We used to
have a Perl script to generate a set of code snippets for different
cases, different numbers of parameters of the called function and
whatnot, but that went away at some stage some year ago. (It is
unclear whether that broke the C++/UNO bridge on iOS, or whether the
stuff continued to work even after that.)

Anyway, this handwritten assembly, or the manual construction of
internal data structures for exceptions, or something else, seemed to
have bit-rotten. Exceptions thrown with cppu::throwException() were
not catchable properly any longer.

Instead of digging in and trying to understand what is wrong, I chose
another solution. 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.

Sadly the cppu::getCaughtException() API still needs some inline
assembly in the C++/UNO brige. That seems to work though, knock on
wood.

This commit also adds a small "unit test" for iOS, copied from
cppuhelperm to ImplSVMain(). Ideally we should not copy code around of
course, but have a separate unit test app for iOS that would somehow
include relevant unit tests from source files all over the place.
Later.

Change-Id: Ib6d9d5b6fb8cc684ec15c97a312ca2f720e87069
Reviewed-on: https://gerrit.libreoffice.org/60506
Tested-by: Jenkins
Reviewed-by: 's avatarTor Lillqvist <tml@collabora.com>
üst e005ab5d
......@@ -434,6 +434,10 @@ namespace
sal_Int32 functionIndex,
sal_Int32 vtableOffset)
{
// For now temporarily assert when we get here. The intent is
// that we won't need the code snippets at all on iOS.
assert(false);
assert(functionIndex < nFunIndexes);
if (!(functionIndex < nFunIndexes))
return NULL;
......
......@@ -29,6 +29,10 @@
#include <cppuhelper/exc_hlp.hxx>
#ifdef IOS
#include <ios/ios.hxx>
#endif
using namespace ::osl;
using namespace ::cppu;
using namespace ::com::sun::star;
......@@ -185,6 +189,9 @@ void SAL_CALL throwException( Any const & exc )
"(must be derived from com::sun::star::uno::Exception)!" );
}
#ifdef IOS
lo_ios_throwException(exc);
#else
Mapping uno2cpp(Environment(UNO_LB_UNO), Environment::getCurrent());
if (! uno2cpp.is())
{
......@@ -199,6 +206,7 @@ void SAL_CALL throwException( Any const & exc )
ExceptionThrower::getCppuType() );
OSL_ASSERT( xThrower.is() );
xThrower->throwException( exc );
#endif
}
......
......@@ -43,7 +43,10 @@ $(eval $(call gb_Library_use_custom_headers,sofficeapp,\
officecfg/registry \
))
$(eval $(call gb_Library_use_sdk_api,sofficeapp))
$(eval $(call gb_Library_use_api,sofficeapp,\
udkapi \
offapi \
))
$(eval $(call gb_Library_add_defs,sofficeapp,\
-DDESKTOP_DLLIMPLEMENTATION \
......
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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_IOS_IOS_HXX
#define INCLUDED_IOS_IOS_HXX
#include "com/sun/star/uno/Any.hxx"
extern void lo_ios_throwException(css::uno::Any const& aException);
#endif // INCLUDED_IOS_IOS_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -11,6 +11,7 @@ $(eval $(call gb_Module_Module,ios))
ifeq ($(OS),IOS)
$(eval $(call gb_Module_add_targets,ios,\
StaticLibrary_ios \
CustomTarget_iOS_setup \
))
......
# -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
#
# 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/.
$(eval $(call gb_StaticLibrary_StaticLibrary,ios))
$(eval $(call gb_StaticLibrary_use_api,ios,\
udkapi \
offapi \
))
$(eval $(call gb_StaticLibrary_add_exception_objects,ios,\
ios/source/ios \
))
# vim: set noet sw=4 ts=4:
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* 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/.
*/
#include <cassert>
#include "com/sun/star/uno/Any.hxx"
#include "com/sun/star/ucb/InteractiveAugmentedIOException.hpp"
#include "ios/ios.hxx"
namespace
{
template <class E> void tryThrow(css::uno::Any const& aException)
{
E aSpecificException;
if (aException >>= aSpecificException)
throw aSpecificException;
}
}
void lo_ios_throwException(css::uno::Any const& aException)
{
assert(aException.getValueTypeClass() == css::uno::TypeClass_EXCEPTION);
tryThrow<css::ucb::InteractiveAugmentedIOException>(aException);
assert(false);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -181,6 +181,85 @@ oslSignalAction VCLExceptionSignal_impl( void* /*pData*/, oslSignalInfo* pInfo)
}
#ifdef IOS
#include <cppuhelper/exc_hlp.hxx>
#include <com/sun/star/ucb/InteractiveAugmentedIOException.hpp>
// Swiped from cppuhelper/qa/misc/test_misc.cxx. Ideally we should
// have a unit test app for iOS that would somehow include relevant
// unit tests from source files all over the place.
static void testExceptions()
{
css::uno::Any aSavedExceptionAny;
std::exception_ptr
aSavedException; /// exception caught during unzipping is saved to be thrown during reading
try
{
throw css::uno::RuntimeException("RuntimeException");
}
catch (...)
{
aSavedException = std::current_exception();
}
assert(bool(aSavedException));
try
{
std::rethrow_exception(aSavedException);
}
catch (const css::uno::RuntimeException&)
{
// the expected case
aSavedExceptionAny = cppu::getCaughtException();
}
catch (...)
{
assert(false);
}
assert(aSavedExceptionAny.hasValue());
try
{
throw css::ucb::InteractiveAugmentedIOException();
}
catch (const css::ucb::InteractiveAugmentedIOException&)
{
aSavedExceptionAny = cppu::getCaughtException();
}
catch (const css::uno::Exception&)
{
assert(false);
}
catch (...)
{
assert(false);
}
assert(aSavedExceptionAny.hasValue());
try
{
css::ucb::InteractiveAugmentedIOException iaie;
css::uno::Any aEx = css::uno::makeAny(iaie);
// css::uno::Exception e;
// css::uno::Any aEx = css::uno::makeAny(e);
cppu::throwException(aEx);
}
catch (const css::ucb::InteractiveAugmentedIOException&)
{
}
catch (const css::uno::Exception& e)
{
assert(false);
}
catch (...)
{
assert(false);
}
}
#endif
int ImplSVMain()
{
// The 'real' SVMain()
......@@ -196,6 +275,10 @@ int ImplSVMain()
postInitVCLinitNSApp();
#endif
#ifdef IOS
testExceptions();
#endif
if( bInit )
{
// call application main
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment