/*
******************************************************************************
*
-* Copyright (C) 2002-2003, International Business Machines
+* Copyright (C) 2002-2011, International Business Machines
* Corporation and others. All Rights Reserved.
*
******************************************************************************
*/
#include "unicode/uclean.h"
#include "cmemory.h"
+#include "putilimp.h"
#include <stdlib.h>
/* uprv_malloc(0) returns a pointer to this read-only data. */
if (pAlloc) {
return (*pAlloc)(pContext, s);
} else {
- return malloc(s);
+ return uprv_default_malloc(s);
}
} else {
return (void *)zeroMem;
if (pFree) {
(*pFree)(pContext, buffer);
} else {
- free(buffer);
+ uprv_default_free(buffer);
}
return (void *)zeroMem;
} else {
if (pRealloc) {
return (*pRealloc)(pContext, buffer, size);
} else {
- return realloc(buffer, size);
+ return uprv_default_realloc(buffer, size);
}
}
}
if (pFree) {
(*pFree)(pContext, buffer);
} else {
- free(buffer);
+ uprv_default_free(buffer);
}
}
}
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;
*/
/* 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
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)
* 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.
## -*-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.
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)))
else
ok:
@echo "$(MAKE_VERSION) (we wanted at least $(at_least))"
- @true
endif
## -*-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)
# -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
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);
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;
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();
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'
;;
/* 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))
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);
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);
}
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;
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));
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.");
}
// 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
case 19: name = "Bug 7029";
if (exec) Bug7029();
break;
+ case 20: name = "CheckInvBufSize";
+ if (exec) CheckInvBufSize();
+ break;
default: name = "";
break; //needed to end loop
}
+
/**
* Calls utext_openUTF8 after, potentially, converting invariant text from the compilation codepage
* into ASCII.
*/
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.
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", \
#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
*/
*/
#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
+}
+
//---------------------------------------------------------------------------
//
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;
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 */
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);
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");
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",
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",
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,
/* 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);
}