ICU-7689 fix memleak, fix InternalIbm:132 and other cleanup
X-SVN-Rev: 29893
diff --git a/source/common/norm2.c b/source/common/norm2.c
index d40cd8a..667c942 100644
--- a/source/common/norm2.c
+++ b/source/common/norm2.c
@@ -109,10 +109,13 @@
UNormalizationMode mode,
UErrorCode *errorCode);
+
+#if 0
static const UChar *
Normalizer2_decomp_decompose(Normalizer2 *_this, const UChar *src, const UChar *limit,
ReorderingBuffer *buffer,
UErrorCode *errorCode);
+#endif
static const UChar *Normalizer2Impl_findPreviousCompBoundary(Normalizer2 *_this, const UChar *start, const UChar *p);
@@ -158,13 +161,14 @@
int i;
for(i=0;i<UNORM_MODE_COUNT;i++) {
if(singletons[i]!=NULL) {
- unorm2_close(singletons[i]);
+ unorm2_close((UNormalizer2*)singletons[i]);
singletons[i]=NULL;
}
}
uprv_free(singletons);
singletons=NULL;
}
+ return TRUE;
}
static UNormalizer2 *getSingleton(UNormalizationMode mode, const char *str, UErrorCode *errorCode) {
@@ -433,9 +437,11 @@
static uint8_t getCCFromYesOrMaybe(uint16_t norm16) {
return norm16>=MIN_NORMAL_MAYBE_YES ? (uint8_t)norm16 : 0;
}
+#if 0
static UBool isMostDecompYesAndZeroCC(Normalizer2* _this, uint16_t norm16) {
return norm16<_this->minYesNo || norm16==MIN_NORMAL_MAYBE_YES || norm16==JAMO_VT;
}
+#endif
static UBool isDecompYes(Normalizer2* _this,uint16_t norm16) { return (norm16<_this->minYesNo) || (_this->minMaybeYes<=norm16); }
@@ -466,9 +472,11 @@
static UChar *ReorderingBuffer_getStart(ReorderingBuffer* buffer) {
return buffer->start;
}
+#if 0
static UBool ReorderingBuffer_isEmpty(ReorderingBuffer* buffer) {
return buffer->start==buffer->limit;
}
+#endif
static void ReorderingBuffer_setLastChar(ReorderingBuffer* buffer, UChar c) {
*(buffer->limit-1)=c;
}
@@ -1095,6 +1103,7 @@
}
}
+#if 0
/* Dual functionality: */
/* buffer!=NULL: normalize */
@@ -1183,6 +1192,7 @@
}
return src;
}
+#endif
@@ -1202,7 +1212,7 @@
}
}
-
+#if 0
static void Normalizer2Impl_composeAndAppend(Normalizer2 *_this, const UChar *src, const UChar *limit,
UBool doCompose,
UBool onlyContiguous,
@@ -1259,6 +1269,7 @@
ReorderingBuffer_appendZeroCCStr(buffer, src, limit, errorCode);
}
}
+#endif
/**
* Does c have a composition boundary before it?
@@ -1279,7 +1290,7 @@
} else {
/* c decomposes, get everything from the variable-length extra data */
int32_t i=0;
- UChar32 c;
+ UChar32 c2;
const uint16_t *mapping=getMapping(norm16);
{
uint16_t firstUnit=*mapping++;
@@ -1289,13 +1300,14 @@
if((firstUnit&MAPPING_HAS_CCC_LCCC_WORD) && (*mapping++&0xff00)) {
return FALSE; /* non-zero leadCC */
}
- U16_NEXT_UNSAFE(mapping, i, c);
- return isCompYesAndZeroCC(getNorm16(c));
+ U16_NEXT_UNSAFE(mapping, i, c2);
+ return isCompYesAndZeroCC(getNorm16(c2));
}
}
}
}
+#if 0
static UBool Normalizer2Impl_hasCompBoundaryAfter(Normalizer2 *_this, UChar32 c, UBool onlyContiguous, UBool testInert) {
for(;;) {
uint16_t norm16=getNorm16(c);
@@ -1328,6 +1340,7 @@
}
}
}
+#endif
typedef struct {
const UTrie2 *trie;
@@ -1383,6 +1396,7 @@
return result;
}
+#if 0
static const UChar *Normalizer2Impl_findPreviousCompBoundary(Normalizer2 *_this, const UChar *start, const UChar *p) {
BackwardsUTrie2StringIterator iter;
uint16_t norm16;
@@ -1394,6 +1408,7 @@
/* but that's probably not worth the extra cost. */
return iter.codePointStart;
}
+#endif
static const UChar *Normalizer2Impl_findNextCompBoundary(Normalizer2 *_this, const UChar *p, const UChar *limit) {
uint16_t norm16;
@@ -1719,7 +1734,7 @@
if(limit==NULL) {
UErrorCode errorCode2=U_ZERO_ERROR;
- src=Normalizer2_fcd_copyLowPrefixFromNulTerminated(_this, src, minNoMaybeCP, NULL, &errorCode2);
+ src=Normalizer2_fcd_copyLowPrefixFromNulTerminated(_this, src, minNoMaybeCP, doCompose? buffer : NULL, &errorCode2);
limit=u_strchr(src, 0);
}
@@ -2062,9 +2077,11 @@
return Normalizer2_decomp_decompose(n, s, limit, NULL, pErrorCode);
}
#endif
+#if 0
static const UChar* Normalizer2_comp_spanQuickCheckYes(struct Normalizer2* n, const UChar *s, const UChar* limit, UErrorCode *pErrorCode) {
return Normalizer2_comp_composeQuickCheck(n, s, limit, n->onlyContiguous, NULL);
}
+#endif
#if UNORM_ENABLE_FCD
static UBool Normalizer2_fcd_isNormalized(struct Normalizer2* n, const UChar *s, int32_t length, UErrorCode *pErrorCode) {
@@ -2321,7 +2338,7 @@
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
return 0;
}
- return ((const Normalizer2 *)norm2)->isNormalized(norm2, s, length, pErrorCode);
+ return ((const Normalizer2 *)norm2)->isNormalized((Normalizer2*)norm2, s, length, pErrorCode);
}
U_CAPI UBool U_EXPORT2
@@ -2357,7 +2374,7 @@
unorm_getQuickCheck(UChar32 c, UNormalizationMode mode) {
Normalizer2 *norm2;
UErrorCode errorCode=U_ZERO_ERROR;
- norm2 = Normalizer2Factory_getInstance(mode, &errorCode);
+ norm2 = (Normalizer2*)Normalizer2Factory_getInstance(mode, &errorCode);
if(mode<=UNORM_NONE || UNORM_FCD<=mode) {
return UNORM_YES;
}
diff --git a/source/common/norm2imp.h b/source/common/norm2imp.h
index 66ce591..566fe4e 100644
--- a/source/common/norm2imp.h
+++ b/source/common/norm2imp.h
@@ -27,7 +27,7 @@
const UChar *src, int32_t length,
UChar *dest, int32_t capacity,
UErrorCode *pErrorCode);
- int32_t (U_EXPORT2 *isNormalized) (struct Normalizer2 *n,
+ UBool (U_EXPORT2 *isNormalized) (struct Normalizer2 *n,
const UChar *src, int32_t length,
UErrorCode *pErrorCode);
UNormalizationCheckResult (U_EXPORT2 *getQuickCheck) (struct Normalizer2 *n,
@@ -160,5 +160,12 @@
#define isJamoVT(norm16) ( (norm16)==JAMO_VT )
+/**
+ * Get the NF*_QC property for a code point, for u_getIntPropertyValue().
+ * @internal
+ */
+U_CFUNC UNormalizationCheckResult U_EXPORT2
+unorm_getQuickCheck(UChar32 c, UNormalizationMode mode);
+
#endif
diff --git a/source/samples/c0test/c0test.c b/source/samples/c0test/c0test.c
index 62f80cb..b25a8ea 100644
--- a/source/samples/c0test/c0test.c
+++ b/source/samples/c0test/c0test.c
@@ -43,6 +43,28 @@
}
}
+void **chainDel = NULL;
+
+/**
+ * Use this to allocate stuff (such as test strings) to be cleaned up at the end
+ */
+void *c_malloc(size_t s) {
+ void **next = malloc(s+sizeof(void*));
+ next[0]=chainDel;
+ chainDel = next;
+ return (void*)(next+1);
+}
+
+void c_cleanup() {
+ while(chainDel) {
+ void **chainNext = *chainDel;
+ free(chainDel);
+ chainDel = chainNext;
+ }
+}
+
+
+
static void TestQuickCheckResultNO()
{
@@ -280,7 +302,7 @@
length = u_strlen ( unichars );
/*newString = (char*)malloc ( sizeof( char ) * 4 * ( length + 1 ) );*/ /* this leaks for now */
- newString = (char*)malloc ( sizeof( char ) * 4 * ( length + 1 ) ); /* this shouldn't */
+ newString = (char*)c_malloc ( sizeof( char ) * 4 * ( length + 1 ) ); /* this shouldn't */
if ( newString == NULL )
return NULL;
@@ -308,7 +330,7 @@
if(length==-1){
length = u_strlen( unichars);
}
- newString = (char*)malloc ( sizeof(char) * 8 * (length +1));
+ newString = (char*)c_malloc ( sizeof(char) * 8 * (length +1));
target = newString;
targetLimit = newString+sizeof(char) * 8 * (length +1);
ucnv_setFromUCallBack(conv, UCNV_FROM_U_CALLBACK_ESCAPE, UCNV_ESCAPE_C, &cb, &p, &errorCode);
@@ -439,7 +461,7 @@
{
char *dl = NULL;
UErrorCode status = U_ZERO_ERROR;
-
+ int fail=0;
u_init(&status);
@@ -469,7 +491,8 @@
const UNormalizer2 *norm2;
int length;
UChar buffer16[300];
- UChar source[50];
+ UChar source[50] = { 0x000A, 0x0000 };
+ int rc;
/*
* Test for an example that unorm_getCanonStartSet() delivers
@@ -484,10 +507,35 @@
norm2=unorm2_getInstance(NULL, "nfc", UNORM2_COMPOSE, &errorCode);
if(U_FAILURE(errorCode)) {
log_data_err("unorm2_getInstance(NFC) failed - %s\n", u_errorName(errorCode));
- return -1;
+ fail++;
+ }
+ memset(buffer16,0,300*sizeof(buffer16[0]));
+ length=unorm2_normalize(norm2, source, 1, buffer16, LENGTHOF(buffer16), &errorCode);
+
+ printf("test1, returned length %d\n", length);
+ if(length!=1) {
+ printf("Error, length should be 1\n");
+ fail++;
+ }
+ rc=memcmp(buffer16,source,1);
+ if(rc) {
+ printf("Error: comparison failed!\n");
+ fail++;
}
- length=unorm2_normalize(norm2, source, 1, buffer16, LENGTHOF(buffer16), &errorCode);
+ memset(buffer16,0,300*sizeof(buffer16[0]));
+ length=unorm2_normalize(norm2, source, -1, buffer16, LENGTHOF(buffer16), &errorCode);
+ printf("test2, returned length %d\n", length);
+ if(length!=1) {
+ printf("Error, length should be 1\n");
+ fail++;
+ }
+
+ rc=memcmp(buffer16,source,1);
+ if(rc) {
+ printf("Error: comparison failed!\n");
+ fail++;
+ }
unorm2_close(norm2);
}
@@ -509,8 +557,9 @@
printf("Pure C test OK: %s\n", u_errorName(status));
fflush(stdout);
+ c_cleanup();
u_cleanup();
printf("u_cleanup() OK: %s\n", u_errorName(status));
fflush(stdout);
- return status;
+ return status || fail;
}