diff options
author | Daniel Boelzle <dbo@openoffice.org> | 2001-03-30 12:29:02 +0000 |
---|---|---|
committer | Daniel Boelzle <dbo@openoffice.org> | 2001-03-30 12:29:02 +0000 |
commit | 9a172ac8b87022ef6d4c90bc9591cc953657d33a (patch) | |
tree | e37631d15df94eeaeea9a76554563e35c46927d0 | |
parent | 1f265fc1cec1f22fa73f1b732bfb5246f9bd344a (diff) |
added cppu_no_leak building option to avoid leaking of generated RTTI, vtables
-rw-r--r-- | bridges/source/cpp_uno/cc50_solaris_sparc/cpp2uno.cxx | 10 | ||||
-rw-r--r-- | bridges/source/cpp_uno/cc50_solaris_sparc/except.cxx | 60 | ||||
-rw-r--r-- | bridges/source/cpp_uno/cc50_solaris_sparc/makefile.mk | 8 |
3 files changed, 52 insertions, 26 deletions
diff --git a/bridges/source/cpp_uno/cc50_solaris_sparc/cpp2uno.cxx b/bridges/source/cpp_uno/cc50_solaris_sparc/cpp2uno.cxx index d1eea232d22f..2062087ede6c 100644 --- a/bridges/source/cpp_uno/cc50_solaris_sparc/cpp2uno.cxx +++ b/bridges/source/cpp_uno/cc50_solaris_sparc/cpp2uno.cxx @@ -2,9 +2,9 @@ * * $RCSfile: cpp2uno.cxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: jl $ $Date: 2001-03-12 14:39:54 $ + * last change: $Author: dbo $ $Date: 2001-03-30 13:29:02 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -59,9 +59,11 @@ * ************************************************************************/ -#define LEAK_STATIC_DATA -// #define TRACE(x) OSL_TRACE(x) +#ifdef DEBUG +#define TRACE(x) OSL_TRACE(x) +#else #define TRACE(x) +#endif #include <alloca.h> #include <list> diff --git a/bridges/source/cpp_uno/cc50_solaris_sparc/except.cxx b/bridges/source/cpp_uno/cc50_solaris_sparc/except.cxx index 69cdead3cd3b..64e05b595913 100644 --- a/bridges/source/cpp_uno/cc50_solaris_sparc/except.cxx +++ b/bridges/source/cpp_uno/cc50_solaris_sparc/except.cxx @@ -2,9 +2,9 @@ * * $RCSfile: except.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: pl $ $Date: 2001-03-16 15:24:35 $ + * last change: $Author: dbo $ $Date: 2001-03-30 13:29:02 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -190,24 +190,30 @@ static OString toRTTImangledname( const OString & rRTTIname ) class RTTIHolder { - static std::map< OString, void* > aAllRTTI; + std::map< OString, void* > aAllRTTI; public: - static void* getRTTI( const OString& rTypename ); - static void* getRTTI_UnoName( const OString& rUnoTypename ) + ~RTTIHolder(); + + void* getRTTI( const OString& rTypename ); + void* getRTTI_UnoName( const OString& rUnoTypename ) { return getRTTI( toRTTIname( rUnoTypename ) ); } - static void* insertRTTI( const OString& rTypename ); - static void* insertRTTI_UnoName( const OString& rTypename ) + void* insertRTTI( const OString& rTypename ); + void* insertRTTI_UnoName( const OString& rTypename ) { return insertRTTI( toRTTIname( rTypename ) ); } - static void* generateRTTI( typelib_CompoundTypeDescription* pCompTypeDescr ); + void* generateRTTI( typelib_CompoundTypeDescription* pCompTypeDescr ); }; -/* - * note: the contents of this map are not freed causing a leak - * this was suggested by dbo because the bridge may - * even be called while being unloaded (sounds like a bug, but ...) - */ -std::map< OString, void* > RTTIHolder::aAllRTTI; +RTTIHolder::~RTTIHolder() +{ + for ( std::map< OString, void* >::const_iterator iPos( aAllRTTI.begin() ); + iPos != aAllRTTI.end(); ++iPos ) + { + void ** pRTTI = (void **)iPos->second; + ::free( pRTTI[ 0 ] ); + delete (void *)pRTTI; + } +} #ifdef DEBUG #include <stdio.h> @@ -269,19 +275,16 @@ void* RTTIHolder::insertRTTI( const OString& rTypename ) void* RTTIHolder::generateRTTI( typelib_CompoundTypeDescription * pCompTypeDescr ) { - static ::osl::Mutex aMutex; - ::osl::Guard< ::osl::Mutex > guard( aMutex ); - OString aUNOCompTypeName( OUStringToOString( pCompTypeDescr->aBase.pTypeName, RTL_TEXTENCODING_ASCII_US ) ); OString aRTTICompTypeName( toRTTIname( aUNOCompTypeName ) ); - void* pHaveRTTI = RTTIHolder::getRTTI( aRTTICompTypeName ); + void* pHaveRTTI = getRTTI( aRTTICompTypeName ); if( pHaveRTTI ) return pHaveRTTI; if( ! pCompTypeDescr->pBaseTypeDescription ) // this is a base type - return RTTIHolder::insertRTTI( aRTTICompTypeName ); + return insertRTTI( aRTTICompTypeName ); // get base class RTTI void* pSuperRTTI = generateRTTI( pCompTypeDescr->pBaseTypeDescription ); @@ -352,7 +355,24 @@ void cc50_solaris_sparc_raiseException( uno_Any * pUnoExc, uno_Mapping * pUno2Cp // will be released by deleteException typelib_typedescriptionreference_getDescription( &pTypeDescr, pUnoExc->pType ); - void* pRTTI = RTTIHolder::generateRTTI( (typelib_CompoundTypeDescription *)pTypeDescr ); + void* pRTTI; + { + static ::osl::Mutex aMutex; + ::osl::Guard< ::osl::Mutex > guard( aMutex ); + + static RTTIHolder * s_pRTTI = 0; + if (! s_pRTTI) + { +#ifdef LEAK_STATIC_DATA + s_pRTTI = new RTTIHolder(); +#else + static RTTIHolder s_aRTTI; + s_pRTTI = &s_aRTTI; +#endif + } + + pRTTI = s_pRTTI->generateRTTI( (typelib_CompoundTypeDescription *)pTypeDescr ); + } // a must be OSL_ENSURE( sizeof(sal_Int32) == sizeof(void *), "### pointer size differs from sal_Int32!" ); diff --git a/bridges/source/cpp_uno/cc50_solaris_sparc/makefile.mk b/bridges/source/cpp_uno/cc50_solaris_sparc/makefile.mk index 0439b732a4c1..2636d9bf426a 100644 --- a/bridges/source/cpp_uno/cc50_solaris_sparc/makefile.mk +++ b/bridges/source/cpp_uno/cc50_solaris_sparc/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.3 $ +# $Revision: 1.4 $ # -# last change: $Author: dbo $ $Date: 2001-03-08 14:37:58 $ +# last change: $Author: dbo $ $Date: 2001-03-30 13:29:02 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -80,6 +80,10 @@ NO_BSYMBOLIC=TRUE #CFLAGS += -O5 -xO5 +.IF "$(cppu_no_leak)" == "" +CFLAGS += -DLEAK_STATIC_DATA +.ENDIF + SLOFILES= \ $(SLO)$/cpp2uno.obj \ $(SLO)$/uno2cpp.obj \ |