BreakIterator::BreakIterator()
{
- fBufferClone = FALSE;
*validLocale = *actualLocale = 0;
}
//-----------------------------------------------------------------------------
void RuleBasedBreakIterator::init() {
UErrorCode status = U_ZERO_ERROR;
- fBufferClone = FALSE;
fText = utext_openUChars(NULL, NULL, 0, &status);
fCharIter = NULL;
fSCharIter = NULL;
}
-
-
-//-------------------------------------------------------------------------------
-//
-// 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)
{
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;
}
/*
********************************************************************************
-* Copyright (C) 1996-2012, International Business Machines
+* Copyright (C) 1996-2013, International Business Machines
* Corporation and others. All Rights Reserved.
********************************************************************************
*/
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;
}
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
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.
}
/*
******************************************************************************
*
-* Copyright (C) 1998-2012, International Business Machines
+* Copyright (C) 1998-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
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;
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",
/* 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
{
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;
+ }
}
*/
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);
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 {
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.
* 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.
/** @internal */
BreakIterator();
/** @internal */
- UBool fBufferClone;
- /** @internal */
- BreakIterator (const BreakIterator &other) : UObject(other), fBufferClone(FALSE) {}
+ BreakIterator (const BreakIterator &other) : UObject(other) {}
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
-
*/
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.
* @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,
#ifndef U_HIDE_INTERNAL_API
/**
* Common initialization function, used by constructors and bufferClone.
- * (Also used by DictionaryBasedBreakIterator::createBufferClone().)
* @internal
*/
void init();
/**
* 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,
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.
/*
**********************************************************************
-* Copyright (C) 1999-2012, International Business Machines
+* Copyright (C) 1999-2013, International Business Machines
* Corporation and others. All Rights Reserved.
**********************************************************************
* ucnv.h:
* 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.
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.
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) {
}
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;
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) {
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);
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;
}
/**
* 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,
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.
/**************************************************************************
*
-* Copyright (C) 2000-2011, International Business Machines
+* Copyright (C) 2000-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*
***************************************************************************
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);
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 \
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) {
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);
/* 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");
}
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");
}
/* 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");
}
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");
}
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);
/* 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");
}
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");
}
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");
}
/* 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);
/* 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");
}
/* 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");
}
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");
}
/* 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");
}
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");
}
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");
}
<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
<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
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");
}
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++;
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;
}
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;
}
/* 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;
+++ /dev/null
-/********************************************************************
- * 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
/*
*******************************************************************************
*
-* Copyright (C) 2002-2012, International Business Machines
+* Copyright (C) 2002-2013, International Business Machines
* Corporation and others. All Rights Reserved.
*
*******************************************************************************
#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