]> granicus.if.org Git - icu/commitdiff
ICU-9932 deprecate & disable cloning-into-user-buffer, except keep ucnv_safeClone...
authorMarkus Scherer <markus.icu@gmail.com>
Tue, 17 Sep 2013 19:48:50 +0000 (19:48 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Tue, 17 Sep 2013 19:48:50 +0000 (19:48 +0000)
X-SVN-Rev: 34359

21 files changed:
icu4c/source/common/brkiter.cpp
icu4c/source/common/rbbi.cpp
icu4c/source/common/ubrk.cpp
icu4c/source/common/ucnv.c
icu4c/source/common/unicode/brkiter.h
icu4c/source/common/unicode/rbbi.h
icu4c/source/common/unicode/ubrk.h
icu4c/source/common/unicode/ucnv.h
icu4c/source/i18n/tblcoll.cpp
icu4c/source/i18n/ucol.cpp
icu4c/source/i18n/unicode/ucol.h
icu4c/source/samples/ucnv/convsamp.cpp
icu4c/source/test/cintltst/Makefile.in
icu4c/source/test/cintltst/capitst.c
icu4c/source/test/cintltst/cbiapts.c
icu4c/source/test/cintltst/ccapitst.c
icu4c/source/test/cintltst/cintltst.vcxproj
icu4c/source/test/cintltst/cintltst.vcxproj.filters
icu4c/source/test/cintltst/cmsccoll.c
icu4c/source/test/cintltst/colutil.c [deleted file]
icu4c/source/test/intltest/strcase.cpp

index 3b6c94dc611cfa453f3645706e3fcbfa191d18a3..adbfd6501aa3bbb921c5f82259df6a87202f0e66 100644 (file)
@@ -204,7 +204,6 @@ BreakIterator::getAvailableLocales(int32_t& count)
 
 BreakIterator::BreakIterator()
 {
-    fBufferClone = FALSE;
     *validLocale = *actualLocale = 0;
 }
 
index 2f0d1ba99e5338627dfc4d4790a49baacd1c67ca..6ab57a7c1175d5769e091c4c70edf8b09b364e28 100644 (file)
@@ -270,7 +270,6 @@ RuleBasedBreakIterator::operator=(const RuleBasedBreakIterator& that) {
 //-----------------------------------------------------------------------------
 void RuleBasedBreakIterator::init() {
     UErrorCode  status    = U_ZERO_ERROR;
-    fBufferClone          = FALSE;
     fText                 = utext_openUChars(NULL, NULL, 0, &status);
     fCharIter             = NULL;
     fSCharIter            = NULL;
@@ -1515,19 +1514,7 @@ const uint8_t  *RuleBasedBreakIterator::getBinaryRules(uint32_t &length) {
 }
 
 
-
-
-//-------------------------------------------------------------------------------
-//
-//  BufferClone       TODO:  In my (Andy) opinion, this function should be deprecated.
-//                    Saving one heap allocation isn't worth the trouble.
-//                    Cloning shouldn't be done in tight loops, and
-//                    making the clone copy involves other heap operations anyway.
-//                    And the application code for correctly dealing with buffer
-//                    size problems and the eventual object destruction is ugly.
-//
-//-------------------------------------------------------------------------------
-BreakIterator *  RuleBasedBreakIterator::createBufferClone(void *stackBuffer,
+BreakIterator *  RuleBasedBreakIterator::createBufferClone(void * /*stackBuffer*/,
                                    int32_t &bufferSize,
                                    UErrorCode &status)
 {
@@ -1535,51 +1522,18 @@ BreakIterator *  RuleBasedBreakIterator::createBufferClone(void *stackBuffer,
         return NULL;
     }
 
-    //
-    //  If user buffer size is zero this is a preflight operation to
-    //    obtain the needed buffer size, allowing for worst case misalignment.
-    //
     if (bufferSize == 0) {
-        bufferSize = sizeof(RuleBasedBreakIterator) + U_ALIGNMENT_OFFSET_UP(0);
+        bufferSize = 1;  // preflighting for deprecated functionality
         return NULL;
     }
 
-
-    //
-    //  Check the alignment and size of the user supplied buffer.
-    //  Allocate heap memory if the user supplied memory is insufficient.
-    //
-    char    *buf   = (char *)stackBuffer;
-    uint32_t s      = bufferSize;
-
-    if (stackBuffer == NULL) {
-        s = 0;   // Ignore size, force allocation if user didn't give us a buffer.
-    }
-    if (U_ALIGNMENT_OFFSET(stackBuffer) != 0) {
-        uint32_t offsetUp = (uint32_t)U_ALIGNMENT_OFFSET_UP(buf);
-        s   -= offsetUp;
-        buf += offsetUp;
-    }
-    if (s < sizeof(RuleBasedBreakIterator)) {
-        // Not enough room in the caller-supplied buffer.
-        // Do a plain-vanilla heap based clone and return that, along with
-        //   a warning that the clone was allocated.
-        RuleBasedBreakIterator *clonedBI = new RuleBasedBreakIterator(*this);
-        if (clonedBI == 0) {
-            status = U_MEMORY_ALLOCATION_ERROR;
-        } else {
-            status = U_SAFECLONE_ALLOCATED_WARNING;
-        }
-        return clonedBI;
+    BreakIterator *clonedBI = clone();
+    if (clonedBI == NULL) {
+        status = U_MEMORY_ALLOCATION_ERROR;
+    } else {
+        status = U_SAFECLONE_ALLOCATED_WARNING;
     }
-
-    //
-    //  Clone the source BI into the caller-supplied buffer.
-    //
-    RuleBasedBreakIterator *clone = new(buf) RuleBasedBreakIterator(*this);
-    clone->fBufferClone = TRUE;   // Flag to prevent deleting storage on close (From C code)
-
-    return clone;
+    return (RuleBasedBreakIterator *)clonedBI;
 }
 
 
index 6ae60a38fab7d24dbd43078617c2579c4f8cbf03..a0002c21cea90effce913adf5652fcc6e48951ab 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ********************************************************************************
-*   Copyright (C) 1996-2012, International Business Machines
+*   Copyright (C) 1996-2013, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 ********************************************************************************
 */
@@ -123,25 +123,31 @@ ubrk_openRules(  const UChar        *rules,
 U_CAPI UBreakIterator * U_EXPORT2
 ubrk_safeClone(
           const UBreakIterator *bi,
-          void *stackBuffer,
+          void * /*stackBuffer*/,
           int32_t *pBufferSize,
           UErrorCode *status)
 {
     if (status == NULL || U_FAILURE(*status)){
-        return 0;
+        return NULL;
     }
-    if (!pBufferSize || !bi){
+    if (bi == NULL) {
        *status = U_ILLEGAL_ARGUMENT_ERROR;
-        return 0;
+        return NULL;
     }
-    // Clear any incoming Safe Clone Allocated warning.
-    //  Propagating this through to our return would really
-    //  confuse our caller.
-    if (*status==U_SAFECLONE_ALLOCATED_WARNING) {
-        *status = U_ZERO_ERROR;
+    if (pBufferSize != NULL) {
+        int32_t inputSize = *pBufferSize;
+        *pBufferSize = 1;
+        if (inputSize == 0) {
+            return NULL;  // preflighting for deprecated functionality
+        }
+    }
+    BreakIterator *newBI = ((BreakIterator *)bi)->clone();
+    if (newBI == NULL) {
+        *status = U_MEMORY_ALLOCATION_ERROR;
+    } else {
+        *status = U_SAFECLONE_ALLOCATED_WARNING;
     }
-    return (UBreakIterator *)(((BreakIterator*)bi)->
-        createBufferClone(stackBuffer, *pBufferSize, *status));
+    return (UBreakIterator *)newBI;
 }
 
 
@@ -149,15 +155,7 @@ ubrk_safeClone(
 U_CAPI void U_EXPORT2
 ubrk_close(UBreakIterator *bi)
 {
-    BreakIterator *ubi = (BreakIterator*) bi;
-    if (ubi) {
-        if (ubi->isBufferClone()) {
-            ubi->~BreakIterator();
-            *(uint32_t *)ubi = 0xdeadbeef;
-        } else {
-            delete ubi;
-        }
-    }
+    delete (BreakIterator *)bi;
 }
 
 U_CAPI void U_EXPORT2
@@ -170,7 +168,7 @@ ubrk_setText(UBreakIterator* bi,
     UText  ut = UTEXT_INITIALIZER;
     utext_openUChars(&ut, text, textLength, status);
     brit->setText(&ut, *status);
-    // A stack allocated UText wrapping a UCHar * string
+    // A stack allocated UText wrapping a UChar * string
     //   can be dumped without explicitly closing it.
 }
 
index 52d4f6d6267aff89a86d88bb45d141a27c58e01e..5cf4d15cc63f1e5b38bebac5ea6aee3a18e9fc0b 100644 (file)
@@ -1,7 +1,7 @@
 /*
 ******************************************************************************
 *
-*   Copyright (C) 1998-2012, International Business Machines
+*   Copyright (C) 1998-2013, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 ******************************************************************************
@@ -154,6 +154,7 @@ U_CAPI UConverter* U_EXPORT2
 ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, UErrorCode *status)
 {
     UConverter *localConverter, *allocatedConverter;
+    int32_t stackBufferSize;
     int32_t bufferSizeNeeded;
     char *stackBufferChars = (char *)stackBuffer;
     UErrorCode cbErr;
@@ -182,13 +183,13 @@ ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, U
 
     if (status == NULL || U_FAILURE(*status)){
         UTRACE_EXIT_STATUS(status? *status: U_ILLEGAL_ARGUMENT_ERROR);
-        return 0;
+        return NULL;
     }
 
-    if (!pBufferSize || !cnv){
+    if (cnv == NULL) {
         *status = U_ILLEGAL_ARGUMENT_ERROR;
         UTRACE_EXIT_STATUS(*status);
-        return 0;
+        return NULL;
     }
 
     UTRACE_DATA3(UTRACE_OPEN_CLOSE, "clone converter %s at %p into stackBuffer %p",
@@ -198,6 +199,10 @@ ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, U
         /* call the custom safeClone function for sizing */
         bufferSizeNeeded = 0;
         cnv->sharedData->impl->safeClone(cnv, NULL, &bufferSizeNeeded, status);
+        if (U_FAILURE(*status)) {
+            UTRACE_EXIT_STATUS(*status);
+            return NULL;
+        }
     }
     else
     {
@@ -205,10 +210,16 @@ ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, U
         bufferSizeNeeded = sizeof(UConverter);
     }
 
-    if (*pBufferSize <= 0){ /* 'preflighting' request - set needed size into *pBufferSize */
-        *pBufferSize = bufferSizeNeeded;
-        UTRACE_EXIT_VALUE(bufferSizeNeeded);
-        return 0;
+    if (pBufferSize == NULL) {
+        stackBufferSize = 1;
+        pBufferSize = &stackBufferSize;
+    } else {
+        stackBufferSize = *pBufferSize;
+        if (stackBufferSize <= 0){ /* 'preflighting' request - set needed size into *pBufferSize */
+            *pBufferSize = bufferSizeNeeded;
+            UTRACE_EXIT_VALUE(bufferSizeNeeded);
+            return NULL;
+        }
     }
 
 
@@ -217,19 +228,19 @@ ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, U
      */
     if (U_ALIGNMENT_OFFSET(stackBuffer) != 0) {
         int32_t offsetUp = (int32_t)U_ALIGNMENT_OFFSET_UP(stackBufferChars);
-        if(*pBufferSize > offsetUp) {
-            *pBufferSize -= offsetUp;
+        if(stackBufferSize > offsetUp) {
+            stackBufferSize -= offsetUp;
             stackBufferChars += offsetUp;
         } else {
             /* prevent using the stack buffer but keep the size > 0 so that we do not just preflight */
-            *pBufferSize = 1;
+            stackBufferSize = 1;
         }
     }
 
     stackBuffer = (void *)stackBufferChars;
     
     /* Now, see if we must allocate any memory */
-    if (*pBufferSize < bufferSizeNeeded || stackBuffer == NULL)
+    if (stackBufferSize < bufferSizeNeeded || stackBuffer == NULL)
     {
         /* allocate one here...*/
         localConverter = allocatedConverter = (UConverter *) uprv_malloc (bufferSizeNeeded);
@@ -239,11 +250,8 @@ ucnv_safeClone(const UConverter* cnv, void *stackBuffer, int32_t *pBufferSize, U
             UTRACE_EXIT_STATUS(*status);
             return NULL;
         }
-        
-        if (U_SUCCESS(*status)) {
-            *status = U_SAFECLONE_ALLOCATED_WARNING;
-        }
-        
+        *status = U_SAFECLONE_ALLOCATED_WARNING;
+
         /* record the fact that memory was allocated */
         *pBufferSize = bufferSizeNeeded;
     } else {
index 947059a801f1b61ec5246ae26dd5d25a44cce8f6..4e601bad899515dad3219c710b829f09eea090e3 100644 (file)
@@ -486,6 +486,8 @@ public:
                                          UnicodeString& name);
 
     /**
+     * Deprecated functionality. Use clone() instead.
+     *
      * Thread safe client-buffer-based cloning operation
      *    Do NOT call delete on a safeclone, since 'new' is not used to create it.
      * @param stackBuffer user allocated space for the new clone. If NULL new memory will be allocated.
@@ -500,20 +502,24 @@ public:
      *  necessary.
      * @return pointer to the new clone
      *
-     * @stable ICU 2.0
+     * @deprecated ICU 52. Use clone() instead.
      */
     virtual BreakIterator *  createBufferClone(void *stackBuffer,
                                                int32_t &BufferSize,
                                                UErrorCode &status) = 0;
 
+#ifndef U_HIDE_DEPRECATED_API
+
     /**
      *   Determine whether the BreakIterator was created in user memory by
      *   createBufferClone(), and thus should not be deleted.  Such objects
      *   must be closed by an explicit call to the destructor (not delete).
-     *  @stable ICU 2.0
+     * @deprecated ICU 52. Always delete the BreakIterator.
      */
     inline UBool isBufferClone(void);
 
+#endif /* U_HIDE_DEPRECATED_API */
+
 #if !UCONFIG_NO_SERVICE
     /**
      * Register a new break iterator of the indicated kind, to use in the given locale.
@@ -610,9 +616,7 @@ protected:
     /** @internal */
     BreakIterator();
     /** @internal */
-    UBool fBufferClone;
-    /** @internal */
-    BreakIterator (const BreakIterator &other) : UObject(other), fBufferClone(FALSE) {}
+    BreakIterator (const BreakIterator &other) : UObject(other) {}
 
 private:
 
@@ -627,15 +631,18 @@ private:
     BreakIterator& operator=(const BreakIterator&);
 };
 
+#ifndef U_HIDE_DEPRECATED_API
+
 inline UBool BreakIterator::isBufferClone()
 {
-    return fBufferClone;
+    return FALSE;
 }
 
+#endif /* U_HIDE_DEPRECATED_API */
+
 U_NAMESPACE_END
 
 #endif /* #if !UCONFIG_NO_BREAK_ITERATION */
 
 #endif // _BRKITER
 //eof
-
index 15993781731f1bc3f47d3977dc497e694beef16b..aa6cf47ba42f315adac3aecb45ecd7c5f5ce976f 100644 (file)
@@ -583,7 +583,9 @@ public:
      */
     static UClassID U_EXPORT2 getStaticClassID(void);
 
-    /*
+    /**
+     * Deprecated functionality. Use clone() instead.
+     *
      * Create a clone (copy) of this break iterator in memory provided
      *  by the caller.  The idea is to increase performance by avoiding
      *  a storage allocation.  Use of this functoin is NOT RECOMMENDED.
@@ -605,7 +607,7 @@ public:
      * @return  Pointer to the clone object.  This may differ from the stackBuffer
      *          address if the byte alignment of the stack buffer was not suitable
      *          or if the stackBuffer was too small to hold the clone.
-     * @stable ICU 2.0
+     * @deprecated ICU 52. Use clone() instead.
      */
     virtual BreakIterator *  createBufferClone(void *stackBuffer,
                                                int32_t &BufferSize,
@@ -697,7 +699,6 @@ protected:
 #ifndef U_HIDE_INTERNAL_API
     /**
       * Common initialization function, used by constructors and bufferClone.
-      *   (Also used by DictionaryBasedBreakIterator::createBufferClone().)
       * @internal
       */
     void init();
index 2506540dfb572137cf82d8abcf94942b5b2c295b..e9c0ef627b67279f86e46044bf0f257102e0c6cd 100644 (file)
@@ -243,10 +243,12 @@ ubrk_openRules(const UChar     *rules,
 /**
  * Thread safe cloning operation
  * @param bi iterator to be cloned
- * @param stackBuffer user allocated space for the new clone. If NULL new memory will be allocated.
+ * @param stackBuffer <em>Deprecated functionality as of ICU 52, use NULL.</em><br>
+ *  user allocated space for the new clone. If NULL new memory will be allocated.
  *  If buffer is not large enough, new memory will be allocated.
- *  Clients can use the U_BRK_SAFECLONE_BUFFERSIZE. This will probably be enough to avoid memory allocations.
- * @param pBufferSize pointer to size of allocated space.
+ *  Clients can use the U_BRK_SAFECLONE_BUFFERSIZE.
+ * @param pBufferSize <em>Deprecated functionality as of ICU 52, use NULL or 1.</em><br>
+ *  pointer to size of allocated space.
  *  If *pBufferSize == 0, a sufficient size for use in cloning will
  *  be returned ('pre-flighting')
  *  If *pBufferSize is not enough for a stack-based safe clone,
@@ -263,11 +265,15 @@ ubrk_safeClone(
           int32_t *pBufferSize,
           UErrorCode *status);
 
+#ifndef U_HIDE_DEPRECATED_API
+
 /**
   * A recommended size (in bytes) for the memory buffer to be passed to ubrk_saveClone().
-  * @stable ICU 2.0
+  * @deprecated ICU 52. Do not rely on ubrk_safeClone() cloning into any provided buffer.
   */
-#define U_BRK_SAFECLONE_BUFFERSIZE 528
+#define U_BRK_SAFECLONE_BUFFERSIZE 1
+
+#endif /* U_HIDE_DEPRECATED_API */
 
 /**
 * Close a UBreakIterator.
index 183573a14fb9ab6f48c2678bd628b52a9d16811b..c5fc2dc7856a16e21fd307917b738027f566059d 100644 (file)
@@ -1,6 +1,6 @@
 /*
 **********************************************************************
-*   Copyright (C) 1999-2012, International Business Machines
+*   Copyright (C) 1999-2013, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 **********************************************************************
  *  ucnv.h:
@@ -521,10 +521,12 @@ ucnv_openPackage(const char *packageName, const char *converterName, UErrorCode
  * adjusted pointer and use an accordingly smaller buffer size.
  *
  * @param cnv converter to be cloned
- * @param stackBuffer user allocated space for the new clone. If NULL new memory will be allocated. 
+ * @param stackBuffer <em>Deprecated functionality as of ICU 52, use NULL.</em><br>
+ *  user allocated space for the new clone. If NULL new memory will be allocated. 
  *  If buffer is not large enough, new memory will be allocated.
  *  Clients can use the U_CNV_SAFECLONE_BUFFERSIZE. This will probably be enough to avoid memory allocations.
- * @param pBufferSize pointer to size of allocated space. pBufferSize must not be NULL.
+ * @param pBufferSize <em>Deprecated functionality as of ICU 52, use NULL or 1.</em><br>
+ *  pointer to size of allocated space.
  * @param status to indicate whether the operation went on smoothly or there were errors
  *  An informational status value, U_SAFECLONE_ALLOCATED_WARNING,
  *  is used if any allocations were necessary.
@@ -540,14 +542,18 @@ ucnv_safeClone(const UConverter *cnv,
                int32_t          *pBufferSize, 
                UErrorCode       *status);
 
+#ifndef U_HIDE_DEPRECATED_API
+
 /**
  * \def U_CNV_SAFECLONE_BUFFERSIZE
  * Definition of a buffer size that is designed to be large enough for
  * converters to be cloned with ucnv_safeClone().
- * @stable ICU 2.0
+ * @deprecated ICU 52. Do not rely on ucnv_safeClone() cloning into any provided buffer.
  */
 #define U_CNV_SAFECLONE_BUFFERSIZE  1024
 
+#endif /* U_HIDE_DEPRECATED_API */
+
 /**
  * Deletes the unicode converter and releases resources associated
  * with just this instance.
index 75458542ff81fba95dd43e47efd0b174d6499a0c..744600d18c63f5b11379a66c45b81535bc21fe9b 100644 (file)
@@ -209,8 +209,7 @@ RuleBasedCollator& RuleBasedCollator::operator=(const RuleBasedCollator& that)
     if (this == &that) { return *this; }
 
     UErrorCode intStatus = U_ZERO_ERROR;
-    int32_t buffersize = U_COL_SAFECLONE_BUFFERSIZE;
-    UCollator *ucol = ucol_safeClone(that.ucollator, NULL, &buffersize, &intStatus);
+    UCollator *ucol = ucol_safeClone(that.ucollator, NULL, NULL, &intStatus);
     if (U_FAILURE(intStatus)) { return *this; }
 
     if (dataIsOwned) {
index c8febdf2d2d617f050ac54ec2cdfd73c27909fd6..d60ad8152f07c5423a692797430e218858827944 100644 (file)
@@ -556,11 +556,10 @@ ucol_cloneBinary(const UCollator *coll,
 }
 
 U_CAPI UCollator* U_EXPORT2
-ucol_safeClone(const UCollator *coll, void *stackBuffer, int32_t * pBufferSize, UErrorCode *status)
+ucol_safeClone(const UCollator *coll, void * /*stackBuffer*/, int32_t * pBufferSize, UErrorCode *status)
 {
     UCollator * localCollator;
     int32_t bufferSizeNeeded = (int32_t)sizeof(UCollator);
-    char *stackBufferChars = (char *)stackBuffer;
     int32_t imageSize = 0;
     int32_t rulesSize = 0;
     int32_t rulesPadding = 0;
@@ -571,15 +570,14 @@ ucol_safeClone(const UCollator *coll, void *stackBuffer, int32_t * pBufferSize,
     int32_t* defaultReorderCodes;
     int32_t* reorderCodes;
     uint8_t* leadBytePermutationTable;
-    UBool colAllocated = FALSE;
     UBool imageAllocated = FALSE;
 
     if (status == NULL || U_FAILURE(*status)){
-        return 0;
+        return NULL;
     }
-    if ((stackBuffer && !pBufferSize) || !coll){
+    if (coll == NULL) {
        *status = U_ILLEGAL_ARGUMENT_ERROR;
-        return 0;
+        return NULL;
     }
 
     if (coll->rules && coll->freeRulesOnClose) {
@@ -599,41 +597,23 @@ ucol_safeClone(const UCollator *coll, void *stackBuffer, int32_t * pBufferSize,
     if (coll->leadBytePermutationTable) {
         bufferSizeNeeded += 256 * sizeof(uint8_t);
     }
-    
-    if (stackBuffer && *pBufferSize <= 0) { /* 'preflighting' request - set needed size into *pBufferSize */
-        *pBufferSize =  bufferSizeNeeded;
-        return 0;
-    }
 
-    /* Pointers on 64-bit platforms need to be aligned
-     * on a 64-bit boundry in memory.
-     */
-    if (U_ALIGNMENT_OFFSET(stackBuffer) != 0) {
-        int32_t offsetUp = (int32_t)U_ALIGNMENT_OFFSET_UP(stackBufferChars);
-        if (*pBufferSize > offsetUp) {
-            *pBufferSize -= offsetUp;
-            stackBufferChars += offsetUp;
-        }
-        else {
-            /* prevent using the stack buffer but keep the size > 0 so that we do not just preflight */
-            *pBufferSize = 1;
+    if (pBufferSize != NULL) {
+        int32_t inputSize = *pBufferSize;
+        *pBufferSize = 1;
+        if (inputSize == 0) {
+            return NULL;  // preflighting for deprecated functionality
         }
     }
-    stackBuffer = (void *)stackBufferChars;
 
-    if (stackBuffer == NULL || *pBufferSize < bufferSizeNeeded) {
-        /* allocate one here...*/
-        stackBufferChars = (char *)uprv_malloc(bufferSizeNeeded);
-        // Null pointer check.
-        if (stackBufferChars == NULL) {
-            *status = U_MEMORY_ALLOCATION_ERROR;
-            return NULL;
-        }
-        colAllocated = TRUE;
-        if (U_SUCCESS(*status)) {
-            *status = U_SAFECLONE_ALLOCATED_WARNING;
-        }
+    char *stackBufferChars = (char *)uprv_malloc(bufferSizeNeeded);
+    // Null pointer check.
+    if (stackBufferChars == NULL) {
+        *status = U_MEMORY_ALLOCATION_ERROR;
+        return NULL;
     }
+    *status = U_SAFECLONE_ALLOCATED_WARNING;
+
     localCollator = (UCollator *)stackBufferChars;
     rules = (UChar *)(stackBufferChars + sizeof(UCollator) + rulesPadding);
     defaultReorderCodes = (int32_t*)((uint8_t*)rules + rulesSize);
@@ -702,7 +682,7 @@ ucol_safeClone(const UCollator *coll, void *stackBuffer, int32_t * pBufferSize,
     localCollator->validLocale = NULL;
     localCollator->requestedLocale = NULL;
     localCollator->ucaRules = coll->ucaRules; // There should only be one copy here.
-    localCollator->freeOnClose = colAllocated;
+    localCollator->freeOnClose = TRUE;
     localCollator->freeImageOnClose = imageAllocated;
     return localCollator;
 }
index 41fdc317bc13259682fd34e1e36530260094442e..3bb4bc1c3dc90465c9ea52dfa3145e7b19a14e95 100644 (file)
@@ -1212,12 +1212,13 @@ ucol_restoreVariableTop(UCollator *coll, const uint32_t varTop, UErrorCode *stat
 /**
  * Thread safe cloning operation. The result is a clone of a given collator.
  * @param coll collator to be cloned
- * @param stackBuffer user allocated space for the new clone. 
+ * @param stackBuffer <em>Deprecated functionality as of ICU 52, use NULL.</em><br>
+ * user allocated space for the new clone. 
  * If NULL new memory will be allocated. 
  *  If buffer is not large enough, new memory will be allocated.
- *  Clients can use the U_COL_SAFECLONE_BUFFERSIZE. 
- *  This will probably be enough to avoid memory allocations.
- * @param pBufferSize pointer to size of allocated space. 
+ *  Clients can use the U_COL_SAFECLONE_BUFFERSIZE.
+ * @param pBufferSize <em>Deprecated functionality as of ICU 52, use NULL or 1.</em><br>
+ *  pointer to size of allocated space. 
  *  If *pBufferSize == 0, a sufficient size for use in cloning will 
  *  be returned ('pre-flighting')
  *  If *pBufferSize is not enough for a stack-based safe clone, 
@@ -1237,10 +1238,14 @@ ucol_safeClone(const UCollator *coll,
                int32_t         *pBufferSize,
                UErrorCode      *status);
 
-/** default memory size for the new clone. It needs to be this large for os/400 large pointers 
- * @stable ICU 2.0
+#ifndef U_HIDE_DEPRECATED_API
+
+/** default memory size for the new clone.
+ * @deprecated ICU 52. Do not rely on ucol_safeClone() cloning into any provided buffer.
  */
-#define U_COL_SAFECLONE_BUFFERSIZE 528
+#define U_COL_SAFECLONE_BUFFERSIZE 1
+
+#endif /* U_HIDE_DEPRECATED_API */
 
 /**
  * Returns current rules. Delta defines whether full rules are returned or just the tailoring. 
index 63922c773639c613f8b916adc23a9718316ce50a..fb17f500038ae5c04b579a127c29d8bcf873a822 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
 *
-*   Copyright (C) 2000-2011, International Business Machines
+*   Copyright (C) 2000-2013, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 ***************************************************************************
@@ -786,8 +786,7 @@ UBool convsample_21_didSubstitute(const char *source)
          debugCtx1->subContext, flagCtx, debugCtx2, debugCtx2->subCallback);
 #endif
 
-  cloneLen = 1; /* but passing in null so it will clone */
-  cloneCnv = ucnv_safeClone(conv,  NULL,  &cloneLen, &status);
+  cloneCnv = ucnv_safeClone(conv, NULL, NULL, &status);
 
   U_ASSERT(status);
 
index 935e8ffb4880fa70fe40c68fe5e15d0148869d04..f26c6583ba9a85b700c7341f0e4e10ac99813ad8 100644 (file)
@@ -37,7 +37,7 @@ CPPFLAGS += -I$(top_srcdir)/common -I$(top_srcdir)/i18n -I$(top_srcdir)/tools/ct
 DEFS += -D'ICU_UNICODE_VERSION="$(UNICODE_VERSION)"' -D'ICU_VERSION="@VERSION@"' -D'ICUDATA_NAME="$(ICUDATA_PLATFORM_NAME)"' -D'U_TOPSRCDIR="$(top_srcdir)/"' -D'U_TOPBUILDDIR="$(BUILDDIR)"'
 LIBS = $(LIBCTESTFW) $(LIBICUI18N) $(LIBICUTOOLUTIL) $(LIBICUUC) $(DEFAULT_LIBS) $(LIB_M)
 
-OBJECTS = callcoll.o calltest.o colutil.o capitst.o cbiapts.o cbkittst.o \
+OBJECTS = callcoll.o calltest.o capitst.o cbiapts.o cbkittst.o \
 ccaltst.o ucnvseltst.o cctest.o ccapitst.o ccolltst.o encoll.o cconvtst.o ccurrtst.o \
 cdateintervalformattest.o cdattst.o cdetst.o cdtdptst.o cdtrgtst.o cestst.o cfintst.o \
 cformtst.o cfrtst.o cg7coll.o chashtst.o cintltst.o citertst.o cjaptst.o cloctst.o \
index 11083b932846bd3f96dd2aa1df22b5cbb74e62a6..90ca87a2bfa264c10d1850f10fc4a075be9ab609 100644 (file)
@@ -36,7 +36,6 @@ static void TestAttribute(void);
 static void TestDefault(void);
 static void TestDefaultKeyword(void);
 static void TestBengaliSortKey(void);
-        int TestBufferSize();    /* defined in "colutil.c" */
 
 
 static char* U_EXPORT2 ucol_sortKeyToString(const UCollator *coll, const uint8_t *sortkey, char *buffer, uint32_t len) {
@@ -650,11 +649,6 @@ void TestSafeClone() {
     const char sampleRuleChars[] = "&Z < CH";
     UChar sampleRule[sizeof(sampleRuleChars)];
 
-    if (TestBufferSize()) {
-        log_err("U_COL_SAFECLONE_BUFFERSIZE should be larger than sizeof(UCollator)\n");
-        return;
-    }
-
     u_uastrcpy(test1, "abCda");
     u_uastrcpy(test2, "abcda");
     u_uastrcpy(sampleRule, sampleRuleChars);
@@ -675,28 +669,30 @@ void TestSafeClone() {
     /* Check the various error & informational states: */
 
     /* Null status - just returns NULL */
-    if (0 != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, 0))
+    if (NULL != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, NULL))
     {
         log_err("FAIL: Cloned Collator failed to deal correctly with null status\n");
     }
     /* error status - should return 0 & keep error the same */
     err = U_MEMORY_ALLOCATION_ERROR;
-    if (0 != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err) || err != U_MEMORY_ALLOCATION_ERROR)
+    if (NULL != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err) || err != U_MEMORY_ALLOCATION_ERROR)
     {
         log_err("FAIL: Cloned Collator failed to deal correctly with incoming error status\n");
     }
     err = U_ZERO_ERROR;
 
-    /* Null buffer size pointer - just returns NULL & set error to U_ILLEGAL_ARGUMENT_ERROR*/
-    if (0 != ucol_safeClone(someCollators[0], buffer[0], 0, &err) || err != U_ILLEGAL_ARGUMENT_ERROR)
+    /* Null buffer size pointer is ok */
+    if (NULL == (col = ucol_safeClone(someCollators[0], buffer[0], NULL, &err)) || U_FAILURE(err))
     {
         log_err("FAIL: Cloned Collator failed to deal correctly with null bufferSize pointer\n");
     }
+    ucol_close(col);
     err = U_ZERO_ERROR;
 
     /* buffer size pointer is 0 - fill in pbufferSize with a size */
     bufferSize = 0;
-    if (0 != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err) || U_FAILURE(err) || bufferSize <= 0)
+    if (NULL != ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err) ||
+            U_FAILURE(err) || bufferSize <= 0)
     {
         log_err("FAIL: Cloned Collator failed a sizing request ('preflighting')\n");
     }
@@ -706,14 +702,16 @@ void TestSafeClone() {
         log_err("FAIL: Pre-calculated buffer size is too small\n");
     }
     /* Verify we can use this run-time calculated size */
-    if (0 == (col = ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err)) || U_FAILURE(err))
+    if (NULL == (col = ucol_safeClone(someCollators[0], buffer[0], &bufferSize, &err)) || U_FAILURE(err))
     {
         log_err("FAIL: Collator can't be cloned with run-time size\n");
     }
     if (col) ucol_close(col);
     /* size one byte too small - should allocate & let us know */
-    --bufferSize;
-    if (0 == (col = ucol_safeClone(someCollators[0], 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
+    if (bufferSize > 1) {
+        --bufferSize;
+    }
+    if (NULL == (col = ucol_safeClone(someCollators[0], 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
     {
         log_err("FAIL: Cloned Collator failed to deal correctly with too-small buffer size\n");
     }
@@ -723,7 +721,7 @@ void TestSafeClone() {
 
 
     /* Null buffer pointer - return Collator & set error to U_SAFECLONE_ALLOCATED_ERROR */
-    if (0 == (col = ucol_safeClone(someCollators[0], 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
+    if (NULL == (col = ucol_safeClone(someCollators[0], 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
     {
         log_err("FAIL: Cloned Collator failed to deal correctly with null buffer pointer\n");
     }
@@ -731,7 +729,7 @@ void TestSafeClone() {
     err = U_ZERO_ERROR;
 
     /* Null Collator - return NULL & set U_ILLEGAL_ARGUMENT_ERROR */
-    if (0 != ucol_safeClone(0, buffer[0], &bufferSize, &err) || err != U_ILLEGAL_ARGUMENT_ERROR)
+    if (NULL != ucol_safeClone(NULL, buffer[0], &bufferSize, &err) || err != U_ILLEGAL_ARGUMENT_ERROR)
     {
         log_err("FAIL: Cloned Collator failed to deal correctly with null Collator pointer\n");
     }
@@ -768,14 +766,9 @@ void TestSafeClone() {
         bufferSize = U_COL_SAFECLONE_BUFFERSIZE;
         err = U_ZERO_ERROR;
         someClonedCollators[idx] = ucol_safeClone(someCollators[idx], buffer[idx], &bufferSize, &err);
-        if (someClonedCollators[idx] == NULL
-            || someClonedCollators[idx] < (UCollator *)buffer[idx]
-            || someClonedCollators[idx] > (UCollator *)(buffer[idx]+(U_COL_SAFECLONE_BUFFERSIZE-1)))
-        {
-            /* TODO: The use of U_COL_SAFECLONE_BUFFERSIZE will be deprecated per #9932.
-               In the meantime, just turn the following former error into a log message. */
-            log_verbose("NOTE: Cloned collator did not use provided buffer, index %d, status %s, clone NULL? %d\n",
-                                                        idx, myErrorName(err), someClonedCollators[idx] == NULL);
+        if (U_FAILURE(err)) {
+            log_err("FAIL: Unable to clone collator %d - %s\n", idx, u_errorName(err));
+            continue;
         }
         if (!ucol_equals(someClonedCollators[idx], someCollators[idx])) {
             log_err("FAIL: Cloned collator is not equal to original at index = %d.\n", idx);
index 787552713178e6ffd296b310dd66bd2d9c99da48..c9080f2d153a828cfe44edce22c4665782b9a0bc 100644 (file)
@@ -401,28 +401,30 @@ static void TestBreakIteratorSafeClone(void)
         /* Check the various error & informational states */
 
         /* Null status - just returns NULL */
-        if (0 != ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, 0))
+        if (NULL != ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, NULL))
         {
             log_err("FAIL: Cloned Iterator failed to deal correctly with null status\n");
         }
         /* error status - should return 0 & keep error the same */
         status = U_MEMORY_ALLOCATION_ERROR;
-        if (0 != ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, &status) || status != U_MEMORY_ALLOCATION_ERROR)
+        if (NULL != ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, &status) || status != U_MEMORY_ALLOCATION_ERROR)
         {
             log_err("FAIL: Cloned Iterator failed to deal correctly with incoming error status\n");
         }
         status = U_ZERO_ERROR;
 
-        /* Null buffer size pointer - just returns NULL & set error to U_ILLEGAL_ARGUMENT_ERROR*/
-        if (0 != ubrk_safeClone(someIterators[i], buffer[i], 0, &status) || status != U_ILLEGAL_ARGUMENT_ERROR)
+        /* Null buffer size pointer is ok */
+        if (NULL == (brk = ubrk_safeClone(someIterators[i], buffer[i], NULL, &status)) || U_FAILURE(status))
         {
             log_err("FAIL: Cloned Iterator failed to deal correctly with null bufferSize pointer\n");
         }
+        ubrk_close(brk);
         status = U_ZERO_ERROR;
-    
+
         /* buffer size pointer is 0 - fill in pbufferSize with a size */
         bufferSize = 0;
-        if (0 != ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, &status) || U_FAILURE(status) || bufferSize <= 0)
+        if (NULL != ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, &status) ||
+                U_FAILURE(status) || bufferSize <= 0)
         {
             log_err("FAIL: Cloned Iterator failed a sizing request ('preflighting')\n");
         }
@@ -432,15 +434,17 @@ static void TestBreakIteratorSafeClone(void)
           log_err("FAIL: Pre-calculated buffer size is too small - %d but needed %d\n", U_BRK_SAFECLONE_BUFFERSIZE, bufferSize);
         }
         /* Verify we can use this run-time calculated size */
-        if (0 == (brk = ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, &status)) || U_FAILURE(status))
+        if (NULL == (brk = ubrk_safeClone(someIterators[i], buffer[i], &bufferSize, &status)) || U_FAILURE(status))
         {
             log_err("FAIL: Iterator can't be cloned with run-time size\n");
         }
         if (brk)
             ubrk_close(brk);
         /* size one byte too small - should allocate & let us know */
-        --bufferSize;
-        if (0 == (brk = ubrk_safeClone(someIterators[i], 0, &bufferSize, &status)) || status != U_SAFECLONE_ALLOCATED_WARNING)
+        if (bufferSize > 1) {
+            --bufferSize;
+        }
+        if (NULL == (brk = ubrk_safeClone(someIterators[i], NULL, &bufferSize, &status)) || status != U_SAFECLONE_ALLOCATED_WARNING)
         {
             log_err("FAIL: Cloned Iterator failed to deal correctly with too-small buffer size\n");
         }
@@ -450,7 +454,7 @@ static void TestBreakIteratorSafeClone(void)
         bufferSize = U_BRK_SAFECLONE_BUFFERSIZE;
 
         /* Null buffer pointer - return Iterator & set error to U_SAFECLONE_ALLOCATED_ERROR */
-        if (0 == (brk = ubrk_safeClone(someIterators[i], 0, &bufferSize, &status)) || status != U_SAFECLONE_ALLOCATED_WARNING)
+        if (NULL == (brk = ubrk_safeClone(someIterators[i], NULL, &bufferSize, &status)) || status != U_SAFECLONE_ALLOCATED_WARNING)
         {
             log_err("FAIL: Cloned Iterator failed to deal correctly with null buffer pointer\n");
         }
@@ -461,22 +465,13 @@ static void TestBreakIteratorSafeClone(void)
         /* Mis-aligned buffer pointer. */
         {
             char  stackBuf[U_BRK_SAFECLONE_BUFFERSIZE+sizeof(void *)];
-            void  *p;
-            int32_t offset;
 
             brk = ubrk_safeClone(someIterators[i], &stackBuf[1], &bufferSize, &status);
-            if (U_FAILURE(status) || brk == 0) {
+            if (U_FAILURE(status) || brk == NULL) {
                 log_err("FAIL: Cloned Iterator failed with misaligned buffer pointer\n");
             }
             if (status == U_SAFECLONE_ALLOCATED_WARNING) {
-                log_err("FAIL: Cloned Iterator allocated when using a mis-aligned buffer.\n");
-            }
-            offset = (int32_t)((char *)&p-(char*)brk);
-            if (offset < 0) {
-                offset = -offset;
-            }
-            if (offset % sizeof(void *) != 0) {
-                log_err("FAIL: Cloned Iterator failed to align correctly with misaligned buffer pointer\n");
+                log_verbose("Cloned Iterator allocated when using a mis-aligned buffer.\n");
             }
             if (brk)
                 ubrk_close(brk);
@@ -484,7 +479,7 @@ static void TestBreakIteratorSafeClone(void)
 
 
         /* Null Iterator - return NULL & set U_ILLEGAL_ARGUMENT_ERROR */
-        if (0 != ubrk_safeClone(0, buffer[i], &bufferSize, &status) || status != U_ILLEGAL_ARGUMENT_ERROR)
+        if (NULL != ubrk_safeClone(NULL, buffer[i], &bufferSize, &status) || status != U_ILLEGAL_ARGUMENT_ERROR)
         {
             log_err("FAIL: Cloned Iterator failed to deal correctly with null Iterator pointer\n");
         }
index 7d0725ce4a7e607af7c04c09f8db98421a6197e8..04d1524a3fee32fd197e9b497e5a4883458537dd 100644 (file)
@@ -1712,28 +1712,29 @@ static void TestConvertSafeClone()
 
         /* Null status - just returns NULL */
         bufferSize = U_CNV_SAFECLONE_BUFFERSIZE;
-        if (0 != ucnv_safeClone(cnv, buffer[0], &bufferSize, 0))
+        if (NULL != ucnv_safeClone(cnv, buffer[0], &bufferSize, NULL))
         {
             log_err("FAIL: Cloned converter failed to deal correctly with null status\n");
         }
         /* error status - should return 0 & keep error the same */
         err = U_MEMORY_ALLOCATION_ERROR;
-        if (0 != ucnv_safeClone(cnv, buffer[0], &bufferSize, &err) || err != U_MEMORY_ALLOCATION_ERROR)
+        if (NULL != ucnv_safeClone(cnv, buffer[0], &bufferSize, &err) || err != U_MEMORY_ALLOCATION_ERROR)
         {
             log_err("FAIL: Cloned converter failed to deal correctly with incoming error status\n");
         }
         err = U_ZERO_ERROR;
 
-        /* Null buffer size pointer - just returns NULL & set error to U_ILLEGAL_ARGUMENT_ERROR*/
-        if (0 != ucnv_safeClone(cnv, buffer[0], 0, &err) || err != U_ILLEGAL_ARGUMENT_ERROR)
+        /* Null buffer size pointer is ok */
+        if (NULL == (cnv2 = ucnv_safeClone(cnv, buffer[0], NULL, &err)) || U_FAILURE(err))
         {
             log_err("FAIL: Cloned converter failed to deal correctly with null bufferSize pointer\n");
         }
+        ucnv_close(cnv2);
         err = U_ZERO_ERROR;
 
         /* buffer size pointer is 0 - fill in pbufferSize with a size */
         bufferSize = 0;
-        if (0 != ucnv_safeClone(cnv, buffer[0], &bufferSize, &err) || U_FAILURE(err) || bufferSize <= 0)
+        if (NULL != ucnv_safeClone(cnv, buffer[0], &bufferSize, &err) || U_FAILURE(err) || bufferSize <= 0)
         {
             log_err("FAIL: Cloned converter failed a sizing request ('preflighting')\n");
         }
@@ -1743,7 +1744,7 @@ static void TestConvertSafeClone()
             log_err("FAIL: Pre-calculated buffer size is too small\n");
         }
         /* Verify we can use this run-time calculated size */
-        if (0 == (cnv2 = ucnv_safeClone(cnv, buffer[0], &bufferSize, &err)) || U_FAILURE(err))
+        if (NULL == (cnv2 = ucnv_safeClone(cnv, buffer[0], &bufferSize, &err)) || U_FAILURE(err))
         {
             log_err("FAIL: Converter can't be cloned with run-time size\n");
         }
@@ -1753,7 +1754,7 @@ static void TestConvertSafeClone()
 
         /* size one byte too small - should allocate & let us know */
         --bufferSize;
-        if (0 == (cnv2 = ucnv_safeClone(cnv, 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
+        if (NULL == (cnv2 = ucnv_safeClone(cnv, NULL, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
         {
             log_err("FAIL: Cloned converter failed to deal correctly with too-small buffer size\n");
         }
@@ -1765,7 +1766,7 @@ static void TestConvertSafeClone()
         bufferSize = U_CNV_SAFECLONE_BUFFERSIZE;
 
         /* Null buffer pointer - return converter & set error to U_SAFECLONE_ALLOCATED_ERROR */
-        if (0 == (cnv2 = ucnv_safeClone(cnv, 0, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
+        if (NULL == (cnv2 = ucnv_safeClone(cnv, NULL, &bufferSize, &err)) || err != U_SAFECLONE_ALLOCATED_WARNING)
         {
             log_err("FAIL: Cloned converter failed to deal correctly with null buffer pointer\n");
         }
@@ -1776,7 +1777,7 @@ static void TestConvertSafeClone()
         err = U_ZERO_ERROR;
     
         /* Null converter - return NULL & set U_ILLEGAL_ARGUMENT_ERROR */
-        if (0 != ucnv_safeClone(0, buffer[0], &bufferSize, &err) || err != U_ILLEGAL_ARGUMENT_ERROR)
+        if (NULL != ucnv_safeClone(NULL, buffer[0], &bufferSize, &err) || err != U_ILLEGAL_ARGUMENT_ERROR)
         {
             log_err("FAIL: Cloned converter failed to deal correctly with null converter pointer\n");
         }
index b53641122770cff262f299947db22d24ea1854a7..17529b6200a70fc5ee293fa9a355dbe961391ea3 100644 (file)
     <ClCompile Include="citertst.c" />\r
     <ClCompile Include="cjaptst.c" />\r
     <ClCompile Include="cmsccoll.c" />\r
-    <ClCompile Include="colutil.c" />\r
     <ClCompile Include="cturtst.c" />\r
     <ClCompile Include="encoll.c" />\r
     <ClCompile Include="usrchdat.c">\r
index ff6b1614a130aab57e0f0f11b38aab0aca34440a..c12ab5a432fe106f9397f34454a635ac18830f77 100644 (file)
@@ -99,9 +99,6 @@
     <ClCompile Include="cmsccoll.c">\r
       <Filter>collation</Filter>\r
     </ClCompile>\r
-    <ClCompile Include="colutil.c">\r
-      <Filter>collation</Filter>\r
-    </ClCompile>\r
     <ClCompile Include="cturtst.c">\r
       <Filter>collation</Filter>\r
     </ClCompile>\r
index 4145eaae148bd98e29074225f89ca2d4e43ba969..b47472806b246bc3c294b6ed7f7dbe2014a7577b 100644 (file)
@@ -4071,10 +4071,10 @@ static void TestSettings(void) {
 static int32_t TestEqualsForCollator(const char* locName, UCollator *source, UCollator *target) {
     UErrorCode status = U_ZERO_ERROR;
     int32_t errorNo = 0;
-    /*const UChar *sourceRules = NULL;*/
-    /*int32_t sourceRulesLen = 0;*/
+    const UChar *sourceRules = NULL;
+    int32_t sourceRulesLen = 0;
+    UParseError parseError;
     UColAttributeValue french = UCOL_OFF;
-    int32_t cloneSize = 0;
 
     if(!ucol_equals(source, target)) {
         log_err("Same collators, different address not equal\n");
@@ -4082,11 +4082,7 @@ static int32_t TestEqualsForCollator(const char* locName, UCollator *source, UCo
     }
     ucol_close(target);
     if(uprv_strcmp(ucol_getLocaleByType(source, ULOC_REQUESTED_LOCALE, &status), ucol_getLocaleByType(source, ULOC_ACTUAL_LOCALE, &status)) == 0) {
-        /* currently, safeClone is implemented through getRules/openRules
-        * so it is the same as the test below - I will comment that test out.
-        */
-        /* real thing */
-        target = ucol_safeClone(source, NULL, &cloneSize, &status);
+        target = ucol_safeClone(source, NULL, NULL, &status);
         if(U_FAILURE(status)) {
             log_err("Error creating clone\n");
             errorNo++;
@@ -4112,21 +4108,19 @@ static int32_t TestEqualsForCollator(const char* locName, UCollator *source, UCo
             errorNo++;
         }
         ucol_close(target);
-        /* commented out since safeClone uses exactly the same technique */
-        /*
+
         sourceRules = ucol_getRules(source, &sourceRulesLen);
         target = ucol_openRules(sourceRules, sourceRulesLen, UCOL_DEFAULT, UCOL_DEFAULT, &parseError, &status);
         if(U_FAILURE(status)) {
-        log_err("Error instantiating target from rules\n");
-        errorNo++;
-        return errorNo;
+            log_err("Error instantiating target from rules - %s\n", u_errorName(status));
+            errorNo++;
+            return errorNo;
         }
         if(!ucol_equals(source, target)) {
-        log_err("Collator different from collator that was created from the same rules\n");
-        errorNo++;
+            log_err("Collator different from collator that was created from the same rules\n");
+            errorNo++;
         }
         ucol_close(target);
-        */
     }
     return errorNo;
 }
@@ -6367,7 +6361,6 @@ static void TestReorderingAcrossCloning(void)
     UCollator  *myCollation;
     int32_t reorderCodes[3] = {USCRIPT_GREEK, USCRIPT_HAN, UCOL_REORDER_CODE_PUNCTUATION};
     UCollator *clonedCollation;
-    int32_t bufferSize;
     int32_t retrievedReorderCodesLength;
     int32_t retrievedReorderCodes[10];
     int loopIndex;
@@ -6390,7 +6383,7 @@ static void TestReorderingAcrossCloning(void)
     }
     
     /* clone the collator */
-    clonedCollation = ucol_safeClone(myCollation, NULL, &bufferSize, &status);
+    clonedCollation = ucol_safeClone(myCollation, NULL, NULL, &status);
     if (U_FAILURE(status)) {
         log_err_status(status, "ERROR: cloning collator: %s\n", myErrorName(status));
         return;
diff --git a/icu4c/source/test/cintltst/colutil.c b/icu4c/source/test/cintltst/colutil.c
deleted file mode 100644 (file)
index 8e9f360..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-/********************************************************************
- * COPYRIGHT: 
- * Copyright (c) 1997-2003, International Business Machines Corporation and
- * others. All Rights Reserved.
- ********************************************************************/
-
-#include "ucol_imp.h"
-
-#if !UCONFIG_NO_COLLATION
-
-int TestBufferSize(void); /* keep gcc happy */
-
-int TestBufferSize(void)
-{
-    return (U_COL_SAFECLONE_BUFFERSIZE < sizeof(UCollator));
-}
-#endif
index 75fc74047dafc77c3c201ec33cf29677383fb85a..a35d5532782707218cc8296b18681731bfbc148b 100644 (file)
@@ -1,7 +1,7 @@
 /*
 *******************************************************************************
 *
-*   Copyright (C) 2002-2012, International Business Machines
+*   Copyright (C) 2002-2013, International Business Machines
 *   Corporation and others.  All Rights Reserved.
 *
 *******************************************************************************
@@ -397,8 +397,7 @@ StringCaseTest::TestCasingImpl(const UnicodeString &input,
 #if !UCONFIG_NO_BREAK_ITERATION
     if(iter!=NULL) {
         // Clone the break iterator so that the UCaseMap can safely adopt it.
-        int32_t size=1;  // Not 0 because that only gives preflighting.
-        UBreakIterator *clone=ubrk_safeClone((UBreakIterator *)iter, NULL, &size, errorCode);
+        UBreakIterator *clone=ubrk_safeClone((UBreakIterator *)iter, NULL, NULL, errorCode);
         ucasemap_setBreakIterator(csm.getAlias(), clone, errorCode);
     }
 #endif