24#include <rtl/strbuf.hxx>
25#include <rtl/ustrbuf.hxx>
26#include <osl/mutex.hxx>
29#include <com/sun/star/uno/genfunc.hxx>
30#include <com/sun/star/uno/RuntimeException.hpp>
31#include <typelib/typedescription.hxx>
33#include <unordered_map>
42extern sal_Int32 *
pHack;
43extern sal_Int32
nHack;
53#if OSL_DEBUG_LEVEL > 1
59 OUStringBuffer buf( 64 );
67 while (
'0' <= *
p &&
'9' >= *
p)
72 buf.appendAscii(
p,
n );
78#if OSL_DEBUG_LEVEL > 1
79 OUString ret( buf.makeStringAndClear() );
81 fprintf( stderr,
"> toUNOname(): %s => %s\n",
start, c_ret.getStr() );
84 return buf.makeStringAndClear();
91 typedef std::unordered_map< OUString, type_info * >
t_rtti_map;
105 type_info *
getRTTI(typelib_CompoundTypeDescription *);
111 :
m_hApp( dlopen(
nullptr, RTLD_LAZY ) )
124 type_info *
RTTI::getRTTI( typelib_CompoundTypeDescription *pTypeDescr )
128 OUString
const & unoName = *
reinterpret_cast<OUString
const *
>(&pTypeDescr->aBase.pTypeName);
131 t_rtti_map::const_iterator iFind(
m_rttis.find( unoName ) );
135 OStringBuffer buf( 64 );
136 buf.append(
"_ZTIN" );
140 OUString token( unoName.getToken( 0,
'.', index ) );
141 buf.append( token.getLength() );
143 buf.append( c_token );
148 OString symName( buf.makeStringAndClear() );
150 rtti =
static_cast<type_info *
>(dlsym(
m_hApp, symName.getStr() ));
152 rtti = (type_info *)dlsym( RTLD_DEFAULT, symName.getStr() );
157 pair< t_rtti_map::iterator, bool > insertion(
158 m_rttis.insert( t_rtti_map::value_type( unoName, rtti ) ) );
160 assert(insertion.second &&
"### inserting new rtti failed?!");
182 char const * rttiName = symName.getStr() +4;
183#if OSL_DEBUG_LEVEL > 1
184 fprintf( stderr,
"generated rtti for %s\n", rttiName );
186 if (pTypeDescr->pBaseTypeDescription)
189 type_info * base_rtti =
getRTTI( pTypeDescr->pBaseTypeDescription );
190 rtti =
new __si_class_type_info(
191 strdup( rttiName ),
static_cast<__class_type_info *
>(base_rtti) );
196 rtti =
new __class_type_info( strdup( rttiName ) );
199 pair< t_rtti_map::iterator, bool > insertion(
202 assert(insertion.second &&
"### inserting new generated rtti failed?!");
206 rtti = iFind2->second;
212 rtti = iFind->second;
224 ::typelib_typedescription_getByName( &pTD, unoName.pData );
225 assert(pTD &&
"### unknown exception type! leaving out destruction => leaking!!!");
228 ::uno_destructData( pExc, pTD, cpp_release );
229 ::typelib_typedescription_release( pTD );
235#if OSL_DEBUG_LEVEL > 1
238 OUString::unacquired( &pUnoExc->pType->pTypeName ),
239 RTL_TEXTENCODING_ASCII_US ) );
240 fprintf( stderr,
"> uno exception occurred: %s\n", cstr.getStr() );
248 TYPELIB_DANGER_GET( &pTypeDescr, pUnoExc->pType );
253 "cannot get typedescription for type " +
254 OUString::unacquired( &pUnoExc->pType->pTypeName ) );
258 ::uno_copyAndConvertData( pCppExc, pUnoExc->pData, pTypeDescr, pUno2Cpp );
261 ::uno_any_destruct( pUnoExc,
nullptr );
263 static RTTI rtti_data;
264 rtti = rtti_data.getRTTI(
reinterpret_cast<typelib_CompoundTypeDescription*
>(pTypeDescr));
265 TYPELIB_DANGER_RELEASE( pTypeDescr );
266 assert(rtti &&
"### no rtti for throwing exception!");
270 "no rtti for type " +
271 OUString::unacquired( &pUnoExc->pType->pTypeName ) );
281 return reinterpret_cast<void*
>(
header->unwindHeader.barrier_cache.bitpattern[0]);
286 return header->adjustedPtr;
305 OUString unoName(
toUNOname( exceptionType->name() ) );
306#if OSL_DEBUG_LEVEL > 1
308 fprintf( stderr,
"> c++ exception occurred: %s\n", cstr_unoName.getStr() );
311 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
#define SAL_WARN(area, stream)
struct _uno_Mapping uno_Mapping
struct _typelib_TypeDescription typelib_TypeDescription
static void * getAdjustedPtr(__cxa_exception *header)
static void deleteException(void *pExc)
__cxa_eh_globals * __cxa_get_globals()
void __cxa_throw(void *thrown_exception, std::type_info *tinfo, void(*dest)(void *)) __attribute__((noreturn))
void dummy_can_throw_anything(char const *)
void * __cxa_allocate_exception(std::size_t thrown_size)
void fillUnoException(uno_Any *pUnoExc, uno_Mapping *pCpp2Uno)
std::type_info * __cxa_current_exception_type()
static OUString toUNOname(char const *p)
void raiseException(uno_Any *pUnoExc, uno_Mapping *pUno2Cpp)
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()