diff options
author | Michael Meeks <michael.meeks@suse.com> | 2012-03-30 15:14:10 +0100 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2012-03-30 15:15:27 +0100 |
commit | 81a4e4ba99b1534949e66bf81c723c2123fd47f0 (patch) | |
tree | 68047448510b32e615766ef5bd15a654cd4b5d12 /sal | |
parent | f447ac9ec99e5db055056e2f89dab741f94fba0a (diff) |
sal: add a more permanant set of annotations for lifetime tracking.
Having done this on a temporary basis a couple of times before,
it'd be good to avoid having to do the instrumentation again.
Diffstat (limited to 'sal')
-rw-r--r-- | sal/rtl/source/strtmpl.cxx | 46 | ||||
-rw-r--r-- | sal/rtl/source/ustring.cxx | 18 |
2 files changed, 51 insertions, 13 deletions
diff --git a/sal/rtl/source/strtmpl.cxx b/sal/rtl/source/strtmpl.cxx index 2d8c44bbe4fa..026d6473b6d1 100644 --- a/sal/rtl/source/strtmpl.cxx +++ b/sal/rtl/source/strtmpl.cxx @@ -49,6 +49,12 @@ inline void rtl_str_ImplCopy( IMPL_RTL_STRCODE* pDest, } */ +// for instrumentation / diagnostics +#ifndef RTL_LOG_STRING_NEW +# define RTL_LOG_STRING_NEW(s) +# define RTL_LOG_STRING_DELETE(s) +#endif + #define rtl_str_ImplCopy( _pDest, _pSrc, _nCount ) \ { \ IMPL_RTL_STRCODE* __mm_pDest = _pDest; \ @@ -1014,6 +1020,8 @@ static IMPL_RTL_STRCODE* IMPL_RTL_STRINGNAME( ImplNewCopy )( IMPL_RTL_STRINGDATA } *ppThis = pData; + + RTL_LOG_STRING_NEW( pData ); return pDest; } @@ -1055,6 +1063,7 @@ void SAL_CALL IMPL_RTL_STRINGNAME( release )( IMPL_RTL_STRINGDATA* pThis ) if ( pThis->refCount == 1 || !osl_decrementInterlockedCount( &(pThis->refCount) ) ) { + RTL_LOG_STRING_DELETE( pThis ); rtl_freeMemory( pThis ); } } @@ -1112,8 +1121,9 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newFromString )( IMPL_RTL_STRINGDATA** ppThis *ppThis = IMPL_RTL_STRINGNAME( ImplAlloc )( pStr->length ); OSL_ASSERT(*ppThis != NULL); rtl_str_ImplCopy( (*ppThis)->buffer, pStr->buffer, pStr->length ); + RTL_LOG_STRING_NEW( *ppThis ); - /* must be done at least, if pStr == *ppThis */ + /* must be done last, if pStr == *ppThis */ if ( pOrg ) IMPL_RTL_STRINGNAME( release )( pOrg ); } @@ -1156,7 +1166,9 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newFromStr )( IMPL_RTL_STRINGDATA** ppThis, } while ( *pCharStr ); - /* must be done at least, if pCharStr == *ppThis */ + RTL_LOG_STRING_NEW( *ppThis ); + + /* must be done last, if pCharStr == *ppThis */ if ( pOrg ) IMPL_RTL_STRINGNAME( release )( pOrg ); } @@ -1181,7 +1193,9 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newFromStr_WithLength )( IMPL_RTL_STRINGDATA* OSL_ASSERT(*ppThis != NULL); rtl_str_ImplCopy( (*ppThis)->buffer, pCharStr, nLen ); - /* must be done at least, if pCharStr == *ppThis */ + RTL_LOG_STRING_NEW( *ppThis ); + + /* must be done last, if pCharStr == *ppThis */ if ( pOrg ) IMPL_RTL_STRINGNAME( release )( pOrg ); } @@ -1220,6 +1234,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newFromLiteral)( IMPL_RTL_STRINGDATA** ppThis pCharStr++; } } + + RTL_LOG_STRING_NEW( *ppThis ); } /* ----------------------------------------------------------------------- */ @@ -1280,9 +1296,11 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newConcat )( IMPL_RTL_STRINGDATA** ppThis, rtl_str_ImplCopy( pTempStr->buffer, pLeft->buffer, pLeft->length ); rtl_str_ImplCopy( pTempStr->buffer+pLeft->length, pRight->buffer, pRight->length ); *ppThis = pTempStr; + + RTL_LOG_STRING_NEW( *ppThis ); } - /* must be done at least, if left or right == *ppThis */ + /* must be done last, if left or right == *ppThis */ if ( pOrg ) IMPL_RTL_STRINGNAME( release )( pOrg ); } @@ -1334,7 +1352,6 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newReplaceStrAt )( IMPL_RTL_STRINGDATA** ppTh return; } - { IMPL_RTL_STRINGDATA* pOrg = *ppThis; IMPL_RTL_STRCODE* pBuffer; sal_Int32 nNewLen; @@ -1360,10 +1377,10 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newReplaceStrAt )( IMPL_RTL_STRINGDATA** ppTh } rtl_str_ImplCopy( pBuffer, pStr->buffer+nIndex+nCount, pStr->length-nIndex-nCount ); - /* must be done at least, if pStr or pNewSubStr == *ppThis */ + RTL_LOG_STRING_NEW( *ppThis ); + /* must be done last, if pStr or pNewSubStr == *ppThis */ if ( pOrg ) IMPL_RTL_STRINGNAME( release )( pOrg ); - } } /* ----------------------------------------------------------------------- */ @@ -1421,7 +1438,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newReplace )( IMPL_RTL_STRINGDATA** ppThis, IMPL_RTL_AQUIRE( pStr ); } - /* must be done at least, if pStr == *ppThis */ + RTL_LOG_STRING_NEW( *ppThis ); + /* must be done last, if pStr == *ppThis */ if ( pOrg ) IMPL_RTL_STRINGNAME( release )( pOrg ); } @@ -1482,7 +1500,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiLowerCase )( IMPL_RTL_STRINGDATA** IMPL_RTL_AQUIRE( pStr ); } - /* must be done at least, if pStr == *ppThis */ + RTL_LOG_STRING_NEW( *ppThis ); + /* must be done last, if pStr == *ppThis */ if ( pOrg ) IMPL_RTL_STRINGNAME( release )( pOrg ); } @@ -1543,7 +1562,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newToAsciiUpperCase )( IMPL_RTL_STRINGDATA** IMPL_RTL_AQUIRE( pStr ); } - /* must be done at least, if pStr == *ppThis */ + RTL_LOG_STRING_NEW( *ppThis ); + /* must be done last, if pStr == *ppThis */ if ( pOrg ) IMPL_RTL_STRINGNAME( release )( pOrg ); } @@ -1584,7 +1604,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( newTrim )( IMPL_RTL_STRINGDATA** ppThis, rtl_str_ImplCopy( (*ppThis)->buffer, pStr->buffer+nPreSpaces, nLen ); } - /* must be done at least, if pStr == *ppThis */ + RTL_LOG_STRING_NEW( *ppThis ); + /* must be done last, if pStr == *ppThis */ if ( pOrg ) IMPL_RTL_STRINGNAME( release )( pOrg ); } @@ -1606,9 +1627,8 @@ sal_Int32 SAL_CALL IMPL_RTL_STRINGNAME( getToken )( IMPL_RTL_STRINGDATA** ppThis // Set ppThis to an empty string and return -1 if either nToken or nIndex is // negative: - if (nIndex < 0) { + if (nIndex < 0) nToken = -1; - } pCharStr += nIndex; pOrgCharStr = pCharStr; diff --git a/sal/rtl/source/ustring.cxx b/sal/rtl/source/ustring.cxx index 7c99758a9b6c..5cdc5ed4031f 100644 --- a/sal/rtl/source/ustring.cxx +++ b/sal/rtl/source/ustring.cxx @@ -79,6 +79,20 @@ static rtl_uString const aImplEmpty_rtl_uString = #define IMPL_RTL_INTERN static void internRelease (rtl_uString *pThis); +#if 0 // string lifetime / logging debug +# include <rtl/ustring.hxx> +# define RTL_LOG_STRING_NEW(s) \ + do { \ + fprintf (stderr, "+%s\n", \ + rtl::OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()); \ + } while (0) +# define RTL_LOG_STRING_DELETE(s) \ + do { \ + fprintf (stderr, "-%s\n", \ + rtl::OUStringToOString(s, RTL_TEXTENCODING_UTF8).getStr()); \ + } while (0) +#endif + /* ======================================================================= */ /* Include String/UString template code */ @@ -497,6 +511,8 @@ void SAL_CALL rtl_uString_newFromAscii( rtl_uString** ppThis, } while ( *pCharStr ); } + + RTL_LOG_STRING_NEW( *ppThis ); } void SAL_CALL rtl_uString_newFromCodePoints( @@ -547,6 +563,7 @@ void SAL_CALL rtl_uString_newFromCodePoints( *p++ = (sal_Unicode) ((c & 0x3FF) | SAL_RTL_FIRST_LOW_SURROGATE); } } + RTL_LOG_STRING_NEW( *newString ); } /* ======================================================================= */ @@ -759,6 +776,7 @@ static void rtl_string2UString_status( rtl_uString** ppThis, rtl_uString_new( ppThis ); } } + RTL_LOG_STRING_NEW( *ppThis ); } void SAL_CALL rtl_string2UString( rtl_uString** ppThis, |