23#include <rtl/strbuf.hxx>
24#include <rtl/ustrbuf.hxx>
26#include <osl/mutex.hxx>
28#include <com/sun/star/uno/genfunc.hxx>
29#include <typelib/typedescription.hxx>
31#include <unordered_map>
50#if defined BRIDGES_DEBUG
56 OUStringBuffer buf( 64 );
63 long n = (*
p++ -
'0');
64 while (
'0' <= *
p &&
'9' >= *
p)
69 buf.appendAscii(
p,
n );
75#if defined BRIDGES_DEBUG
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;
99 type_info *
getRTTI( typelib_CompoundTypeDescription * );
103 :
m_hApp( dlopen( 0, RTLD_LAZY ) )
113type_info *
RTTI::getRTTI( typelib_CompoundTypeDescription *pTypeDescr )
117 OUString
const & unoName = *(OUString
const *)&pTypeDescr->aBase.pTypeName;
120 t_rtti_map::const_iterator iRttiFind(
m_rttis.find( unoName ) );
121 if (iRttiFind ==
m_rttis.end())
124 OStringBuffer buf( 64 );
125 buf.append(
"_ZTIN" );
129 OUString token( unoName.getToken( 0,
'.', index ) );
130 buf.append( token.getLength() );
132 buf.append( c_token );
137 OString symName( buf.makeStringAndClear() );
138 rtti = (type_info *)dlsym(
m_hApp, symName.getStr() );
142 pair< t_rtti_map::iterator, bool > insertion(
143 m_rttis.insert( t_rtti_map::value_type( unoName, rtti ) ) );
144 assert(insertion.second &&
"### inserting new rtti failed?!");
155 char const * rttiName = symName.getStr() +4;
156#if defined BRIDGES_DEBUG
157 fprintf( stderr,
"generated rtti for %s\n", rttiName );
159 if (pTypeDescr->pBaseTypeDescription)
162 type_info * base_rtti =
getRTTI(
163 (typelib_CompoundTypeDescription *)pTypeDescr->pBaseTypeDescription );
164 rtti =
new __si_class_type_info(
165 strdup( rttiName ), (__class_type_info *)base_rtti );
170 rtti =
new __class_type_info( strdup( rttiName ) );
173 pair< t_rtti_map::iterator, bool > insertion(
175 assert(insertion.second &&
"### inserting new generated rtti failed?!");
179 rtti = iFind->second;
185 rtti = iRttiFind->second;
197 ::typelib_typedescription_getByName( &pTD, unoName.pData );
198 assert(pTD &&
"### unknown exception type! leaving out destruction => leaking!!!");
201 ::uno_destructData( pExc, pTD, cpp_release );
202 ::typelib_typedescription_release( pTD );
208#if defined BRIDGES_DEBUG
211 OUString::unacquired( &pUnoExc->pType->pTypeName ),
212 RTL_TEXTENCODING_ASCII_US ) );
213 fprintf( stderr,
"> uno exception occurred: %s\n", cstr.getStr() );
221 TYPELIB_DANGER_GET( &pTypeDescr, pUnoExc->pType );
226 OUString(
"cannot get typedescription for type ") +
227 OUString::unacquired( &pUnoExc->pType->pTypeName ) );
231 ::uno_copyAndConvertData( pCppExc, pUnoExc->pData, pTypeDescr, pUno2Cpp );
234 ::uno_any_destruct( pUnoExc, 0 );
236 static RTTI rtti_data;
237 rtti = (type_info*)rtti_data.getRTTI((typelib_CompoundTypeDescription*)pTypeDescr);
238 TYPELIB_DANGER_RELEASE( pTypeDescr );
239 assert(rtti &&
"### no rtti for throwing exception!");
243 OUString(
"no rtti for type ") +
244 OUString::unacquired( &pUnoExc->pType->pTypeName ) );
266 OUString unoName(
toUNOname( exceptionType->name() ) );
267#if defined BRIDGES_DEBUG
269 fprintf( stderr,
"> c++ exception occurred: %s\n", cstr_unoName.getStr() );
272 if (0 == 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 SAL_WARN(area, stream)
struct _uno_Mapping uno_Mapping
struct _typelib_TypeDescription typelib_TypeDescription
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()