31#include <com/sun/star/uno/RuntimeException.hpp>
32#include <com/sun/star/uno/genfunc.hxx>
34#include <osl/mutex.hxx>
35#include <rtl/strbuf.hxx>
36#include <rtl/ustrbuf.hxx>
37#include <typelib/typedescription.h>
39#include <unordered_map>
49struct Fake_type_info {
50 virtual ~Fake_type_info() =
delete;
54struct Fake_class_type_info: Fake_type_info {
55 virtual ~Fake_class_type_info()
override =
delete;
58struct Fake_si_class_type_info: Fake_class_type_info {
59 virtual ~Fake_si_class_type_info()
override =
delete;
64struct Derived:
Base {};
66std::type_info * createFake_class_type_info(
char const *
name) {
67 char * buf =
new char[
sizeof (Fake_class_type_info)];
69 *
reinterpret_cast<void **
>(buf) = *
reinterpret_cast<void *
const *
>(
72 Fake_class_type_info * fake =
reinterpret_cast<Fake_class_type_info *
>(buf);
74 return reinterpret_cast<std::type_info *
>(
75 static_cast<Fake_type_info *
>(fake));
78std::type_info * createFake_si_class_type_info(
79 char const *
name, std::type_info
const *
base)
81 char * buf =
new char[
sizeof (Fake_si_class_type_info)];
83 *
reinterpret_cast<void **
>(buf) = *
reinterpret_cast<void *
const *
>(
86 Fake_si_class_type_info * fake
87 =
reinterpret_cast<Fake_si_class_type_info *
>(buf);
90 return reinterpret_cast<std::type_info *
>(
91 static_cast<Fake_type_info *
>(fake));
97#pragma GCC diagnostic push
98#pragma GCC diagnostic ignored "-Wunused-function"
104#pragma GCC diagnostic pop
109#if OSL_DEBUG_LEVEL > 1
115 OUStringBuffer buf( 64 );
123 while (
'0' <= *
p &&
'9' >= *
p)
128 buf.appendAscii(
p,
n );
134#if OSL_DEBUG_LEVEL > 1
135 OUString ret( buf.makeStringAndClear() );
137 fprintf( stderr,
"> toUNOname(): %s => %s\n",
start, c_ret.getStr() );
140 return buf.makeStringAndClear();
148 typedef std::unordered_map< OUString, std::type_info * >
t_rtti_map;
160 std::type_info *
getRTTI( typelib_CompoundTypeDescription * );
166 :
m_hApp( dlopen( nullptr, RTLD_LAZY ) )
176std::type_info * RTTI::getRTTI( typelib_CompoundTypeDescription *pTypeDescr )
178 std::type_info * rtti;
180 OUString
const & unoName = OUString::unacquired(&pTypeDescr->aBase.pTypeName);
183 t_rtti_map::const_iterator iFind(
m_rttis.find( unoName ) );
187 OStringBuffer buf( 64 );
188 buf.append(
"_ZTIN" );
192 OUString token( unoName.getToken( 0,
'.', index ) );
193 buf.append( token.getLength() );
195 buf.append( c_token );
200 OString symName( buf.makeStringAndClear() );
201 rtti =
static_cast<std::type_info *
>(dlsym(
m_hApp, symName.getStr() ));
205 std::pair< t_rtti_map::iterator, bool > insertion(
206 m_rttis.insert( t_rtti_map::value_type( unoName, rtti ) ) );
209 "inserting new rtti failed" );
220 char * rttiName = strdup(symName.getStr() + 4);
221 if (rttiName ==
nullptr) {
222 throw std::bad_alloc();
224#if OSL_DEBUG_LEVEL > 1
225 fprintf( stderr,
"generated rtti for %s\n", rttiName );
227 if (pTypeDescr->pBaseTypeDescription)
230 std::type_info * base_rtti = getRTTI(
231 pTypeDescr->pBaseTypeDescription );
232 rtti = createFake_si_class_type_info(rttiName, base_rtti);
236 rtti = createFake_class_type_info(rttiName);
239 std::pair< t_rtti_map::iterator, bool > insertion(
243 "inserting new generated rtti failed" );
247 rtti = iFind2->second;
253 rtti = iFind->second;
284 reinterpret_cast<char const *
>(
header) - 8);
289 ::typelib_typedescription_getByName( &pTD, unoName.pData );
290 assert(pTD &&
"### unknown exception type! leaving out destruction => leaking!!!");
293 ::uno_destructData( pExc, pTD, cpp_release );
294 ::typelib_typedescription_release( pTD );
300#if OSL_DEBUG_LEVEL > 1
303 OUString::unacquired( &pUnoExc->pType->pTypeName ),
304 RTL_TEXTENCODING_ASCII_US ) );
305 fprintf( stderr,
"> uno exception occurred: %s\n", cstr.getStr() );
308 std::type_info * rtti;
313 TYPELIB_DANGER_GET( &pTypeDescr, pUnoExc->pType );
318 "cannot get typedescription for type " +
319 OUString::unacquired( &pUnoExc->pType->pTypeName ) );
323 ::uno_copyAndConvertData( pCppExc, pUnoExc->pData, pTypeDescr, pUno2Cpp );
326 ::uno_any_destruct( pUnoExc,
nullptr );
328 static RTTI rtti_data;
329 rtti = rtti_data.getRTTI(
reinterpret_cast<typelib_CompoundTypeDescription*
>(pTypeDescr));
330 TYPELIB_DANGER_RELEASE( pTypeDescr );
331 assert(rtti &&
"### no rtti for throwing exception!");
335 "no rtti for type " +
336 OUString::unacquired( &pUnoExc->pType->pTypeName ) );
377 if (*
reinterpret_cast<void **
>(header) ==
nullptr) {
378 header =
reinterpret_cast<__cxa_exception *
>(
reinterpret_cast<void **
>(
header) + 1);
384 OUString unoName(
toUNOname( exceptionType->name() ) );
385#if OSL_DEBUG_LEVEL > 1
387 fprintf( stderr,
"> c++ exception occurred: %s\n", cstr_unoName.getStr() );
390 if (
nullptr == pExcTypeDescr)
constexpr sal_Int8 header[]
void SAL_CALL uno_type_any_constructAndConvert(uno_Any *pDest, void *pSource, typelib_TypeDescriptionReference *pType, uno_Mapping *mapping) SAL_THROW_EXTERN_C()
void SAL_CALL uno_any_constructAndConvert(uno_Any *pDest, void *pSource, typelib_TypeDescription *pTypeDescr, uno_Mapping *mapping) SAL_THROW_EXTERN_C()
std::type_info * getRTTI(typelib_CompoundTypeDescription *)
std::unordered_map< OUString, std::type_info *, OUStringHash > t_rtti_map
t_rtti_map m_generatedRttis
t_rtti_map m_generatedRttis
CPPU_CURRENT_NAMESPACE::__cxa_eh_globals * __cxa_get_globals() noexcept
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
struct _uno_Mapping uno_Mapping
struct _typelib_TypeDescription typelib_TypeDescription
static OUString toUNOname(OUString const &rRTTIname) noexcept
static void deleteException(void *pExc)
void dummy_can_throw_anything(char const *)
void fillUnoException(uno_Any *pUnoExc, uno_Mapping *pCpp2Uno)
static OUString toUNOname(char const *p)
void __cxa_throw(void *thrown_exception, std::type_info *tinfo, void(*dest)(void *)) __attribute__((noreturn))
void * __cxa_allocate_exception(size_t thrown_size)
std::type_info * __cxa_current_exception_type()
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
__cxa_exception * caughtExceptions
void SAL_CALL typelib_typedescription_release(typelib_TypeDescription *pTD) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescription_getByName(typelib_TypeDescription **ppRet, rtl_uString *pName) SAL_THROW_EXTERN_C()