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>
32#include <unordered_map>
50#if OSL_DEBUG_LEVEL > 1
56 OUStringBuffer buf( 64 );
63 long n = (*
p++ -
'0');
64 while (
'0' <= *
p &&
'9' >= *
p)
69 buf.appendAscii(
p,
n );
75#if OSL_DEBUG_LEVEL > 1
76 OUString ret( buf.makeStringAndClear() );
78 fprintf( stderr,
"> toUNOname(): %s => %s\n",
start, c_ret.getStr() );
81 return buf.makeStringAndClear();
87 typedef std::unordered_map< OUString, type_info * >
t_rtti_map;
101 type_info *
getRTTI( typelib_CompoundTypeDescription * );
106 :
m_hApp( dlopen(
nullptr, RTLD_LAZY) )
119type_info *
RTTI::getRTTI( typelib_CompoundTypeDescription *pTypeDescr )
123 OUString
const & unoName = OUString::unacquired(&pTypeDescr->aBase.pTypeName);
126 t_rtti_map::const_iterator iRttiFind(
m_rttis.find( unoName ) );
127 if (iRttiFind ==
m_rttis.end())
130 OStringBuffer buf( 64 );
131 buf.append(
"_ZTIN" );
135 OUString token( unoName.getToken( 0,
'.', index ) );
136 buf.append( token.getLength() );
138 buf.append( c_token );
143 OString symName( buf.makeStringAndClear() );
145 rtti =
static_cast<type_info *
>(dlsym(
m_hApp, symName.getStr() ));
147 rtti =
static_cast<type_info *
>(dlsym( RTLD_DEFAULT, symName.getStr() ));
152 pair< t_rtti_map::iterator, bool > insertion(
153 m_rttis.insert( t_rtti_map::value_type( unoName, rtti ) ) );
154 SAL_WARN_IF( !insertion.second,
"bridges",
"### inserting new rtti failed?!" );
165 char const * rttiName = symName.getStr() +4;
166#if OSL_DEBUG_LEVEL > 1
167 fprintf( stderr,
"generated rtti for %s\n", rttiName );
169 if (pTypeDescr->pBaseTypeDescription)
172 type_info * base_rtti =
getRTTI(
173 pTypeDescr->pBaseTypeDescription);
174 rtti =
new __si_class_type_info(
175 strdup( rttiName ),
static_cast<__class_type_info *
>(base_rtti) );
180 rtti =
new __class_type_info( strdup( rttiName ) );
183 pair< t_rtti_map::iterator, bool > insertion(
185 SAL_WARN_IF( !insertion.second,
"bridges",
"### inserting new generated rtti failed?!" );
189 rtti = iFind->second;
195 rtti = iRttiFind->second;
208 ::typelib_typedescription_getByName( &pTD, unoName.pData );
209 assert(pTD &&
"### unknown exception type! leaving out destruction => leaking!!!");
212 ::uno_destructData( pExc, pTD, cpp_release );
213 ::typelib_typedescription_release( pTD );
220#if OSL_DEBUG_LEVEL > 1
223 OUString::unacquired( &pUnoExc->pType->pTypeName ),
224 RTL_TEXTENCODING_ASCII_US ) );
225 fprintf( stderr,
"> uno exception occurred: %s\n", cstr.getStr() );
233 TYPELIB_DANGER_GET( &pTypeDescr, pUnoExc->pType );
238 "cannot get typedescription for type " +
239 OUString::unacquired( &pUnoExc->pType->pTypeName ) );
243 ::uno_copyAndConvertData( pCppExc, pUnoExc->pData, pTypeDescr, pUno2Cpp );
246 ::uno_any_destruct( pUnoExc,
nullptr );
248 static RTTI rtti_data;
249 rtti = rtti_data.getRTTI(
reinterpret_cast<typelib_CompoundTypeDescription*
>(pTypeDescr));
250 TYPELIB_DANGER_RELEASE( pTypeDescr );
251 assert(rtti &&
"### no rtti for throwing exception!");
255 "no rtti for type " +
256 OUString::unacquired( &pUnoExc->pType->pTypeName ) );
279 OUString unoName(
toUNOname( exceptionType->name() ) );
280#if OSL_DEBUG_LEVEL > 1
282 fprintf( stderr,
"> c++ exception occurred: %s\n", cstr_unoName.getStr() );
285 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 *)
type_info * getRTTI(typelib_CompoundTypeDescription *)
std::unordered_map< OUString, type_info * > t_rtti_map
std::unordered_map< OUString, std::type_info *, OUStringHash > t_rtti_map
t_rtti_map m_generatedRttis
#define _GLIBCXX_CDTOR_CALLABI
#define SAL_WARN_IF(condition, area, stream)
#define SAL_WARN(area, stream)
struct _uno_Mapping uno_Mapping
struct _typelib_TypeDescription typelib_TypeDescription
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 raiseException(uno_Any *pUnoExc, uno_Mapping *pUno2Cpp)
void __cxa_throw(void *thrown_exception, std::type_info *tinfo, void(*dest)(void *)) __attribute__((noreturn))
__cxa_eh_globals * __cxa_get_globals()
void * __cxa_allocate_exception(size_t thrown_size)
std::type_info * __cxa_current_exception_type()
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
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()