From 2c5bdad1ea62253e987fc522868452e747da653c Mon Sep 17 00:00:00 2001 From: sb Date: Mon, 28 Jun 2010 13:46:02 +0200 Subject: sb126: #i111793# make cppuhelper/interfacecontainer strict aliasing safe (patch by cmc, with slight modifications) --- cppuhelper/source/interfacecontainer.cxx | 108 +++++++++++++++---------------- 1 file changed, 53 insertions(+), 55 deletions(-) (limited to 'cppuhelper/source') diff --git a/cppuhelper/source/interfacecontainer.cxx b/cppuhelper/source/interfacecontainer.cxx index 3053193d5ee6..b0c8d687a0a8 100644 --- a/cppuhelper/source/interfacecontainer.cxx +++ b/cppuhelper/source/interfacecontainer.cxx @@ -99,15 +99,15 @@ OInterfaceIteratorHelper::OInterfaceIteratorHelper( OInterfaceContainerHelper & // worst case, two iterators at the same time rCont.copyAndResetInUse(); bIsList = rCont_.bIsList; - pData = rCont_.pData; + aData = rCont_.aData; if( bIsList ) { rCont.bInUse = sal_True; - nRemain = ((Sequence< Reference< XInterface > >*)pData)->getLength(); + nRemain = aData.pAsSequence->getLength(); } - else if( pData ) + else if( aData.pAsInterface ) { - ((XInterface *)pData)->acquire(); + aData.pAsInterface->acquire(); nRemain = 1; } else @@ -120,7 +120,7 @@ OInterfaceIteratorHelper::~OInterfaceIteratorHelper() SAL_THROW( () ) { MutexGuard aGuard( rCont.rMutex ); // bResetInUse protect the iterator against recursion - bShared = pData == rCont.pData && rCont.bIsList; + bShared = aData.pAsSequence == rCont.aData.pAsSequence && rCont.bIsList; if( bShared ) { OSL_ENSURE( rCont.bInUse, "OInterfaceContainerHelper must be in use" ); @@ -132,10 +132,10 @@ OInterfaceIteratorHelper::~OInterfaceIteratorHelper() SAL_THROW( () ) { if( bIsList ) // Sequence owned by the iterator - delete (Sequence< Reference< XInterface > >*)pData; - else if( pData ) + delete aData.pAsSequence; + else if( aData.pAsInterface ) // Interface is acquired by the iterator - ((XInterface*)pData)->release(); + aData.pAsInterface->release(); } } @@ -146,9 +146,9 @@ XInterface * OInterfaceIteratorHelper::next() SAL_THROW( () ) nRemain--; if( bIsList ) // typecase to const,so the getArray method is faster - return ((const Sequence< Reference< XInterface > >*)pData)->getConstArray()[nRemain].get(); - else if( pData ) - return (XInterface*)pData; + return aData.pAsSequence->getConstArray()[nRemain].get(); + else if( aData.pAsInterface ) + return aData.pAsInterface; } // exception return 0; @@ -159,15 +159,14 @@ void OInterfaceIteratorHelper::remove() SAL_THROW( () ) if( bIsList ) { OSL_ASSERT( nRemain >= 0 && - nRemain < ((const Sequence< Reference< XInterface > >*)pData)->getLength() ); - XInterface * p = - ((const Sequence< Reference< XInterface > >*)pData)->getConstArray()[nRemain].get(); + nRemain < aData.pAsSequence->getLength() ); + XInterface * p = aData.pAsSequence->getConstArray()[nRemain].get(); rCont.removeInterface( * reinterpret_cast< const Reference< XInterface > * >( &p ) ); } else { OSL_ASSERT( 0 == nRemain ); - rCont.removeInterface( * reinterpret_cast< const Reference< XInterface > * >(&pData)); + rCont.removeInterface( * reinterpret_cast< const Reference< XInterface > * >(&aData.pAsInterface)); } } @@ -177,8 +176,7 @@ void OInterfaceIteratorHelper::remove() SAL_THROW( () ) OInterfaceContainerHelper::OInterfaceContainerHelper( Mutex & rMutex_ ) SAL_THROW( () ) - : pData( 0 ) - , rMutex( rMutex_ ) + : rMutex( rMutex_ ) , bInUse( sal_False ) , bIsList( sal_False ) { @@ -188,17 +186,17 @@ OInterfaceContainerHelper::~OInterfaceContainerHelper() SAL_THROW( () ) { OSL_ENSURE( !bInUse, "~OInterfaceContainerHelper but is in use" ); if( bIsList ) - delete (Sequence< Reference< XInterface > >*)pData; - else if( pData ) - ((XInterface*)pData)->release(); + delete aData.pAsSequence; + else if( aData.pAsInterface ) + aData.pAsInterface->release(); } sal_Int32 OInterfaceContainerHelper::getLength() const SAL_THROW( () ) { MutexGuard aGuard( rMutex ); if( bIsList ) - return ((Sequence< Reference< XInterface > >*)pData)->getLength(); - else if( pData ) + return aData.pAsSequence->getLength(); + else if( aData.pAsInterface ) return 1; return 0; } @@ -207,10 +205,10 @@ Sequence< Reference > OInterfaceContainerHelper::getElements() const { MutexGuard aGuard( rMutex ); if( bIsList ) - return *(Sequence< Reference< XInterface > >*)pData; - else if( pData ) + return *aData.pAsSequence; + else if( aData.pAsInterface ) { - Reference x( (XInterface *)pData ); + Reference x( aData.pAsInterface ); return Sequence< Reference< XInterface > >( &x, 1 ); } return Sequence< Reference< XInterface > >(); @@ -224,9 +222,9 @@ void OInterfaceContainerHelper::copyAndResetInUse() SAL_THROW( () ) // this should be the worst case. If a iterator is active // and a new Listener is added. if( bIsList ) - pData = new Sequence< Reference< XInterface > >( *(Sequence< Reference< XInterface > >*)pData ); - else if( pData ) - ((XInterface*)pData)->acquire(); + aData.pAsSequence = new Sequence< Reference< XInterface > >( *aData.pAsSequence ); + else if( aData.pAsInterface ) + aData.pAsInterface->acquire(); bInUse = sal_False; } @@ -241,25 +239,25 @@ sal_Int32 OInterfaceContainerHelper::addInterface( const Reference & if( bIsList ) { - sal_Int32 nLen = ((Sequence< Reference< XInterface > >*)pData)->getLength(); - realloc( *(Sequence< Reference< XInterface > >*)pData, nLen +1 ); - ((Sequence< Reference< XInterface > >*)pData)->getArray()[ nLen ] = rListener; + sal_Int32 nLen = aData.pAsSequence->getLength(); + realloc( *aData.pAsSequence, nLen +1 ); + aData.pAsSequence->getArray()[ nLen ] = rListener; return nLen +1; } - else if( pData ) + else if( aData.pAsInterface ) { Sequence< Reference< XInterface > > * pSeq = new Sequence< Reference< XInterface > >( 2 ); Reference * pArray = pSeq->getArray(); - pArray[0] = (XInterface *)pData; + pArray[0] = aData.pAsInterface; pArray[1] = rListener; - ((XInterface *)pData)->release(); - pData = pSeq; + aData.pAsInterface->release(); + aData.pAsSequence = pSeq; bIsList = sal_True; return 2; } else { - pData = rListener.get(); + aData.pAsInterface = rListener.get(); if( rListener.is() ) rListener->acquire(); return 1; @@ -275,8 +273,8 @@ sal_Int32 OInterfaceContainerHelper::removeInterface( const Reference * pL = ((const Sequence< Reference< XInterface > >*)pData)->getConstArray(); - sal_Int32 nLen = ((Sequence< Reference< XInterface > >*)pData)->getLength(); + const Reference * pL = aData.pAsSequence->getConstArray(); + sal_Int32 nLen = aData.pAsSequence->getLength(); sal_Int32 i; for( i = 0; i < nLen; i++ ) { @@ -284,7 +282,7 @@ sal_Int32 OInterfaceContainerHelper::removeInterface( const Reference >*)pData, i ); + sequenceRemoveElementAt( *aData.pAsSequence, i ); break; } } @@ -296,30 +294,30 @@ sal_Int32 OInterfaceContainerHelper::removeInterface( const Reference >*)pData, i ); + sequenceRemoveElementAt(*aData.pAsSequence, i ); break; } } } - if( ((Sequence< Reference< XInterface > >*)pData)->getLength() == 1 ) + if( aData.pAsSequence->getLength() == 1 ) { - XInterface * p = ((const Sequence< Reference< XInterface > >*)pData)->getConstArray()[0].get(); + XInterface * p = aData.pAsSequence->getConstArray()[0].get(); p->acquire(); - delete (Sequence< Reference< XInterface > >*)pData; - pData = p; + delete aData.pAsSequence; + aData.pAsInterface = p; bIsList = sal_False; return 1; } else - return ((Sequence< Reference< XInterface > >*)pData)->getLength(); + return aData.pAsSequence->getLength(); } - else if( pData && Reference( (XInterface*)pData ) == rListener ) + else if( aData.pAsInterface && Reference( aData.pAsInterface ) == rListener ) { - ((XInterface *)pData)->release(); - pData = 0; + aData.pAsInterface->release(); + aData.pAsInterface = 0; } - return pData ? 1 : 0; + return aData.pAsInterface ? 1 : 0; } void OInterfaceContainerHelper::disposeAndClear( const EventObject & rEvt ) SAL_THROW( () ) @@ -328,10 +326,10 @@ void OInterfaceContainerHelper::disposeAndClear( const EventObject & rEvt ) SAL_ OInterfaceIteratorHelper aIt( *this ); // Container freigeben, falls im disposing neue Einträge kommen OSL_ENSURE( !bIsList || bInUse, "OInterfaceContainerHelper not in use" ); - if( !bIsList && pData ) - ((XInterface *)pData)->release(); + if( !bIsList && aData.pAsInterface ) + aData.pAsInterface->release(); // set the member to null, the iterator delete the values - pData = NULL; + aData.pAsInterface = NULL; bIsList = sal_False; bInUse = sal_False; aGuard.clear(); @@ -358,10 +356,10 @@ void OInterfaceContainerHelper::clear() SAL_THROW( () ) OInterfaceIteratorHelper aIt( *this ); // Container freigeben, falls im disposing neue Einträge kommen OSL_ENSURE( !bIsList || bInUse, "OInterfaceContainerHelper not in use" ); - if( !bIsList && pData ) - ((XInterface *)pData)->release(); + if( !bIsList && aData.pAsInterface ) + aData.pAsInterface->release(); // set the member to null, the iterator delete the values - pData = 0; + aData.pAsInterface = 0; bIsList = sal_False; bInUse = sal_False; // release mutex before aIt destructor call -- cgit From e21f2f0f0187ebaa4a5b7c64a6e5c08d5efc6116 Mon Sep 17 00:00:00 2001 From: sb Date: Tue, 14 Sep 2010 09:15:02 +0200 Subject: sb129: #i113189# adapted tests; improved subsequenttests --- cppuhelper/source/bootstrap.cxx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'cppuhelper/source') diff --git a/cppuhelper/source/bootstrap.cxx b/cppuhelper/source/bootstrap.cxx index 5575c118420e..f892cdcab0f3 100644 --- a/cppuhelper/source/bootstrap.cxx +++ b/cppuhelper/source/bootstrap.cxx @@ -380,9 +380,15 @@ SAL_CALL defaultBootstrap_InitialComponentContext( Bootstrap const & bootstrap ) SAL_THROW( (Exception) ) { - OUString bootstrapPath( get_this_libpath() ); - OUString iniDir; + OUString bootstrapPath; + if (!bootstrap.getFrom( + rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URE_INTERNAL_LIB_DIR")), + bootstrapPath)) + { + bootstrapPath = get_this_libpath(); + } + OUString iniDir; osl_getProcessWorkingDir(&iniDir.pData); Reference smgr_XMultiComponentFactory( -- cgit From de5774389070ac3edaac754c43d387b75dc27bd1 Mon Sep 17 00:00:00 2001 From: sb Date: Wed, 15 Sep 2010 16:35:54 +0200 Subject: sb129: #i113189# textualservices no longer associates singletons with services, adapted bootstrapInitialContext accordingly --- cppuhelper/source/servicefactory.cxx | 73 ++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 36 deletions(-) (limited to 'cppuhelper/source') diff --git a/cppuhelper/source/servicefactory.cxx b/cppuhelper/source/servicefactory.cxx index 57eae9a51087..bcc58b74af59 100644 --- a/cppuhelper/source/servicefactory.cxx +++ b/cppuhelper/source/servicefactory.cxx @@ -28,13 +28,9 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_cppuhelper.hxx" -#if OSL_DEBUG_LEVEL > 0 -#include -#endif #include #include "rtl/string.hxx" -#include "rtl/ustrbuf.hxx" #include "rtl/bootstrap.hxx" #include "osl/diagnose.h" #include "osl/file.h" @@ -46,6 +42,7 @@ #include "cppuhelper/servicefactory.hxx" #include "cppuhelper/bootstrap.hxx" +#include "com/sun/star/uno/DeploymentException.hpp" #include "com/sun/star/uno/XComponentContext.hpp" #include "com/sun/star/lang/XInitialization.hpp" #include "com/sun/star/lang/XSingleServiceFactory.hpp" @@ -64,6 +61,7 @@ using namespace ::rtl; using namespace ::osl; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; +namespace css = com::sun::star; namespace cppu { @@ -417,39 +415,42 @@ Reference< XComponentContext > bootstrapInitialContext( keys.getConstArray(); for ( sal_Int32 nPos = keys.getLength(); nPos--; ) { - Reference< registry::XRegistryKey > const & xKey2 = - pKeys[ nPos ]; - try - { - OUStringBuffer buf( 32 ); - buf.appendAscii( - RTL_CONSTASCII_STRINGPARAM("/singletons/") ); - buf.append( - xKey2->getKeyName().copy( - sizeof("/SINGLETONS") /* -\0 +'/' */ ) ); - entry.name = buf.makeStringAndClear(); - entry.value <<= xKey2->getStringValue(); - context_values.push_back( entry ); - } - catch (Exception & rExc) - { -#if OSL_DEBUG_LEVEL > 0 - OString aStr( - OUStringToOString( - xKey2->getKeyName().copy( 11 ), - RTL_TEXTENCODING_ASCII_US ) ); - OString aStr2( - OUStringToOString( - rExc.Message, RTL_TEXTENCODING_ASCII_US ) ); - fprintf( - stderr, - "### failed reading singleton [%s]" - " service name from registry: %s\n", - aStr.getStr(), aStr2.getStr() ); -#else - (void) rExc; // avoid warning about unused variable -#endif + css::uno::Sequence< rtl::OUString > impls( + css::uno::Reference< css::registry::XRegistryKey >( + pKeys[nPos]->openKey( + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "REGISTERED_BY"))), + css::uno::UNO_SET_THROW)->getAsciiListValue()); + switch (impls.getLength()) { + case 0: + throw css::uno::DeploymentException( + (pKeys[nPos]->getKeyName() + + rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM( + "/REGISTERED_BY is empty"))), + css::uno::Reference< css::uno::XInterface >()); + case 1: + break; + default: + OSL_TRACE( + ("arbitrarily chosing \"%s\" among multiple" + " implementations for \"%s\""), + rtl::OUStringToOString( + impls[0], RTL_TEXTENCODING_UTF8).getStr(), + rtl::OUStringToOString( + pKeys[nPos]->getKeyName(), + RTL_TEXTENCODING_UTF8).getStr()); + break; } + context_values.push_back( + ContextEntry_Init( + (rtl::OUString( + RTL_CONSTASCII_USTRINGPARAM("/singletons/")) + + pKeys[nPos]->getKeyName().copy( + RTL_CONSTASCII_LENGTH("/SINGLETONS/"))), + css::uno::makeAny(impls[0]), + true)); } } } -- cgit