diff options
Diffstat (limited to 'cppuhelper/source')
27 files changed, 906 insertions, 747 deletions
diff --git a/cppuhelper/source/access_control.cxx b/cppuhelper/source/access_control.cxx index 0e18ef78684a..09001b7fda0e 100644 --- a/cppuhelper/source/access_control.cxx +++ b/cppuhelper/source/access_control.cxx @@ -26,26 +26,19 @@ #include <com/sun/star/connection/SocketPermission.hpp> #include <com/sun/star/uno/XComponentContext.hpp> -using namespace ::osl; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; -namespace -{ - OUString str_ac_singleton() - { - return "/singletons/com.sun.star.security.theAccessController"; - } -} +constexpr OUStringLiteral ACCESS_CONTROLLER_SINGLETON = u"/singletons/com.sun.star.security.theAccessController"; namespace cppu { AccessControl::AccessControl( Reference< XComponentContext > const & xContext ) { - if (! (xContext->getValueByName( str_ac_singleton() ) >>= m_xController)) + if (! (xContext->getValueByName( ACCESS_CONTROLLER_SINGLETON ) >>= m_xController)) { - throw SecurityException( "no access controller!" ); + throw SecurityException( u"no access controller!"_ustr ); } } @@ -55,7 +48,7 @@ AccessControl::AccessControl( { if (! m_xController.is()) { - throw SecurityException( "no access controller!" ); + throw SecurityException( u"no access controller!"_ustr ); } } @@ -64,7 +57,7 @@ AccessControl::AccessControl( AccessControl const & ac ) { if (! m_xController.is()) { - throw SecurityException( "no access controller!" ); + throw SecurityException( u"no access controller!"_ustr ); } } diff --git a/cppuhelper/source/bootstrap.cxx b/cppuhelper/source/bootstrap.cxx index 34ae38823bec..a6387c1ff1aa 100644 --- a/cppuhelper/source/bootstrap.cxx +++ b/cppuhelper/source/bootstrap.cxx @@ -21,6 +21,7 @@ #include <chrono> #include <cstring> +#include <thread> #include <rtl/bootstrap.hxx> #include <rtl/random.h> @@ -89,7 +90,7 @@ Reference< XComponentContext > SAL_CALL bootstrap() auto* p1 = cppuhelper_detail_findSofficePath(); if (p1 == nullptr) { throw BootstrapException( - "no soffice installation found!"); + u"no soffice installation found!"_ustr); } OUString p2; #if defined(_WIN32) @@ -105,7 +106,7 @@ Reference< XComponentContext > SAL_CALL bootstrap() if (!bOk) { throw BootstrapException( - "bad characters in soffice installation path!"); + u"bad characters in soffice installation path!"_ustr); } #endif OUString path; @@ -113,16 +114,16 @@ Reference< XComponentContext > SAL_CALL bootstrap() osl::FileBase::E_None) { throw BootstrapException( - "cannot convert soffice installation path to URL!"); + u"cannot convert soffice installation path to URL!"_ustr); } if (!path.isEmpty() && !path.endsWith("/")) { path += "/"; } OUString uri; - if (!Bootstrap::get("URE_BOOTSTRAP", uri)) { + if (!Bootstrap::get(u"URE_BOOTSTRAP"_ustr, uri)) { Bootstrap::set( - "URE_BOOTSTRAP", + u"URE_BOOTSTRAP"_ustr, Bootstrap::encode( path + #if defined MACOSX @@ -135,16 +136,16 @@ Reference< XComponentContext > SAL_CALL bootstrap() Reference< XComponentContext > xLocalContext( defaultBootstrap_InitialComponentContext() ); if ( !xLocalContext.is() ) - throw BootstrapException( "no local component context!" ); + throw BootstrapException( u"no local component context!"_ustr ); // create a random pipe name rtlRandomPool hPool = rtl_random_createPool(); if ( hPool == nullptr ) - throw BootstrapException( "cannot create random pool!" ); + throw BootstrapException( u"cannot create random pool!"_ustr ); sal_uInt8 bytes[ 16 ]; - if ( rtl_random_getBytes( hPool, bytes, SAL_N_ELEMENTS( bytes ) ) + if ( rtl_random_getBytes( hPool, bytes, std::size( bytes ) ) != rtl_Random_E_None ) - throw BootstrapException( "random pool error!" ); + throw BootstrapException( u"random pool error!"_ustr ); rtl_random_destroyPool( hPool ); OUStringBuffer buf("uno"); for (unsigned char byte : bytes) @@ -153,10 +154,10 @@ Reference< XComponentContext > SAL_CALL bootstrap() // arguments OUString args [] = { - OUString("--nologo"), - OUString("--nodefault"), - OUString("--norestore"), - OUString("--nolockcheck"), + u"--nologo"_ustr, + u"--nodefault"_ustr, + u"--norestore"_ustr, + u"--nolockcheck"_ustr, OUString("--accept=pipe,name=" + sPipeName + ";urp;") }; rtl_uString * ar_args [] = { @@ -171,7 +172,7 @@ Reference< XComponentContext > SAL_CALL bootstrap() // start office process oslProcess hProcess = nullptr; oslProcessError rc = osl_executeProcess( - OUString(path + "soffice").pData, ar_args, SAL_N_ELEMENTS( ar_args ), + OUString(path + "soffice").pData, ar_args, std::size( ar_args ), osl_Process_DETACHED, sec.getHandle(), nullptr, // => current working dir @@ -183,16 +184,16 @@ Reference< XComponentContext > SAL_CALL bootstrap() osl_freeProcessHandle( hProcess ); break; case osl_Process_E_NotFound: - throw BootstrapException( "image not found!" ); + throw BootstrapException( u"image not found!"_ustr ); case osl_Process_E_TimedOut: - throw BootstrapException( "timeout occurred!" ); + throw BootstrapException( u"timeout occurred!"_ustr ); case osl_Process_E_NoPermission: - throw BootstrapException( "permission denied!" ); + throw BootstrapException( u"permission denied!"_ustr ); case osl_Process_E_Unknown: - throw BootstrapException( "unknown error!" ); + throw BootstrapException( u"unknown error!"_ustr ); case osl_Process_E_InvalidError: default: - throw BootstrapException( "unmapped error!" ); + throw BootstrapException( u"unmapped error!"_ustr ); } // create a URL resolver @@ -215,7 +216,7 @@ Reference< XComponentContext > SAL_CALL bootstrap() catch ( connection::NoConnectException & ) { // wait 500 ms, then try to connect again - ::osl::Thread::wait( std::chrono::milliseconds(500) ); + std::this_thread::sleep_for(std::chrono::milliseconds(500)); } } } diff --git a/cppuhelper/source/compbase.cxx b/cppuhelper/source/compbase.cxx new file mode 100644 index 000000000000..ed4909b71106 --- /dev/null +++ b/cppuhelper/source/compbase.cxx @@ -0,0 +1,231 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <compbase2.hxx> +#include <sal/log.hxx> +#include <osl/diagnose.h> + +namespace cppuhelper +{ +WeakComponentImplHelperBase2::~WeakComponentImplHelperBase2() {} + +// css::lang::XComponent +void SAL_CALL WeakComponentImplHelperBase2::dispose() +{ + std::unique_lock aGuard(m_aMutex); + if (m_bDisposed) + return; + m_bDisposed = true; + disposing(aGuard); + if (!aGuard.owns_lock()) + aGuard.lock(); + css::lang::EventObject aEvt(static_cast<OWeakObject*>(this)); + maEventListeners.disposeAndClear(aGuard, aEvt); +} + +void WeakComponentImplHelperBase2::disposing(std::unique_lock<std::mutex>&) {} + +void SAL_CALL WeakComponentImplHelperBase2::addEventListener( + css::uno::Reference<css::lang::XEventListener> const& rxListener) +{ + std::unique_lock aGuard(m_aMutex); + if (m_bDisposed) + return; + maEventListeners.addInterface(aGuard, rxListener); +} + +void SAL_CALL WeakComponentImplHelperBase2::removeEventListener( + css::uno::Reference<css::lang::XEventListener> const& rxListener) +{ + std::unique_lock aGuard(m_aMutex); + maEventListeners.removeInterface(aGuard, rxListener); +} + +css::uno::Any SAL_CALL WeakComponentImplHelperBase2::queryInterface(css::uno::Type const& rType) +{ + css::uno::Any aReturn = ::cppu::queryInterface(rType, static_cast<css::uno::XWeak*>(this), + static_cast<css::lang::XComponent*>(this)); + if (aReturn.hasValue()) + return aReturn; + return OWeakObject::queryInterface(rType); +} + +static void checkInterface(css::uno::Type const& rType) +{ + if (css::uno::TypeClass_INTERFACE != rType.getTypeClass()) + { + OUString msg("querying for interface \"" + rType.getTypeName() + "\": no interface type!"); + SAL_WARN("cppuhelper", msg); + throw css::uno::RuntimeException(msg); + } +} + +static bool isXInterface(rtl_uString* pStr) +{ + return OUString::unacquired(&pStr) == "com.sun.star.uno.XInterface"; +} + +static bool td_equals(typelib_TypeDescriptionReference const* pTDR1, + typelib_TypeDescriptionReference const* pTDR2) +{ + return ((pTDR1 == pTDR2) + || OUString::unacquired(&pTDR1->pTypeName) == OUString::unacquired(&pTDR2->pTypeName)); +} + +static cppu::type_entry* getTypeEntries(cppu::class_data* cd) +{ + cppu::type_entry* pEntries = cd->m_typeEntries; + if (!cd->m_storedTypeRefs) // not inited? + { + static std::mutex aMutex; + std::scoped_lock guard(aMutex); + if (!cd->m_storedTypeRefs) // not inited? + { + // get all types + for (sal_Int32 n = cd->m_nTypes; n--;) + { + cppu::type_entry* pEntry = &pEntries[n]; + css::uno::Type const& rType = (*pEntry->m_type.getCppuType)(nullptr); + OSL_ENSURE(rType.getTypeClass() == css::uno::TypeClass_INTERFACE, + "### wrong helper init: expected interface!"); + OSL_ENSURE( + !isXInterface(rType.getTypeLibType()->pTypeName), + "### want to implement XInterface: template argument is XInterface?!?!?!"); + if (rType.getTypeClass() != css::uno::TypeClass_INTERFACE) + { + OUString msg("type \"" + rType.getTypeName() + "\" is no interface type!"); + SAL_WARN("cppuhelper", msg); + throw css::uno::RuntimeException(msg); + } + // ref is statically held by getCppuType() + pEntry->m_type.typeRef = rType.getTypeLibType(); + } + OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); + cd->m_storedTypeRefs = true; + } + } + else + { + OSL_DOUBLE_CHECKED_LOCKING_MEMORY_BARRIER(); + } + return pEntries; +} + +static void* makeInterface(sal_IntPtr nOffset, void* that) +{ + return (static_cast<char*>(that) + nOffset); +} + +static bool recursivelyFindType(typelib_TypeDescriptionReference const* demandedType, + typelib_InterfaceTypeDescription const* type, sal_IntPtr* offset) +{ + // This code assumes that the vtables of a multiple-inheritance class (the + // offset amount by which to adjust the this pointer) follow one another in + // the object layout, and that they contain slots for the inherited classes + // in a specific order. In theory, that need not hold for any given + // platform; in practice, it seems to work well on all supported platforms: +next: + for (sal_Int32 i = 0; i < type->nBaseTypes; ++i) + { + if (i > 0) + { + *offset += sizeof(void*); + } + typelib_InterfaceTypeDescription const* base = type->ppBaseTypes[i]; + // ignore XInterface: + if (base->nBaseTypes > 0) + { + if (td_equals(reinterpret_cast<typelib_TypeDescriptionReference const*>(base), + demandedType)) + { + return true; + } + // Profiling showed that it is important to speed up the common case + // of only one base: + if (type->nBaseTypes == 1) + { + type = base; + goto next; + } + if (recursivelyFindType(demandedType, base, offset)) + { + return true; + } + } + } + return false; +} + +static void* queryDeepNoXInterface(typelib_TypeDescriptionReference const* pDemandedTDR, + cppu::class_data* cd, void* that) +{ + cppu::type_entry* pEntries = getTypeEntries(cd); + sal_Int32 nTypes = cd->m_nTypes; + sal_Int32 n; + + // try top interfaces without getting td + for (n = 0; n < nTypes; ++n) + { + if (td_equals(pEntries[n].m_type.typeRef, pDemandedTDR)) + { + return makeInterface(pEntries[n].m_offset, that); + } + } + // query deep getting td + for (n = 0; n < nTypes; ++n) + { + typelib_TypeDescription* pTD = nullptr; + TYPELIB_DANGER_GET(&pTD, pEntries[n].m_type.typeRef); + if (pTD) + { + // exclude top (already tested) and bottom (XInterface) interface + OSL_ENSURE(reinterpret_cast<typelib_InterfaceTypeDescription*>(pTD)->nBaseTypes > 0, + "### want to implement XInterface:" + " template argument is XInterface?!?!?!"); + sal_IntPtr offset = pEntries[n].m_offset; + bool found = recursivelyFindType( + pDemandedTDR, reinterpret_cast<typelib_InterfaceTypeDescription*>(pTD), &offset); + TYPELIB_DANGER_RELEASE(pTD); + if (found) + { + return makeInterface(offset, that); + } + } + else + { + OUString msg("cannot get type description for type \"" + + OUString::unacquired(&pEntries[n].m_type.typeRef->pTypeName) + "\"!"); + SAL_WARN("cppuhelper", msg); + throw css::uno::RuntimeException(msg); + } + } + return nullptr; +} + +css::uno::Any WeakComponentImplHelper_query(css::uno::Type const& rType, cppu::class_data* cd, + WeakComponentImplHelperBase2* pBase) +{ + checkInterface(rType); + typelib_TypeDescriptionReference* pTDR = rType.getTypeLibType(); + + // shortcut XInterface to WeakComponentImplHelperBase + if (!isXInterface(pTDR->pTypeName)) + { + void* p = queryDeepNoXInterface(pTDR, cd, pBase); + if (p) + { + return css::uno::Any(&p, pTDR); + } + } + return pBase->cppuhelper::WeakComponentImplHelperBase2::queryInterface(rType); +} + +} // namespace cppuextra + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/cppuhelper/source/component.cxx b/cppuhelper/source/component.cxx index 369e2ead7be5..5c7226f93a1a 100644 --- a/cppuhelper/source/component.cxx +++ b/cppuhelper/source/component.cxx @@ -150,10 +150,8 @@ void OComponentHelper::dispose() { try { - Reference<XInterface > xSource( - Reference<XInterface >::query( static_cast<XComponent *>(this) ) ); EventObject aEvt; - aEvt.Source = xSource; + aEvt.Source = Reference<XInterface >::query( static_cast<XComponent *>(this) ); // inform all listeners to release this object // The listener container are automatically cleared rBHelper.aLC.disposeAndClear( aEvt ); diff --git a/cppuhelper/source/component_context.cxx b/cppuhelper/source/component_context.cxx index 440fe18cfa4d..893e484be44d 100644 --- a/cppuhelper/source/component_context.cxx +++ b/cppuhelper/source/component_context.cxx @@ -31,6 +31,7 @@ #include <cppuhelper/compbase.hxx> #include <cppuhelper/component_context.hxx> #include <cppuhelper/implbase.hxx> +#include <compbase2.hxx> #include <com/sun/star/container/XNameContainer.hpp> #include <com/sun/star/lang/XSingleServiceFactory.hpp> @@ -44,32 +45,36 @@ #include <comphelper/sequence.hxx> #include <memory> +#include <utility> -constexpr OUStringLiteral SMGR_SINGLETON = u"/singletons/com.sun.star.lang.theServiceManager"; +constexpr OUString SMGR_SINGLETON = u"/singletons/com.sun.star.lang.theServiceManager"_ustr; constexpr OUStringLiteral TDMGR_SINGLETON = u"/singletons/com.sun.star.reflection.theTypeDescriptionManager"; constexpr OUStringLiteral AC_SINGLETON = u"/singletons/com.sun.star.security.theAccessController"; -using namespace ::osl; using namespace ::com::sun::star::uno; using namespace ::com::sun::star; namespace cppu { -static void try_dispose( Reference< XInterface > const & xInstance ) +static void try_dispose( std::unique_lock<std::mutex>& rGuard, Reference< XInterface > const & xInstance ) { Reference< lang::XComponent > xComp( xInstance, UNO_QUERY ); if (xComp.is()) { + rGuard.unlock(); xComp->dispose(); + rGuard.lock(); } } -static void try_dispose( Reference< lang::XComponent > const & xComp ) +static void try_dispose( std::unique_lock<std::mutex>& rGuard, Reference< lang::XComponent > const & xComp ) { if (xComp.is()) { + rGuard.unlock(); xComp->dispose(); + rGuard.lock(); } } @@ -115,8 +120,7 @@ void DisposingForwarder::disposing( lang::EventObject const & ) namespace { class ComponentContext - : private cppu::BaseMutex - , public WeakComponentImplHelper< XComponentContext, + : public cppuhelper::WeakComponentImplHelper2< XComponentContext, container::XNameContainer > { protected: @@ -127,8 +131,8 @@ protected: Any value; bool lateInit; - ContextEntry( Any const & value_, bool lateInit_ ) - : value( value_ ) + ContextEntry( Any value_, bool lateInit_ ) + : value(std::move( value_ )) , lateInit( lateInit_ ) {} }; @@ -140,7 +144,7 @@ protected: protected: Any lookupMap( OUString const & rName ); - virtual void SAL_CALL disposing() override; + virtual void disposing(std::unique_lock<std::mutex>&) override; public: ComponentContext( ContextEntry_Init const * pEntries, sal_Int32 nEntries, @@ -178,7 +182,7 @@ void ComponentContext::insertByName( /* lateInit_: */ name.startsWith( "/singletons/" ) && !element.hasValue() ); - MutexGuard guard( m_aMutex ); + std::unique_lock guard( m_aMutex ); std::pair<t_map::iterator, bool> insertion( m_map.emplace( name, entry ) ); if (! insertion.second) @@ -190,7 +194,7 @@ void ComponentContext::insertByName( void ComponentContext::removeByName( OUString const & name ) { - MutexGuard guard( m_aMutex ); + std::unique_lock guard( m_aMutex ); t_map::iterator iFind( m_map.find( name ) ); if (iFind == m_map.end()) throw container::NoSuchElementException( @@ -205,7 +209,7 @@ void ComponentContext::removeByName( OUString const & name ) void ComponentContext::replaceByName( OUString const & name, Any const & element ) { - MutexGuard guard( m_aMutex ); + std::unique_lock guard( m_aMutex ); t_map::iterator iFind( m_map.find( name ) ); if (iFind == m_map.end()) throw container::NoSuchElementException( @@ -234,14 +238,14 @@ Any ComponentContext::getByName( OUString const & name ) Sequence<OUString> ComponentContext::getElementNames() { - MutexGuard guard( m_aMutex ); + std::unique_lock guard( m_aMutex ); return comphelper::mapKeysToSequence(m_map); } sal_Bool ComponentContext::hasByName( OUString const & name ) { - MutexGuard guard( m_aMutex ); + std::unique_lock guard( m_aMutex ); return m_map.find( name ) != m_map.end(); } @@ -255,14 +259,14 @@ Type ComponentContext::getElementType() sal_Bool ComponentContext::hasElements() { - MutexGuard guard( m_aMutex ); + std::unique_lock guard( m_aMutex ); return ! m_map.empty(); } Any ComponentContext::lookupMap( OUString const & rName ) { - ResettableMutexGuard guard( m_aMutex ); + std::unique_lock guard( m_aMutex ); t_map::iterator iFind( m_map.find( rName ) ); if (iFind == m_map.end()) return Any(); @@ -273,7 +277,7 @@ Any ComponentContext::lookupMap( OUString const & rName ) // late init singleton entry Reference< XInterface > xInstance; - guard.clear(); + guard.unlock(); try { @@ -333,7 +337,7 @@ Any ComponentContext::lookupMap( OUString const & rName ) "cppuhelper", "no service object raising singleton " << rName); Any ret; - guard.reset(); + guard.lock(); iFind = m_map.find( rName ); if (iFind != m_map.end()) { @@ -346,9 +350,8 @@ Any ComponentContext::lookupMap( OUString const & rName ) } ret = rEntry.value; } - guard.clear(); if (ret != xInstance) { - try_dispose( xInstance ); + try_dispose( guard, xInstance ); } return ret; } @@ -377,13 +380,13 @@ Reference< lang::XMultiComponentFactory > ComponentContext::getServiceManager() if ( !m_xSMgr.is() ) { throw DeploymentException( - "null component context service manager", + u"null component context service manager"_ustr, static_cast<OWeakObject *>(this) ); } return m_xSMgr; } -void ComponentContext::disposing() +void ComponentContext::disposing(std::unique_lock<std::mutex>& rGuard) { Reference< lang::XComponent > xTDMgr, xAC; // to be disposed separately @@ -397,7 +400,6 @@ void ComponentContext::disposing() if (rEntry.lateInit) { // late init - MutexGuard guard( m_aMutex ); if (rEntry.lateInit) { rEntry.value.clear(); // release factory @@ -420,19 +422,21 @@ void ComponentContext::disposing() } else // dispose immediately { + rGuard.unlock(); xComp->dispose(); + rGuard.lock(); } } } } // dispose service manager - try_dispose( m_xSMgr ); + try_dispose( rGuard, m_xSMgr ); m_xSMgr.clear(); // dispose ac - try_dispose( xAC ); + try_dispose( rGuard, xAC ); // dispose tdmgr; revokes callback from cppu runtime - try_dispose( xTDMgr ); + try_dispose( rGuard, xTDMgr ); m_map.clear(); @@ -442,7 +446,7 @@ void ComponentContext::disposing() uno_Environment ** envs; sal_Int32 envCount; uno_getRegisteredEnvironments( - &envs, &envCount, &rtl_allocateMemory, OUString("java").pData); + &envs, &envCount, &rtl_allocateMemory, u"java"_ustr.pData); assert(envCount >= 0); assert(envCount == 0 || envs != nullptr); if (envs) { @@ -458,8 +462,7 @@ void ComponentContext::disposing() ComponentContext::ComponentContext( ContextEntry_Init const * pEntries, sal_Int32 nEntries, Reference< XComponentContext > const & xDelegate ) - : WeakComponentImplHelper( m_aMutex ), - m_xDelegate( xDelegate ) + : m_xDelegate( xDelegate ) { for ( sal_Int32 nPos = 0; nPos < nEntries; ++nPos ) { @@ -499,7 +502,7 @@ ComponentContext::ComponentContext( // create new smgr based on delegate's one m_xSMgr.set( xMgr->createInstanceWithContext( - "com.sun.star.comp.stoc.OServiceManagerWrapper", xDelegate ), + u"com.sun.star.comp.stoc.OServiceManagerWrapper"_ustr, xDelegate ), UNO_QUERY ); // patch DefaultContext property of new one Reference< beans::XPropertySet > xProps( m_xSMgr, UNO_QUERY ); @@ -507,7 +510,7 @@ ComponentContext::ComponentContext( if (xProps.is()) { Reference< XComponentContext > xThis( this ); - xProps->setPropertyValue( "DefaultContext", Any( xThis ) ); + xProps->setPropertyValue( u"DefaultContext"_ustr, Any( xThis ) ); } } catch (...) diff --git a/cppuhelper/source/defaultbootstrap.cxx b/cppuhelper/source/defaultbootstrap.cxx index 6e80c9697158..ca70a91d3f57 100644 --- a/cppuhelper/source/defaultbootstrap.cxx +++ b/cppuhelper/source/defaultbootstrap.cxx @@ -54,25 +54,25 @@ cppu::defaultBootstrap_InitialComponentContext(OUString const & iniUri) } rtl::Reference smgr( new cppuhelper::ServiceManager); - smgr->init(getBootstrapVariable(bs, "UNO_SERVICES")); + smgr->init(getBootstrapVariable(bs, u"UNO_SERVICES"_ustr)); rtl::Reference tmgr(new cppuhelper::TypeManager); - tmgr->init(getBootstrapVariable(bs, "UNO_TYPES")); + tmgr->init(getBootstrapVariable(bs, u"UNO_TYPES"_ustr)); std::vector< cppu::ContextEntry_Init > context_values { cppu::ContextEntry_Init( - "/singletons/com.sun.star.lang.theServiceManager", + u"/singletons/com.sun.star.lang.theServiceManager"_ustr, css::uno::Any( css::uno::Reference< css::uno::XInterface >( static_cast< cppu::OWeakObject * >(smgr.get()))), false), cppu::ContextEntry_Init( - "/singletons/com.sun.star.reflection.theTypeDescriptionManager", + u"/singletons/com.sun.star.reflection.theTypeDescriptionManager"_ustr, css::uno::Any( css::uno::Reference< css::uno::XInterface >( static_cast< cppu::OWeakObject * >(tmgr.get()))), false), cppu::ContextEntry_Init( //TODO: from services.rdb? - "/singletons/com.sun.star.util.theMacroExpander", + u"/singletons/com.sun.star.util.theMacroExpander"_ustr, css::uno::Any( cppuhelper::detail::create_bootstrap_macro_expander_factory()), true) @@ -80,13 +80,13 @@ cppu::defaultBootstrap_InitialComponentContext(OUString const & iniUri) smgr->addSingletonContextEntries(&context_values); context_values.push_back( cppu::ContextEntry_Init( - "/services/com.sun.star.security.AccessController/mode", - css::uno::Any(OUString("off")), false)); + u"/services/com.sun.star.security.AccessController/mode"_ustr, + css::uno::Any(u"off"_ustr), false)); context_values.push_back( cppu::ContextEntry_Init( - "/singletons/com.sun.star.security.theAccessController", + u"/singletons/com.sun.star.security.theAccessController"_ustr, css::uno::Any( - OUString("com.sun.star.security.AccessController")), + u"com.sun.star.security.AccessController"_ustr), true)); css::uno::Reference< css::uno::XComponentContext > context( createComponentContext(context_values.data(), context_values.size())); diff --git a/cppuhelper/source/exc_thrower.cxx b/cppuhelper/source/exc_thrower.cxx index c0d441fcd48b..eec416775038 100644 --- a/cppuhelper/source/exc_thrower.cxx +++ b/cppuhelper/source/exc_thrower.cxx @@ -30,7 +30,6 @@ #include <cppuhelper/exc_hlp.hxx> -using namespace ::osl; using namespace ::cppu; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -116,7 +115,7 @@ void ExceptionThrower_dispatch( default: { OSL_ASSERT( false ); - RuntimeException exc( "not implemented!" ); + RuntimeException exc( u"not implemented!"_ustr ); uno_type_any_construct( *ppException, &exc, cppu::UnoType<decltype(exc)>::get().getTypeLibType(), nullptr ); break; @@ -168,7 +167,7 @@ ExceptionThrower::ExceptionThrower() uno_Interface::pDispatcher = ExceptionThrower_dispatch; } -#if defined(IOS) || (defined(__aarch64__) && defined(ANDROID)) || defined(EMSCRIPTEN) +#if defined(IOS) || defined(ANDROID) || defined(EMSCRIPTEN) #define RETHROW_FAKE_EXCEPTIONS 1 #else #define RETHROW_FAKE_EXCEPTIONS 0 @@ -228,18 +227,18 @@ void SAL_CALL throwException( Any const & exc ) if (exc.getValueTypeClass() != TypeClass_EXCEPTION) { throw RuntimeException( - "no UNO exception given " - "(must be derived from com::sun::star::uno::Exception)!" ); + u"no UNO exception given " + "(must be derived from com::sun::star::uno::Exception)!"_ustr ); } #if RETHROW_FAKE_EXCEPTIONS lo_mobile_throwException(exc); #else - Mapping uno2cpp(Environment(UNO_LB_UNO), Environment::getCurrent()); + Mapping uno2cpp(Environment(u"" UNO_LB_UNO ""_ustr), Environment::getCurrent()); if (! uno2cpp.is()) { throw RuntimeException( - "cannot get binary UNO to C++ mapping!" ); + u"cannot get binary UNO to C++ mapping!"_ustr ); } Reference< XExceptionThrower > xThrower; @@ -256,22 +255,20 @@ void SAL_CALL throwException( Any const & exc ) Any SAL_CALL getCaughtException() { // why does this differ from RETHROW_FAKE_EXCEPTIONS? -#if (defined(__aarch64__) && defined(ANDROID)) || defined(EMSCRIPTEN) - // FIXME This stuff works on 32bit ARM, let's use the shortcut only for - // the 64bit ARM. +#if defined(ANDROID) || defined(EMSCRIPTEN) return Any(); #else - Mapping cpp2uno(Environment::getCurrent(), Environment(UNO_LB_UNO)); + Mapping cpp2uno(Environment::getCurrent(), Environment(u"" UNO_LB_UNO ""_ustr)); if (! cpp2uno.is()) { throw RuntimeException( - "cannot get C++ to binary UNO mapping!" ); + u"cannot get C++ to binary UNO mapping!"_ustr ); } - Mapping uno2cpp(Environment(UNO_LB_UNO), Environment::getCurrent()); + Mapping uno2cpp(Environment(u"" UNO_LB_UNO ""_ustr), Environment::getCurrent()); if (! uno2cpp.is()) { throw RuntimeException( - "cannot get binary UNO to C++ mapping!" ); + u"cannot get binary UNO to C++ mapping!"_ustr ); } typelib_TypeDescription * pTD = nullptr; @@ -299,7 +296,7 @@ Any SAL_CALL getCaughtException() if (exc == nullptr) { - throw RuntimeException( "rethrowing C++ exception failed!" ); + throw RuntimeException( u"rethrowing C++ exception failed!"_ustr ); } Any ret; diff --git a/cppuhelper/source/factory.cxx b/cppuhelper/source/factory.cxx index 8768d9817ab7..b4a9d06c4d9e 100644 --- a/cppuhelper/source/factory.cxx +++ b/cppuhelper/source/factory.cxx @@ -20,8 +20,9 @@ #include <sal/log.hxx> #include <osl/diagnose.h> #include <osl/mutex.hxx> +#include <cppuhelper/basemutex.hxx> #include <cppuhelper/weak.hxx> -#include <cppuhelper/component.hxx> +#include <cppuhelper/compbase.hxx> #include <cppuhelper/factory.hxx> #include <cppuhelper/implbase.hxx> #include <cppuhelper/queryinterface.hxx> @@ -29,6 +30,7 @@ #include <rtl/unload.h> #include <cppuhelper/propshlp.hxx> +#include <o3tl/string_view.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XSingleServiceFactory.hpp> @@ -42,6 +44,7 @@ #include <com/sun/star/beans/PropertyAttribute.hpp> #include <memory> +#include <utility> using namespace osl; @@ -56,36 +59,36 @@ namespace cppu namespace { -class OSingleFactoryHelper - : public XServiceInfo - , public XSingleServiceFactory - , public lang::XSingleComponentFactory - , public XUnloadingPreference +class OFactoryComponentHelper + : public cppu::BaseMutex + , public WeakComponentImplHelper< + XServiceInfo, + XSingleServiceFactory, + lang::XSingleComponentFactory, + XUnloadingPreference> { public: - OSingleFactoryHelper( + OFactoryComponentHelper( const Reference<XMultiServiceFactory > & rServiceManager, - const OUString & rImplementationName_, + OUString aImplementationName_, ComponentInstantiation pCreateFunction_, ComponentFactoryFunc fptr, - const Sequence< OUString > * pServiceNames_ ) - : xSMgr( rServiceManager ) + const Sequence< OUString > * pServiceNames_, + bool bOneInstance_ ) + : WeakComponentImplHelper( m_aMutex ) + , bOneInstance( bOneInstance_ ) + , xSMgr( rServiceManager ) , pCreateFunction( pCreateFunction_ ) , m_fptr( fptr ) - , aImplementationName( rImplementationName_ ) + , aImplementationName(std::move( aImplementationName_ )) { if( pServiceNames_ ) aServiceNames = *pServiceNames_; } - virtual ~OSingleFactoryHelper(); - - // XInterface - Any SAL_CALL queryInterface( const Type & rType ) override; - // XSingleServiceFactory Reference<XInterface > SAL_CALL createInstance() override; - virtual Reference<XInterface > SAL_CALL createInstanceWithArguments(const Sequence<Any>& Arguments) override; + Reference<XInterface > SAL_CALL createInstanceWithArguments( const Sequence<Any>& Arguments ) override; // XSingleComponentFactory virtual Reference< XInterface > SAL_CALL createInstanceWithContext( Reference< XComponentContext > const & xContext ) override; @@ -98,7 +101,27 @@ public: sal_Bool SAL_CALL supportsService(const OUString& ServiceName) override; Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + // XTypeProvider + virtual Sequence< Type > SAL_CALL getTypes() override; + + // XUnloadingPreference + virtual sal_Bool SAL_CALL releaseOnNotification() override; + + // WeakComponentImplHelper + void SAL_CALL disposing() override; + +private: + css::uno::Reference<css::uno::XInterface> createInstanceWithArgumentsEveryTime( + css::uno::Sequence<css::uno::Any> const & rArguments, + css::uno::Reference<css::uno::XComponentContext> const & xContext); + + Reference<XInterface > xTheInstance; + bool bOneInstance; protected: + // needed for implementing XUnloadingPreference in inheriting classes + bool isOneInstance() const {return bOneInstance;} + bool isInstance() const {return xTheInstance.is();} + /** * Create an instance specified by the factory. The one instance logic is implemented * in the createInstance and createInstanceWithArguments methods. @@ -118,23 +141,22 @@ protected: } -OSingleFactoryHelper::~OSingleFactoryHelper() +// XTypeProvider +Sequence< Type > OFactoryComponentHelper::getTypes() { -} + Type ar[ 4 ]; + ar[ 0 ] = cppu::UnoType<XSingleServiceFactory>::get(); + ar[ 1 ] = cppu::UnoType<XServiceInfo>::get(); + ar[ 2 ] = cppu::UnoType<XUnloadingPreference>::get(); + if (m_fptr) + ar[ 3 ] = cppu::UnoType<XSingleComponentFactory>::get(); -Any OSingleFactoryHelper::queryInterface( const Type & rType ) -{ - return ::cppu::queryInterface( - rType, - static_cast< XSingleComponentFactory * >( this ), - static_cast< XSingleServiceFactory * >( this ), - static_cast< XServiceInfo * >( this ) , - static_cast< XUnloadingPreference * >( this )); + return Sequence< Type >( ar, m_fptr ? 4 : 3 ); } -// OSingleFactoryHelper -Reference<XInterface > OSingleFactoryHelper::createInstanceEveryTime( +// OFactoryComponentHelper +Reference<XInterface > OFactoryComponentHelper::createInstanceEveryTime( Reference< XComponentContext > const & xContext ) { if (m_fptr) @@ -156,195 +178,19 @@ Reference<XInterface > OSingleFactoryHelper::createInstanceEveryTime( } // XSingleServiceFactory -Reference<XInterface > OSingleFactoryHelper::createInstance() -{ - return createInstanceWithContext( Reference< XComponentContext >() ); -} - -// XSingleServiceFactory -Reference<XInterface > OSingleFactoryHelper::createInstanceWithArguments( - const Sequence<Any>& Arguments ) -{ - return createInstanceWithArgumentsAndContext( - Arguments, Reference< XComponentContext >() ); -} - -// XSingleComponentFactory - -Reference< XInterface > OSingleFactoryHelper::createInstanceWithContext( - Reference< XComponentContext > const & xContext ) -{ - return createInstanceEveryTime( xContext ); -} - -Reference< XInterface > OSingleFactoryHelper::createInstanceWithArgumentsAndContext( - Sequence< Any > const & rArguments, - Reference< XComponentContext > const & xContext ) -{ - Reference< XInterface > xRet( createInstanceWithContext( xContext ) ); - - Reference< lang::XInitialization > xInit( xRet, UNO_QUERY ); - // always call initialize, even if there are no arguments. #i63511# - if (xInit.is()) - { - xInit->initialize( rArguments ); - } - else - { - if ( rArguments.hasElements() ) - { - // dispose the here created UNO object before throwing out exception - // to avoid risk of memory leaks #i113722# - Reference<XComponent> xComp( xRet, UNO_QUERY ); - if (xComp.is()) - xComp->dispose(); - - throw lang::IllegalArgumentException( - "cannot pass arguments to component => no XInitialization implemented!", - Reference< XInterface >(), 0 ); - } - } - - return xRet; -} - -// XServiceInfo -OUString OSingleFactoryHelper::getImplementationName() -{ - return aImplementationName; -} - -// XServiceInfo -sal_Bool OSingleFactoryHelper::supportsService( - const OUString& ServiceName ) -{ - return cppu::supportsService(this, ServiceName); -} - -// XServiceInfo -Sequence< OUString > OSingleFactoryHelper::getSupportedServiceNames() -{ - return aServiceNames; -} - -namespace { - -struct OFactoryComponentHelper_Mutex -{ - Mutex aMutex; -}; - -class OFactoryComponentHelper - : public OFactoryComponentHelper_Mutex - , public OComponentHelper - , public OSingleFactoryHelper -{ -public: - OFactoryComponentHelper( - const Reference<XMultiServiceFactory > & rServiceManager, - const OUString & rImplementationName_, - ComponentInstantiation pCreateFunction_, - ComponentFactoryFunc fptr, - const Sequence< OUString > * pServiceNames_, - bool bOneInstance_ ) - : OComponentHelper( aMutex ) - , OSingleFactoryHelper( rServiceManager, rImplementationName_, pCreateFunction_, fptr, pServiceNames_ ) - , bOneInstance( bOneInstance_ ) - { - } - - // XInterface - Any SAL_CALL queryInterface( const Type & rType ) override; - void SAL_CALL acquire() noexcept override - { OComponentHelper::acquire(); } - void SAL_CALL release() noexcept override - { OComponentHelper::release(); } - - // XSingleServiceFactory - Reference<XInterface > SAL_CALL createInstance() override; - Reference<XInterface > SAL_CALL createInstanceWithArguments( const Sequence<Any>& Arguments ) override; - // XSingleComponentFactory - virtual Reference< XInterface > SAL_CALL createInstanceWithContext( - Reference< XComponentContext > const & xContext ) override; - virtual Reference< XInterface > SAL_CALL createInstanceWithArgumentsAndContext( - Sequence< Any > const & rArguments, - Reference< XComponentContext > const & xContext ) override; - - // XTypeProvider - virtual Sequence< Type > SAL_CALL getTypes() override; - virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() override; - - // XAggregation - Any SAL_CALL queryAggregation( const Type & rType ) override; - - // XUnloadingPreference - virtual sal_Bool SAL_CALL releaseOnNotification() override; - - // OComponentHelper - void SAL_CALL dispose() override; - -private: - Reference<XInterface > xTheInstance; - bool bOneInstance; -protected: - // needed for implementing XUnloadingPreference in inheriting classes - bool isOneInstance() const {return bOneInstance;} - bool isInstance() const {return xTheInstance.is();} -}; - -} - -Any SAL_CALL OFactoryComponentHelper::queryInterface( const Type & rType ) -{ - if( rType == cppu::UnoType<XUnloadingPreference>::get() ) - { - return Any( - Reference< XUnloadingPreference >( - static_cast< XUnloadingPreference * >(this) ) ); - } - return OComponentHelper::queryInterface( rType ); -} - -// XAggregation -Any OFactoryComponentHelper::queryAggregation( const Type & rType ) -{ - Any aRet( OComponentHelper::queryAggregation( rType ) ); - return (aRet.hasValue() ? aRet : OSingleFactoryHelper::queryInterface( rType )); -} - -// XTypeProvider -Sequence< Type > OFactoryComponentHelper::getTypes() -{ - Type ar[ 4 ]; - ar[ 0 ] = cppu::UnoType<XSingleServiceFactory>::get(); - ar[ 1 ] = cppu::UnoType<XServiceInfo>::get(); - ar[ 2 ] = cppu::UnoType<XUnloadingPreference>::get(); - - if (m_fptr) - ar[ 3 ] = cppu::UnoType<XSingleComponentFactory>::get(); - - return Sequence< Type >( ar, m_fptr ? 4 : 3 ); -} - -Sequence< sal_Int8 > OFactoryComponentHelper::getImplementationId() -{ - return css::uno::Sequence<sal_Int8>(); -} - -// XSingleServiceFactory Reference<XInterface > OFactoryComponentHelper::createInstance() { if( bOneInstance ) { if( !xTheInstance.is() ) { - MutexGuard aGuard( aMutex ); + MutexGuard aGuard( m_aMutex ); if( !xTheInstance.is() ) - xTheInstance = OSingleFactoryHelper::createInstance(); + xTheInstance = createInstanceEveryTime( Reference< XComponentContext >() ); } return xTheInstance; } - return OSingleFactoryHelper::createInstance(); + return createInstanceEveryTime( Reference< XComponentContext >() ); } Reference<XInterface > OFactoryComponentHelper::createInstanceWithArguments( @@ -354,14 +200,15 @@ Reference<XInterface > OFactoryComponentHelper::createInstanceWithArguments( { if( !xTheInstance.is() ) { - MutexGuard aGuard( aMutex ); + MutexGuard aGuard( m_aMutex ); // OSL_ENSURE( !xTheInstance.is(), "### arguments will be ignored!" ); if( !xTheInstance.is() ) - xTheInstance = OSingleFactoryHelper::createInstanceWithArguments( Arguments ); + xTheInstance = createInstanceWithArgumentsEveryTime( + Arguments, Reference< XComponentContext >() ); } return xTheInstance; } - return OSingleFactoryHelper::createInstanceWithArguments( Arguments ); + return createInstanceWithArgumentsEveryTime( Arguments, Reference< XComponentContext >() ); } // XSingleComponentFactory @@ -373,14 +220,14 @@ Reference< XInterface > OFactoryComponentHelper::createInstanceWithContext( { if( !xTheInstance.is() ) { - MutexGuard aGuard( aMutex ); + MutexGuard aGuard( m_aMutex ); // OSL_ENSURE( !xTheInstance.is(), "### context will be ignored!" ); if( !xTheInstance.is() ) - xTheInstance = OSingleFactoryHelper::createInstanceWithContext( xContext ); + xTheInstance = createInstanceEveryTime( xContext ); } return xTheInstance; } - return OSingleFactoryHelper::createInstanceWithContext( xContext ); + return createInstanceEveryTime( xContext ); } Reference< XInterface > OFactoryComponentHelper::createInstanceWithArgumentsAndContext( @@ -391,26 +238,56 @@ Reference< XInterface > OFactoryComponentHelper::createInstanceWithArgumentsAndC { if( !xTheInstance.is() ) { - MutexGuard aGuard( aMutex ); + MutexGuard aGuard( m_aMutex ); // OSL_ENSURE( !xTheInstance.is(), "### context and arguments will be ignored!" ); if( !xTheInstance.is() ) - xTheInstance = OSingleFactoryHelper::createInstanceWithArgumentsAndContext( rArguments, xContext ); + xTheInstance = createInstanceWithArgumentsEveryTime( rArguments, xContext ); } return xTheInstance; } - return OSingleFactoryHelper::createInstanceWithArgumentsAndContext( rArguments, xContext ); + return createInstanceWithArgumentsEveryTime( rArguments, xContext ); } - -// OComponentHelper -void OFactoryComponentHelper::dispose() +css::uno::Reference<css::uno::XInterface> +OFactoryComponentHelper::createInstanceWithArgumentsEveryTime( + css::uno::Sequence<css::uno::Any> const & rArguments, + css::uno::Reference<css::uno::XComponentContext> const & xContext) { - OComponentHelper::dispose(); + Reference< XInterface > xRet( createInstanceEveryTime( xContext ) ); + + Reference< lang::XInitialization > xInit( xRet, UNO_QUERY ); + // always call initialize, even if there are no arguments. #i63511# + if (xInit.is()) + { + xInit->initialize( rArguments ); + } + else + { + if ( rArguments.hasElements() ) + { + // dispose the here created UNO object before throwing out exception + // to avoid risk of memory leaks #i113722# + Reference<XComponent> xComp( xRet, UNO_QUERY ); + if (xComp.is()) + xComp->dispose(); + throw lang::IllegalArgumentException( + u"cannot pass arguments to component => no XInitialization implemented!"_ustr, + Reference< XInterface >(), 0 ); + } + } + + return xRet; +} + + +// WeakComponentImplHelper +void OFactoryComponentHelper::disposing() +{ Reference<XInterface > x; { // do not delete in the guard section - MutexGuard aGuard( aMutex ); + MutexGuard aGuard( m_aMutex ); x = xTheInstance; xTheInstance.clear(); } @@ -420,6 +297,25 @@ void OFactoryComponentHelper::dispose() xComp->dispose(); } +// XServiceInfo +OUString OFactoryComponentHelper::getImplementationName() +{ + return aImplementationName; +} + +// XServiceInfo +sal_Bool OFactoryComponentHelper::supportsService( + const OUString& ServiceName ) +{ + return cppu::supportsService(this, ServiceName); +} + +// XServiceInfo +Sequence< OUString > OFactoryComponentHelper::getSupportedServiceNames() +{ + return aServiceNames; +} + // XUnloadingPreference // This class is used for single factories, component factories and // one-instance factories. Depending on the usage this function has @@ -448,7 +344,7 @@ public: bool bOneInstance_ ) : OFactoryComponentHelper( rServiceManager, rImplementationName_, nullptr, nullptr, nullptr, bOneInstance_ ), - OPropertySetHelper( OComponentHelper::rBHelper ), + OPropertySetHelper( WeakComponentImplHelper::rBHelper ), xImplementationKey( xImplementationKey_ ) {} @@ -472,7 +368,7 @@ public: virtual void SAL_CALL getFastPropertyValue( Any & rValue, sal_Int32 nHandle ) const override; - // OSingleFactoryHelper + // OFactoryComponentHelper Reference<XInterface > createInstanceEveryTime( Reference< XComponentContext > const & xContext ) override; @@ -549,7 +445,7 @@ Sequence< Type > ORegistryFactoryHelper::getTypes() Reference< beans::XPropertySetInfo > ORegistryFactoryHelper::getPropertySetInfo() { - ::osl::MutexGuard guard( aMutex ); + ::osl::MutexGuard guard( m_aMutex ); if (! m_xInfo.is()) m_xInfo = createPropertySetInfo( getInfoHelper() ); return m_xInfo; @@ -559,11 +455,11 @@ ORegistryFactoryHelper::getPropertySetInfo() IPropertyArrayHelper & ORegistryFactoryHelper::getInfoHelper() { - ::osl::MutexGuard guard( aMutex ); + ::osl::MutexGuard guard( m_aMutex ); if (m_property_array_helper == nullptr) { beans::Property prop( - "ImplementationKey" /* name */, + u"ImplementationKey"_ustr /* name */, 0 /* handle */, cppu::UnoType<decltype(xImplementationKey)>::get(), beans::PropertyAttribute::READONLY | @@ -587,7 +483,7 @@ void ORegistryFactoryHelper::setFastPropertyValue_NoBroadcast( sal_Int32, Any const & ) { throw beans::PropertyVetoException( - "unexpected: only readonly properties!", + u"unexpected: only readonly properties!"_ustr, static_cast< OWeakObject * >(this) ); } @@ -603,7 +499,7 @@ void ORegistryFactoryHelper::getFastPropertyValue( { rValue.clear(); throw beans::UnknownPropertyException( - "unknown property!", static_cast< OWeakObject * >( + u"unknown property!"_ustr, static_cast< OWeakObject * >( const_cast< ORegistryFactoryHelper * >(this) ) ); } } @@ -616,7 +512,7 @@ Reference<XInterface > ORegistryFactoryHelper::createInstanceEveryTime( Reference< XInterface > x( createModuleFactory() ); if (x.is()) { - MutexGuard aGuard( aMutex ); + MutexGuard aGuard( m_aMutex ); if( !xModuleFactory.is() && !xModuleFactoryDepr.is() ) { xModuleFactory.set( x, UNO_QUERY ); @@ -644,7 +540,7 @@ Reference<XInterface > SAL_CALL ORegistryFactoryHelper::createInstanceWithArgume Reference< XInterface > x( createModuleFactory() ); if (x.is()) { - MutexGuard aGuard( aMutex ); + MutexGuard aGuard( m_aMutex ); if( !xModuleFactory.is() && !xModuleFactoryDepr.is() ) { xModuleFactory.set( x, UNO_QUERY ); @@ -674,7 +570,7 @@ Reference< XInterface > ORegistryFactoryHelper::createInstanceWithArgumentsAndCo Reference< XInterface > x( createModuleFactory() ); if (x.is()) { - MutexGuard aGuard( aMutex ); + MutexGuard aGuard( m_aMutex ); if( !xModuleFactory.is() && !xModuleFactoryDepr.is() ) { xModuleFactory.set( x, UNO_QUERY ); @@ -696,7 +592,6 @@ Reference< XInterface > ORegistryFactoryHelper::createInstanceWithArgumentsAndCo } -// OSingleFactoryHelper Reference< XInterface > ORegistryFactoryHelper::createModuleFactory() { OUString aActivatorUrl; @@ -704,15 +599,15 @@ Reference< XInterface > ORegistryFactoryHelper::createModuleFactory() OUString aLocation; Reference<XRegistryKey > xActivatorKey = xImplementationKey->openKey( - "/UNO/ACTIVATOR" ); + u"/UNO/ACTIVATOR"_ustr ); if( xActivatorKey.is() && xActivatorKey->getValueType() == RegistryValueType_ASCII ) { aActivatorUrl = xActivatorKey->getAsciiValue(); - aActivatorName = aActivatorUrl.getToken(0, ':'); + aActivatorName = o3tl::getToken(aActivatorUrl, 0, ':'); Reference<XRegistryKey > xLocationKey = xImplementationKey->openKey( - "/UNO/LOCATION" ); + u"/UNO/LOCATION"_ustr ); if( xLocationKey.is() && xLocationKey->getValueType() == RegistryValueType_ASCII ) aLocation = xLocationKey->getAsciiValue(); } @@ -721,7 +616,7 @@ Reference< XInterface > ORegistryFactoryHelper::createModuleFactory() // old style"url" // the location of the program code of the implementation Reference<XRegistryKey > xLocationKey = xImplementationKey->openKey( - "/UNO/URL" ); + u"/UNO/URL"_ustr ); // is the key of the right type ? if( xLocationKey.is() && xLocationKey->getValueType() == RegistryValueType_ASCII ) { @@ -732,11 +627,11 @@ Reference< XInterface > ORegistryFactoryHelper::createModuleFactory() sal_Int32 nPos = aLocation.indexOf("://"); if( nPos != -1 ) { - aActivatorName = aLocation.copy( 0, nPos ); - if( aActivatorName == "java" ) - aActivatorName = "com.sun.star.loader.Java"; - else if( aActivatorName == "module" ) - aActivatorName = "com.sun.star.loader.SharedLibrary"; + aActivatorName = aLocation.subView( 0, nPos ); + if( aActivatorName == u"java" ) + aActivatorName = u"com.sun.star.loader.Java"_ustr; + else if( aActivatorName == u"module" ) + aActivatorName = u"com.sun.star.loader.SharedLibrary"_ustr; aLocation = aLocation.copy( nPos + 3 ); } } @@ -758,13 +653,13 @@ Reference< XInterface > ORegistryFactoryHelper::createModuleFactory() // XServiceInfo Sequence< OUString > ORegistryFactoryHelper::getSupportedServiceNames() { - MutexGuard aGuard( aMutex ); + MutexGuard aGuard( m_aMutex ); if( !aServiceNames.hasElements() ) { // not yet loaded try { - Reference<XRegistryKey > xKey = xImplementationKey->openKey( "UNO/SERVICES" ); + Reference<XRegistryKey > xKey = xImplementationKey->openKey( u"UNO/SERVICES"_ustr ); if (xKey.is()) { diff --git a/cppuhelper/source/findsofficepath.c b/cppuhelper/source/findsofficepath.c index 75d370981968..a46cfb88a1e7 100644 --- a/cppuhelper/source/findsofficepath.c +++ b/cppuhelper/source/findsofficepath.c @@ -87,7 +87,7 @@ static wchar_t* getPathFromRegistryKey( HKEY hroot, const wchar_t* subKeyName ) * @return the installation path or NULL, if no installation was found or * if an error occurred */ -static wchar_t* platformSpecific() +static wchar_t* platformSpecific(void) { const wchar_t* UNOPATHVARNAME = L"UNO_PATH"; @@ -211,7 +211,7 @@ wchar_t* #else char* #endif -cppuhelper_detail_findSofficePath() +cppuhelper_detail_findSofficePath(void) { return platformSpecific(); } diff --git a/cppuhelper/source/gcc3.map b/cppuhelper/source/gcc3.map index d5af50655c1a..2af95d60a7e1 100644 --- a/cppuhelper/source/gcc3.map +++ b/cppuhelper/source/gcc3.map @@ -435,6 +435,13 @@ global: _ZN3com3sun4star3uno19WeakReferenceHelperaSEOS3_; # com::sun::star::uno::WeakReferenceHelper::operator=(com::sun::star::uno::WeakReferenceHelper&&) } LIBO_UDK_3.9; +LIBO_UDK_7.4 { # LibO 7.4 +global: + _ZN3com3sun4star3uno19WeakReferenceHelperaSERKNS2_9ReferenceINS2_5XWeakEEE; # com::sun::star::uno::WeakReferenceHelper::operator=(com::sun::star::uno::Reference<com::sun::star::uno::XWeak> const&) + _ZN3com3sun4star3uno19WeakReferenceHelperC1ERKNS2_9ReferenceINS2_5XWeakEEE; # com::sun::star::uno::WeakReferenceHelper::WeakReferenceHelper(com::sun::star::uno::Reference<com::sun::star::uno::XWeak> const&) + _ZN3com3sun4star3uno19WeakReferenceHelperC2ERKNS2_9ReferenceINS2_5XWeakEEE; # com::sun::star::uno::WeakReferenceHelper::WeakReferenceHelper(com::sun::star::uno::Reference<com::sun::star::uno::XWeak> const&) +} LIBO_UDK_5.3; + # Unique libstdc++ symbols: GLIBCXX_3.4 { global: diff --git a/cppuhelper/source/implbase_ex.cxx b/cppuhelper/source/implbase_ex.cxx index 4ced30adbe5c..731299d9cf06 100644 --- a/cppuhelper/source/implbase_ex.cxx +++ b/cppuhelper/source/implbase_ex.cxx @@ -27,7 +27,6 @@ #include <mutex> using namespace ::cppu; -using namespace ::osl; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; diff --git a/cppuhelper/source/interfacecontainer.cxx b/cppuhelper/source/interfacecontainer.cxx index 035f93848bf2..c97a8ba9908c 100644 --- a/cppuhelper/source/interfacecontainer.cxx +++ b/cppuhelper/source/interfacecontainer.cxx @@ -22,6 +22,7 @@ #include <cppuhelper/propshlp.hxx> #include <comphelper/sequence.hxx> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> #include <osl/mutex.hxx> #include <sal/log.hxx> @@ -106,7 +107,7 @@ void OInterfaceIteratorHelper::remove() if( bIsList ) { OSL_ASSERT( nRemain >= 0 && - nRemain < static_cast<sal_Int32>(aData.pAsVector->size()) ); + o3tl::make_unsigned(nRemain) < aData.pAsVector->size() ); XInterface * p = (*aData.pAsVector)[nRemain].get(); rCont.removeInterface( * reinterpret_cast< const Reference< XInterface > * >( &p ) ); } diff --git a/cppuhelper/source/loadsharedlibcomponentfactory.hxx b/cppuhelper/source/loadsharedlibcomponentfactory.hxx index 3678c32e76fb..d8c7bb55536b 100644 --- a/cppuhelper/source/loadsharedlibcomponentfactory.hxx +++ b/cppuhelper/source/loadsharedlibcomponentfactory.hxx @@ -26,7 +26,7 @@ namespace com::sun::star { namespace cppuhelper::detail { css::uno::Environment getEnvironment( - OUString const & name, OUString const & implementation); + OUString const & name, std::u16string_view implementation); void loadSharedLibComponentFactory( OUString const & uri, OUString const & environment, diff --git a/cppuhelper/source/macro_expander.cxx b/cppuhelper/source/macro_expander.cxx index 93f758becc12..ee4efe089410 100644 --- a/cppuhelper/source/macro_expander.cxx +++ b/cppuhelper/source/macro_expander.cxx @@ -24,7 +24,7 @@ #include <uno/mapping.hxx> #include <cppuhelper/factory.hxx> -#include <cppuhelper/compbase.hxx> +#include <compbase2.hxx> #include <cppuhelper/supportsservice.hxx> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -34,11 +34,10 @@ #include "macro_expander.hxx" #include "paths.hxx" -constexpr OUStringLiteral SERVICE_NAME_A = u"com.sun.star.lang.MacroExpander"; -constexpr OUStringLiteral SERVICE_NAME_B = u"com.sun.star.lang.BootstrapMacroExpander"; +constexpr OUString SERVICE_NAME_A = u"com.sun.star.lang.MacroExpander"_ustr; +constexpr OUString SERVICE_NAME_B = u"com.sun.star.lang.BootstrapMacroExpander"_ustr; constexpr OUStringLiteral IMPL_NAME = u"com.sun.star.lang.comp.cppuhelper.BootstrapMacroExpander"; -using namespace ::osl; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; @@ -83,22 +82,13 @@ Sequence< OUString > const & s_get_service_names() return IMPL_NAMES; } -typedef cppu::WeakComponentImplHelper< +typedef cppuhelper::WeakComponentImplHelper2< util::XMacroExpander, lang::XServiceInfo > t_uno_impl; -struct mutex_holder +class Bootstrap_MacroExpander : public t_uno_impl { - Mutex m_mutex; -}; - -class Bootstrap_MacroExpander : public mutex_holder, public t_uno_impl -{ -protected: - virtual void SAL_CALL disposing() override; - public: Bootstrap_MacroExpander() - : t_uno_impl( m_mutex ) {} // XMacroExpander impl @@ -110,9 +100,6 @@ public: }; -void Bootstrap_MacroExpander::disposing() -{} - // XServiceInfo impl OUString Bootstrap_MacroExpander::getImplementationName() diff --git a/cppuhelper/source/paths.cxx b/cppuhelper/source/paths.cxx index d2f37bb549a7..0a4ccf76e6ef 100644 --- a/cppuhelper/source/paths.cxx +++ b/cppuhelper/source/paths.cxx @@ -28,6 +28,7 @@ #include <osl/module.hxx> #include <rtl/ustring.hxx> #include <sal/types.h> +#include <o3tl/string_view.hxx> #include "paths.hxx" @@ -37,12 +38,11 @@ namespace { OUString get_this_libpath() { static OUString s_uri = []() { OUString uri; - osl::Module::getUrlFromAddress(reinterpret_cast<oslGenericFunction>(get_this_libpath), uri); - sal_Int32 i = uri.lastIndexOf('/'); + sal_Int32 i = -1; + if (osl::Module::getUrlFromAddress(reinterpret_cast<oslGenericFunction>(get_this_libpath), uri)) + i = uri.lastIndexOf('/'); if (i == -1) - { throw css::uno::DeploymentException("URI " + uri + " is expected to contain a slash"); - } return uri.copy(0, i); }(); @@ -52,7 +52,7 @@ OUString get_this_libpath() { } OUString cppu::getUnoIniUri() { -#if defined ANDROID || defined EMSCRIPTEN +#if defined ANDROID // Wouldn't it be lovely to avoid this ugly hard-coding. // The problem is that the 'create_bootstrap_macro_expander_factory()' // required for bootstrapping services, calls cppu::get_unorc directly @@ -88,19 +88,21 @@ bool cppu::nextDirectoryItem(osl::Directory & directory, OUString * url) { return false; default: throw css::uno::DeploymentException( - "Cannot iterate directory"); + u"Cannot iterate directory"_ustr); } osl::FileStatus stat( osl_FileStatus_Mask_Type | osl_FileStatus_Mask_FileName | osl_FileStatus_Mask_FileURL); if (i.getFileStatus(stat) != osl::FileBase::E_None) { throw css::uno::DeploymentException( - "Cannot stat in directory"); + u"Cannot stat in directory"_ustr); } if (stat.getFileType() != osl::FileStatus::Directory) { //TODO: symlinks - // Ignore backup files: + // Ignore backup and spurious junk files: OUString name(stat.getFileName()); - if (!(name.match(".") || name.endsWith("~"))) { + if (name.startsWith(".") || !name.endsWithIgnoreAsciiCase(u".rdb")) { + SAL_WARN("cppuhelper", "ignoring <" << stat.getFileURL() << ">"); + } else { *url = stat.getFileURL(); return true; } @@ -108,18 +110,18 @@ bool cppu::nextDirectoryItem(osl::Directory & directory, OUString * url) { } } -void cppu::decodeRdbUri(OUString * uri, bool * optional, bool * directory) +void cppu::decodeRdbUri(std::u16string_view * uri, bool * optional, bool * directory) { assert(uri != nullptr && optional != nullptr && directory != nullptr); - if(!(uri->isEmpty())) + if(!(uri->empty())) { *optional = (*uri)[0] == '?'; if (*optional) { - *uri = uri->copy(1); + *uri = uri->substr(1); } - *directory = uri->startsWith("<") && uri->endsWith(">*"); + *directory = o3tl::starts_with(*uri, u"<") && o3tl::ends_with(*uri, u">*"); if (*directory) { - *uri = uri->copy(1, uri->getLength() - 3); + *uri = uri->substr(1, uri->size() - 3); } } else diff --git a/cppuhelper/source/paths.hxx b/cppuhelper/source/paths.hxx index c1e3724c0aa1..b4681048998a 100644 --- a/cppuhelper/source/paths.hxx +++ b/cppuhelper/source/paths.hxx @@ -21,6 +21,7 @@ #include <sal/config.h> #include <rtl/ustring.hxx> +#include <string_view> namespace osl { @@ -33,7 +34,7 @@ OUString getUnoIniUri(); bool nextDirectoryItem(osl::Directory& directory, OUString* url); -void decodeRdbUri(OUString* uri, bool* optional, bool* directory); +void decodeRdbUri(std::u16string_view* uri, bool* optional, bool* directory); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/source/propertysetmixin.cxx b/cppuhelper/source/propertysetmixin.cxx index 030160c65f0f..b2c23dc2b507 100644 --- a/cppuhelper/source/propertysetmixin.cxx +++ b/cppuhelper/source/propertysetmixin.cxx @@ -24,6 +24,7 @@ #include <map> #include <mutex> #include <set> +#include <utility> #include <vector> #include <com/sun/star/beans/Property.hpp> @@ -64,6 +65,7 @@ #include <com/sun/star/uno/TypeClass.hpp> #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/uno/XInterface.hpp> +#include <cppu/unotype.hxx> #include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/implbase.hxx> #include <cppuhelper/propertysetmixin.hxx> @@ -79,8 +81,8 @@ namespace { struct PropertyData { explicit PropertyData( - css::beans::Property const & theProperty, bool thePresent): - property(theProperty), present(thePresent) {} + css::beans::Property theProperty, bool thePresent): + property(std::move(theProperty)), present(thePresent) {} css::beans::Property property; bool present; @@ -174,7 +176,7 @@ void Data::initProperties( //XXX Special interpretation of getter/setter exceptions only // works if the specified exceptions are of the exact type, not // of a supertype: - for (const auto & ex : std::as_const(excs)) { + for (const auto & ex : excs) { if ( ex->getName() == "com.sun.star.beans.UnknownPropertyException" ) { bGetUnknown = true; @@ -182,7 +184,7 @@ void Data::initProperties( } } excs = attr->getSetExceptions(); - for (const auto & ex : std::as_const(excs)) { + for (const auto & ex : excs) { if ( ex->getName() == "com.sun.star.beans.UnknownPropertyException" ) { bSetUnknown = true; @@ -229,7 +231,7 @@ void Data::initProperties( getTypeArguments()); if (args.getLength() != 1) { throw css::uno::RuntimeException( - "inconsistent UNO type registry"); + u"inconsistent UNO type registry"_ustr); } t = args[0]; } @@ -237,7 +239,7 @@ void Data::initProperties( = handleNames->size(); if (handles > SAL_MAX_INT32) { throw css::uno::RuntimeException( - "interface type has too many attributes"); + u"interface type has too many attributes"_ustr); } OUString name(m->getMemberName()); if (!properties.emplace( @@ -253,7 +255,7 @@ void Data::initProperties( second) { throw css::uno::RuntimeException( - "inconsistent UNO type registry"); + u"inconsistent UNO type registry"_ustr); } handleNames->push_back(name); } @@ -423,8 +425,8 @@ PropertySetMixinImpl::Impl::Impl( ifc.set( css::uno::Reference< css::container::XHierarchicalNameAccess >( m_context->getValueByName( - "/singletons/com.sun.star.reflection." - "theTypeDescriptionManager"), + u"/singletons/com.sun.star.reflection." + "theTypeDescriptionManager"_ustr), css::uno::UNO_QUERY_THROW)->getByHierarchicalName( m_type.getTypeName()), css::uno::UNO_QUERY_THROW); @@ -605,17 +607,17 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty( getReflection(value.getValueTypeName())); try { if (!(css::uno::Reference< css::reflection::XIdlField2 >( - ambiguous->getField("IsAmbiguous"), + ambiguous->getField(u"IsAmbiguous"_ustr), css::uno::UNO_QUERY_THROW)->get(value) >>= isAmbiguous)) { throw css::uno::RuntimeException( - ("unexpected type of com.sun.star.beans.Ambiguous" - " IsAmbiguous member"), + (u"unexpected type of com.sun.star.beans.Ambiguous" + " IsAmbiguous member"_ustr), object); } value = css::uno::Reference< css::reflection::XIdlField2 >( - ambiguous->getField("Value"), css::uno::UNO_QUERY_THROW)-> + ambiguous->getField(u"Value"_ustr), css::uno::UNO_QUERY_THROW)-> get(value); } catch (css::lang::IllegalArgumentException & e) { css::uno::Any anyEx = cppu::getCaughtException(); @@ -634,17 +636,17 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty( try { if (!(css::uno::Reference< css::reflection::XIdlField2 >( - defaulted->getField("IsDefaulted"), + defaulted->getField(u"IsDefaulted"_ustr), css::uno::UNO_QUERY_THROW)->get(value) >>= isDefaulted)) { throw css::uno::RuntimeException( - ("unexpected type of com.sun.star.beans.Defaulted" - " IsDefaulted member"), + (u"unexpected type of com.sun.star.beans.Defaulted" + " IsDefaulted member"_ustr), object); } value = css::uno::Reference< css::reflection::XIdlField2 >( - defaulted->getField("Value"), css::uno::UNO_QUERY_THROW)-> + defaulted->getField(u"Value"_ustr), css::uno::UNO_QUERY_THROW)-> get(value); } catch (css::lang::IllegalArgumentException & e) { css::uno::Any anyEx = cppu::getCaughtException(); @@ -663,13 +665,13 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty( try { bool present = false; if (!(css::uno::Reference< css::reflection::XIdlField2 >( - optional->getField("IsPresent"), + optional->getField(u"IsPresent"_ustr), css::uno::UNO_QUERY_THROW)->get(value) >>= present)) { throw css::uno::RuntimeException( - ("unexpected type of com.sun.star.beans.Optional" - " IsPresent member"), + (u"unexpected type of com.sun.star.beans.Optional" + " IsPresent member"_ustr), object); } if (!present) { @@ -677,7 +679,7 @@ css::uno::Any PropertySetMixinImpl::Impl::getProperty( break; } value = css::uno::Reference< css::reflection::XIdlField2 >( - optional->getField("Value"), css::uno::UNO_QUERY_THROW)-> + optional->getField(u"Value"_ustr), css::uno::UNO_QUERY_THROW)-> get(value); } catch (css::lang::IllegalArgumentException & e) { css::uno::Any anyEx = cppu::getCaughtException(); @@ -728,14 +730,14 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue( type->createObject(strct); try { css::uno::Reference< css::reflection::XIdlField2 > field( - type->getField("Value"), css::uno::UNO_QUERY_THROW); + type->getField(u"Value"_ustr), css::uno::UNO_QUERY_THROW); field->set( strct, wrapValue( object, value, field->getType(), false, false, wrapDefaulted, isDefaulted, wrapOptional)); css::uno::Reference< css::reflection::XIdlField2 >( - type->getField("IsAmbiguous"), css::uno::UNO_QUERY_THROW)->set( + type->getField(u"IsAmbiguous"_ustr), css::uno::UNO_QUERY_THROW)->set( strct, css::uno::Any(isAmbiguous)); } catch (css::lang::IllegalArgumentException & e) { css::uno::Any anyEx = cppu::getCaughtException(); @@ -759,14 +761,14 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue( type->createObject(strct); try { css::uno::Reference< css::reflection::XIdlField2 > field( - type->getField("Value"), css::uno::UNO_QUERY_THROW); + type->getField(u"Value"_ustr), css::uno::UNO_QUERY_THROW); field->set( strct, wrapValue( object, value, field->getType(), wrapAmbiguous, isAmbiguous, false, false, wrapOptional)); css::uno::Reference< css::reflection::XIdlField2 >( - type->getField("IsDefaulted"), css::uno::UNO_QUERY_THROW)->set( + type->getField(u"IsDefaulted"_ustr), css::uno::UNO_QUERY_THROW)->set( strct, css::uno::Any(isDefaulted)); } catch (css::lang::IllegalArgumentException & e) { css::uno::Any anyEx = cppu::getCaughtException(); @@ -791,11 +793,11 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue( bool present = value.hasValue(); try { css::uno::Reference< css::reflection::XIdlField2 >( - type->getField("IsPresent"), css::uno::UNO_QUERY_THROW)->set( + type->getField(u"IsPresent"_ustr), css::uno::UNO_QUERY_THROW)->set( strct, css::uno::Any(present)); if (present) { css::uno::Reference< css::reflection::XIdlField2 > field( - type->getField("Value"), css::uno::UNO_QUERY_THROW); + type->getField(u"Value"_ustr), css::uno::UNO_QUERY_THROW); field->set( strct, wrapValue( @@ -819,7 +821,7 @@ css::uno::Any PropertySetMixinImpl::Impl::wrapValue( } if (wrapAmbiguous || wrapDefaulted || wrapOptional) { throw css::uno::RuntimeException( - "unexpected type of attribute", object); + u"unexpected type of attribute"_ustr, object); } return value; } @@ -857,7 +859,7 @@ void PropertySetMixinImpl::prepareSet( std::scoped_lock g(m_impl->mutex); if (m_impl->disposed) { throw css::lang::DisposedException( - "disposed", static_cast< css::beans::XPropertySet * >(this)); + u"disposed"_ustr, static_cast< css::beans::XPropertySet * >(this)); } if ((it->second.property.Attributes & css::beans::PropertyAttribute::CONSTRAINED) @@ -868,7 +870,7 @@ void PropertySetMixinImpl::prepareSet( if (i != m_impl->vetoListeners.end()) { specificVeto = i->second; } - i = m_impl->vetoListeners.find(""); + i = m_impl->vetoListeners.find(u""_ustr); if (i != m_impl->vetoListeners.end()) { unspecificVeto = i->second; } @@ -883,7 +885,7 @@ void PropertySetMixinImpl::prepareSet( if (i != m_impl->boundListeners.end()) { boundListeners->m_impl->specificListeners = i->second; } - i = m_impl->boundListeners.find(""); + i = m_impl->boundListeners.find(u""_ustr); if (i != m_impl->boundListeners.end()) { boundListeners->m_impl->unspecificListeners = i->second; } @@ -949,21 +951,21 @@ void PropertySetMixinImpl::dispose() { css::uno::Any PropertySetMixinImpl::queryInterface(css::uno::Type const & type) { if ((m_impl->implements & IMPLEMENTS_PROPERTY_SET) != 0 - && type == css::beans::XPropertySet::static_type()) + && type == cppu::UnoType<css::beans::XPropertySet>::get()) { css::uno::Reference< css::uno::XInterface > ifc( static_cast< css::beans::XPropertySet * >(this)); return css::uno::Any(&ifc, type); } if ((m_impl->implements & IMPLEMENTS_FAST_PROPERTY_SET) != 0 - && type == css::beans::XFastPropertySet::static_type()) + && type == cppu::UnoType<css::beans::XFastPropertySet>::get()) { css::uno::Reference< css::uno::XInterface > ifc( static_cast< css::beans::XFastPropertySet * >(this)); return css::uno::Any(&ifc, type); } if ((m_impl->implements & IMPLEMENTS_PROPERTY_ACCESS) != 0 - && type == css::beans::XPropertyAccess::static_type()) + && type == cppu::UnoType<css::beans::XPropertyAccess>::get()) { css::uno::Reference< css::uno::XInterface > ifc( static_cast< css::beans::XPropertyAccess * >(this)); diff --git a/cppuhelper/source/propshlp.cxx b/cppuhelper/source/propshlp.cxx index 3af4cda49bb7..1dfca5e2a6ec 100644 --- a/cppuhelper/source/propshlp.cxx +++ b/cppuhelper/source/propshlp.cxx @@ -25,6 +25,7 @@ #include <cppuhelper/exc_hlp.hxx> #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/lang/IllegalArgumentException.hpp> #include <memory> #include <sal/log.hxx> @@ -867,6 +868,9 @@ void OPropertySetHelper::setPropertyValues( const Sequence<Any>& rValues ) { sal_Int32 nSeqLen = rPropertyNames.getLength(); + if (nSeqLen != rValues.getLength()) + throw IllegalArgumentException(u"lengths do not match"_ustr, static_cast<XPropertySet*>(this), + -1); std::unique_ptr<sal_Int32[]> pHandles(new sal_Int32[ nSeqLen ]); // get the map table IPropertyArrayHelper & rPH = getInfoHelper(); diff --git a/cppuhelper/source/servicemanager.cxx b/cppuhelper/source/servicemanager.cxx index 6e2f12813445..790a776392c4 100644 --- a/cppuhelper/source/servicemanager.cxx +++ b/cppuhelper/source/servicemanager.cxx @@ -14,8 +14,11 @@ #include <iostream> #include <mutex> #include <string_view> +#include <utility> #include <vector> +#include <config_fuzzers.h> + #include <com/sun/star/beans/NamedValue.hpp> #include <com/sun/star/beans/PropertyAttribute.hpp> #include <com/sun/star/container/ElementExistException.hpp> @@ -46,6 +49,7 @@ #include <sal/log.hxx> #include <uno/environment.hxx> #include <uno/mapping.hxx> +#include <o3tl/string_view.hxx> #include "loadsharedlibcomponentfactory.hxx" @@ -105,7 +109,7 @@ class Parser { public: Parser( OUString const & uri, - css::uno::Reference< css::uno::XComponentContext > const & alienContext, + css::uno::Reference< css::uno::XComponentContext > alienContext, cppuhelper::ServiceManager::Data * data); Parser(const Parser&) = delete; @@ -135,9 +139,9 @@ private: Parser::Parser( OUString const & uri, - css::uno::Reference< css::uno::XComponentContext > const & alienContext, + css::uno::Reference< css::uno::XComponentContext > alienContext, cppuhelper::ServiceManager::Data * data): - reader_(uri), alienContext_(alienContext), data_(data) + reader_(uri), alienContext_(std::move(alienContext)), data_(data) { assert(data != nullptr); int ucNsId = reader_.registerNamespaceIri( @@ -480,7 +484,7 @@ css::uno::Any ContentEnumeration::nextElement() std::scoped_lock g(mutex_); if (iterator_ == factories_.end()) { throw css::container::NoSuchElementException( - "Bootstrap service manager service enumerator has no more elements", + u"Bootstrap service manager service enumerator has no more elements"_ustr, static_cast< cppu::OWeakObject * >(this)); } return *iterator_++; @@ -488,7 +492,7 @@ css::uno::Any ContentEnumeration::nextElement() css::beans::Property getDefaultContextProperty() { return css::beans::Property( - "DefaultContext", -1, + u"DefaultContext"_ustr, -1, cppu::UnoType< css::uno::XComponentContext >::get(), css::beans::PropertyAttribute::READONLY); } @@ -664,7 +668,7 @@ cppuhelper::ServiceManager::Data::Implementation::createInstance( { css::uno::Reference<css::uno::XInterface> inst; if (isSingleInstance) { - osl::MutexGuard g(mutex); + std::unique_lock g(mutex); if (!singleInstance.is()) { singleInstance = doCreateInstance(context); } @@ -683,7 +687,7 @@ cppuhelper::ServiceManager::Data::Implementation::createInstanceWithArguments( { css::uno::Reference<css::uno::XInterface> inst; if (isSingleInstance) { - osl::MutexGuard g(mutex); + std::unique_lock g(mutex); if (!singleInstance.is()) { singleInstance = doCreateInstanceWithArguments(context, arguments); } @@ -750,14 +754,14 @@ void cppuhelper::ServiceManager::Data::Implementation::updateDisposeInstance( // at most one of the instances obtained via the service manager, in case // the implementation hands out different instances): if (singletonRequest) { - osl::MutexGuard g(mutex); + std::unique_lock g(mutex); disposeInstance.clear(); dispose = false; } else if (shallDispose()) { css::uno::Reference<css::lang::XComponent> comp( instance, css::uno::UNO_QUERY); if (comp.is()) { - osl::MutexGuard g(mutex); + std::unique_lock g(mutex); if (dispose) { disposeInstance = comp; } @@ -780,9 +784,9 @@ void cppuhelper::ServiceManager::addSingletonContextEntries( entries->push_back( cppu::ContextEntry_Init( "/singletons/" + rName, - css::uno::makeAny< - css::uno::Reference<css::lang::XSingleComponentFactory> >( - new SingletonFactory(this, rImpls[0])), + css::uno::Any( + css::uno::Reference<css::lang::XSingleComponentFactory>( + new SingletonFactory(this, rImpls[0]))), true)); } } @@ -793,7 +797,7 @@ void cppuhelper::ServiceManager::loadImplementation( { assert(implementation); { - osl::MutexGuard g(rBHelper.rMutex); + std::unique_lock g(m_aMutex); if (implementation->status == Data::Implementation::STATUS_LOADED) { return; } @@ -869,8 +873,8 @@ void cppuhelper::ServiceManager::loadImplementation( //TODO: There is a race here, as the relevant service factory can be removed // while the mutex is unlocked and loading can thus fail, as the entity from // which to load can disappear once the service factory is removed. - osl::MutexGuard g(rBHelper.rMutex); - if (!(isDisposed() + std::unique_lock g(m_aMutex); + if (!(m_bDisposed || implementation->status == Data::Implementation::STATUS_LOADED)) { implementation->status = Data::Implementation::STATUS_LOADED; @@ -880,17 +884,16 @@ void cppuhelper::ServiceManager::loadImplementation( } } -void cppuhelper::ServiceManager::disposing() { +void cppuhelper::ServiceManager::disposing(std::unique_lock<std::mutex>& rGuard) { std::vector< css::uno::Reference<css::lang::XComponent> > sngls; std::vector< css::uno::Reference< css::lang::XComponent > > comps; Data clear; { - osl::MutexGuard g(rBHelper.rMutex); for (const auto& rEntry : data_.namedImplementations) { assert(rEntry.second); if (rEntry.second->shallDispose()) { - osl::MutexGuard g2(rEntry.second->mutex); + std::unique_lock g2(rEntry.second->mutex); if (rEntry.second->disposeInstance.is()) { sngls.push_back(rEntry.second->disposeInstance); } @@ -900,7 +903,7 @@ void cppuhelper::ServiceManager::disposing() { { assert(rEntry.second); if (rEntry.second->shallDispose()) { - osl::MutexGuard g2(rEntry.second->mutex); + std::unique_lock g2(rEntry.second->mutex); if (rEntry.second->disposeInstance.is()) { sngls.push_back(rEntry.second->disposeInstance); } @@ -914,6 +917,7 @@ void cppuhelper::ServiceManager::disposing() { data_.services.swap(clear.services); data_.singletons.swap(clear.singletons); } + rGuard.unlock(); for (const auto& rxSngl : sngls) { try { @@ -926,6 +930,7 @@ void cppuhelper::ServiceManager::disposing() { { removeEventListenerFromComponent(rxComp); } + rGuard.lock(); } void cppuhelper::ServiceManager::initialize( @@ -936,7 +941,7 @@ void cppuhelper::ServiceManager::initialize( || arg != "preload") { throw css::lang::IllegalArgumentException( - "invalid ServiceManager::initialize argument", + u"invalid ServiceManager::initialize argument"_ustr, css::uno::Reference<css::uno::XInterface>(), 0); } preloadImplementations(); @@ -945,7 +950,7 @@ void cppuhelper::ServiceManager::initialize( OUString cppuhelper::ServiceManager::getImplementationName() { return - "com.sun.star.comp.cppuhelper.bootstrap.ServiceManager"; + u"com.sun.star.comp.cppuhelper.bootstrap.ServiceManager"_ustr; } sal_Bool cppuhelper::ServiceManager::supportsService( @@ -957,7 +962,7 @@ sal_Bool cppuhelper::ServiceManager::supportsService( css::uno::Sequence< OUString > cppuhelper::ServiceManager::getSupportedServiceNames() { - return { "com.sun.star.lang.MultiServiceFactory", "com.sun.star.lang.ServiceManager" }; + return { u"com.sun.star.lang.MultiServiceFactory"_ustr, u"com.sun.star.lang.ServiceManager"_ustr }; } css::uno::Reference< css::uno::XInterface > @@ -981,13 +986,13 @@ cppuhelper::ServiceManager::createInstanceWithArguments( css::uno::Sequence< OUString > cppuhelper::ServiceManager::getAvailableServiceNames() { - osl::MutexGuard g(rBHelper.rMutex); - if (isDisposed()) { + std::unique_lock g(m_aMutex); + if (m_bDisposed) { return css::uno::Sequence< OUString >(); } if (data_.services.size() > o3tl::make_unsigned(SAL_MAX_INT32)) { throw css::uno::RuntimeException( - "getAvailableServiceNames: too many services", + u"getAvailableServiceNames: too many services"_ustr, static_cast< cppu::OWeakObject * >(this)); } return comphelper::mapKeysToSequence(data_.services); @@ -1023,7 +1028,7 @@ css::uno::Type cppuhelper::ServiceManager::getElementType() sal_Bool cppuhelper::ServiceManager::hasElements() { - osl::MutexGuard g(rBHelper.rMutex); + std::unique_lock g(m_aMutex); return !(data_.namedImplementations.empty() && data_.dynamicImplementations.empty()); @@ -1033,14 +1038,14 @@ css::uno::Reference< css::container::XEnumeration > cppuhelper::ServiceManager::createEnumeration() { throw css::uno::RuntimeException( - "ServiceManager createEnumeration: method not supported", + u"ServiceManager createEnumeration: method not supported"_ustr, static_cast< cppu::OWeakObject * >(this)); } sal_Bool cppuhelper::ServiceManager::has(css::uno::Any const &) { throw css::uno::RuntimeException( - "ServiceManager has: method not supported", + u"ServiceManager has: method not supported"_ustr, static_cast< cppu::OWeakObject * >(this)); } @@ -1050,24 +1055,24 @@ void cppuhelper::ServiceManager::insert(css::uno::Any const & aElement) if (aElement >>= args) { std::vector< OUString > uris; css::uno::Reference< css::uno::XComponentContext > alienContext; - for (const auto & arg : std::as_const(args)) { + for (const auto & arg : args) { if (arg.Name == "uri") { OUString uri; if (!(arg.Value >>= uri)) { throw css::lang::IllegalArgumentException( - "Bad uri argument", + u"Bad uri argument"_ustr, static_cast< cppu::OWeakObject * >(this), 0); } uris.push_back(uri); } else if (arg.Name == "component-context") { if (alienContext.is()) { throw css::lang::IllegalArgumentException( - "Multiple component-context arguments", + u"Multiple component-context arguments"_ustr, static_cast< cppu::OWeakObject * >(this), 0); } if (!(arg.Value >>= alienContext) || !alienContext.is()) { throw css::lang::IllegalArgumentException( - "Bad component-context argument", + u"Bad component-context argument"_ustr, static_cast< cppu::OWeakObject * >(this), 0); } } else { @@ -1084,27 +1089,9 @@ void cppuhelper::ServiceManager::insert(css::uno::Any const & aElement) insertLegacyFactory(info); return; } -// At least revisions up to 1.7 of LanguageTool.oxt (incl. the bundled 1.4.0 in -// module languagetool) contain an (actively registered) factory that does not -// implement XServiceInfo (see <http://sourceforge.net/tracker/? -// func=detail&aid=3526635&group_id=110216&atid=655717> "SingletonFactory should -// implement XServiceInfo"); the old OServiceManager::insert -// (stoc/source/servicemanager/servicemanager.cxx) silently did not add such -// broken factories to its m_ImplementationNameMap, so ignore them here for -// backwards compatibility of live-insertion of extensions, too. - -// (The plan was that this warning would go away (and we would do the -// throw instead) for the incompatible LO 4, but we changed our mind): - css::uno::Reference< css::lang::XSingleComponentFactory > legacy; - if ((aElement >>= legacy) && legacy.is()) { - SAL_WARN( - "cppuhelper", - "Ignored XSingleComponentFactory not implementing XServiceInfo"); - return; - } throw css::lang::IllegalArgumentException( - "Bad insert element", static_cast< cppu::OWeakObject * >(this), 0); + u"Bad insert element"_ustr, static_cast< cppu::OWeakObject * >(this), 0); } void cppuhelper::ServiceManager::remove(css::uno::Any const & aElement) @@ -1112,7 +1099,7 @@ void cppuhelper::ServiceManager::remove(css::uno::Any const & aElement) css::uno::Sequence< css::beans::NamedValue > args; if (aElement >>= args) { std::vector< OUString > uris; - for (const auto & i : std::as_const(args)) { + for (const auto & i : args) { if (i.Name != "uri") { throw css::lang::IllegalArgumentException( "Bad argument " + i.Name, @@ -1121,7 +1108,7 @@ void cppuhelper::ServiceManager::remove(css::uno::Any const & aElement) OUString uri; if (!(i.Value >>= uri)) { throw css::lang::IllegalArgumentException( - "Bad uri argument", + u"Bad uri argument"_ustr, static_cast< cppu::OWeakObject * >(this), 0); } uris.push_back(uri); @@ -1133,7 +1120,7 @@ void cppuhelper::ServiceManager::remove(css::uno::Any const & aElement) if ((aElement >>= info) && info.is()) { if (!removeLegacyFactory(info, true)) { throw css::container::NoSuchElementException( - "Remove non-inserted factory object", + u"Remove non-inserted factory object"_ustr, static_cast< cppu::OWeakObject * >(this)); } return; @@ -1145,7 +1132,7 @@ void cppuhelper::ServiceManager::remove(css::uno::Any const & aElement) return; } throw css::lang::IllegalArgumentException( - "Bad remove element", static_cast< cppu::OWeakObject * >(this), 0); + u"Bad remove element"_ustr, static_cast< cppu::OWeakObject * >(this), 0); } css::uno::Reference< css::container::XEnumeration > @@ -1154,7 +1141,7 @@ cppuhelper::ServiceManager::createContentEnumeration( { std::vector< std::shared_ptr< Data::Implementation > > impls; { - osl::MutexGuard g(rBHelper.rMutex); + std::unique_lock g(m_aMutex); Data::ImplementationMap::const_iterator i( data_.services.find(aServiceName)); if (i != data_.services.end()) { @@ -1167,8 +1154,8 @@ cppuhelper::ServiceManager::createContentEnumeration( Data::Implementation * impl = rxImpl.get(); assert(impl != nullptr); { - osl::MutexGuard g(rBHelper.rMutex); - if (isDisposed()) { + std::unique_lock g(m_aMutex); + if (m_bDisposed) { factories.clear(); break; } @@ -1322,10 +1309,10 @@ void cppuhelper::ServiceManager::removeEventListenerFromComponent( } } -void cppuhelper::ServiceManager::init(OUString const & rdbUris) { +void cppuhelper::ServiceManager::init(std::u16string_view rdbUris) { for (sal_Int32 i = 0; i != -1;) { - OUString uri(rdbUris.getToken(0, ' ', i)); - if (uri.isEmpty()) { + std::u16string_view uri(o3tl::getToken(rdbUris, 0, ' ', i)); + if (uri.empty()) { continue; } bool optional; @@ -1334,27 +1321,27 @@ void cppuhelper::ServiceManager::init(OUString const & rdbUris) { if (directory) { readRdbDirectory(uri, optional); } else { - readRdbFile(uri, optional); + readRdbFile(OUString(uri), optional); } } } void cppuhelper::ServiceManager::readRdbDirectory( - OUString const & uri, bool optional) + std::u16string_view uri, bool optional) { - osl::Directory dir(uri); + osl::Directory dir = OUString(uri); switch (dir.open()) { case osl::FileBase::E_None: break; case osl::FileBase::E_NOENT: if (optional) { - SAL_INFO("cppuhelper", "Ignored optional " << uri); + SAL_INFO("cppuhelper", "Ignored optional " << OUString(uri)); return; } [[fallthrough]]; default: throw css::uno::DeploymentException( - "Cannot open directory " + uri, + OUString::Concat("Cannot open directory ") + uri, static_cast< cppu::OWeakObject * >(this)); } for (;;) { @@ -1379,7 +1366,9 @@ void cppuhelper::ServiceManager::readRdbFile( static_cast< cppu::OWeakObject * >(this)); } SAL_INFO("cppuhelper", "Ignored optional " << uri); - } catch (css::registry::InvalidRegistryException & e) { + } +#if !ENABLE_FUZZERS + catch (css::registry::InvalidRegistryException & e) { if (!readLegacyRdbFile(uri)) { throw css::uno::DeploymentException( "InvalidRegistryException: " + e.Message, @@ -1390,8 +1379,10 @@ void cppuhelper::ServiceManager::readRdbFile( throw; } } +#endif } +#if !ENABLE_FUZZERS bool cppuhelper::ServiceManager::readLegacyRdbFile(OUString const & uri) { Registry reg; switch (reg.open(uri, RegAccessMode::READONLY)) { @@ -1424,7 +1415,7 @@ bool cppuhelper::ServiceManager::readLegacyRdbFile(OUString const & uri) { static_cast< cppu::OWeakObject * >(this)); } RegistryKeyArray impls; - switch (rootKey.openSubKeys("IMPLEMENTATIONS", impls)) { + switch (rootKey.openSubKeys(u"IMPLEMENTATIONS"_ustr, impls)) { case RegError::NO_ERROR: break; case RegError::KEY_NOT_EXISTS: @@ -1441,8 +1432,8 @@ bool cppuhelper::ServiceManager::readLegacyRdbFile(OUString const & uri) { implKey.getName().copy(RTL_CONSTASCII_LENGTH("/IMPLEMENTATIONS/"))); std::shared_ptr< Data::Implementation > impl = std::make_shared<Data::Implementation>( - name, readLegacyRdbString(uri, implKey, "UNO/ACTIVATOR"), - readLegacyRdbString(uri, implKey, "UNO/LOCATION"), "", "", "", false, + name, readLegacyRdbString(uri, implKey, u"UNO/ACTIVATOR"_ustr), + readLegacyRdbString(uri, implKey, u"UNO/LOCATION"_ustr), "", "", "", false, css::uno::Reference< css::uno::XComponentContext >(), uri); if (!data_.namedImplementations.emplace(name, impl).second) { @@ -1450,13 +1441,13 @@ bool cppuhelper::ServiceManager::readLegacyRdbFile(OUString const & uri) { uri + ": duplicate <implementation name=\"" + name + "\">"); } readLegacyRdbStrings( - uri, implKey, "UNO/SERVICES", &impl->services); + uri, implKey, u"UNO/SERVICES"_ustr, &impl->services); for (const auto& rService : impl->services) { data_.services[rService].push_back(impl); } readLegacyRdbStrings( - uri, implKey, "UNO/SINGLETONS", &impl->singletons); + uri, implKey, u"UNO/SINGLETONS"_ustr, &impl->singletons); for (const auto& rSingleton : impl->singletons) { data_.singletons[rSingleton].push_back(impl); @@ -1526,6 +1517,7 @@ void cppuhelper::ServiceManager::readLegacyRdbStrings( strings->push_back(names.getElement(i).copy(prefix.getLength())); } } +#endif void cppuhelper::ServiceManager::insertRdbFiles( std::vector< OUString > const & uris, @@ -1561,8 +1553,8 @@ void cppuhelper::ServiceManager::insertLegacyFactory( f2.set(factoryInfo, css::uno::UNO_QUERY); if (!f2.is()) { throw css::lang::IllegalArgumentException( - ("Bad XServiceInfo argument implements neither" - " XSingleComponentFactory nor XSingleServiceFactory"), + (u"Bad XServiceInfo argument implements neither" + " XSingleComponentFactory nor XSingleServiceFactory"_ustr), static_cast< cppu::OWeakObject * >(this), 0); } } @@ -1588,8 +1580,8 @@ void cppuhelper::ServiceManager::insertLegacyFactory( bool cppuhelper::ServiceManager::insertExtraData(Data const & extra) { { - osl::MutexGuard g(rBHelper.rMutex); - if (isDisposed()) { + std::unique_lock g(m_aMutex); + if (m_bDisposed) { return false; } auto i = std::find_if(extra.namedImplementations.begin(), extra.namedImplementations.end(), @@ -1607,7 +1599,7 @@ bool cppuhelper::ServiceManager::insertExtraData(Data const & extra) { if (bDuplicate) { throw css::lang::IllegalArgumentException( - "Insert duplicate factory object", + u"Insert duplicate factory object"_ustr, static_cast< cppu::OWeakObject * >(this), 0); } //TODO: The below leaves data_ in an inconsistent state upon exceptions: @@ -1667,7 +1659,7 @@ void cppuhelper::ServiceManager::removeRdbFiles( // it is called with a uris vector of size one): std::vector< std::shared_ptr< Data::Implementation > > clear; { - osl::MutexGuard g(rBHelper.rMutex); + std::unique_lock g(m_aMutex); for (const auto& rUri : uris) { for (Data::NamedImplementations::iterator j( @@ -1702,11 +1694,11 @@ bool cppuhelper::ServiceManager::removeLegacyFactory( std::shared_ptr< Data::Implementation > clear; css::uno::Reference< css::lang::XComponent > comp; { - osl::MutexGuard g(rBHelper.rMutex); + std::unique_lock g(m_aMutex); Data::DynamicImplementations::iterator i( data_.dynamicImplementations.find(factoryInfo)); if (i == data_.dynamicImplementations.end()) { - return isDisposed(); + return m_bDisposed; } assert(i->second); clear = i->second; @@ -1734,8 +1726,8 @@ void cppuhelper::ServiceManager::removeImplementation(const OUString & name) { // but the assumption is that it is rarely called: std::shared_ptr< Data::Implementation > clear; { - osl::MutexGuard g(rBHelper.rMutex); - if (isDisposed()) { + std::unique_lock g(m_aMutex); + if (m_bDisposed) { return; } Data::NamedImplementations::iterator i( @@ -1768,7 +1760,7 @@ cppuhelper::ServiceManager::findServiceImplementation( std::shared_ptr< Data::Implementation > impl; bool loaded; { - osl::MutexGuard g(rBHelper.rMutex); + std::unique_lock g(m_aMutex); Data::ImplementationMap::const_iterator i( data_.services.find(specifier)); if (i == data_.services.end()) { @@ -1830,7 +1822,7 @@ void cppuhelper::ServiceManager::preloadImplementations() { abort(); #else OUString aUri; - osl::MutexGuard g(rBHelper.rMutex); + std::unique_lock g(m_aMutex); css::uno::Environment aSourceEnv(css::uno::Environment::getCurrent()); std::cerr << "preload:"; @@ -1846,7 +1838,7 @@ void cppuhelper::ServiceManager::preloadImplementations() { OUString aDisable(pDisable, strlen(pDisable), RTL_TEXTENCODING_UTF8); for (sal_Int32 i = 0; i >= 0; ) { - OUString tok = aDisable.getToken(0, ' ', i); + OUString tok( aDisable.getToken(0, ' ', i) ); tok = tok.trim(); if (!tok.isEmpty()) aDisabled.push_back(tok); @@ -1877,8 +1869,7 @@ void cppuhelper::ServiceManager::preloadImplementations() { { if (bDisabled) { - aDisabledMsg.append(simplified); - aDisabledMsg.append(" "); + aDisabledMsg.append(simplified + " "); } else { @@ -1906,8 +1897,7 @@ void cppuhelper::ServiceManager::preloadImplementations() { if (!aModule.is()) { - aMissingMsg.append(simplified); - aMissingMsg.append(" "); + aMissingMsg.append(simplified + " "); } if (aModule.is() && @@ -1991,7 +1981,10 @@ void cppuhelper::ServiceManager::preloadImplementations() { if (std::find(aPreloaded.begin(), aPreloaded.end(), fpPreload) == aPreloaded.end()) { aPreloaded.push_back(fpPreload); + // unlock because we may be instantiating some services here + g.unlock(); fpPreload(); + g.lock(); } } diff --git a/cppuhelper/source/servicemanager.hxx b/cppuhelper/source/servicemanager.hxx index d086a8d65ead..af80be25a183 100644 --- a/cppuhelper/source/servicemanager.hxx +++ b/cppuhelper/source/servicemanager.hxx @@ -12,9 +12,12 @@ #include <sal/config.h> #include <cassert> -#include <unordered_map> +#include <functional> #include <memory> +#include <mutex> #include <string_view> +#include <unordered_map> +#include <utility> #include <vector> #include <com/sun/star/beans/XPropertySet.hpp> @@ -27,9 +30,7 @@ #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/uno/Reference.hxx> -#include <cppuhelper/basemutex.hxx> -#include <cppuhelper/compbase.hxx> -#include <osl/mutex.hxx> +#include <compbase2.hxx> #include <rtl/ustring.hxx> namespace com::sun::star::lang { @@ -52,7 +53,7 @@ typedef css::uno::XInterface * ImplementationConstructorFn( typedef std::function<css::uno::XInterface * (css::uno::XComponentContext *, css::uno::Sequence<css::uno::Any> const&)> WrapperConstructorFn; -typedef cppu::WeakComponentImplHelper< +typedef WeakComponentImplHelper2< css::lang::XServiceInfo, css::lang::XMultiServiceFactory, css::lang::XMultiComponentFactory, css::container::XSet, css::container::XContentEnumerationAccess, css::beans::XPropertySet, @@ -60,8 +61,7 @@ typedef cppu::WeakComponentImplHelper< css::lang::XInitialization> ServiceManagerBase; -class ServiceManager: - private cppu::BaseMutex, public ServiceManagerBase +class ServiceManager : public ServiceManagerBase { public: struct Data { @@ -71,32 +71,30 @@ public: struct Implementation { Implementation( - OUString const & theName, OUString const & theLoader, - OUString const & theUri, OUString const & theEnvironment, - OUString const & theConstructorName, - OUString const & thePrefix, + OUString theName, OUString theLoader, + OUString theUri, OUString theEnvironment, + OUString theConstructorName, + OUString thePrefix, bool theIsSingleInstance, - css::uno::Reference< css::uno::XComponentContext > const & - theAlienContext, - OUString const & theRdbFile): - name(theName), loader(theLoader), uri(theUri), environment(theEnvironment), - constructorName(theConstructorName), prefix(thePrefix), + css::uno::Reference< css::uno::XComponentContext > theAlienContext, + OUString theRdbFile): + name(std::move(theName)), loader(std::move(theLoader)), uri(std::move(theUri)), environment(std::move(theEnvironment)), + constructorName(std::move(theConstructorName)), prefix(std::move(thePrefix)), isSingleInstance(theIsSingleInstance), - alienContext(theAlienContext), rdbFile(theRdbFile), + alienContext(std::move(theAlienContext)), rdbFile(std::move(theRdbFile)), constructorFn(nullptr), status(STATUS_NEW), dispose(true) {} Implementation( - OUString const & theName, + OUString theName, css::uno::Reference< css::lang::XSingleComponentFactory > const & theFactory1, css::uno::Reference< css::lang::XSingleServiceFactory > const & theFactory2, - css::uno::Reference< css::lang::XComponent > const & - theComponent): - name(theName), isSingleInstance(false), constructorFn(nullptr), + css::uno::Reference< css::lang::XComponent > theComponent): + name(std::move(theName)), isSingleInstance(false), constructorFn(nullptr), factory1(theFactory1), factory2(theFactory2), - component(theComponent), status(STATUS_LOADED), dispose(true) + component(std::move(theComponent)), status(STATUS_LOADED), dispose(true) { assert(theFactory1.is() || theFactory2.is()); } Implementation(const Implementation&) = delete; @@ -146,7 +144,7 @@ public: css::uno::Reference< css::lang::XComponent > component; Status status; - osl::Mutex mutex; + std::mutex mutex; css::uno::Reference<css::uno::XInterface> singleInstance; css::uno::Reference< css::lang::XComponent > disposeInstance; bool dispose; @@ -185,7 +183,7 @@ public: ImplementationMap singletons; }; - ServiceManager(): ServiceManagerBase(m_aMutex) {} + ServiceManager() {} ServiceManager(const ServiceManager&) = delete; const ServiceManager& operator=(const ServiceManager&) = delete; @@ -193,7 +191,7 @@ public: using ServiceManagerBase::acquire; using ServiceManagerBase::release; - void init(OUString const & rdbUris); + void init(std::u16string_view rdbUris); void setContext( css::uno::Reference< css::uno::XComponentContext > const & context) @@ -220,7 +218,7 @@ public: private: virtual ~ServiceManager() override; - virtual void SAL_CALL disposing() override; + virtual void disposing(std::unique_lock<std::mutex>&) override; virtual OUString SAL_CALL getImplementationName() override; @@ -309,13 +307,10 @@ private: css::uno::Sequence<css::uno::Any> const & aArguments) override; - // needs to be called with rBHelper.rMutex locked: - bool isDisposed() const { return rBHelper.bDisposed || rBHelper.bInDispose; } - void removeEventListenerFromComponent( css::uno::Reference< css::lang::XComponent > const & component); - void readRdbDirectory(OUString const & uri, bool optional); + void readRdbDirectory(std::u16string_view uri, bool optional); void readRdbFile(OUString const & uri, bool optional); diff --git a/cppuhelper/source/shlib.cxx b/cppuhelper/source/shlib.cxx index 41af3dd80ebc..b6885cbed770 100644 --- a/cppuhelper/source/shlib.cxx +++ b/cppuhelper/source/shlib.cxx @@ -34,6 +34,7 @@ #include <com/sun/star/registry/XRegistryKey.hpp> #include <cppuhelper/factory.hxx> #include <cppuhelper/shlib.hxx> +#include <o3tl/string_view.hxx> #include <osl/module.hxx> #include <sal/log.hxx> #include <uno/environment.hxx> @@ -46,17 +47,17 @@ #endif css::uno::Environment cppuhelper::detail::getEnvironment( - OUString const & name, OUString const & implementation) + OUString const & name, std::u16string_view implementation) { OUString n(name); - if (!implementation.isEmpty()) { + if (!implementation.empty()) { static char const * log = std::getenv("UNO_ENV_LOG"); if (log != nullptr && *log != 0) { OString imps(log); for (sal_Int32 i = 0; i != -1;) { - OString imp(imps.getToken(0, ';', i)); + std::string_view imp(o3tl::getToken(imps, 0, ';', i)); //TODO: this assumes UNO_ENV_LOG only contains ASCII characters: - if (implementation.equalsAsciiL(imp.getStr(), imp.getLength())) + if (o3tl::equalsAscii(implementation, imp)) { n += ":log"; break; @@ -73,7 +74,7 @@ namespace { css::uno::Environment getEnvironmentFromModule( osl::Module const & module, css::uno::Environment const & target, - OUString const & implementation, OUString const & prefix) + std::u16string_view implementation, OUString const & prefix) { char const * name = nullptr; css::uno::Environment env; @@ -125,7 +126,7 @@ css::uno::Reference<css::uno::XInterface> invokeComponentFactory( { if (!(source.is() && target.is())) { throw css::loader::CannotActivateFactoryException( - "cannot get environments", + u"cannot get environments"_ustr, css::uno::Reference<css::uno::XInterface>()); } OString impl( @@ -140,7 +141,7 @@ css::uno::Reference<css::uno::XInterface> invokeComponentFactory( css::uno::Mapping mapFrom(target, source); if (!(mapTo.is() && mapFrom.is())) { throw css::loader::CannotActivateFactoryException( - "cannot get mappings", + u"cannot get mappings"_ustr, css::uno::Reference<css::uno::XInterface>()); } void * smgr = mapTo.mapInterface( @@ -188,7 +189,7 @@ cppuhelper::WrapperConstructorFn mapConstructorFn( { if (!(source.is() && target.is())) { throw css::loader::CannotActivateFactoryException( - "cannot get environments", + u"cannot get environments"_ustr, css::uno::Reference<css::uno::XInterface>()); } if (source.get() == target.get()) { @@ -201,7 +202,7 @@ cppuhelper::WrapperConstructorFn mapConstructorFn( css::uno::Mapping mapFrom(target, source); if (!(mapTo.is() && mapFrom.is())) { throw css::loader::CannotActivateFactoryException( - "cannot get mappings", + u"cannot get mappings"_ustr, css::uno::Reference<css::uno::XInterface>()); } return [mapFrom, mapTo, target, constructorFunction] @@ -364,7 +365,7 @@ css::uno::Reference<css::uno::XInterface> cppu::loadSharedLibComponentFactory( assert(!xKey.is()); (void) xKey; css::uno::Reference<css::uno::XInterface> fac; cppuhelper::detail::loadSharedLibComponentFactory( - uri, "", "", rImplName, "", xMgr, nullptr, &fac); + uri, u""_ustr, u""_ustr, rImplName, u""_ustr, xMgr, nullptr, &fac); return fac; } @@ -402,16 +403,16 @@ void cppu::writeSharedLibComponentInfo( css::uno::Reference<css::uno::XInterface>()); } css::uno::Environment curEnv(css::uno::Environment::getCurrent()); - css::uno::Environment env(getEnvironmentFromModule(mod, curEnv, "", "")); + css::uno::Environment env(getEnvironmentFromModule(mod, curEnv, u"", u""_ustr)); if (!(curEnv.is() && env.is())) { throw css::registry::CannotRegisterImplementationException( - "cannot get environments", + u"cannot get environments"_ustr, css::uno::Reference<css::uno::XInterface>()); } css::uno::Mapping map(curEnv, env); if (!map.is()) { throw css::registry::CannotRegisterImplementationException( - "cannot get mapping", css::uno::Reference<css::uno::XInterface>()); + u"cannot get mapping"_ustr, css::uno::Reference<css::uno::XInterface>()); } void * smgr = map.mapInterface( xMgr.get(), cppu::UnoType<css::lang::XMultiServiceFactory>::get()); diff --git a/cppuhelper/source/tdmgr.cxx b/cppuhelper/source/tdmgr.cxx index 1e5826e248c7..821e4871204a 100644 --- a/cppuhelper/source/tdmgr.cxx +++ b/cppuhelper/source/tdmgr.cxx @@ -431,91 +431,91 @@ static typelib_TypeDescription * createCTD( // built in types case TypeClass_VOID: { - OUString aTypeName("void"); + OUString aTypeName(u"void"_ustr); typelib_typedescription_new( &pRet, typelib_TypeClass_VOID, aTypeName.pData, nullptr, 0, nullptr ); break; } case TypeClass_CHAR: { - OUString aTypeName("char"); + OUString aTypeName(u"char"_ustr); typelib_typedescription_new( &pRet, typelib_TypeClass_CHAR, aTypeName.pData, nullptr, 0, nullptr ); break; } case TypeClass_BOOLEAN: { - OUString aTypeName("boolean"); + OUString aTypeName(u"boolean"_ustr); typelib_typedescription_new( &pRet, typelib_TypeClass_BOOLEAN, aTypeName.pData, nullptr, 0, nullptr ); break; } case TypeClass_BYTE: { - OUString aTypeName("byte"); + OUString aTypeName(u"byte"_ustr); typelib_typedescription_new( &pRet, typelib_TypeClass_BYTE, aTypeName.pData, nullptr, 0, nullptr ); break; } case TypeClass_SHORT: { - OUString aTypeName("short"); + OUString aTypeName(u"short"_ustr); typelib_typedescription_new( &pRet, typelib_TypeClass_SHORT, aTypeName.pData, nullptr, 0, nullptr ); break; } case TypeClass_UNSIGNED_SHORT: { - OUString aTypeName("unsigned short"); + OUString aTypeName(u"unsigned short"_ustr); typelib_typedescription_new( &pRet, typelib_TypeClass_UNSIGNED_SHORT, aTypeName.pData, nullptr, 0, nullptr ); break; } case TypeClass_LONG: { - OUString aTypeName("long"); + OUString aTypeName(u"long"_ustr); typelib_typedescription_new( &pRet, typelib_TypeClass_LONG, aTypeName.pData, nullptr, 0, nullptr ); break; } case TypeClass_UNSIGNED_LONG: { - OUString aTypeName("unsigned long"); + OUString aTypeName(u"unsigned long"_ustr); typelib_typedescription_new( &pRet, typelib_TypeClass_UNSIGNED_LONG, aTypeName.pData, nullptr, 0, nullptr ); break; } case TypeClass_HYPER: { - OUString aTypeName("hyper"); + OUString aTypeName(u"hyper"_ustr); typelib_typedescription_new( &pRet, typelib_TypeClass_HYPER, aTypeName.pData, nullptr, 0, nullptr ); break; } case TypeClass_UNSIGNED_HYPER: { - OUString aTypeName("unsigned hyper"); + OUString aTypeName(u"unsigned hyper"_ustr); typelib_typedescription_new( &pRet, typelib_TypeClass_UNSIGNED_HYPER, aTypeName.pData, nullptr, 0, nullptr ); break; } case TypeClass_FLOAT: { - OUString aTypeName("float"); + OUString aTypeName(u"float"_ustr); typelib_typedescription_new( &pRet, typelib_TypeClass_FLOAT, aTypeName.pData, nullptr, 0, nullptr ); break; } case TypeClass_DOUBLE: { - OUString aTypeName("double"); + OUString aTypeName(u"double"_ustr); typelib_typedescription_new( &pRet, typelib_TypeClass_DOUBLE, aTypeName.pData, nullptr, 0, nullptr ); break; } case TypeClass_STRING: { - OUString aTypeName("string"); + OUString aTypeName(u"string"_ustr); typelib_typedescription_new( &pRet, typelib_TypeClass_STRING, aTypeName.pData, nullptr, 0, nullptr ); break; } case TypeClass_TYPE: { - OUString aTypeName("type"); + OUString aTypeName(u"type"_ustr); typelib_typedescription_new( &pRet, typelib_TypeClass_TYPE, aTypeName.pData, nullptr, 0, nullptr ); break; } case TypeClass_ANY: { - OUString aTypeName("any"); + OUString aTypeName(u"any"_ustr); typelib_typedescription_new( &pRet, typelib_TypeClass_ANY, aTypeName.pData, nullptr, 0, nullptr ); break; } diff --git a/cppuhelper/source/typemanager.cxx b/cppuhelper/source/typemanager.cxx index 7d22994a1767..2d48326e540b 100644 --- a/cppuhelper/source/typemanager.cxx +++ b/cppuhelper/source/typemanager.cxx @@ -17,7 +17,9 @@ #include <set> #include <stack> #include <string_view> +#include <utility> #include <vector> +#include <algorithm> #include <com/sun/star/container/NoSuchElementException.hpp> #include <com/sun/star/lang/IllegalArgumentException.hpp> @@ -52,6 +54,7 @@ #include <sal/log.hxx> #include <sal/macros.h> #include <sal/types.h> +#include <o3tl/string_view.hxx> #include <unoidl/unoidl.hxx> @@ -80,8 +83,8 @@ class SimpleTypeDescription: { public: SimpleTypeDescription( - css::uno::TypeClass typeClass, OUString const & name): - typeClass_(typeClass), name_(name) + css::uno::TypeClass typeClass, OUString name): + typeClass_(typeClass), name_(std::move(name)) {} private: @@ -103,8 +106,8 @@ class SequenceTypeDescription: public: SequenceTypeDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - OUString const & name, OUString const & componentType): - manager_(manager), name_(name), componentType_(componentType) + OUString name, OUString componentType): + manager_(manager), name_(std::move(name)), componentType_(std::move(componentType)) { assert(manager.is()); } private: @@ -146,9 +149,9 @@ class ModuleDescription: public: ModuleDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - OUString const & name, + OUString name, rtl::Reference< unoidl::ModuleEntity > const & entity): - manager_(manager), name_(name), entity_(entity) + manager_(manager), name_(std::move(name)), entity_(entity) { assert(manager.is()); assert(entity.is()); } private: @@ -197,9 +200,9 @@ EnumTypeDescription_Base; class EnumTypeDescription: public EnumTypeDescription_Base { public: EnumTypeDescription( - OUString const & name, + OUString name, rtl::Reference< unoidl::EnumTypeEntity > const & entity): - EnumTypeDescription_Base(entity->isPublished()), name_(name), + EnumTypeDescription_Base(entity->isPublished()), name_(std::move(name)), entity_(entity) { assert(entity.is()); } @@ -255,10 +258,10 @@ class PlainStructTypeDescription: public PlainStructTypeDescription_Base { public: PlainStructTypeDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - OUString const & name, + OUString name, rtl::Reference< unoidl::PlainStructTypeEntity > const & entity): PlainStructTypeDescription_Base(entity->isPublished()), - manager_(manager), name_(name), entity_(entity) + manager_(manager), name_(std::move(name)), entity_(entity) { assert(manager.is()); assert(entity.is()); } private: @@ -331,8 +334,8 @@ class ParameterizedMemberTypeDescription: { public: explicit ParameterizedMemberTypeDescription( - OUString const & typeParameterName): - typeParameterName_(typeParameterName) + OUString typeParameterName): + typeParameterName_(std::move(typeParameterName)) {} private: @@ -357,11 +360,11 @@ class PolymorphicStructTypeTemplateDescription: public: PolymorphicStructTypeTemplateDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - OUString const & name, + OUString name, rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const & entity): PolymorphicStructTypeTemplateDescription_Base(entity->isPublished()), - manager_(manager), name_(name), entity_(entity) + manager_(manager), name_(std::move(name)), entity_(entity) { assert(manager.is()); assert(entity.is()); } private: @@ -448,11 +451,11 @@ class InstantiatedPolymorphicStructTypeDescription: public: InstantiatedPolymorphicStructTypeDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - OUString const & name, + OUString name, rtl::Reference< unoidl::PolymorphicStructTypeTemplateEntity > const & entity, std::vector< OUString >&& arguments): - manager_(manager), name_(name), entity_(entity), arguments_(std::move(arguments)) + manager_(manager), name_(std::move(name)), entity_(entity), arguments_(std::move(arguments)) { assert(manager.is()); assert(entity.is()); @@ -551,10 +554,10 @@ class ExceptionTypeDescription: public ExceptionTypeDescription_Base { public: ExceptionTypeDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - OUString const & name, + OUString name, rtl::Reference< unoidl::ExceptionTypeEntity > const & entity): ExceptionTypeDescription_Base(entity->isPublished()), manager_(manager), - name_(name), entity_(entity) + name_(std::move(name)), entity_(entity) { assert(manager.is()); assert(entity.is()); } private: @@ -617,10 +620,10 @@ class AttributeDescription: public: AttributeDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - OUString const & name, - unoidl::InterfaceTypeEntity::Attribute const & attribute, + OUString name, + unoidl::InterfaceTypeEntity::Attribute attribute, sal_Int32 position): - manager_(manager), name_(name), attribute_(attribute), + manager_(manager), name_(std::move(name)), attribute_(std::move(attribute)), position_(position) { assert(manager.is()); } @@ -703,9 +706,9 @@ class MethodParameter: public: MethodParameter( rtl::Reference< cppuhelper::TypeManager > const & manager, - unoidl::InterfaceTypeEntity::Method::Parameter const & parameter, + unoidl::InterfaceTypeEntity::Method::Parameter parameter, sal_Int32 position): - manager_(manager), parameter_(parameter), position_(position) + manager_(manager), parameter_(std::move(parameter)), position_(position) { assert(manager.is()); } private: @@ -751,9 +754,9 @@ class MethodDescription: public: MethodDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - OUString const & name, - unoidl::InterfaceTypeEntity::Method const & method, sal_Int32 position): - manager_(manager), name_(name), method_(method), position_(position) + OUString name, + unoidl::InterfaceTypeEntity::Method method, sal_Int32 position): + manager_(manager), name_(std::move(name)), method_(std::move(method)), position_(position) { assert(manager.is()); } private: @@ -862,7 +865,7 @@ void BaseOffset::calculateBases( for (const auto & i : bases) { calculate( css::uno::Reference< css::reflection::XInterfaceTypeDescription2 >( - resolveTypedefs(css::uno::makeAny(i)), + resolveTypedefs(css::uno::Any(i)), css::uno::UNO_QUERY_THROW)); } } @@ -885,10 +888,10 @@ class InterfaceTypeDescription: public InterfaceTypeDescription_Base { public: InterfaceTypeDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - OUString const & name, + OUString name, rtl::Reference< unoidl::InterfaceTypeEntity > const & entity): InterfaceTypeDescription_Base(entity->isPublished()), manager_(manager), - name_(name), entity_(entity) + name_(std::move(name)), entity_(entity) { assert(manager.is()); assert(entity.is()); } private: @@ -1060,9 +1063,9 @@ ConstantGroupDescription_Base; class ConstantGroupDescription: public ConstantGroupDescription_Base { public: ConstantGroupDescription( - OUString const & name, + OUString name, rtl::Reference< unoidl::ConstantGroupEntity > const & entity): - ConstantGroupDescription_Base(entity->isPublished()), name_(name), + ConstantGroupDescription_Base(entity->isPublished()), name_(std::move(name)), entity_(entity) { assert(entity.is()); } @@ -1106,10 +1109,10 @@ class TypedefDescription: public TypedefDescription_Base { public: TypedefDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - OUString const & name, + OUString name, rtl::Reference< unoidl::TypedefEntity > const & entity): TypedefDescription_Base(entity->isPublished()), manager_(manager), - name_(name), entity_(entity) + name_(std::move(name)), entity_(entity) { assert(manager.is()); assert(entity.is()); } private: @@ -1136,10 +1139,9 @@ class ConstructorParameter: public: ConstructorParameter( rtl::Reference< cppuhelper::TypeManager > const & manager, - unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter - const & parameter, + unoidl::SingleInterfaceBasedServiceEntity::Constructor::Parameter parameter, sal_Int32 position): - manager_(manager), parameter_(parameter), position_(position) + manager_(manager), parameter_(std::move(parameter)), position_(position) { assert(manager.is()); } private: @@ -1177,9 +1179,8 @@ class ConstructorDescription: public: ConstructorDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - unoidl::SingleInterfaceBasedServiceEntity::Constructor const & - constructor): - manager_(manager), constructor_(constructor) + unoidl::SingleInterfaceBasedServiceEntity::Constructor constructor): + manager_(manager), constructor_(std::move(constructor)) { assert(manager.is()); } private: @@ -1245,11 +1246,11 @@ class SingleInterfaceBasedServiceDescription: public: SingleInterfaceBasedServiceDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - OUString const & name, + OUString name, rtl::Reference< unoidl::SingleInterfaceBasedServiceEntity > const & entity): SingleInterfaceBasedServiceDescription_Base(entity->isPublished()), - manager_(manager), name_(name), entity_(entity) + manager_(manager), name_(std::move(name)), entity_(entity) { assert(manager.is()); assert(entity.is()); } private: @@ -1349,8 +1350,8 @@ class PropertyDescription: public: PropertyDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - unoidl::AccumulationBasedServiceEntity::Property const & property): - manager_(manager), property_(property) + unoidl::AccumulationBasedServiceEntity::Property property): + manager_(manager), property_(std::move(property)) { assert(manager.is()); } private: @@ -1383,11 +1384,11 @@ class AccumulationBasedServiceDescription: public: AccumulationBasedServiceDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - OUString const & name, + OUString name, rtl::Reference< unoidl::AccumulationBasedServiceEntity > const & entity): AccumulationBasedServiceDescription_Base(entity->isPublished()), - manager_(manager), name_(name), entity_(entity) + manager_(manager), name_(std::move(name)), entity_(entity) { assert(manager.is()); assert(entity.is()); } private: @@ -1552,10 +1553,10 @@ class InterfaceBasedSingletonDescription: public: InterfaceBasedSingletonDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - OUString const & name, + OUString name, rtl::Reference< unoidl::InterfaceBasedSingletonEntity > const & entity): InterfaceBasedSingletonDescription_Base(entity->isPublished()), - manager_(manager), name_(name), entity_(entity) + manager_(manager), name_(std::move(name)), entity_(entity) { assert(manager.is()); assert(entity.is()); } private: @@ -1596,10 +1597,10 @@ class ServiceBasedSingletonDescription: public: ServiceBasedSingletonDescription( rtl::Reference< cppuhelper::TypeManager > const & manager, - OUString const & name, + OUString name, rtl::Reference< unoidl::ServiceBasedSingletonEntity > const & entity): ServiceBasedSingletonDescription_Base(entity->isPublished()), - manager_(manager), name_(name), entity_(entity) + manager_(manager), name_(std::move(name)), entity_(entity) { assert(manager.is()); assert(entity.is()); } private: @@ -1653,7 +1654,7 @@ private: { return !positions_.empty(); } virtual css::uno::Any SAL_CALL nextElement() override - { return css::uno::makeAny(nextTypeDescription()); } + { return css::uno::Any(nextTypeDescription()); } virtual css::uno::Reference< css::reflection::XTypeDescription > SAL_CALL nextTypeDescription() override; @@ -1664,16 +1665,16 @@ private: struct Position { Position( - OUString const & thePrefix, + OUString thePrefix, rtl::Reference< unoidl::MapCursor > const & theCursor): - prefix(thePrefix), cursor(theCursor) + prefix(std::move(thePrefix)), cursor(theCursor) { assert(theCursor.is()); } Position( - OUString const & thePrefix, + OUString thePrefix, rtl::Reference< unoidl::ConstantGroupEntity > const & theConstantGroup): - prefix(thePrefix), constantGroup(theConstantGroup), + prefix(std::move(thePrefix)), constantGroup(theConstantGroup), constantGroupIndex(constantGroup->getMembers().begin()) { assert(theConstantGroup.is()); } @@ -1710,7 +1711,7 @@ Enumeration::nextTypeDescription() std::scoped_lock g(mutex_); if (positions_.empty()) { throw css::container::NoSuchElementException( - "exhausted XTypeDescriptionEnumeration", + u"exhausted XTypeDescriptionEnumeration"_ustr, static_cast< cppu::OWeakObject * >(this)); } name = current_; @@ -1723,12 +1724,8 @@ bool Enumeration::matches(css::uno::TypeClass tc) const { if (!types_.hasElements()) { return true; } - for (const auto & i : types_) { - if (i == tc) { - return true; - } - } - return false; + + return std::any_of(types_.begin(), types_.end(), [&tc](const auto& i) { return i == tc; }); } void Enumeration::findNextMatch() { @@ -1825,39 +1822,32 @@ void Enumeration::findNextMatch() { } cppuhelper::TypeManager::TypeManager(): - TypeManager_Base(m_aMutex), manager_(new unoidl::Manager) {} css::uno::Any cppuhelper::TypeManager::find(OUString const & name) { //TODO: caching? (here or in unoidl::Manager?) - struct Simple { - std::u16string_view name; - css::uno::TypeClass typeClass; - }; - static Simple const simple[] = { - { std::u16string_view(u"void"), css::uno::TypeClass_VOID }, - { std::u16string_view(u"boolean"), css::uno::TypeClass_BOOLEAN }, - { std::u16string_view(u"byte"), css::uno::TypeClass_BYTE }, - { std::u16string_view(u"short"), css::uno::TypeClass_SHORT }, - { std::u16string_view(u"unsigned short"), - css::uno::TypeClass_UNSIGNED_SHORT }, - { std::u16string_view(u"long"), css::uno::TypeClass_LONG }, - { std::u16string_view(u"unsigned long"), css::uno::TypeClass_UNSIGNED_LONG }, - { std::u16string_view(u"hyper"), css::uno::TypeClass_HYPER }, - { std::u16string_view(u"unsigned hyper"), - css::uno::TypeClass_UNSIGNED_HYPER }, - { std::u16string_view(u"float"), css::uno::TypeClass_FLOAT }, - { std::u16string_view(u"double"), css::uno::TypeClass_DOUBLE }, - { std::u16string_view(u"char"), css::uno::TypeClass_CHAR }, - { std::u16string_view(u"string"), css::uno::TypeClass_STRING }, - { std::u16string_view(u"type"), css::uno::TypeClass_TYPE }, - { std::u16string_view(u"any"), css::uno::TypeClass_ANY } }; - for (std::size_t i = 0; i != SAL_N_ELEMENTS(simple); ++i) { - if (name == simple[i].name) { - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( - new SimpleTypeDescription(simple[i].typeClass, name)); + static constexpr std::pair<std::u16string_view, css::uno::TypeClass> const simple[] = { + { u"void", css::uno::TypeClass_VOID }, + { u"boolean", css::uno::TypeClass_BOOLEAN }, + { u"byte", css::uno::TypeClass_BYTE }, + { u"short", css::uno::TypeClass_SHORT }, + { u"unsigned short", css::uno::TypeClass_UNSIGNED_SHORT }, + { u"long", css::uno::TypeClass_LONG }, + { u"unsigned long", css::uno::TypeClass_UNSIGNED_LONG }, + { u"hyper", css::uno::TypeClass_HYPER }, + { u"unsigned hyper", css::uno::TypeClass_UNSIGNED_HYPER }, + { u"float", css::uno::TypeClass_FLOAT }, + { u"double", css::uno::TypeClass_DOUBLE }, + { u"char", css::uno::TypeClass_CHAR }, + { u"string", css::uno::TypeClass_STRING }, + { u"type", css::uno::TypeClass_TYPE }, + { u"any", css::uno::TypeClass_ANY } }; + for (const auto& [ rName, rTypeClass ] : simple) { + if (name == rName) { + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( + new SimpleTypeDescription(rTypeClass, name))); } } if (name.startsWith("[]")) { @@ -1884,12 +1874,12 @@ css::uno::Any cppuhelper::TypeManager::find(OUString const & name) { case unoidl::Entity::SORT_ENUM_TYPE: return getEnumMember( static_cast< unoidl::EnumTypeEntity * >(ent.get()), - name.copy(i + 1)); + name.subView(i + 1)); case unoidl::Entity::SORT_CONSTANT_GROUP: return getConstant( parent, static_cast< unoidl::ConstantGroupEntity * >(ent.get()), - name.copy(i + 1)); + name.subView(i + 1)); default: break; } @@ -1912,12 +1902,10 @@ cppuhelper::TypeManager::resolve(OUString const & name) { cppuhelper::TypeManager::~TypeManager() noexcept {} -void cppuhelper::TypeManager::disposing() {} //TODO - OUString cppuhelper::TypeManager::getImplementationName() { return - "com.sun.star.comp.cppuhelper.bootstrap.TypeManager"; + u"com.sun.star.comp.cppuhelper.bootstrap.TypeManager"_ustr; } sal_Bool cppuhelper::TypeManager::supportsService( @@ -1929,7 +1917,7 @@ sal_Bool cppuhelper::TypeManager::supportsService( css::uno::Sequence< OUString > cppuhelper::TypeManager::getSupportedServiceNames() { - return { "com.sun.star.reflection.TypeDescriptionManager" }; //TODO + return { u"com.sun.star.reflection.TypeDescriptionManager"_ustr }; //TODO } css::uno::Any cppuhelper::TypeManager::getByHierarchicalName( @@ -1957,7 +1945,7 @@ css::uno::Type cppuhelper::TypeManager::getElementType() sal_Bool cppuhelper::TypeManager::hasElements() { throw css::uno::RuntimeException( - "TypeManager hasElements: method not supported", + u"TypeManager hasElements: method not supported"_ustr, static_cast< cppu::OWeakObject * >(this)); } @@ -1965,14 +1953,14 @@ css::uno::Reference< css::container::XEnumeration > cppuhelper::TypeManager::createEnumeration() { throw css::uno::RuntimeException( - "TypeManager createEnumeration: method not supported", + u"TypeManager createEnumeration: method not supported"_ustr, static_cast< cppu::OWeakObject * >(this)); } sal_Bool cppuhelper::TypeManager::has(css::uno::Any const &) { throw css::uno::RuntimeException( - "TypeManager has: method not supported", + u"TypeManager has: method not supported"_ustr, static_cast< cppu::OWeakObject * >(this)); } @@ -1981,8 +1969,8 @@ void cppuhelper::TypeManager::insert(css::uno::Any const & aElement) OUString uri; if (!(aElement >>= uri)) { throw css::lang::IllegalArgumentException( - ("css.uno.theTypeDescriptionManager.insert expects a string URI" - " argument"), + (u"css.uno.theTypeDescriptionManager.insert expects a string URI" + " argument"_ustr), static_cast< cppu::OWeakObject * >(this), 0); } //TODO: check for ElementExistException @@ -1995,8 +1983,8 @@ void cppuhelper::TypeManager::remove(css::uno::Any const & aElement) OUString uri; if (!(aElement >>= uri)) { throw css::lang::IllegalArgumentException( - ("css.uno.theTypeDescriptionManager.remove expects a string URI" - " argument"), + (u"css.uno.theTypeDescriptionManager.remove expects a string URI" + " argument"_ustr), static_cast< cppu::OWeakObject * >(this), 0); } //TODO: remove requests are silently ignored for now @@ -2028,10 +2016,10 @@ cppuhelper::TypeManager::createTypeDescriptionEnumeration( depth == css::reflection::TypeDescriptionSearchDepth_INFINITE); } -void cppuhelper::TypeManager::init(OUString const & rdbUris) { +void cppuhelper::TypeManager::init(std::u16string_view rdbUris) { for (sal_Int32 i = 0; i != -1;) { - OUString uri(rdbUris.getToken(0, ' ', i)); - if (uri.isEmpty()) { + std::u16string_view uri(o3tl::getToken(rdbUris, 0, ' ', i)); + if (uri.empty()) { continue; } bool optional; @@ -2046,21 +2034,21 @@ void cppuhelper::TypeManager::init(OUString const & rdbUris) { } void cppuhelper::TypeManager::readRdbDirectory( - OUString const & uri, bool optional) + std::u16string_view uri, bool optional) { - osl::Directory dir(uri); + osl::Directory dir = OUString(uri); switch (dir.open()) { case osl::FileBase::E_None: break; case osl::FileBase::E_NOENT: if (optional) { - SAL_INFO("cppuhelper", "Ignored optional " << uri); + SAL_INFO("cppuhelper", "Ignored optional " << OUString(uri)); return; } [[fallthrough]]; default: throw css::uno::DeploymentException( - "Cannot open directory " + uri, + OUString::Concat("Cannot open directory ") + uri, static_cast< cppu::OWeakObject * >(this)); } for (;;) { @@ -2073,17 +2061,17 @@ void cppuhelper::TypeManager::readRdbDirectory( } void cppuhelper::TypeManager::readRdbFile( - OUString const & uri, bool optional) + std::u16string_view uri, bool optional) { try { - manager_->addProvider(uri); + manager_->addProvider(OUString(uri)); } catch (unoidl::NoSuchFileException &) { if (!optional) { throw css::uno::DeploymentException( - uri + ": no such file", + OUString::Concat(uri) + ": no such file", static_cast< cppu::OWeakObject * >(this)); } - SAL_INFO("cppuhelper", "Ignored optional " << uri); + SAL_INFO("cppuhelper", "Ignored optional " << OUString(uri)); } catch (unoidl::FileFormatException & e) { throw css::uno::DeploymentException( ("unoidl::FileFormatException for <" + e.getUri() + ">: " @@ -2096,10 +2084,10 @@ css::uno::Any cppuhelper::TypeManager::getSequenceType( OUString const & name) { assert(name.startsWith("[]")); - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( new SequenceTypeDescription( - this, name, name.copy(std::strlen("[]")))); + this, name, name.copy(std::strlen("[]"))))); } css::uno::Any cppuhelper::TypeManager::getInstantiatedStruct( @@ -2146,30 +2134,30 @@ css::uno::Any cppuhelper::TypeManager::getInstantiatedStruct( { return css::uno::Any(); } - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( new InstantiatedPolymorphicStructTypeDescription( - this, name, ent2, std::move(args))); + this, name, ent2, std::move(args)))); } css::uno::Any cppuhelper::TypeManager::getInterfaceMember( - OUString const & name, sal_Int32 separator) + std::u16string_view name, std::size_t separator) { - assert(name.indexOf("::") == separator && separator != -1); + assert(name.find(u"::") == separator && separator != std::u16string_view::npos); css::uno::Reference< css::reflection::XInterfaceTypeDescription2 > ifc( - resolveTypedefs(find(name.copy(0, separator))), css::uno::UNO_QUERY); + resolveTypedefs(find(OUString(name.substr(0, separator)))), css::uno::UNO_QUERY); if (!ifc.is()) { return css::uno::Any(); } - OUString member(name.copy(separator + std::strlen("::"))); + std::u16string_view member = name.substr(separator + std::strlen("::")); const css::uno::Sequence< css::uno::Reference< css::reflection::XInterfaceMemberTypeDescription > > mems( ifc->getMembers()); for (const auto & m : mems) { if (m->getMemberName() == member) { - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >(m); + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >(m)); } } return css::uno::Any(); @@ -2181,87 +2169,87 @@ css::uno::Any cppuhelper::TypeManager::getNamed( assert(entity.is()); switch (entity->getSort()) { case unoidl::Entity::SORT_MODULE: - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( new ModuleDescription( this, name, - static_cast< unoidl::ModuleEntity * >(entity.get()))); + static_cast< unoidl::ModuleEntity * >(entity.get())))); case unoidl::Entity::SORT_ENUM_TYPE: - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( new EnumTypeDescription( name, - static_cast< unoidl::EnumTypeEntity * >(entity.get()))); + static_cast< unoidl::EnumTypeEntity * >(entity.get())))); case unoidl::Entity::SORT_PLAIN_STRUCT_TYPE: - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( new PlainStructTypeDescription( this, name, static_cast< unoidl::PlainStructTypeEntity * >( - entity.get()))); + entity.get())))); case unoidl::Entity::SORT_POLYMORPHIC_STRUCT_TYPE_TEMPLATE: - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( new PolymorphicStructTypeTemplateDescription( this, name, static_cast< unoidl::PolymorphicStructTypeTemplateEntity * >( - entity.get()))); + entity.get())))); case unoidl::Entity::SORT_EXCEPTION_TYPE: - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( new ExceptionTypeDescription( this, name, static_cast< unoidl::ExceptionTypeEntity * >( - entity.get()))); + entity.get())))); case unoidl::Entity::SORT_INTERFACE_TYPE: - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( new InterfaceTypeDescription( this, name, static_cast< unoidl::InterfaceTypeEntity * >( - entity.get()))); + entity.get())))); case unoidl::Entity::SORT_TYPEDEF: - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( new TypedefDescription( this, name, - static_cast< unoidl::TypedefEntity * >(entity.get()))); + static_cast< unoidl::TypedefEntity * >(entity.get())))); case unoidl::Entity::SORT_CONSTANT_GROUP: - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( new ConstantGroupDescription( name, static_cast< unoidl::ConstantGroupEntity * >( - entity.get()))); + entity.get())))); case unoidl::Entity::SORT_SINGLE_INTERFACE_BASED_SERVICE: - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( new SingleInterfaceBasedServiceDescription( this, name, static_cast< unoidl::SingleInterfaceBasedServiceEntity * >( - entity.get()))); + entity.get())))); case unoidl::Entity::SORT_ACCUMULATION_BASED_SERVICE: - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( new AccumulationBasedServiceDescription( this, name, static_cast< unoidl::AccumulationBasedServiceEntity * >( - entity.get()))); + entity.get())))); case unoidl::Entity::SORT_INTERFACE_BASED_SINGLETON: - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( new InterfaceBasedSingletonDescription( this, name, static_cast< unoidl::InterfaceBasedSingletonEntity * >( - entity.get()))); + entity.get())))); case unoidl::Entity::SORT_SERVICE_BASED_SINGLETON: - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( new ServiceBasedSingletonDescription( this, name, static_cast< unoidl::ServiceBasedSingletonEntity * >( - entity.get()))); + entity.get())))); default: for (;;) { std::abort(); } // this cannot happen } @@ -2269,26 +2257,26 @@ css::uno::Any cppuhelper::TypeManager::getNamed( css::uno::Any cppuhelper::TypeManager::getEnumMember( rtl::Reference< unoidl::EnumTypeEntity > const & entity, - OUString const & member) + std::u16string_view member) { auto i = std::find_if(entity->getMembers().begin(), entity->getMembers().end(), [&member](const unoidl::EnumTypeEntity::Member& rMember) { return rMember.name == member; }); if (i != entity->getMembers().end()) - return css::uno::makeAny(i->value); + return css::uno::Any(i->value); return css::uno::Any(); } css::uno::Any cppuhelper::TypeManager::getConstant( - OUString const & constantGroupName, + std::u16string_view constantGroupName, rtl::Reference< unoidl::ConstantGroupEntity > const & entity, - OUString const & member) + std::u16string_view member) { auto i = std::find_if(entity->getMembers().begin(), entity->getMembers().end(), [&member](const unoidl::ConstantGroupEntity::Member& rMember) { return rMember.name == member; }); if (i != entity->getMembers().end()) - return css::uno::makeAny< - css::uno::Reference< css::reflection::XTypeDescription > >( - new ConstantDescription(constantGroupName, *i)); + return css::uno::Any( + css::uno::Reference< css::reflection::XTypeDescription >( + new ConstantDescription(OUString(constantGroupName), *i))); return css::uno::Any(); } diff --git a/cppuhelper/source/typemanager.hxx b/cppuhelper/source/typemanager.hxx index dcd415b888b1..ab1dc4fdbe71 100644 --- a/cppuhelper/source/typemanager.hxx +++ b/cppuhelper/source/typemanager.hxx @@ -11,6 +11,8 @@ #include <sal/config.h> +#include <cstddef> + #include <com/sun/star/container/XHierarchicalNameAccess.hpp> #include <com/sun/star/container/XSet.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> @@ -18,8 +20,7 @@ #include <com/sun/star/reflection/XTypeDescriptionEnumerationAccess.hpp> #include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/uno/Sequence.hxx> -#include <cppuhelper/basemutex.hxx> -#include <cppuhelper/compbase.hxx> +#include <compbase2.hxx> #include <rtl/ref.hxx> #include <sal/types.h> @@ -35,19 +36,19 @@ namespace unoidl { namespace cppuhelper { -typedef cppu::WeakComponentImplHelper< +typedef WeakComponentImplHelper2< css::lang::XServiceInfo, css::container::XHierarchicalNameAccess, css::container::XSet, css::reflection::XTypeDescriptionEnumerationAccess > TypeManager_Base; -class TypeManager: private cppu::BaseMutex, public TypeManager_Base { +class TypeManager: public TypeManager_Base { public: TypeManager(); using TypeManager_Base::acquire; using TypeManager_Base::release; - void init(OUString const & rdbUris); + void init(std::u16string_view rdbUris); css::uno::Any find(OUString const & name); @@ -57,8 +58,6 @@ public: private: virtual ~TypeManager() noexcept override; - virtual void SAL_CALL disposing() override; - virtual OUString SAL_CALL getImplementationName() override; virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override; @@ -90,9 +89,9 @@ private: css::uno::Sequence< css::uno::TypeClass > const & types, css::reflection::TypeDescriptionSearchDepth depth) override; - void readRdbDirectory(OUString const & uri, bool optional); + void readRdbDirectory(std::u16string_view uri, bool optional); - void readRdbFile(OUString const & uri, bool optional); + void readRdbFile(std::u16string_view uri, bool optional); css::uno::Any getSequenceType(OUString const & name); @@ -100,7 +99,7 @@ private: OUString const & name, sal_Int32 separator); css::uno::Any getInterfaceMember( - OUString const & name, sal_Int32 separator); + std::u16string_view name, std::size_t separator); css::uno::Any getNamed( OUString const & name, @@ -108,12 +107,12 @@ private: static css::uno::Any getEnumMember( rtl::Reference< unoidl::EnumTypeEntity > const & entity, - OUString const & member); + std::u16string_view member); static css::uno::Any getConstant( - OUString const & constantGroupName, + std::u16string_view constantGroupName, rtl::Reference< unoidl::ConstantGroupEntity > const & entity, - OUString const & member); + std::u16string_view member); rtl::Reference< unoidl::Entity > findEntity(OUString const & name); diff --git a/cppuhelper/source/unoimplbase.cxx b/cppuhelper/source/unoimplbase.cxx new file mode 100644 index 000000000000..be3d423d24c2 --- /dev/null +++ b/cppuhelper/source/unoimplbase.cxx @@ -0,0 +1,27 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#include <unoimplbase.hxx> + +namespace cppuhelper +{ +UnoImplBase::~UnoImplBase() {} + +} // end namespace cppuextra + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cppuhelper/source/unourl.cxx b/cppuhelper/source/unourl.cxx index 8ee7e593ad20..be01adb460de 100644 --- a/cppuhelper/source/unourl.cxx +++ b/cppuhelper/source/unourl.cxx @@ -31,6 +31,7 @@ #include <map> #include <memory> +#include <utility> using cppu::UnoUrl; using cppu::UnoUrlDescriptor; @@ -67,7 +68,7 @@ inline UnoUrlDescriptor::Impl::Impl(OUString const & rDescriptor) case STATE_NAME0: if (bEnd || !rtl::isAsciiAlphanumeric(c)) throw rtl::MalformedUriException( - "UNO URL contains bad descriptor name"); + u"UNO URL contains bad descriptor name"_ustr); nStart = i; eState = STATE_NAME; break; @@ -81,13 +82,13 @@ inline UnoUrlDescriptor::Impl::Impl(OUString const & rDescriptor) } else if (!rtl::isAsciiAlphanumeric(c)) throw rtl::MalformedUriException( - "UNO URL contains bad descriptor name"); + u"UNO URL contains bad descriptor name"_ustr); break; case STATE_KEY0: if (bEnd || !rtl::isAsciiAlphanumeric(c)) throw rtl::MalformedUriException( - "UNO URL contains bad parameter key"); + u"UNO URL contains bad parameter key"_ustr); nStart = i; eState = STATE_KEY; break; @@ -101,7 +102,7 @@ inline UnoUrlDescriptor::Impl::Impl(OUString const & rDescriptor) } else if (bEnd || !rtl::isAsciiAlphanumeric(c)) throw rtl::MalformedUriException( - "UNO URL contains bad parameter key"); + u"UNO URL contains bad parameter key"_ustr); break; case STATE_VALUE: @@ -114,7 +115,7 @@ inline UnoUrlDescriptor::Impl::Impl(OUString const & rDescriptor) rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8)).second) throw rtl::MalformedUriException( - "UNO URL contains duplicated parameter"); + u"UNO URL contains duplicated parameter"_ustr); eState = STATE_KEY0; } break; @@ -187,30 +188,30 @@ public: private: Impl(OUString const & rConnectionDescriptor, OUString const & rProtocolDescriptor, - OUString const & rObjectName): + OUString aObjectName): m_aConnection(rConnectionDescriptor), m_aProtocol(rProtocolDescriptor), - m_aObjectName(rObjectName) + m_aObjectName(std::move(aObjectName)) {} }; inline UnoUrl::Impl * UnoUrl::Impl::create(OUString const & rUrl) { if (!rUrl.startsWithIgnoreAsciiCase("uno:")) - throw rtl::MalformedUriException("UNO URL does not start with \"uno:\""); + throw rtl::MalformedUriException(u"UNO URL does not start with \"uno:\""_ustr); sal_Int32 i = RTL_CONSTASCII_LENGTH("uno:"); sal_Int32 j = rUrl.indexOf(';', i); if (j < 0) - throw rtl::MalformedUriException("UNO URL has too few semicolons"); + throw rtl::MalformedUriException(u"UNO URL has too few semicolons"_ustr); OUString aConnection(rUrl.copy(i, j - i)); i = j + 1; j = rUrl.indexOf(0x3B, i); // ';' if (j < 0) - throw rtl::MalformedUriException("UNO URL has too few semicolons"); + throw rtl::MalformedUriException(u"UNO URL has too few semicolons"_ustr); OUString aProtocol(rUrl.copy(i, j - i)); i = j + 1; if (i == rUrl.getLength()) - throw rtl::MalformedUriException("UNO URL contains empty ObjectName"); + throw rtl::MalformedUriException(u"UNO URL contains empty ObjectName"_ustr); for (j = i; j < rUrl.getLength(); ++j) { sal_Unicode c = rUrl[j]; @@ -221,7 +222,7 @@ inline UnoUrl::Impl * UnoUrl::Impl::create(OUString const & rUrl) && c != 0x2F && c != 0x3A && c != 0x3D // '/', ':', '=' && c != 0x3F && c != 0x40 && c != 0x5F // '?', '@', '_' && c != 0x7E) // '~' - throw rtl::MalformedUriException("UNO URL contains invalid ObjectName"); + throw rtl::MalformedUriException(u"UNO URL contains invalid ObjectName"_ustr); } return new Impl(aConnection, aProtocol, rUrl.copy(i)); } diff --git a/cppuhelper/source/weak.cxx b/cppuhelper/source/weak.cxx index f45f433e9ce2..6bb353faa9bd 100644 --- a/cppuhelper/source/weak.cxx +++ b/cppuhelper/source/weak.cxx @@ -31,7 +31,6 @@ #include <vector> #include <mutex> -using namespace osl; using namespace com::sun::star::uno; namespace cppu @@ -331,6 +330,7 @@ class OWeakRefListener final : public XReference { public: explicit OWeakRefListener(const Reference< XInterface >& xInt); + explicit OWeakRefListener(const Reference< XWeak >& xInt); virtual ~OWeakRefListener(); // noncopyable @@ -372,6 +372,18 @@ OWeakRefListener::OWeakRefListener(const Reference< XInterface >& xInt) osl_atomic_decrement( &m_aRefCount ); } +OWeakRefListener::OWeakRefListener(const Reference< XWeak >& xWeak) + : m_aRefCount( 1 ) +{ + m_XWeakConnectionPoint = xWeak->queryAdapter(); + + if (m_XWeakConnectionPoint.is()) + { + m_XWeakConnectionPoint->addReference(static_cast<XReference*>(this)); + } + osl_atomic_decrement( &m_aRefCount ); +} + OWeakRefListener::~OWeakRefListener() { try @@ -434,6 +446,16 @@ WeakReferenceHelper::WeakReferenceHelper(const Reference< XInterface >& xInt) } } +WeakReferenceHelper::WeakReferenceHelper(const Reference< XWeak >& xWeak) + : m_pImpl( nullptr ) +{ + if (xWeak.is()) + { + m_pImpl = new OWeakRefListener(xWeak); + m_pImpl->acquire(); + } +} + WeakReferenceHelper::WeakReferenceHelper(const WeakReferenceHelper& rWeakRef) : m_pImpl( nullptr ) { @@ -493,6 +515,18 @@ WeakReferenceHelper::operator= (const Reference< XInterface > & xInt) return *this; } +WeakReferenceHelper & +WeakReferenceHelper::operator= (const Reference< XWeak > & xWeak) +{ + clear(); + if (xWeak) + { + m_pImpl = new OWeakRefListener(xWeak); + m_pImpl->acquire(); + } + return *this; +} + WeakReferenceHelper::~WeakReferenceHelper() { clear(); |