You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openoffice.apache.org by or...@apache.org on 2012/11/19 11:10:48 UTC

svn commit: r1411116 - in /incubator/ooo/trunk/main: i18npool/source/characterclassification/ i18npool/source/nativenumber/ i18npool/source/textconversion/ i18npool/source/transliteration/ i18nutil/inc/i18nutil/ i18nutil/source/utility/

Author: orw
Date: Mon Nov 19 10:10:46 2012
New Revision: 1411116

URL: http://svn.apache.org/viewvc?rev=1411116&view=rev
Log:
#121139# - string handling: clear reference counting and passing ownership

           Found by: Regina Henschel, Ariel Constenla-Haile
           Review by: Herbert Duerr

Modified:
    incubator/ooo/trunk/main/i18npool/source/characterclassification/cclass_unicode.cxx
    incubator/ooo/trunk/main/i18npool/source/nativenumber/nativenumbersupplier.cxx
    incubator/ooo/trunk/main/i18npool/source/textconversion/textconversion_ko.cxx
    incubator/ooo/trunk/main/i18npool/source/textconversion/textconversion_zh.cxx
    incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreIandEfollowedByYa_ja_JP.cxx
    incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreIterationMark_ja_JP.cxx
    incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreKiKuFollowedBySa_ja_JP.cxx
    incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreProlongedSoundMark_ja_JP.cxx
    incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_Ignore.cxx
    incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_Numeric.cxx
    incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_OneToOne.cxx
    incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_body.cxx
    incubator/ooo/trunk/main/i18nutil/inc/i18nutil/x_rtl_ustring.h
    incubator/ooo/trunk/main/i18nutil/source/utility/widthfolding.cxx

Modified: incubator/ooo/trunk/main/i18npool/source/characterclassification/cclass_unicode.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/i18npool/source/characterclassification/cclass_unicode.cxx?rev=1411116&r1=1411115&r2=1411116&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18npool/source/characterclassification/cclass_unicode.cxx (original)
+++ incubator/ooo/trunk/main/i18npool/source/characterclassification/cclass_unicode.cxx Mon Nov 19 10:10:46 2012
@@ -94,7 +94,7 @@ cclass_Unicode::toTitle( const OUString&
         nCount = len - nPos;
 
     trans->setMappingType(MappingTypeToTitle, rLocale);
-    rtl_uString* pStr = x_rtl_uString_new_WithLength( nCount, 1 );
+    rtl_uString* pStr = x_rtl_uString_new_WithLength( nCount ); // defined in x_rtl_ustring.h
     sal_Unicode* out = pStr->buffer;
     BreakIteratorImpl brk(xMSF);
     Boundary bdy = brk.getWordBoundary(Text, nPos, rLocale, 

Modified: incubator/ooo/trunk/main/i18npool/source/nativenumber/nativenumbersupplier.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/i18npool/source/nativenumber/nativenumbersupplier.cxx?rev=1411116&r1=1411115&r2=1411116&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18npool/source/nativenumber/nativenumbersupplier.cxx (original)
+++ incubator/ooo/trunk/main/i18npool/source/nativenumber/nativenumbersupplier.cxx Mon Nov 19 10:10:46 2012
@@ -73,7 +73,7 @@ OUString SAL_CALL AsciiToNativeChar( con
         Sequence< sal_Int32 >& offset, sal_Bool useOffset, sal_Int16 number ) throw(RuntimeException)
 {
         const sal_Unicode *src = inStr.getStr() + startPos;
-        rtl_uString *newStr = x_rtl_uString_new_WithLength(nCount);
+        rtl_uString *newStr = x_rtl_uString_new_WithLength( nCount ); // defined in x_rtl_ustring.h
         if (useOffset)
             offset.realloc(nCount);
 
@@ -93,7 +93,7 @@ OUString SAL_CALL AsciiToNativeChar( con
             if (useOffset)
                 offset[i] = startPos + i;
         }
-        return OUString( newStr, SAL_NO_ACQUIRE);
+        return OUString( newStr, SAL_NO_ACQUIRE); // take over ownership of <newStr>
 }
 
 sal_Bool SAL_CALL AsciiToNative_numberMaker(const sal_Unicode *str, sal_Int32 begin, sal_Int32 len,
@@ -246,7 +246,10 @@ OUString SAL_CALL AsciiToNative( const O
 
             if (useOffset)
                 offset.realloc(count);
-            return OUString(newStr->buffer, count);
+            OUString resultStr( newStr->buffer, count );
+            x_rtl_uString_release( newStr );
+            x_rtl_uString_release( srcStr );
+            return resultStr;
         }
         return OUString();
 }
@@ -309,7 +312,7 @@ static OUString SAL_CALL NativeToAscii(c
 
         if (nCount > 0) { 
             const sal_Unicode *str = inStr.getStr() + startPos;
-            rtl_uString *newStr = x_rtl_uString_new_WithLength(nCount * MultiplierExponent_7_CJK[0] + 1);
+            rtl_uString *newStr = x_rtl_uString_new_WithLength( nCount * MultiplierExponent_7_CJK[0] + 1 );
             if (useOffset)
                 offset.realloc( nCount * MultiplierExponent_7_CJK[0] + 1 );
             sal_Int32 count = 0, index;
@@ -367,7 +370,9 @@ static OUString SAL_CALL NativeToAscii(c
                 for (i = 0; i < count; i++)
                     offset[i] += startPos;
             }
-            return OUString(newStr->buffer, count);
+            OUString resultStr( newStr->buffer, count );
+            x_rtl_uString_release( newStr );
+            return resultStr;
         }
         return OUString();
 }

Modified: incubator/ooo/trunk/main/i18npool/source/textconversion/textconversion_ko.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/i18npool/source/textconversion/textconversion_ko.cxx?rev=1411116&r1=1411115&r2=1411116&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18npool/source/textconversion/textconversion_ko.cxx (original)
+++ incubator/ooo/trunk/main/i18npool/source/textconversion/textconversion_ko.cxx Mon Nov 19 10:10:46 2012
@@ -155,7 +155,8 @@ TextConversion_ko::getCharConversions(co
     } else if (! toHanja && getHanja2HangulIndex && getHanja2HangulData) {
         rtl_uString * newStr = x_rtl_uString_new_WithLength( nLength ); // defined in x_rtl_ustring.h
         sal_Int32 count = 0;
-        while (count < nLength) {
+        while (count < nLength)
+        {
             ch = aText[nStartPos + count];
             sal_Unicode address = getHanja2HangulIndex()[ch>>8];
             if (address != 0xFFFF)
@@ -166,10 +167,12 @@ TextConversion_ko::getCharConversions(co
             else 
                 break;
         }
-        if (count > 0) {
+        if (count > 0)
+        {
             output.realloc(1);
-            output[0] = OUString( newStr->buffer, count);
+            output[0] = OUString( newStr->buffer, count );
         }
+        x_rtl_uString_release( newStr );
     }
     return output;
 }

Modified: incubator/ooo/trunk/main/i18npool/source/textconversion/textconversion_zh.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/i18npool/source/textconversion/textconversion_zh.cxx?rev=1411116&r1=1411115&r2=1411116&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18npool/source/textconversion/textconversion_zh.cxx (original)
+++ incubator/ooo/trunk/main/i18npool/source/textconversion/textconversion_zh.cxx Mon Nov 19 10:10:46 2012
@@ -84,7 +84,7 @@ TextConversion_zh::getCharConversion(con
     for (sal_Int32 i = 0; i < nLength; i++)
         newStr->buffer[i] = 
             getOneCharConversion(aText[nStartPos+i], Data, Index);
-    return OUString( newStr, SAL_NO_ACQUIRE);
+    return OUString( newStr, SAL_NO_ACQUIRE ); // take over ownership of <newStr>
 }
 
 OUString SAL_CALL 
@@ -214,7 +214,9 @@ TextConversion_zh::getWordConversion(con
     }
     if (offset.getLength() > 0)
         offset.realloc(one2one ? 0 : count);
-    return OUString( newStr->buffer, count);
+    OUString resultStr( newStr->buffer, count );
+    x_rtl_uString_release( newStr );
+    return resultStr;
 }
 
 TextConversionResult SAL_CALL

Modified: incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreIandEfollowedByYa_ja_JP.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreIandEfollowedByYa_ja_JP.cxx?rev=1411116&r1=1411115&r2=1411116&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreIandEfollowedByYa_ja_JP.cxx (original)
+++ incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreIandEfollowedByYa_ja_JP.cxx Mon Nov 19 10:10:46 2012
@@ -139,7 +139,7 @@ ignoreIandEfollowedByYa_ja_JP::folding( 
     newStr->length = sal_Int32(dst - newStr->buffer);
     if (useOffset)
         offset.realloc(newStr->length);
-    return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1.
+    return OUString( newStr, SAL_NO_ACQUIRE ); // take over ownership of <newStr>
 }
 
 } } } }

Modified: incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreIterationMark_ja_JP.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreIterationMark_ja_JP.cxx?rev=1411116&r1=1411115&r2=1411116&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreIterationMark_ja_JP.cxx (original)
+++ incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreIterationMark_ja_JP.cxx Mon Nov 19 10:10:46 2012
@@ -146,7 +146,7 @@ ignoreIterationMark_ja_JP::folding( cons
     newStr->length = sal_Int32(dst - newStr->buffer);
     if (useOffset)
         offset.realloc(newStr->length);
-    return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1.
+    return OUString( newStr, SAL_NO_ACQUIRE ); // take over ownership of <newStr>
 
 }
 

Modified: incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreKiKuFollowedBySa_ja_JP.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreKiKuFollowedBySa_ja_JP.cxx?rev=1411116&r1=1411115&r2=1411116&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreKiKuFollowedBySa_ja_JP.cxx (original)
+++ incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreKiKuFollowedBySa_ja_JP.cxx Mon Nov 19 10:10:46 2012
@@ -96,7 +96,7 @@ ignoreKiKuFollowedBySa_ja_JP::folding( c
     newStr->length = sal_Int32(dst - newStr->buffer);
     if (useOffset)
         offset.realloc(newStr->length);
-    return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1.
+    return OUString( newStr, SAL_NO_ACQUIRE ); // take over ownership of <newStr>
 }
 
 } } } }

Modified: incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreProlongedSoundMark_ja_JP.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreProlongedSoundMark_ja_JP.cxx?rev=1411116&r1=1411115&r2=1411116&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreProlongedSoundMark_ja_JP.cxx (original)
+++ incubator/ooo/trunk/main/i18npool/source/transliteration/ignoreProlongedSoundMark_ja_JP.cxx Mon Nov 19 10:10:46 2012
@@ -354,7 +354,7 @@ ignoreProlongedSoundMark_ja_JP::folding(
     newStr->length = sal_Int32(dst - newStr->buffer);
     if (useOffset)
         offset.realloc(newStr->length);
-    return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1.
+    return OUString( newStr, SAL_NO_ACQUIRE ); // take over ownership of <newStr>
 
 }
 

Modified: incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_Ignore.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_Ignore.cxx?rev=1411116&r1=1411115&r2=1411116&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_Ignore.cxx (original)
+++ incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_Ignore.cxx Mon Nov 19 10:10:46 2012
@@ -204,7 +204,7 @@ transliteration_Ignore::folding( const O
       offset.realloc(newStr->length);
     *dst = (sal_Unicode) 0;
 
-    return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1.
+    return OUString( newStr, SAL_NO_ACQUIRE ); // take over ownership of <newStr>
 }
 
 sal_Unicode SAL_CALL 

Modified: incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_Numeric.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_Numeric.cxx?rev=1411116&r1=1411115&r2=1411116&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_Numeric.cxx (original)
+++ incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_Numeric.cxx Mon Nov 19 10:10:46 2012
@@ -72,7 +72,7 @@ transliteration_Numeric::transliterateBu
         if (endPos >  inStr.getLength())
             endPos = inStr.getLength();
 
-        rtl_uString* pStr = x_rtl_uString_new_WithLength( nCount, 1 );  // our x_rtl_ustring.h
+        rtl_uString* pStr = x_rtl_uString_new_WithLength( nCount );  // our x_rtl_ustring.h
         sal_Unicode* out = pStr->buffer;
 
         if (useOffset)
@@ -114,7 +114,7 @@ transliteration_Numeric::transliterateBu
         if (useOffset)
             offset.realloc(j);
 
-        return OUString( pStr, SAL_NO_ACQUIRE );
+        return OUString( pStr, SAL_NO_ACQUIRE ); // take over ownership of <pStr>
 }
 
 OUString SAL_CALL 

Modified: incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_OneToOne.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_OneToOne.cxx?rev=1411116&r1=1411115&r2=1411116&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_OneToOne.cxx (original)
+++ incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_OneToOne.cxx Mon Nov 19 10:10:46 2012
@@ -91,7 +91,7 @@ transliteration_OneToOne::transliterate(
     }
     *dst = (sal_Unicode) 0;
 
-    return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1.
+    return OUString( newStr, SAL_NO_ACQUIRE ); // take over ownership of <newStr>
 }
 
 sal_Unicode SAL_CALL 

Modified: incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_body.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_body.cxx?rev=1411116&r1=1411115&r2=1411116&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_body.cxx (original)
+++ incubator/ooo/trunk/main/i18npool/source/transliteration/transliteration_body.cxx Mon Nov 19 10:10:46 2012
@@ -183,7 +183,7 @@ Transliteration_body::transliterate( 
             const Mapping &map = casefolding::getValue( in, i, nCount, aLocale, nTmpMappingType );
             nOffCount += map.nmap;
         }
-        rtl_uString* pStr = x_rtl_uString_new_WithLength( nOffCount, 1 );  // our x_rtl_ustring.h
+        rtl_uString* pStr = x_rtl_uString_new_WithLength( nOffCount );  // our x_rtl_ustring.h
         sal_Unicode* out = pStr->buffer;
 
         if ( nOffCount != offset.getLength() )
@@ -207,7 +207,7 @@ Transliteration_body::transliterate( 
         }
         out[j] = 0;
 
-        return OUString( pStr, SAL_NO_ACQUIRE );
+        return OUString( pStr, SAL_NO_ACQUIRE ); // take over ownership of <pStr>
     }
     else
     {
@@ -254,7 +254,7 @@ OUString SAL_CALL 
 Transliteration_body::transliterateChar2String( sal_Unicode inChar ) throw(RuntimeException)
 {
         const Mapping &map = casefolding::getValue(&inChar, 0, 1, aLocale, nMappingType);
-        rtl_uString* pStr = x_rtl_uString_new_WithLength( map.nmap, 1 );  // our x_rtl_ustring.h
+        rtl_uString* pStr = x_rtl_uString_new_WithLength( map.nmap );  // our x_rtl_ustring.h
         sal_Unicode* out = pStr->buffer;
         sal_Int32 i;
 
@@ -262,7 +262,7 @@ Transliteration_body::transliterateChar2
             out[i] = map.map[i];
         out[i] = 0;
 
-        return OUString( pStr, SAL_NO_ACQUIRE );
+        return OUString( pStr, SAL_NO_ACQUIRE ); // take over ownership of <pStr>
 }
 
 sal_Unicode SAL_CALL 

Modified: incubator/ooo/trunk/main/i18nutil/inc/i18nutil/x_rtl_ustring.h
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/i18nutil/inc/i18nutil/x_rtl_ustring.h?rev=1411116&r1=1411115&r2=1411116&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18nutil/inc/i18nutil/x_rtl_ustring.h (original)
+++ incubator/ooo/trunk/main/i18nutil/inc/i18nutil/x_rtl_ustring.h Mon Nov 19 10:10:46 2012
@@ -32,18 +32,15 @@
 
 /**
  * Allocates a new <code>rtl_uString</code> which can hold nLen + 1 characters.
- * The reference count is 0. The characters of room is not cleared.
- * This method is similar to rtl_uString_new_WithLength in rtl/ustring.h, but 
- * can allocate a new string more efficiently. You need to "acquire" by such as 
- * OUString( rtl_uString * value ) if you intend to use it for a while.
- * @param	[output] newStr
+ * The reference count is 1. The memory allocated for the characters is not initialized.
  * @param	[input]  nLen
  */
-inline void SAL_CALL x_rtl_uString_new_WithLength( rtl_uString ** newStr, sal_Int32 nLen, sal_Int32 _refCount = 0 )
+inline rtl_uString * SAL_CALL x_rtl_uString_new_WithLength( sal_Int32 nLen )
 {
-  *newStr = (rtl_uString*) rtl_allocateMemory ( sizeof(rtl_uString) + sizeof(sal_Unicode) * nLen);
-  (*newStr)->refCount = _refCount;
-  (*newStr)->length = nLen;
+  rtl_uString *newStr = (rtl_uString*) rtl_allocateMemory ( sizeof(rtl_uString) + sizeof(sal_Unicode) * nLen);
+  newStr->refCount = 1;
+  newStr->length = nLen;
+  return newStr;
 
   // rtl_uString is defined in rtl/ustring.h as below:
   //typedef struct _rtl_uString
@@ -52,15 +49,7 @@ inline void SAL_CALL x_rtl_uString_new_W
   //	sal_Int32		length;
   //	sal_Unicode 	buffer[1];
   //} rtl_uString;
-}	
-
-inline rtl_uString * SAL_CALL x_rtl_uString_new_WithLength( sal_Int32 nLen, sal_Int32 _refCount = 0 )
-{
-  rtl_uString *newStr = (rtl_uString*) rtl_allocateMemory ( sizeof(rtl_uString) + sizeof(sal_Unicode) * nLen);
-  newStr->refCount = _refCount;
-  newStr->length = nLen;
-  return newStr;
-}	
+}
 
 /**
  * Release <code>rtl_uString</code> regardless its reference count.

Modified: incubator/ooo/trunk/main/i18nutil/source/utility/widthfolding.cxx
URL: http://svn.apache.org/viewvc/incubator/ooo/trunk/main/i18nutil/source/utility/widthfolding.cxx?rev=1411116&r1=1411115&r2=1411116&view=diff
==============================================================================
--- incubator/ooo/trunk/main/i18nutil/source/utility/widthfolding.cxx (original)
+++ incubator/ooo/trunk/main/i18nutil/source/utility/widthfolding.cxx Mon Nov 19 10:10:46 2012
@@ -49,8 +49,7 @@ OUString widthfolding::decompose_ja_voic
 {
   // Create a string buffer which can hold nCount * 2 + 1 characters.
   // Its size may become double of nCount.
-  rtl_uString * newStr;
-  x_rtl_uString_new_WithLength( &newStr, nCount * 2 ); // defined in x_rtl_ustring.h  The reference count is 0 now.
+  rtl_uString * newStr = x_rtl_uString_new_WithLength( nCount * 2 ); // defined in x_rtl_ustring.h
 
   sal_Int32 *p = NULL;
   sal_Int32 position = 0;
@@ -94,7 +93,7 @@ OUString widthfolding::decompose_ja_voic
   newStr->length = sal_Int32(dst - newStr->buffer);
   if (useOffset)
       offset.realloc(newStr->length);
-  return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1.
+  return OUString( newStr, SAL_NO_ACQUIRE ); // take over ownership of <newStr>
 }
 
 oneToOneMapping& widthfolding::getfull2halfTable(void)
@@ -111,8 +110,7 @@ OUString widthfolding::compose_ja_voiced
 {
   // Create a string buffer which can hold nCount + 1 characters.
   // Its size may become equal to nCount or smaller.
-  // The reference count is 0 now.
-  rtl_uString * newStr = x_rtl_uString_new_WithLength( nCount ); // defined in x_rtl_ustring.h  
+  rtl_uString * newStr = x_rtl_uString_new_WithLength( nCount ); // defined in x_rtl_ustring.h
 
   // Prepare pointers of unicode character arrays.
   const sal_Unicode* src = inStr.getStr() + startPos;
@@ -199,7 +197,7 @@ OUString widthfolding::compose_ja_voiced
  }
   if (useOffset)
       offset.realloc(newStr->length);
-  return OUString( newStr ); // defined in rtl/usrting. The reference count is increased from 0 to 1.
+  return OUString( newStr, SAL_NO_ACQUIRE ); // take over ownership of <newStr>
 }
 
 oneToOneMapping& widthfolding::gethalf2fullTable(void)