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 );
 
  122        long n = (*
p++ - 
'0');
 
  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();
 
  146    typedef std::unordered_map< OUString, std::type_info *, OUStringHash > 
t_rtti_map;
 
  158    std::type_info * 
getRTTI( typelib_CompoundTypeDescription * );
 
  162    : 
m_hApp( dlopen( nullptr, RTLD_LAZY ) )
 
  172std::type_info * 
RTTI::getRTTI( typelib_CompoundTypeDescription *pTypeDescr )
 
  174    std::type_info * rtti;
 
  176    OUString 
const & unoName = OUString::unacquired(&pTypeDescr->aBase.pTypeName);
 
  179    t_rtti_map::const_iterator iFind( 
m_rttis.find( unoName ) );
 
  183        OStringBuffer buf( 64 );
 
  184        buf.append( 
"_ZTIN" );
 
  188            OUString token( unoName.getToken( 0, 
'.', 
index ) );
 
  189            buf.append( token.getLength() );
 
  191            buf.append( c_token );
 
  196        OString symName( buf.makeStringAndClear() );
 
  197        rtti = 
static_cast<std::type_info *
>(dlsym( 
m_hApp, symName.getStr() ));
 
  201            std::pair< t_rtti_map::iterator, bool > insertion(
 
  202                m_rttis.insert( t_rtti_map::value_type( unoName, rtti ) ) );
 
  205                         "inserting new rtti failed" );
 
  216                char * rttiName = strdup(symName.getStr() + 4);
 
  217                if (rttiName == 
nullptr) {
 
  218                    throw std::bad_alloc();
 
  220#if OSL_DEBUG_LEVEL > 1 
  221                fprintf( stderr,
"generated rtti for %s\n", rttiName );
 
  223                if (pTypeDescr->pBaseTypeDescription)
 
  226                    std::type_info * base_rtti = 
getRTTI(
 
  227                        pTypeDescr->pBaseTypeDescription );
 
  228                    rtti = createFake_si_class_type_info(rttiName, base_rtti);
 
  232                    rtti = createFake_class_type_info(rttiName);
 
  235                std::pair< t_rtti_map::iterator, bool > insertion(
 
  239                             "inserting new generated rtti failed" );
 
  243                rtti = iFind2->second;
 
  249        rtti = iFind->second;
 
  280            reinterpret_cast<char const *
>(
header) - 8);
 
  285    ::typelib_typedescription_getByName( &pTD, unoName.pData );
 
  286    assert(pTD && 
"### unknown exception type! leaving out destruction => leaking!!!");
 
  289        ::uno_destructData( pExc, pTD, cpp_release );
 
  290        ::typelib_typedescription_release( pTD );
 
  296#if OSL_DEBUG_LEVEL > 1 
  299            OUString::unacquired( &pUnoExc->pType->pTypeName ),
 
  300            RTL_TEXTENCODING_ASCII_US ) );
 
  301    fprintf( stderr, 
"> uno exception occurred: %s\n", cstr.getStr() );
 
  304    std::type_info * rtti;
 
  309    TYPELIB_DANGER_GET( &pTypeDescr, pUnoExc->pType );
 
  314            "cannot get typedescription for type " +
 
  315            OUString::unacquired( &pUnoExc->pType->pTypeName ) );
 
  319    ::uno_copyAndConvertData( pCppExc, pUnoExc->pData, pTypeDescr, pUno2Cpp );
 
  322    ::uno_any_destruct( pUnoExc, 
nullptr );
 
  324    static RTTI rtti_data;
 
  325    rtti = rtti_data.
getRTTI(
reinterpret_cast<typelib_CompoundTypeDescription*
>(pTypeDescr));
 
  326    TYPELIB_DANGER_RELEASE( pTypeDescr );
 
  327    assert(rtti && 
"### no rtti for throwing exception!");
 
  331            "no rtti for type " +
 
  332            OUString::unacquired( &pUnoExc->pType->pTypeName ) );
 
  376    if (*
reinterpret_cast<void **
>(
header) == 
nullptr) {
 
  383    OUString unoName( 
toUNOname( exceptionType->name() ) );
 
  384#if OSL_DEBUG_LEVEL > 1 
  386    fprintf( stderr, 
"> c++ exception occurred: %s\n", cstr_unoName.getStr() );
 
  389    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_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)
 
__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()