[Libreoffice-commits] .: sal/inc sal/rtl sal/util tools/inc

Michael Meeks michael at kemper.freedesktop.org
Mon Apr 2 05:53:11 PDT 2012


 sal/inc/rtl/ustrbuf.h      |   28 +++++++++++++++++++++++++
 sal/inc/rtl/ustrbuf.hxx    |    7 ++----
 sal/rtl/source/strimp.hxx  |   18 ++++++++++++++++
 sal/rtl/source/string.cxx  |    5 ++++
 sal/rtl/source/strtmpl.cxx |    8 -------
 sal/rtl/source/uri.cxx     |    2 +
 sal/rtl/source/ustrbuf.cxx |   50 ++++++++++++++++++++++++---------------------
 sal/rtl/source/ustring.cxx |   15 -------------
 sal/util/sal.map           |    2 +
 tools/inc/tools/string.hxx |    4 ++-
 10 files changed, 89 insertions(+), 50 deletions(-)

New commits:
commit 1426d4432c59ef42f28642ec63e57517223eb32d
Author: Michael Meeks <michael.meeks at suse.com>
Date:   Fri Mar 30 18:27:58 2012 +0100

    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.

diff --git a/sal/inc/rtl/ustrbuf.h b/sal/inc/rtl/ustrbuf.h
index 0863da0..1051d0d 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 99afe44..02a507c 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 a9e5a38..82f7f41 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 9c5393f..42c8ae2 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 8e1de8b..2a33907 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 743acbd..5febefd 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 82b2fcb..72cf4c4 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 5cdc5ed..2909432 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 2127011..753dfe7 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 {
diff --git a/tools/inc/tools/string.hxx b/tools/inc/tools/string.hxx
index 2d1e6a9..edecd2f 100644
--- a/tools/inc/tools/string.hxx
+++ b/tools/inc/tools/string.hxx
@@ -33,6 +33,7 @@
 #include <osl/thread.h>
 #include <rtl/textenc.h>
 #include <rtl/textcvt.h>
+#include <rtl/ustrbuf.h>
 #include <rtl/string.hxx>
 #include <rtl/ustring.hxx>
 #include "tools/toolsdllapi.h"
@@ -173,7 +174,8 @@ public:
 
     operator rtl::OUString () const
     {
-        return rtl::OUString (reinterpret_cast<rtl_uString*>(mpData));
+        return rtl::OUString( rtl_uStringBuffer_refReturn(
+                                reinterpret_cast<rtl_uString*>(mpData)), SAL_NO_ACQUIRE );
     }
 
     static UniString    CreateFromAscii( const sal_Char* pAsciiStr );


More information about the Libreoffice-commits mailing list