30#include <com/sun/star/uno/RuntimeException.hpp>
31#include <com/sun/star/uno/genfunc.h>
33#include <rtl/strbuf.hxx>
34#include <rtl/ustrbuf.hxx>
35#include <rtl/ustring.hxx>
37#include <typelib/typeclass.h>
38#include <typelib/typedescription.h>
40#include <uno/mapping.h>
43#include <osl/mutex.hxx>
44#include <unordered_map>
48OUString toUnoName(
char const *
name) {
49 assert(
name !=
nullptr);
51 bool scoped = *
name ==
'N';
56 assert(*
name >=
'0' && *
name <=
'9');
57 std::size_t
n = *
name++ -
'0';
58 while (*
name >=
'0' && *
name <=
'9') {
59 n = 10 *
n + (*
name++ -
'0');
61 b.appendAscii(
name,
n);
73 return b.makeStringAndClear();
78 Rtti(): app_(dlopen(nullptr, RTLD_LAZY)) {}
80 ~Rtti() { dlclose(app_); }
85 typedef std::unordered_map<OUString, std::type_info *> Map;
94 OUString unoName(
type.pTypeName);
95 osl::MutexGuard g(mutex_);
96 Map::iterator
i(
map_.find(unoName));
97 if (i ==
map_.end()) {
98 OStringBuffer b(
"_ZTIN");
99 for (sal_Int32 j = 0; j != -1;) {
103 b.append(OString::number(
t.getLength()) + t);
106 OString sym(b.makeStringAndClear());
107 std::type_info * rtti =
static_cast<std::type_info *
>(
108 dlsym(app_, sym.getStr()));
109 if (rtti ==
nullptr) {
110 char const * rttiName = strdup(sym.getStr() + std::strlen(
"_ZTI"));
111 if (rttiName ==
nullptr) {
112 throw std::bad_alloc();
118 rttiName =
reinterpret_cast<char const *
>(
119 reinterpret_cast<std::uintptr_t
>(rttiName) | 0x8000'0000'0000'0000);
121 assert(
type.eTypeClass == typelib_TypeClass_EXCEPTION);
122 typelib_CompoundTypeDescription
const & ctd
123 =
reinterpret_cast<typelib_CompoundTypeDescription
const &
>(
125 if (ctd.pBaseTypeDescription ==
nullptr) {
129 ctd.pBaseTypeDescription->aBase);
135 i =
map_.insert(Map::value_type(unoName, rtti)).first;
140struct theRttiFactory:
public rtl::Static<Rtti, theRttiFactory> {};
143 return theRttiFactory::get().getRtti(type);
149#if !defined MACOSX && defined _LIBCPPABI_VERSION
187 reinterpret_cast<char *
>(
header) - 8);
192 reinterpret_cast<char *
>(
header) + 8);
202 OUString unoName(toUnoName(
header->exceptionType->name()));
205 assert(td !=
nullptr);
218 for (sal_Int32 i = 0;
i !=
type->nMembers; ++
i) {
220 switch (
type->ppTypeRefs[i]->eTypeClass) {
221 case typelib_TypeClass_BOOLEAN:
222 case typelib_TypeClass_BYTE:
223 case typelib_TypeClass_SHORT:
224 case typelib_TypeClass_UNSIGNED_SHORT:
225 case typelib_TypeClass_LONG:
226 case typelib_TypeClass_UNSIGNED_LONG:
227 case typelib_TypeClass_HYPER:
228 case typelib_TypeClass_UNSIGNED_HYPER:
229 case typelib_TypeClass_CHAR:
230 case typelib_TypeClass_ENUM:
233 case typelib_TypeClass_FLOAT:
236 case typelib_TypeClass_DOUBLE:
239 case typelib_TypeClass_STRING:
240 case typelib_TypeClass_TYPE:
241 case typelib_TypeClass_ANY:
242 case typelib_TypeClass_SEQUENCE:
243 case typelib_TypeClass_INTERFACE:
246 case typelib_TypeClass_STRUCT:
249 TYPELIB_DANGER_GET(&td,
type->ppTypeRefs[i]);
251 reinterpret_cast<typelib_CompoundTypeDescription
const *
>(
253 TYPELIB_DANGER_RELEASE(td);
272 }
else if (k != k2) {
291 assert(exception !=
nullptr);
292 assert(
type !=
nullptr);
293 OUString unoName(toUnoName(
type->name()));
297 css::uno::RuntimeException e(
"exception type not found: " + unoName);
310 TYPELIB_DANGER_GET(&td,
any->pType);
312 throw css::uno::RuntimeException(
313 "no typedescription for " + OUString::unacquired(&
any->pType->pTypeName));
318 std::type_info * rtti =
getRtti(*td);
319 TYPELIB_DANGER_RELEASE(td);
324 switch (
type->eTypeClass) {
330 case typelib_TypeClass_VOID:
331 case typelib_TypeClass_BOOLEAN:
332 case typelib_TypeClass_BYTE:
333 case typelib_TypeClass_SHORT:
334 case typelib_TypeClass_UNSIGNED_SHORT:
335 case typelib_TypeClass_LONG:
336 case typelib_TypeClass_UNSIGNED_LONG:
337 case typelib_TypeClass_HYPER:
338 case typelib_TypeClass_UNSIGNED_HYPER:
339 case typelib_TypeClass_FLOAT:
340 case typelib_TypeClass_DOUBLE:
341 case typelib_TypeClass_CHAR:
342 case typelib_TypeClass_ENUM:
343 assert(
type->nSize <= 16);
345 case typelib_TypeClass_STRING:
346 case typelib_TypeClass_TYPE:
347 case typelib_TypeClass_ANY:
348 case typelib_TypeClass_SEQUENCE:
349 case typelib_TypeClass_INTERFACE:
351 case typelib_TypeClass_STRUCT:
352 if (
type->nSize > 16) {
356 reinterpret_cast<typelib_CompoundTypeDescription
const *
>(
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()
void SAL_CALL uno_any_destruct(uno_Any *pValue, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
void SAL_CALL uno_destructData(void *pValue, typelib_TypeDescription *pTypeDescr, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
void SAL_CALL uno_copyAndConvertData(void *pDest, void *pSource, typelib_TypeDescription *pTypeDescr, uno_Mapping *mapping) SAL_THROW_EXTERN_C()
#define _GLIBCXX_CDTOR_CALLABI
struct _uno_Mapping uno_Mapping
struct _typelib_TypeDescription typelib_TypeDescription
static StructKind getStructKind(typelib_CompoundTypeDescription const *type)
static void deleteException(void *pExc)
void __cxa_throw(void *thrown_exception, std::type_info *tinfo, void(*dest)(void *)) __attribute__((noreturn))
void * __cxa_allocate_exception(size_t thrown_size)
ReturnKind getReturnKind(typelib_TypeDescription const *type)
void raiseException(uno_Any *any, uno_Mapping *mapping)
void mapException(__cxxabiv1::__cxa_exception *exception, std::type_info const *type, uno_Any *any, uno_Mapping *mapping)
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
std::type_info * getRtti(typelib_TypeDescription const &type)
std::map< OUString, rtl::Reference< Entity > > const & map_
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()