diff options
Diffstat (limited to 'cppu/source/typelib/typelib.cxx')
-rw-r--r-- | cppu/source/typelib/typelib.cxx | 507 |
1 files changed, 242 insertions, 265 deletions
diff --git a/cppu/source/typelib/typelib.cxx b/cppu/source/typelib/typelib.cxx index 26875778c22b..e665b2b4273e 100644 --- a/cppu/source/typelib/typelib.cxx +++ b/cppu/source/typelib/typelib.cxx @@ -25,7 +25,6 @@ #include <set> #include <utility> #include <vector> -#include <memory> #include <stdlib.h> #include <string.h> @@ -33,13 +32,12 @@ #include <osl/interlck.h> #include <osl/mutex.hxx> #include <rtl/ustring.hxx> -#include <rtl/instance.hxx> #include <osl/diagnose.h> #include <typelib/typedescription.h> #include <uno/any2.h> +#include <o3tl/string_view.hxx> #include "typelib.hxx" -using namespace std; using namespace osl; #ifdef _WIN32 @@ -57,14 +55,7 @@ namespace { struct AlignSize_Impl { sal_Int16 nInt16; -#ifdef AIX - //double: doubleword aligned if -qalign=natural/-malign=natural - //which isn't the default ABI. Otherwise word aligned, While a long long int - //is always doubleword aligned, so use that instead. - sal_Int64 dDouble; -#else double dDouble; -#endif }; } @@ -158,12 +149,12 @@ struct hashStr_Impl typedef std::unordered_map< const sal_Unicode *, typelib_TypeDescriptionReference *, hashStr_Impl, equalStr_Impl > WeakMap_Impl; -typedef pair< void *, typelib_typedescription_Callback > CallbackEntry; -typedef list< CallbackEntry > CallbackSet_Impl; -typedef list< typelib_TypeDescription * > TypeDescriptionList_Impl; +typedef std::pair< void *, typelib_typedescription_Callback > CallbackEntry; +typedef std::list< CallbackEntry > CallbackSet_Impl; +typedef std::list< typelib_TypeDescription * > TypeDescriptionList_Impl; // # of cached elements -static sal_Int32 nCacheSize = 256; +constexpr auto nCacheSize = 256; namespace { @@ -274,14 +265,20 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl() SAL_INFO_IF( !maCallbacks.empty(), "cppu.typelib", "pCallbacks is not NULL or empty" ); }; -namespace { struct Init : public rtl::Static< TypeDescriptor_Init_Impl, Init > {}; } +namespace { +TypeDescriptor_Init_Impl& Init() +{ + static TypeDescriptor_Init_Impl SINGLETON; + return SINGLETON; +} +} extern "C" void SAL_CALL typelib_typedescription_registerCallback( void * pContext, typelib_typedescription_Callback pCallback ) SAL_THROW_EXTERN_C() { // todo mt safe: guard is no solution, can not acquire while calling callback! - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); // OslGuard aGuard( rInit.getMutex() ); rInit.maCallbacks.push_back( CallbackEntry( pContext, pCallback ) ); } @@ -291,13 +288,12 @@ extern "C" void SAL_CALL typelib_typedescription_revokeCallback( void * pContext, typelib_typedescription_Callback pCallback ) SAL_THROW_EXTERN_C() { - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); { // todo mt safe: guard is no solution, can not acquire while calling callback! // OslGuard aGuard( rInit.getMutex() ); CallbackEntry aEntry( pContext, pCallback ); - rInit.maCallbacks.erase(std::remove(rInit.maCallbacks.begin(), rInit.maCallbacks.end(), aEntry), - rInit.maCallbacks.end()); + std::erase(rInit.maCallbacks, aEntry); } } @@ -327,7 +323,7 @@ static void typelib_typedescription_initTables( } } - MutexGuard aGuard( Init::get().maMutex ); + MutexGuard aGuard( Init().maMutex ); if( pTD->bComplete ) return; @@ -388,84 +384,84 @@ void freeTypeDescription(typelib_TypeDescription const * desc) { // description. The parameter initTables controls whether or not to call // typelib_typedescription_initTables in those situations. bool complete(typelib_TypeDescription ** ppTypeDescr, bool initTables) { - if (! (*ppTypeDescr)->bComplete) + if ((*ppTypeDescr)->bComplete) + return true; + + OSL_ASSERT( (typelib_TypeClass_STRUCT == (*ppTypeDescr)->eTypeClass || + typelib_TypeClass_EXCEPTION == (*ppTypeDescr)->eTypeClass || + typelib_TypeClass_ENUM == (*ppTypeDescr)->eTypeClass || + typelib_TypeClass_INTERFACE == (*ppTypeDescr)->eTypeClass) && + !TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( (*ppTypeDescr)->eTypeClass ) ); + + if (typelib_TypeClass_INTERFACE == (*ppTypeDescr)->eTypeClass && + reinterpret_cast<typelib_InterfaceTypeDescription *>(*ppTypeDescr)->ppAllMembers) { - OSL_ASSERT( (typelib_TypeClass_STRUCT == (*ppTypeDescr)->eTypeClass || - typelib_TypeClass_EXCEPTION == (*ppTypeDescr)->eTypeClass || - typelib_TypeClass_ENUM == (*ppTypeDescr)->eTypeClass || - typelib_TypeClass_INTERFACE == (*ppTypeDescr)->eTypeClass) && - !TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( (*ppTypeDescr)->eTypeClass ) ); - - if (typelib_TypeClass_INTERFACE == (*ppTypeDescr)->eTypeClass && - reinterpret_cast<typelib_InterfaceTypeDescription *>(*ppTypeDescr)->ppAllMembers) - { - if (initTables) { - typelib_typedescription_initTables( *ppTypeDescr ); - } - return true; + if (initTables) { + typelib_typedescription_initTables( *ppTypeDescr ); } + return true; + } - typelib_TypeDescription * pTD = nullptr; - // on demand access of complete td - TypeDescriptor_Init_Impl &rInit = Init::get(); - rInit.callChain( &pTD, (*ppTypeDescr)->pTypeName ); - if (pTD) + typelib_TypeDescription * pTD = nullptr; + // on demand access of complete td + TypeDescriptor_Init_Impl &rInit = Init(); + rInit.callChain( &pTD, (*ppTypeDescr)->pTypeName ); + if (pTD) + { + if (typelib_TypeClass_TYPEDEF == pTD->eTypeClass) { - if (typelib_TypeClass_TYPEDEF == pTD->eTypeClass) - { - typelib_typedescriptionreference_getDescription( - &pTD, reinterpret_cast<typelib_IndirectTypeDescription *>(pTD)->pType ); - OSL_ASSERT( pTD ); - if (! pTD) - return false; - } - - OSL_ASSERT( typelib_TypeClass_TYPEDEF != pTD->eTypeClass ); - // typedescription found - // set to on demand - pTD->bOnDemand = true; - - if (pTD->eTypeClass == typelib_TypeClass_INTERFACE - && !pTD->bComplete && initTables) - { - // mandatory info from callback chain - OSL_ASSERT( reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD)->ppAllMembers ); - // complete except of tables init - typelib_typedescription_initTables( pTD ); - pTD->bComplete = true; - } + typelib_typedescriptionreference_getDescription( + &pTD, reinterpret_cast<typelib_IndirectTypeDescription *>(pTD)->pType ); + OSL_ASSERT( pTD ); + if (! pTD) + return false; + } - // The type description is hold by the reference until - // on demand is activated. - ::typelib_typedescription_register( &pTD ); // replaces incomplete one - OSL_ASSERT( pTD == *ppTypeDescr ); // has to merge into existing one + OSL_ASSERT( typelib_TypeClass_TYPEDEF != pTD->eTypeClass ); + // typedescription found + // set to on demand + pTD->bOnDemand = true; - // insert into the cache - MutexGuard aGuard( rInit.maMutex ); - if( static_cast<sal_Int32>(rInit.maCache.size()) >= nCacheSize ) - { - typelib_typedescription_release( rInit.maCache.front() ); - rInit.maCache.pop_front(); - } - // descriptions in the cache must be acquired! - typelib_typedescription_acquire( pTD ); - rInit.maCache.push_back( pTD ); + if (pTD->eTypeClass == typelib_TypeClass_INTERFACE + && !pTD->bComplete && initTables) + { + // mandatory info from callback chain + OSL_ASSERT( reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD)->ppAllMembers ); + // complete except of tables init + typelib_typedescription_initTables( pTD ); + pTD->bComplete = true; + } - OSL_ASSERT( - pTD->bComplete - || (pTD->eTypeClass == typelib_TypeClass_INTERFACE - && !initTables)); + // The type description is hold by the reference until + // on demand is activated. + ::typelib_typedescription_register( &pTD ); // replaces incomplete one + OSL_ASSERT( pTD == *ppTypeDescr ); // has to merge into existing one - ::typelib_typedescription_release( *ppTypeDescr ); - *ppTypeDescr = pTD; - } - else + // insert into the cache + MutexGuard aGuard( rInit.maMutex ); + if( rInit.maCache.size() >= nCacheSize ) { - SAL_INFO( - "cppu.typelib", - "type cannot be completed: " << OUString::unacquired(&(*ppTypeDescr)->pTypeName)); - return false; + typelib_typedescription_release( rInit.maCache.front() ); + rInit.maCache.pop_front(); } + // descriptions in the cache must be acquired! + typelib_typedescription_acquire( pTD ); + rInit.maCache.push_back( pTD ); + + OSL_ASSERT( + pTD->bComplete + || (pTD->eTypeClass == typelib_TypeClass_INTERFACE + && !initTables)); + + ::typelib_typedescription_release( *ppTypeDescr ); + *ppTypeDescr = pTD; + } + else + { + SAL_INFO( + "cppu.typelib", + "type cannot be completed: " << OUString::unacquired(&(*ppTypeDescr)->pTypeName)); + return false; } return true; } @@ -494,7 +490,7 @@ extern "C" void typelib_typedescription_newEmpty( auto pTmp = allocTypeDescription<typelib_IndirectTypeDescription>(); pRet = &pTmp->aBase; #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nIndirectTypeDescriptionCount ); + osl_atomic_increment( &Init().nIndirectTypeDescriptionCount ); #endif pTmp->pType = nullptr; // coverity[leaked_storage] - this is on purpose @@ -507,7 +503,7 @@ extern "C" void typelib_typedescription_newEmpty( auto pTmp = allocTypeDescription<typelib_StructTypeDescription>(); pRet = &pTmp->aBase.aBase; #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nCompoundTypeDescriptionCount ); + osl_atomic_increment( &Init().nCompoundTypeDescriptionCount ); #endif pTmp->aBase.pBaseTypeDescription = nullptr; pTmp->aBase.nMembers = 0; @@ -525,7 +521,7 @@ extern "C" void typelib_typedescription_newEmpty( auto pTmp = allocTypeDescription<typelib_CompoundTypeDescription>(); pRet = &pTmp->aBase; #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nCompoundTypeDescriptionCount ); + osl_atomic_increment( &Init().nCompoundTypeDescriptionCount ); #endif pTmp->pBaseTypeDescription = nullptr; pTmp->nMembers = 0; @@ -541,7 +537,7 @@ extern "C" void typelib_typedescription_newEmpty( auto pTmp = allocTypeDescription<typelib_EnumTypeDescription>(); pRet = &pTmp->aBase; #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nEnumTypeDescriptionCount ); + osl_atomic_increment( &Init().nEnumTypeDescriptionCount ); #endif pTmp->nDefaultEnumValue = 0; pTmp->nEnumValues = 0; @@ -557,7 +553,7 @@ extern "C" void typelib_typedescription_newEmpty( typelib_InterfaceTypeDescription>(); pRet = &pTmp->aBase; #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nInterfaceTypeDescriptionCount ); + osl_atomic_increment( &Init().nInterfaceTypeDescriptionCount ); #endif pTmp->pBaseTypeDescription = nullptr; pTmp->nMembers = 0; @@ -579,7 +575,7 @@ extern "C" void typelib_typedescription_newEmpty( typelib_InterfaceMethodTypeDescription>(); pRet = &pTmp->aBase.aBase; #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nInterfaceMethodTypeDescriptionCount ); + osl_atomic_increment( &Init().nInterfaceMethodTypeDescriptionCount ); #endif pTmp->aBase.pMemberName = nullptr; pTmp->pReturnTypeRef = nullptr; @@ -600,7 +596,7 @@ extern "C" void typelib_typedescription_newEmpty( typelib_InterfaceAttributeTypeDescription>(); pRet = &pTmp->aBase.aBase; #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nInterfaceAttributeTypeDescriptionCount ); + osl_atomic_increment( &Init().nInterfaceAttributeTypeDescriptionCount ); #endif pTmp->aBase.pMemberName = nullptr; pTmp->pAttributeTypeRef = nullptr; @@ -619,7 +615,7 @@ extern "C" void typelib_typedescription_newEmpty( { pRet = allocTypeDescription<typelib_TypeDescription>(); #if OSL_DEBUG_LEVEL > 0 - osl_atomic_increment( &Init::get().nTypeDescriptionCount ); + osl_atomic_increment( &Init().nTypeDescriptionCount ); #endif } } @@ -863,11 +859,11 @@ private: typedef std::set< OUString > Set; void calculate( + Set& allSet, sal_Int32 directBaseIndex, Set & directBaseSet, sal_Int32 * directBaseMembers, typelib_InterfaceTypeDescription const * desc); - Set set; List list; sal_Int32 members; }; @@ -875,24 +871,26 @@ private: BaseList::BaseList(typelib_InterfaceTypeDescription const * desc) : members(0) { + Set allSet; for (sal_Int32 i = 0; i < desc->nBaseTypes; ++i) { Set directBaseSet; sal_Int32 directBaseMembers = 0; - calculate(i, directBaseSet, &directBaseMembers, desc->ppBaseTypes[i]); + calculate(allSet, i, directBaseSet, &directBaseMembers, desc->ppBaseTypes[i]); } } void BaseList::calculate( + Set& allSet, sal_Int32 directBaseIndex, Set & directBaseSet, sal_Int32 * directBaseMembers, typelib_InterfaceTypeDescription const * desc) { for (sal_Int32 i = 0; i < desc->nBaseTypes; ++i) { - calculate( + calculate(allSet, directBaseIndex, directBaseSet, directBaseMembers, desc->ppBaseTypes[i]); } - if (set.insert(desc->aBase.pTypeName).second) { + if (allSet.insert(desc->aBase.pTypeName).second) { Entry e; e.memberOffset = members; e.directBaseIndex = directBaseIndex; @@ -1332,7 +1330,7 @@ extern "C" void SAL_CALL typelib_typedescription_release( if (0 != ref) return; - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); if( TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK( pTD->eTypeClass ) ) { if( pTD->pWeakRef ) @@ -1396,7 +1394,7 @@ extern "C" void SAL_CALL typelib_typedescription_register( SAL_THROW_EXTERN_C() { // connect the description with the weak reference - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); ClearableMutexGuard aGuard( rInit.maMutex ); typelib_TypeDescriptionReference * pTDR = nullptr; @@ -1655,7 +1653,7 @@ extern "C" sal_Int32 typelib_typedescription_getAlignedUnoSize( // inherit structs extends the base struct. nStructSize = pTmp->pBaseTypeDescription->aBase.nSize; rMaxIntegralTypeSize = pTmp->pBaseTypeDescription->aBase.nAlignment; - } + } for( sal_Int32 i = 0; i < pTmp->nMembers; i++ ) { typelib_TypeDescription * pMemberType = nullptr; @@ -1718,13 +1716,7 @@ extern "C" sal_Int32 typelib_typedescription_getAlignedUnoSize( nSize = rMaxIntegralTypeSize = sal_Int32(sizeof( float )); break; case typelib_TypeClass_DOUBLE: -#ifdef AIX - //See previous AIX ifdef comment for an explanation - nSize = (sal_Int32)(sizeof(double)); - rMaxIntegralTypeSize = (sal_Int32)(sizeof(void*)); -#else nSize = rMaxIntegralTypeSize = sal_Int32(sizeof( double )); -#endif break; case typelib_TypeClass_BYTE: nSize = rMaxIntegralTypeSize = sal_Int32(sizeof( sal_Int8 )); @@ -1773,90 +1765,91 @@ bool createDerivedInterfaceMemberDescription( typelib_TypeDescription const * base, typelib_TypeDescription * interface, sal_Int32 index, sal_Int32 position) { - if (baseRef != nullptr && base != nullptr && interface != nullptr) { - switch (base->eTypeClass) { - case typelib_TypeClass_INTERFACE_METHOD: - { - typelib_typedescription_newEmpty( - result, typelib_TypeClass_INTERFACE_METHOD, name.pData); - typelib_InterfaceMethodTypeDescription const * baseMethod - = reinterpret_cast< - typelib_InterfaceMethodTypeDescription const * >(base); - typelib_InterfaceMethodTypeDescription * newMethod - = reinterpret_cast< - typelib_InterfaceMethodTypeDescription * >(*result); - newMethod->aBase.nPosition = position; - newMethod->aBase.pMemberName - = baseMethod->aBase.pMemberName; + if (!baseRef || !base || !interface) + return false; + + switch (base->eTypeClass) { + case typelib_TypeClass_INTERFACE_METHOD: + { + typelib_typedescription_newEmpty( + result, typelib_TypeClass_INTERFACE_METHOD, name.pData); + typelib_InterfaceMethodTypeDescription const * baseMethod + = reinterpret_cast< + typelib_InterfaceMethodTypeDescription const * >(base); + typelib_InterfaceMethodTypeDescription * newMethod + = reinterpret_cast< + typelib_InterfaceMethodTypeDescription * >(*result); + newMethod->aBase.nPosition = position; + newMethod->aBase.pMemberName + = baseMethod->aBase.pMemberName; + rtl_uString_acquire( + newMethod->aBase.pMemberName); + newMethod->pReturnTypeRef = baseMethod->pReturnTypeRef; + typelib_typedescriptionreference_acquire( + newMethod->pReturnTypeRef); + newMethod->nParams = baseMethod->nParams; + newMethod->pParams = new typelib_MethodParameter[ + newMethod->nParams]; + for (sal_Int32 i = 0; i < newMethod->nParams; ++i) { + newMethod->pParams[i].pName + = baseMethod->pParams[i].pName; rtl_uString_acquire( - newMethod->aBase.pMemberName); - newMethod->pReturnTypeRef = baseMethod->pReturnTypeRef; + newMethod->pParams[i].pName); + newMethod->pParams[i].pTypeRef + = baseMethod->pParams[i].pTypeRef; typelib_typedescriptionreference_acquire( - newMethod->pReturnTypeRef); - newMethod->nParams = baseMethod->nParams; - newMethod->pParams = new typelib_MethodParameter[ - newMethod->nParams]; - for (sal_Int32 i = 0; i < newMethod->nParams; ++i) { - newMethod->pParams[i].pName - = baseMethod->pParams[i].pName; - rtl_uString_acquire( - newMethod->pParams[i].pName); - newMethod->pParams[i].pTypeRef - = baseMethod->pParams[i].pTypeRef; - typelib_typedescriptionreference_acquire( - newMethod->pParams[i].pTypeRef); - newMethod->pParams[i].bIn = baseMethod->pParams[i].bIn; - newMethod->pParams[i].bOut = baseMethod->pParams[i].bOut; - } - newMethod->nExceptions = baseMethod->nExceptions; - newMethod->ppExceptions = copyExceptions( - baseMethod->nExceptions, baseMethod->ppExceptions); - newMethod->bOneWay = baseMethod->bOneWay; - newMethod->pInterface - = reinterpret_cast< typelib_InterfaceTypeDescription * >( - interface); - newMethod->pBaseRef = baseRef; - newMethod->nIndex = index; - return true; - } - - case typelib_TypeClass_INTERFACE_ATTRIBUTE: - { - typelib_typedescription_newEmpty( - result, typelib_TypeClass_INTERFACE_ATTRIBUTE, name.pData); - typelib_InterfaceAttributeTypeDescription const * baseAttribute - = reinterpret_cast< - typelib_InterfaceAttributeTypeDescription const * >(base); - typelib_InterfaceAttributeTypeDescription * newAttribute - = reinterpret_cast< - typelib_InterfaceAttributeTypeDescription * >(*result); - newAttribute->aBase.nPosition = position; - newAttribute->aBase.pMemberName - = baseAttribute->aBase.pMemberName; - rtl_uString_acquire(newAttribute->aBase.pMemberName); - newAttribute->bReadOnly = baseAttribute->bReadOnly; - newAttribute->pAttributeTypeRef - = baseAttribute->pAttributeTypeRef; - typelib_typedescriptionreference_acquire(newAttribute->pAttributeTypeRef); - newAttribute->pInterface - = reinterpret_cast< typelib_InterfaceTypeDescription * >( - interface); - newAttribute->pBaseRef = baseRef; - newAttribute->nIndex = index; - newAttribute->nGetExceptions = baseAttribute->nGetExceptions; - newAttribute->ppGetExceptions = copyExceptions( - baseAttribute->nGetExceptions, - baseAttribute->ppGetExceptions); - newAttribute->nSetExceptions = baseAttribute->nSetExceptions; - newAttribute->ppSetExceptions = copyExceptions( - baseAttribute->nSetExceptions, - baseAttribute->ppSetExceptions); - return true; + newMethod->pParams[i].pTypeRef); + newMethod->pParams[i].bIn = baseMethod->pParams[i].bIn; + newMethod->pParams[i].bOut = baseMethod->pParams[i].bOut; } + newMethod->nExceptions = baseMethod->nExceptions; + newMethod->ppExceptions = copyExceptions( + baseMethod->nExceptions, baseMethod->ppExceptions); + newMethod->bOneWay = baseMethod->bOneWay; + newMethod->pInterface + = reinterpret_cast< typelib_InterfaceTypeDescription * >( + interface); + newMethod->pBaseRef = baseRef; + newMethod->nIndex = index; + return true; + } - default: - break; + case typelib_TypeClass_INTERFACE_ATTRIBUTE: + { + typelib_typedescription_newEmpty( + result, typelib_TypeClass_INTERFACE_ATTRIBUTE, name.pData); + typelib_InterfaceAttributeTypeDescription const * baseAttribute + = reinterpret_cast< + typelib_InterfaceAttributeTypeDescription const * >(base); + typelib_InterfaceAttributeTypeDescription * newAttribute + = reinterpret_cast< + typelib_InterfaceAttributeTypeDescription * >(*result); + newAttribute->aBase.nPosition = position; + newAttribute->aBase.pMemberName + = baseAttribute->aBase.pMemberName; + rtl_uString_acquire(newAttribute->aBase.pMemberName); + newAttribute->bReadOnly = baseAttribute->bReadOnly; + newAttribute->pAttributeTypeRef + = baseAttribute->pAttributeTypeRef; + typelib_typedescriptionreference_acquire(newAttribute->pAttributeTypeRef); + newAttribute->pInterface + = reinterpret_cast< typelib_InterfaceTypeDescription * >( + interface); + newAttribute->pBaseRef = baseRef; + newAttribute->nIndex = index; + newAttribute->nGetExceptions = baseAttribute->nGetExceptions; + newAttribute->ppGetExceptions = copyExceptions( + baseAttribute->nGetExceptions, + baseAttribute->ppGetExceptions); + newAttribute->nSetExceptions = baseAttribute->nSetExceptions; + newAttribute->ppSetExceptions = copyExceptions( + baseAttribute->nSetExceptions, + baseAttribute->ppSetExceptions); + return true; } + + default: + break; } return false; } @@ -1874,7 +1867,7 @@ extern "C" void SAL_CALL typelib_typedescription_getByName( } static bool bInited = false; - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); if( !bInited ) { @@ -1978,8 +1971,8 @@ extern "C" void SAL_CALL typelib_typedescription_getByName( &pInterface, name.copy(i4 + 1).pData); if (!createDerivedInterfaceMemberDescription( ppRet, name, pBaseRef, pBase, pInterface, - name.copy(i2, i3 - i2).toInt32(), - name.copy(i3 + 1, i4 - i3 - 1).toInt32())) + o3tl::toInt32(name.subView(i2, i3 - i2)), + o3tl::toInt32(name.subView(i3 + 1, i4 - i3 - 1)))) { if (pInterface != nullptr) { typelib_typedescription_release(pInterface); @@ -2024,7 +2017,7 @@ extern "C" void SAL_CALL typelib_typedescription_getByName( // insert into the cache MutexGuard aGuard( rInit.maMutex ); - if( static_cast<sal_Int32>(rInit.maCache.size()) >= nCacheSize ) + if( rInit.maCache.size() >= nCacheSize ) { typelib_typedescription_release( rInit.maCache.front() ); rInit.maCache.pop_front(); @@ -2050,7 +2043,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new( typelib_TypeClass eTypeClass, rtl_uString * pTypeName ) SAL_THROW_EXTERN_C() { - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); if( eTypeClass == typelib_TypeClass_TYPEDEF ) { // on demand access @@ -2078,7 +2071,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new( // insert into the cache MutexGuard aGuard( rInit.maMutex ); - if( static_cast<sal_Int32>(rInit.maCache.size()) >= nCacheSize ) + if( rInit.maCache.size() >= nCacheSize ) { typelib_typedescription_release( rInit.maCache.front() ); rInit.maCache.pop_front(); @@ -2153,7 +2146,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_release( { if( ! osl_atomic_decrement( &pRef->nRefCount ) ) { - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); MutexGuard aGuard( rInit.maMutex ); WeakMap_Impl::iterator aIt = rInit.maWeakMap.find( pRef->pTypeName->buffer ); if( aIt != rInit.maWeakMap.end() && (*aIt).second == pRef ) @@ -2196,7 +2189,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_getDescription( } { - MutexGuard aGuard( Init::get().maMutex ); + MutexGuard aGuard( Init().maMutex ); // pRef->pType->pWeakRef == 0 means that the description is empty if( pRef->pType && pRef->pType->pWeakRef ) { @@ -2232,7 +2225,7 @@ extern "C" void typelib_typedescriptionreference_getByName( typelib_typedescriptionreference_release( *ppRet ); *ppRet = nullptr; } - TypeDescriptor_Init_Impl &rInit = Init::get(); + TypeDescriptor_Init_Impl &rInit = Init(); MutexGuard aGuard( rInit.maMutex ); WeakMap_Impl::const_iterator aIt = rInit.maWeakMap.find( pName->buffer ); @@ -2281,24 +2274,9 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_assign( } -extern "C" void SAL_CALL typelib_setCacheSize( sal_Int32 nNewSize ) +extern "C" void SAL_CALL typelib_setCacheSize( sal_Int32 ) SAL_THROW_EXTERN_C() { - OSL_ENSURE( nNewSize >= 0, "### illegal cache size given!" ); - if (nNewSize < 0) - return; - - TypeDescriptor_Init_Impl &rInit = Init::get(); - MutexGuard aGuard( rInit.maMutex ); - if (nNewSize < nCacheSize) - { - while (static_cast<sal_Int32>(rInit.maCache.size()) != nNewSize) - { - typelib_typedescription_release( rInit.maCache.front() ); - rInit.maCache.pop_front(); - } - } - nCacheSize = nNewSize; } @@ -2324,68 +2302,67 @@ extern "C" sal_Bool SAL_CALL typelib_typedescriptionreference_isAssignableFrom( typelib_TypeDescriptionReference * pFrom ) SAL_THROW_EXTERN_C() { - if (pAssignable && pFrom) - { - typelib_TypeClass eAssignable = pAssignable->eTypeClass; - typelib_TypeClass eFrom = pFrom->eTypeClass; + if (!pAssignable || !pFrom) + return false; + + typelib_TypeClass eAssignable = pAssignable->eTypeClass; + typelib_TypeClass eFrom = pFrom->eTypeClass; - if (eAssignable == typelib_TypeClass_ANY) // anything can be assigned to an any .) + if (eAssignable == typelib_TypeClass_ANY) // anything can be assigned to an any .) + return true; + if (eAssignable == eFrom) + { + if (type_equals( pAssignable, pFrom )) // first shot + { return true; - if (eAssignable == eFrom) + } + switch (eAssignable) { - if (type_equals( pAssignable, pFrom )) // first shot - { - return true; - } - switch (eAssignable) - { - case typelib_TypeClass_STRUCT: - case typelib_TypeClass_EXCEPTION: - { - typelib_TypeDescription * pFromDescr = nullptr; - TYPELIB_DANGER_GET( &pFromDescr, pFrom ); - if (!reinterpret_cast<typelib_CompoundTypeDescription *>(pFromDescr)->pBaseTypeDescription) - { - TYPELIB_DANGER_RELEASE( pFromDescr ); - return false; - } - bool bRet = typelib_typedescriptionreference_isAssignableFrom( - pAssignable, - reinterpret_cast<typelib_CompoundTypeDescription *>(pFromDescr)->pBaseTypeDescription->aBase.pWeakRef ); - TYPELIB_DANGER_RELEASE( pFromDescr ); - return bRet; - } - case typelib_TypeClass_INTERFACE: + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + { + typelib_TypeDescription * pFromDescr = nullptr; + TYPELIB_DANGER_GET( &pFromDescr, pFrom ); + if (!reinterpret_cast<typelib_CompoundTypeDescription *>(pFromDescr)->pBaseTypeDescription) { - typelib_TypeDescription * pFromDescr = nullptr; - TYPELIB_DANGER_GET( &pFromDescr, pFrom ); - typelib_InterfaceTypeDescription * pFromIfc - = reinterpret_cast< - typelib_InterfaceTypeDescription * >(pFromDescr); - bool bRet = false; - for (sal_Int32 i = 0; i < pFromIfc->nBaseTypes; ++i) { - if (typelib_typedescriptionreference_isAssignableFrom( - pAssignable, - pFromIfc->ppBaseTypes[i]->aBase.pWeakRef)) - { - bRet = true; - break; - } - } TYPELIB_DANGER_RELEASE( pFromDescr ); - return bRet; - } - default: - { return false; } + bool bRet = typelib_typedescriptionreference_isAssignableFrom( + pAssignable, + reinterpret_cast<typelib_CompoundTypeDescription *>(pFromDescr)->pBaseTypeDescription->aBase.pWeakRef ); + TYPELIB_DANGER_RELEASE( pFromDescr ); + return bRet; + } + case typelib_TypeClass_INTERFACE: + { + typelib_TypeDescription * pFromDescr = nullptr; + TYPELIB_DANGER_GET( &pFromDescr, pFrom ); + typelib_InterfaceTypeDescription * pFromIfc + = reinterpret_cast< + typelib_InterfaceTypeDescription * >(pFromDescr); + bool bRet = false; + for (sal_Int32 i = 0; i < pFromIfc->nBaseTypes; ++i) { + if (typelib_typedescriptionreference_isAssignableFrom( + pAssignable, + pFromIfc->ppBaseTypes[i]->aBase.pWeakRef)) + { + bRet = true; + break; + } } + TYPELIB_DANGER_RELEASE( pFromDescr ); + return bRet; + } + default: + { + return false; + } } - return (eAssignable >= typelib_TypeClass_CHAR && eAssignable <= typelib_TypeClass_DOUBLE && - eFrom >= typelib_TypeClass_CHAR && eFrom <= typelib_TypeClass_DOUBLE && - s_aAssignableFromTab[eAssignable-1][eFrom-1]); } - return false; + return (eAssignable >= typelib_TypeClass_CHAR && eAssignable <= typelib_TypeClass_DOUBLE && + eFrom >= typelib_TypeClass_CHAR && eFrom <= typelib_TypeClass_DOUBLE && + s_aAssignableFromTab[eAssignable-1][eFrom-1]); } extern "C" sal_Bool SAL_CALL typelib_typedescription_isAssignableFrom( |