ICU-8784 commit iSeries porting fixes into trunk

X-SVN-Rev: 30667
This commit is contained in:
Steven R. Loomis 2011-09-15 19:34:17 +00:00
parent f67841a40d
commit 737d129645
19 changed files with 178 additions and 48 deletions

View file

@ -1,7 +1,7 @@
/*
******************************************************************************
*
* Copyright (C) 2002-2003, International Business Machines
* Copyright (C) 2002-2011, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
@ -20,6 +20,7 @@
*/
#include "unicode/uclean.h"
#include "cmemory.h"
#include "putilimp.h"
#include <stdlib.h>
/* uprv_malloc(0) returns a pointer to this read-only data. */
@ -42,7 +43,7 @@ uprv_malloc(size_t s) {
if (pAlloc) {
return (*pAlloc)(pContext, s);
} else {
return malloc(s);
return uprv_default_malloc(s);
}
} else {
return (void *)zeroMem;
@ -57,7 +58,7 @@ uprv_realloc(void * buffer, size_t size) {
if (pFree) {
(*pFree)(pContext, buffer);
} else {
free(buffer);
uprv_default_free(buffer);
}
return (void *)zeroMem;
} else {
@ -65,7 +66,7 @@ uprv_realloc(void * buffer, size_t size) {
if (pRealloc) {
return (*pRealloc)(pContext, buffer, size);
} else {
return realloc(buffer, size);
return uprv_default_realloc(buffer, size);
}
}
}
@ -76,7 +77,7 @@ uprv_free(void *buffer) {
if (pFree) {
(*pFree)(pContext, buffer);
} else {
free(buffer);
uprv_default_free(buffer);
}
}
}

View file

@ -342,7 +342,7 @@ MessagePattern::autoQuoteApostropheDeep() const {
for(int32_t i=count; i>0;) {
const Part &part=getPart(--i);
if(part.getType()==UMSGPAT_PART_TYPE_INSERT_CHAR) {
modified.insert(part.index, (UChar)part.value);
modified.insert(part.index, (UChar)part.value);
}
}
return modified;

View file

@ -502,6 +502,24 @@ U_INTERNAL UVoidFunction* U_EXPORT2 uprv_dlsym_func( void *lib, const char *symb
*/
/* U_INTERNAL void * U_EXPORT2 uprv_dlsym_data( void *lib, const char *symbolName, UErrorCode *status); */
/**
* Define malloc and related functions
* @internal
*/
#if defined(OS400)
# define uprv_default_malloc(x) _C_TS_malloc(x)
# define uprv_default_realloc(x,y) _C_TS_realloc(x,y)
# define uprv_default_free(x) _C_TS_free(x)
/* also _C_TS_calloc(x) */
#else
/* C defaults */
# define uprv_default_malloc(x) malloc(x)
# define uprv_default_realloc(x,y) realloc(x,y)
# define uprv_default_free(x) free(x)
#endif
#endif
#endif

View file

@ -317,7 +317,9 @@ U_CFUNC void udata_checkCommonData(UDataMemory *udm, UErrorCode *err) {
return;
}
if(!(udm->pHeader->dataHeader.magic1==0xda &&
if(udm==NULL || udm->pHeader==NULL) {
*err=U_INVALID_FORMAT_ERROR;
} else if(!(udm->pHeader->dataHeader.magic1==0xda &&
udm->pHeader->dataHeader.magic2==0x27 &&
udm->pHeader->info.isBigEndian==U_IS_BIG_ENDIAN &&
udm->pHeader->info.charsetFamily==U_CHARSET_FAMILY)

View file

@ -267,7 +267,7 @@ ubrk_safeClone(
* A recommended size (in bytes) for the memory buffer to be passed to ubrk_saveClone().
* @stable ICU 2.0
*/
#define U_BRK_SAFECLONE_BUFFERSIZE 512
#define U_BRK_SAFECLONE_BUFFERSIZE 528
/**
* Close a UBreakIterator.

View file

@ -1,6 +1,6 @@
## -*-makefile-*-
#******************************************************************************
# Copyright (C) 2008-2010, International Business Machines
# Copyright (C) 2008-2011, International Business Machines
# Corporation and others. All Rights Reserved.
#******************************************************************************
# Make sure we have the right version of Make.
@ -12,7 +12,9 @@ endif
ifeq ($(PLATFORM),OS390)
at_least=3.79.1
endif
ifeq ($(MACHTYPE),powerpc-ibm-os400)
at_least=3.77
endif
latest_a=$(firstword $(sort $(MAKE_VERSION) $(at_least)))
@ -23,6 +25,5 @@ err:
else
ok:
@echo "$(MAKE_VERSION) (we wanted at least $(at_least))"
@true
endif

View file

@ -1,6 +1,6 @@
## -*-makefile-*-
## OS400-specific setup (for cross build)
## Copyright (c) 1999-2005, International Business Machines Corporation and
## Copyright (c) 1999-2011, International Business Machines Corporation and
## others. All Rights Reserved.
GEN_DEPS.c= $(CC1) -E -M $(DEFS) $(CPPFLAGS)
@ -12,13 +12,16 @@ THREADSCPPFLAGS = -D_MULTI_THREADED
# -qTERASPACE: large pointers
# -qPFROPT=*STRDONLY: Strings are read-only
COMPILE.c= $(CC) $(DEFS) $(CPPFLAGS) $(CFLAGS) -c -qTERASPACE=*YES -qSTGMDL=*INHERIT -qPFROPT=*STRDONLY
COMPILE.cc= $(CXX) $(DEFS) $(CPPFLAGS) $(CXXFLAGS) -c -qTERASPACE=*YES -qSTGMDL=*INHERIT -qPFROPT=*STRDONLY
COMPILE.cc= $(CXX) $(DEFS) $(CPPFLAGS) $(CXXFLAGS) -c -qTERASPACE=*YES -qSTGMDL=*INHERIT -qPFROPT=*STRDONLY -qRTTIALL
## ICULD program - run bldiculd.sh in icu/as_is/os400/ to build it
ICULD=/qsys.lib/$(OUTPUTDIR).lib/iculd.pgm
## Commands to link
## We need to use the C++ linker, even when linking C programs, since
## our libraries contain C++ code (C++ static init not called)
LINK.c= $(CXX) $(CXXFLAGS) $(LDFLAGS) -qOPTION='*DUPPROC *DUPVAR'
LINK.cc= $(CXX) $(CXXFLAGS) $(LDFLAGS) -qOPTION='*DUPPROC *DUPVAR'
LINK.c= $(ICULD) $(CXXFLAGS) $(LDFLAGS) -qOPTION='*DUPPROC *DUPVAR'
LINK.cc= $(ICULD) $(CXXFLAGS) $(LDFLAGS) -qOPTION='*DUPPROC *DUPVAR'
## Commands to make a shared library
# -qALWLIBUPD: It allows the compiled service program to have dependencies on

View file

@ -399,7 +399,7 @@ MessageFormat::operator==(const Format& rhs) const
if (count != rhs_count) {
return FALSE;
}
int idx = 0, rhs_idx = 0, pos = -1, rhs_pos = -1;
int32_t idx = 0, rhs_idx = 0, pos = -1, rhs_pos = -1;
for (; idx < count && rhs_idx < rhs_count && U_SUCCESS(ec); ++idx, ++rhs_idx) {
const UHashElement* cur = uhash_nextElement(customFormatArgStarts, &pos);
const UHashElement* rhs_cur = uhash_nextElement(that.customFormatArgStarts, &rhs_pos);

View file

@ -1394,7 +1394,7 @@ SimpleDateFormat::processOverrideString(const Locale &locale, const UnicodeStrin
UBool moreToProcess = TRUE;
while (moreToProcess) {
int32_t delimiterPosition = str.indexOf(ULOC_KEYWORD_ITEM_SEPARATOR_UNICODE,start);
int32_t delimiterPosition = str.indexOf((UChar)ULOC_KEYWORD_ITEM_SEPARATOR_UNICODE,start);
if (delimiterPosition == -1) {
moreToProcess = FALSE;
len = str.length() - start;
@ -1402,7 +1402,7 @@ SimpleDateFormat::processOverrideString(const Locale &locale, const UnicodeStrin
len = delimiterPosition - start;
}
UnicodeString currentString(str,start,len);
int32_t equalSignPosition = currentString.indexOf(ULOC_KEYWORD_ASSIGN_UNICODE,0);
int32_t equalSignPosition = currentString.indexOf((UChar)ULOC_KEYWORD_ASSIGN_UNICODE,0);
if (equalSignPosition == -1) { // Simple override string such as "hebrew"
nsName.setTo(currentString);
ovrField.setToBogus();

View file

@ -180,10 +180,13 @@ case $platform in
IBMi)
THE_OS="IBM i"
THE_COMP="the iCC C++"
CC=/usr/bin/icc; export CC
CXX=/usr/bin/icc; export CXX
CC=icc; export CC
CXX=icc; export CXX
CPP="$CC -c -qpponly"; export CPP
MAKE=/usr/bin/gmake; export MAKE
MAKE=gmake; export MAKE
U_MAKE=gmake; export U_MAKE
# gmake is a .pgm and may not be on the path. Don't use a full path, just use gmake.
ac_cv_path_U_MAKE=gmake; export ac_cv_path_U_MAKE
RELEASE_CFLAGS='-O4'
RELEASE_CXXFLAGS='-O4'
;;

View file

@ -423,7 +423,7 @@ static void TestBreakIteratorSafeClone(void)
/* Verify our define is large enough */
if (U_BRK_SAFECLONE_BUFFERSIZE < bufferSize)
{
log_err("FAIL: Pre-calculated buffer size is too small\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))

View file

@ -144,7 +144,7 @@ static void TestUSpoofCAPI(void) {
fileName = malloc(strlen(dataSrcDir) + 100);
strcpy(fileName, dataSrcDir);
strcat(fileName, U_FILE_SEP_STRING "unidata" U_FILE_SEP_STRING "confusables.txt");
f = fopen(fileName, "r");
f = fopen(fileName, "rb");
TEST_ASSERT_NE(f, NULL);
confusables = malloc(3000000);
confusablesLength = fread(confusables, 1, 3000000, f);
@ -153,7 +153,7 @@ static void TestUSpoofCAPI(void) {
strcpy(fileName, dataSrcDir);
strcat(fileName, U_FILE_SEP_STRING "unidata" U_FILE_SEP_STRING "confusablesWholeScript.txt");
f = fopen(fileName, "r");
f = fopen(fileName, "rb");
TEST_ASSERT_NE(f, NULL);
confusablesWholeScript = malloc(1000000);
confusablesWholeScriptLength = fread(confusablesWholeScript, 1, 1000000, f);

View file

@ -268,7 +268,7 @@ void PluralFormatTest::pluralFormatUnitTest(/*char *par*/)
}
numberFormatTest(&pluralFmt, numFmt, 5, 5, NULL, NULL, FALSE, &message);
pluralFmt.applyPattern(UNICODE_STRING_SIMPLE("odd__{odd} other{even}"), status);
if (pluralFmt.format(1, status) != UNICODE_STRING_SIMPLE("even")) {
if (pluralFmt.format((int32_t)1, status) != UNICODE_STRING_SIMPLE("even")) {
errln("SetLocale should reset rules but did not.");
}
status = U_ZERO_ERROR;
@ -527,7 +527,7 @@ PluralFormatTest::pluralFormatExtendedTest(void) {
dataerrln("Failed to apply pattern - %s", u_errorName(status));
return;
}
for (int i = 0; i < 7; ++i) {
for (int32_t i = 0; i < 7; ++i) {
UnicodeString result = pf.format(i, status);
if (U_FAILURE(status)) {
errln("PluralFormat.format(value %d) failed - %s", i, u_errorName(status));

View file

@ -439,7 +439,7 @@ void PluralRulesTest::testWithin() {
return;
}
UnicodeString keyword = rules->select(26);
UnicodeString keyword = rules->select((int32_t)26);
if (keyword != "a") {
errln("expected 'a' for 26 but didn't get it.");
}

View file

@ -10,6 +10,16 @@
// ICU Regular Expressions test, part of intltest.
//
/*
NOTE!!
PLEASE be careful about ASCII assumptions in this test.
This test is one of the worst repeat offenders.
If you have questions, contact someone on the ICU PMC
who has access to an EBCDIC system.
*/
#include "intltest.h"
#if !UCONFIG_NO_REGULAR_EXPRESSIONS
@ -114,6 +124,9 @@ void RegexTest::runIndexedTest( int32_t index, UBool exec, const char* &name, ch
case 19: name = "Bug 7029";
if (exec) Bug7029();
break;
case 20: name = "CheckInvBufSize";
if (exec) CheckInvBufSize();
break;
default: name = "";
break; //needed to end loop
@ -121,6 +134,7 @@ void RegexTest::runIndexedTest( int32_t index, UBool exec, const char* &name, ch
}
/**
* Calls utext_openUTF8 after, potentially, converting invariant text from the compilation codepage
* into ASCII.
@ -128,18 +142,6 @@ void RegexTest::runIndexedTest( int32_t index, UBool exec, const char* &name, ch
*/
static UText* regextst_openUTF8FromInvariant(UText* ut, const char *inv, int64_t length, UErrorCode *status);
static UText* regextst_openUTF8FromInvariant(UText *ut, const char *inv, int64_t length, UErrorCode *status) {
#if U_CHARSET_FAMILY==U_ASCII_FAMILY
return utext_openUTF8(ut, inv, length, status);
#else
char buf[1024];
uprv_aestrncpy((uint8_t*)buf, (const uint8_t*)inv, length);
return utext_openUTF8(ut, buf, length, status);
#endif
}
//---------------------------------------------------------------------------
//
// Error Checking / Reporting macros used in all of the tests.
@ -175,6 +177,53 @@ static void utextToPrintable(char *buf, int32_t bufLen, UText *text) {
utext_setNativeIndex(text, oldIndex);
}
static inline UChar toHex(int32_t i) {
return (UChar)(i + (i < 10 ? 0x30 : (0x41 - 10)));
}
static UnicodeString& escape(const UnicodeString& s, UnicodeString& result) {
for (int32_t i=0; i<s.length(); ++i) {
UChar c = s[i];
if ((c <= (UChar)0x7F) && (c>0)) {
result += c;
} else {
result += (UChar)0x5c;
result += (UChar)0x75;
result += toHex((c >> 12) & 0xF);
result += toHex((c >> 8) & 0xF);
result += toHex((c >> 4) & 0xF);
result += toHex( c & 0xF);
}
}
return result;
}
static char ASSERT_BUF[1024];
static const char* extractToAssertBuf(const UnicodeString& message) {
if(message.length()==0) {
strcpy(ASSERT_BUF, "[[empty UnicodeString]]");
} else {
UnicodeString buf;
escape(message, buf);
if(buf.length()==0) {
strcpy(ASSERT_BUF, "[[escape() returned 0 chars]]");
} else {
buf.extract(0, 0x7FFFFFFF, ASSERT_BUF, sizeof(ASSERT_BUF)-1);
if(ASSERT_BUF[0]==0) {
ASSERT_BUF[0]=0;
for(int32_t i=0;i<buf.length();i++) {
UChar ch = buf[i];
sprintf(ASSERT_BUF+strlen(ASSERT_BUF),"\\u%02x",ch);
}
}
}
}
ASSERT_BUF[sizeof(ASSERT_BUF)-1] = 0;
return ASSERT_BUF;
}
#define REGEX_VERBOSE_TEXT(text) {char buf[200];utextToPrintable(buf,sizeof(buf)/sizeof(buf[0]),text);logln("%s:%d: UText %s=\"%s\"", __FILE__, __LINE__, #text, buf);}
#define REGEX_CHECK_STATUS {if (U_FAILURE(status)) {dataerrln("%s:%d: RegexTest failure. status=%s", \
@ -192,6 +241,8 @@ if (status!=errcode) {dataerrln("RegexTest failure at line %d. Expected status=
#define REGEX_ASSERT_L(expr, line) {if ((expr)==FALSE) { \
errln("RegexTest failure at line %d, from %d.", __LINE__, (line)); return;}}
#define REGEX_ASSERT_UNISTR(ustr,inv) {if (!(ustr==inv)) {errln("%s:%d: RegexTest failure: REGEX_ASSERT_UNISTR(%s,%s) failed \n", __FILE__, __LINE__, extractToAssertBuf(ustr),inv);};}
/**
* @param expected expected text in UTF-8 (not platform) codepage
*/
@ -249,6 +300,45 @@ void RegexTest::assertUTextInvariant(const char *expected, UText *actual, const
*/
#define REGEX_ASSERT_UTEXT_INVARIANT(expected, actual) assertUTextInvariant((expected), (actual), __FILE__, __LINE__)
/**
* This buffer ( inv_buf ) is used to hold the UTF-8 strings
* passed into utext_openUTF8. An error will be given if
* INV_BUFSIZ is too small. It's only used on EBCDIC systems.
*/
#define INV_BUFSIZ 2048 /* increase this if too small */
static int32_t inv_next=0;
#if U_CHARSET_FAMILY!=U_ASCII_FAMILY
static char inv_buf[INV_BUFSIZ];
#endif
static UText* regextst_openUTF8FromInvariant(UText *ut, const char *inv, int64_t length, UErrorCode *status) {
if(length==-1) length=strlen(inv);
#if U_CHARSET_FAMILY==U_ASCII_FAMILY
inv_next+=length;
return utext_openUTF8(ut, inv, length, status);
#else
if(inv_next+length+1>INV_BUFSIZ) {
fprintf(stderr, "%s:%d Error: INV_BUFSIZ #defined to be %d but needs to be at least %d.\n",
__FILE__, __LINE__, INV_BUFSIZ, (inv_next+length+1));
*status = U_MEMORY_ALLOCATION_ERROR;
return NULL;
}
unsigned char *buf = (unsigned char*)inv_buf+inv_next;
uprv_aestrncpy(buf, (const uint8_t*)inv, length);
inv_next+=length;
#if 0
fprintf(stderr, " Note: INV_BUFSIZ at %d, used=%d\n", INV_BUFSIZ, inv_next);
#endif
return utext_openUTF8(ut, (const char*)buf, length, status);
#endif
}
//---------------------------------------------------------------------------
//
@ -2965,11 +3055,11 @@ void RegexTest::API_Pattern_UTF8() {
REGEX_ASSERT(pat1->pattern() == "");
REGEX_ASSERT_UTEXT_UTF8("", pat1->patternText(status));
delete pat1;
regextst_openUTF8FromInvariant(&re1, "(Hello, world)*", -1, &status);
const char *helloWorldInvariant = "(Hello, world)*";
regextst_openUTF8FromInvariant(&re1, helloWorldInvariant, -1, &status);
pat1 = RegexPattern::compile(&re1, pe, status);
REGEX_CHECK_STATUS;
REGEX_ASSERT(pat1->pattern() == "(Hello, world)*");
REGEX_ASSERT_UNISTR(pat1->pattern(),"(Hello, world)*");
REGEX_ASSERT_UTEXT_INVARIANT("(Hello, world)*", pat1->patternText(status));
delete pat1;
@ -5088,5 +5178,15 @@ void RegexTest::Bug7029() {
REGEX_ASSERT(numFields == 8);
delete pMatcher;
}
void RegexTest::CheckInvBufSize() {
if(inv_next>=INV_BUFSIZ) {
errln("%s: increase #define of INV_BUFSIZ ( is %d but needs to be at least %d )\n",
__FILE__, INV_BUFSIZ, inv_next);
} else {
logln("%s: INV_BUFSIZ is %d, usage %d\n", __FILE__, INV_BUFSIZ, inv_next);
}
}
#endif /* !UCONFIG_NO_REGULAR_EXPRESSIONS */

View file

@ -45,7 +45,8 @@ public:
virtual void Bug7740();
virtual void Bug8479();
virtual void Bug7029();
virtual void CheckInvBufSize();
// The following functions are internal to the regexp tests.
virtual void assertUText(const char *expected, UText *actual, const char *file, int line);
virtual void assertUTextInvariant(const char *invariant, UText *actual, const char *file, int line);

View file

@ -634,7 +634,7 @@ void TestMessageFormat::testApostropheInPluralAndSelect() {
return;
}
UnicodeString expected = UNICODE_STRING_SIMPLE("abc_3#3{3'_def_sel}ect'_xyz");
Formattable args[] = { 3, UNICODE_STRING_SIMPLE("x") };
Formattable args[] = { (int32_t)3, UNICODE_STRING_SIMPLE("x") };
internalFormat(
&msgFmt, args, 2, expected,
"MessageFormat with apostrophes in plural/select arguments failed:\n");
@ -1639,7 +1639,7 @@ void TestMessageFormat::TestCompatibleApostrophe() {
errln("wrong value from icuMsg.getApostropheMode().");
}
Formattable zero0[] = { 0 };
Formattable zero0[] = { (int32_t)0 };
FieldPosition fieldpos(0);
UnicodeString buffer1, buffer2;
assertEquals("incompatible ICU MessageFormat compatibility-apostrophe behavior",
@ -1798,7 +1798,7 @@ void TestMessageFormat::TestTrimArgumentName() {
if (errorCode.logDataIfFailureAndReset("Unable to instantiate MessageFormat")) {
return;
}
Formattable args[1] = { 2 };
Formattable args[1] = { (int32_t)2 };
FieldPosition ignore(0);
UnicodeString result;
assertEquals("trim-numbered-arg format() failed", "a #,#2.0 z",

View file

@ -1378,7 +1378,7 @@ static int32_t pkg_createWithoutAssemblyCode(UPKGOptions *o, const char *targetD
uprv_strcpy(tempObjectFile, gencmnFile);
tempObjectFile[uprv_strlen(tempObjectFile) - 1] = 'o';
sprintf(cmd, "%s %s -o %s %s"
sprintf(cmd, "%s %s -o %s %s",
pkgDataFlags[COMPILER],
pkgDataFlags[LIBFLAGS],
tempObjectFile,

View file

@ -329,9 +329,10 @@ readFile(const char *path, const char *name, int32_t &length, char &type) {
/* allocate the buffer, pad to multiple of 16 */
length=(fileLength+0xf)&~0xf;
data=(uint8_t *)malloc(length);
data=(uint8_t *)uprv_malloc(length);
if(data==NULL) {
fclose(file);
fprintf(stderr, "icupkg: malloc error allocating %d bytes.\n", (int)length);
exit(U_MEMORY_ALLOCATION_ERROR);
}