summaryrefslogtreecommitdiff
path: root/sal
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@suse.com>2012-03-30 18:27:58 +0100
committerMichael Meeks <michael.meeks@suse.com>2012-04-02 13:51:55 +0100
commit1426d4432c59ef42f28642ec63e57517223eb32d (patch)
tree75b6d769d309b2564e6a730a278e9c1c126ce777 /sal
parent0f330ea25840690d05516adc20cfb3d1a9d33317 (diff)
sal: expose more stringbuffer related instrumentation points
Avoid ref/unref pair in makeStringAndClear, hook into the stringbuffer-like 'String' class to expose it's conversion to immutable strings, and fixup misc. missing instrumentation.
Diffstat (limited to 'sal')
-rw-r--r--sal/inc/rtl/ustrbuf.h28
-rw-r--r--sal/inc/rtl/ustrbuf.hxx7
-rw-r--r--sal/rtl/source/strimp.hxx18
-rw-r--r--sal/rtl/source/string.cxx5
-rw-r--r--sal/rtl/source/strtmpl.cxx8
-rw-r--r--sal/rtl/source/uri.cxx2
-rw-r--r--sal/rtl/source/ustrbuf.cxx50
-rw-r--r--sal/rtl/source/ustring.cxx15
-rw-r--r--sal/util/sal.map2
9 files changed, 86 insertions, 49 deletions
diff --git a/sal/inc/rtl/ustrbuf.h b/sal/inc/rtl/ustrbuf.h
index 0863da0bda1c..1051d0db7fdc 100644
--- a/sal/inc/rtl/ustrbuf.h
+++ b/sal/inc/rtl/ustrbuf.h
@@ -179,6 +179,34 @@ SAL_DLLPUBLIC void SAL_CALL rtl_uStringbuffer_remove(
sal_Int32 start,
sal_Int32 len );
+/**
+ Returns an immutable rtl_uString object, while clearing the string buffer.
+
+ This method is primarily used to allow these completed
+ string allocation events to be traced.
+
+ @param ppThis The string, on that the operation should take place
+ @param nCapacity pointer to the capacity of the string buffer
+
+ @since LibreOffice 3.6
+ */
+SAL_DLLPUBLIC rtl_uString * SAL_CALL rtl_uStringBuffer_makeStringAndClear(
+ /*inout*/ rtl_uString ** ppThis,
+ sal_Int32 *nCapacity );
+
+/**
+ References and returns an immutable rtl_uString object, from a mutable
+ string-buffer object.
+
+ This method is primarily used to allow legacy 'String' class
+ conversions to OUString to be accurately traced.
+
+ @param pThis The string, on that the operation should take place
+
+ @since LibreOffice 3.6
+ */
+SAL_DLLPUBLIC rtl_uString * SAL_CALL rtl_uStringBuffer_refReturn( rtl_uString *pThis );
+
#ifdef __cplusplus
}
#endif
diff --git a/sal/inc/rtl/ustrbuf.hxx b/sal/inc/rtl/ustrbuf.hxx
index 99afe44b782b..02a507ce18cf 100644
--- a/sal/inc/rtl/ustrbuf.hxx
+++ b/sal/inc/rtl/ustrbuf.hxx
@@ -181,10 +181,9 @@ public:
*/
OUString makeStringAndClear()
{
- OUString aRet( pData );
- rtl_uString_new(&pData);
- nCapacity = 0;
- return aRet;
+ return OUString(
+ rtl_uStringBuffer_makeStringAndClear( &pData, &nCapacity ),
+ SAL_NO_ACQUIRE );
}
/**
diff --git a/sal/rtl/source/strimp.hxx b/sal/rtl/source/strimp.hxx
index a9e5a38f6da7..82f7f41fee74 100644
--- a/sal/rtl/source/strimp.hxx
+++ b/sal/rtl/source/strimp.hxx
@@ -54,6 +54,24 @@ sal_Int16 rtl_ImplGetDigit( sal_Unicode ch, sal_Int16 nRadix );
sal_Bool rtl_ImplIsWhitespace( sal_Unicode c );
+// string lifetime instrumentation / diagnostics
+#if 0
+# 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)
+#else
+# define RTL_LOG_STRING_NEW(s)
+# define RTL_LOG_STRING_DELETE(s)
+#endif
+
#endif /* INCLUDED_RTL_SOURCE_STRIMP_HXX */
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/rtl/source/string.cxx b/sal/rtl/source/string.cxx
index 9c5393f32779..42c8ae2a3fdc 100644
--- a/sal/rtl/source/string.cxx
+++ b/sal/rtl/source/string.cxx
@@ -71,6 +71,11 @@ static rtl_String const aImplEmpty_rtl_String =
#define IMPL_RTL_STRINGDATA rtl_String
#define IMPL_RTL_EMPTYSTRING aImplEmpty_rtl_String
+#undef RTL_LOG_STRING_NEW
+#define RTL_LOG_STRING_NEW(s)
+#undef RTL_LOG_STRING_DELETE
+#define RTL_LOG_STRING_DELETE(s)
+
/* ======================================================================= */
/* Include String/UString template code */
diff --git a/sal/rtl/source/strtmpl.cxx b/sal/rtl/source/strtmpl.cxx
index 8e1de8bdab0f..2a339079a89f 100644
--- a/sal/rtl/source/strtmpl.cxx
+++ b/sal/rtl/source/strtmpl.cxx
@@ -49,12 +49,6 @@ 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; \
@@ -1096,10 +1090,8 @@ void SAL_CALL IMPL_RTL_STRINGNAME( new_WithLength )( IMPL_RTL_STRINGDATA** ppThi
OSL_ASSERT(*ppThis != NULL);
(*ppThis)->length = 0;
- {
IMPL_RTL_STRCODE* pTempStr = (*ppThis)->buffer;
memset(pTempStr, 0, nLen*sizeof(IMPL_RTL_STRCODE));
- }
}
}
diff --git a/sal/rtl/source/uri.cxx b/sal/rtl/source/uri.cxx
index 743acbdd2e61..5febefd03bf9 100644
--- a/sal/rtl/source/uri.cxx
+++ b/sal/rtl/source/uri.cxx
@@ -656,6 +656,7 @@ void SAL_CALL rtl_uriEncode(rtl_uString * pText, sal_Bool const * pCharClass,
break;
}
}
+ *pResult = rtl_uStringBuffer_makeStringAndClear( pResult, &nCapacity );
}
void SAL_CALL rtl_uriDecode(rtl_uString * pText,
@@ -702,6 +703,7 @@ void SAL_CALL rtl_uriDecode(rtl_uString * pText,
break;
}
}
+ *pResult = rtl_uStringBuffer_makeStringAndClear( pResult, &nCapacity );
}
break;
}
diff --git a/sal/rtl/source/ustrbuf.cxx b/sal/rtl/source/ustrbuf.cxx
index 82b2fcb43d1b..72cf4c47c041 100644
--- a/sal/rtl/source/ustrbuf.cxx
+++ b/sal/rtl/source/ustrbuf.cxx
@@ -28,20 +28,10 @@
#include <osl/interlck.h>
-#ifndef _RTL_STRING_HXX_
#include <rtl/ustrbuf.hxx>
-#endif
#include <rtl/memory.h>
+#include <strimp.hxx>
-/*
-#include <rtl/alloc.h>
-*/
-
-
-
-/*************************************************************************
- * rtl_uStringbuffer_newFromStr_WithLength
- */
void SAL_CALL rtl_uStringbuffer_newFromStr_WithLength( rtl_uString ** newStr,
const sal_Unicode * value,
sal_Int32 count)
@@ -55,12 +45,32 @@ void SAL_CALL rtl_uStringbuffer_newFromStr_WithLength( rtl_uString ** newStr,
rtl_uString_new_WithLength( newStr, count + 16 );
(*newStr)->length = count;
rtl_copyMemory( (*newStr)->buffer, value, count * sizeof(sal_Unicode));
+ RTL_LOG_STRING_NEW( *newStr );
return;
}
-/*************************************************************************
- * rtl_uStringbuffer_newFromStringBuffer
- */
+rtl_uString * SAL_CALL rtl_uStringBuffer_refReturn( rtl_uString * pThis )
+{
+ RTL_LOG_STRING_NEW( pThis );
+ rtl_uString_acquire( pThis );
+ return pThis;
+}
+
+rtl_uString * SAL_CALL rtl_uStringBuffer_makeStringAndClear( rtl_uString ** ppThis,
+ sal_Int32 *nCapacity )
+{
+ // avoid an un-necessary atomic ref/unref pair
+ rtl_uString *pStr = *ppThis;
+ *ppThis = NULL;
+
+ rtl_uString_new (ppThis);
+ *nCapacity = 0;
+
+ RTL_LOG_STRING_NEW( pStr );
+
+ return pStr;
+}
+
sal_Int32 SAL_CALL rtl_uStringbuffer_newFromStringBuffer( rtl_uString ** newStr,
sal_Int32 capacity,
rtl_uString * oldStr )
@@ -76,12 +86,10 @@ sal_Int32 SAL_CALL rtl_uStringbuffer_newFromStringBuffer( rtl_uString ** newStr,
(*newStr)->length = oldStr->length;
rtl_copyMemory( (*newStr)->buffer, oldStr->buffer, oldStr->length * sizeof(sal_Unicode));
}
+ RTL_LOG_STRING_NEW( *newStr );
return newCapacity;
}
-/*************************************************************************
- * rtl_uStringbuffer_ensureCapacity
- */
void SAL_CALL rtl_uStringbuffer_ensureCapacity
(rtl_uString ** This, sal_Int32* capacity, sal_Int32 minimumCapacity)
{
@@ -99,13 +107,12 @@ void SAL_CALL rtl_uStringbuffer_ensureCapacity
*This = pNew;
rtl_copyMemory( (*This)->buffer, pTmp->buffer, pTmp->length * sizeof(sal_Unicode) );
+
+ RTL_LOG_STRING_NEW( pTmp ); // with accurate contents
rtl_uString_release( pTmp );
}
}
-/*************************************************************************
- * rtl_uStringbuffer_insert
- */
void SAL_CALL rtl_uStringbuffer_insert( rtl_uString ** This,
sal_Int32 * capacity,
sal_Int32 offset,
@@ -165,9 +172,6 @@ void rtl_uStringbuffer_insertUtf32(
rtl_uStringbuffer_insert(pThis, capacity, offset, buf, len);
}
-/*************************************************************************
- * rtl_uStringbuffer_insert_ascii
- */
void SAL_CALL rtl_uStringbuffer_insert_ascii( /*inout*/rtl_uString ** This,
/*inout*/sal_Int32 * capacity,
sal_Int32 offset,
diff --git a/sal/rtl/source/ustring.cxx b/sal/rtl/source/ustring.cxx
index 5cdc5ed4031f..2909432345a2 100644
--- a/sal/rtl/source/ustring.cxx
+++ b/sal/rtl/source/ustring.cxx
@@ -79,20 +79,6 @@ 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 */
@@ -700,6 +686,7 @@ static void rtl_string2UString_status( rtl_uString** ppThis,
if (pInfo != NULL) {
*pInfo = 0;
}
+ RTL_LOG_STRING_NEW( *ppThis );
return;
}
}
diff --git a/sal/util/sal.map b/sal/util/sal.map
index 2127011a1ccb..753dfe718500 100644
--- a/sal/util/sal.map
+++ b/sal/util/sal.map
@@ -623,6 +623,8 @@ LIBO_UDK_3.6 { # symbols available in >= LibO 3.6
rtl_uString_newReplaceFirst;
rtl_uString_newReplaceFirstAsciiL;
rtl_uString_newReplaceFirstAsciiLAsciiL;
+ rtl_uStringBuffer_refReturn;
+ rtl_uStringBuffer_makeStringAndClear;
} UDK_3.10;
PRIVATE_1.0 {