Fix problems with sed and gcc caused by reintegration of posix-locale:

* support invocation of ctype/wctype macros with EOF/WEOF (-1), which would
  access more or less random memory before - I don't know why this worked
  more or less reliably for the POSIX locale, but it didn't for any other


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37730 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Oliver Tappe
2010-07-24 16:20:52 +00:00
parent c0f9765409
commit a4823efd7d
5 changed files with 67 additions and 34 deletions
@@ -32,9 +32,14 @@ public:
const char* GetLanginfo(int index); const char* GetLanginfo(int index);
private: private:
unsigned short fClassInfo[256]; /*
int fToLowerMap[256]; * the following arrays have 257 elements where the first is a
int fToUpperMap[256]; * dummy element (containing the neutral/identity value) used when
* the array is accessed as in 'isblank(EOF)' (i.e. with index -1).
*/
unsigned short fClassInfo[257];
int fToLowerMap[257];
int fToUpperMap[257];
LocaleCtypeDataBridge* fDataBridge; LocaleCtypeDataBridge* fDataBridge;
}; };
+8 -3
View File
@@ -9,9 +9,14 @@
namespace BPrivate { namespace BPrivate {
extern const unsigned short gPosixClassInfo[256]; /*
extern const int gPosixToLowerMap[256]; * the following arrays have 257 elements where the first is a
extern const int gPosixToUpperMap[256]; * dummy element (containing the neutral/identity value) used when
* the array is accessed as in 'isblank(EOF)' (i.e. with index -1).
*/
extern const unsigned short gPosixClassInfo[257];
extern const int gPosixToLowerMap[257];
extern const int gPosixToUpperMap[257];
} // namespace BPrivate } // namespace BPrivate
@@ -30,9 +30,9 @@ ICUCtypeData::~ICUCtypeData()
void void
ICUCtypeData::Initialize(LocaleCtypeDataBridge* dataBridge) ICUCtypeData::Initialize(LocaleCtypeDataBridge* dataBridge)
{ {
*dataBridge->addrOfClassInfoTable = fClassInfo; *dataBridge->addrOfClassInfoTable = &fClassInfo[1];
*dataBridge->addrOfToLowerTable = fToLowerMap; *dataBridge->addrOfToLowerTable = &fToLowerMap[1];
*dataBridge->addrOfToUpperTable = fToUpperMap; *dataBridge->addrOfToUpperTable = &fToUpperMap[1];
fDataBridge = dataBridge; fDataBridge = dataBridge;
} }
@@ -97,9 +97,9 @@ ICUCtypeData::SetTo(const Locale& locale, const char* posixLocaleName)
if (U_SUCCESS(icuStatus)) if (U_SUCCESS(icuStatus))
toUpper = (unsigned char)buffer[0]; toUpper = (unsigned char)buffer[0];
} }
fClassInfo[i] = classInfo; fClassInfo[i + 1] = classInfo;
fToLowerMap[i] = toLower; fToLowerMap[i + 1] = toLower;
fToUpperMap[i] = toUpper; fToUpperMap[i + 1] = toUpper;
} }
return B_OK; return B_OK;
@@ -124,6 +124,9 @@ ICUCtypeData::SetToPosix()
int int
ICUCtypeData::IsWCType(wint_t wc, wctype_t charClass) ICUCtypeData::IsWCType(wint_t wc, wctype_t charClass)
{ {
if (wc == WEOF)
return 0;
switch (charClass) { switch (charClass) {
case _ISalnum: case _ISalnum:
return u_hasBinaryProperty(wc, UCHAR_POSIX_ALNUM); return u_hasBinaryProperty(wc, UCHAR_POSIX_ALNUM);
+14 -6
View File
@@ -27,7 +27,13 @@
namespace BPrivate { namespace BPrivate {
const unsigned short gPosixClassInfo[256] = { /*
* the following arrays have 257 elements where the first is a
* dummy element (containing the neutral/identity value) used when
* the array is accessed as in 'isblank(EOF)' (i.e. with index -1).
*/
const unsigned short gPosixClassInfo[257] = {
/* -1 */ 0, // neutral value
/* 0 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, /* 0 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl,
/* 8 */ _IScntrl, _ISblank|_IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl, _IScntrl, /* 8 */ _IScntrl, _ISblank|_IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl, _IScntrl,
/* 16 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, /* 16 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl,
@@ -62,7 +68,8 @@ const unsigned short gPosixClassInfo[256] = {
/* 248 */ 0, 0, 0, 0, 0, 0, 0, 0 /* 248 */ 0, 0, 0, 0, 0, 0, 0, 0
}; };
const int gPosixToLowerMap[256] = { const int gPosixToLowerMap[257] = {
/* -1 */ -1, // identity value
/* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, /* 0 */ 0, 1, 2, 3, 4, 5, 6, 7,
/* 8 */ 8, 9, 10, 11, 12, 13, 14, 15, /* 8 */ 8, 9, 10, 11, 12, 13, 14, 15,
/* 16 */ 16, 17, 18, 19, 20, 21, 22, 23, /* 16 */ 16, 17, 18, 19, 20, 21, 22, 23,
@@ -98,7 +105,8 @@ const int gPosixToLowerMap[256] = {
}; };
const int gPosixToUpperMap[256] = { const int gPosixToUpperMap[257] = {
/* -1 */ -1, // identity value
/* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, /* 0 */ 0, 1, 2, 3, 4, 5, 6, 7,
/* 8 */ 8, 9, 10, 11, 12, 13, 14, 15, /* 8 */ 8, 9, 10, 11, 12, 13, 14, 15,
/* 16 */ 16, 17, 18, 19, 20, 21, 22, 23, /* 16 */ 16, 17, 18, 19, 20, 21, 22, 23,
@@ -267,6 +275,6 @@ const char* gPosixLanginfo[_NL_LANGINFO_LAST] = {
} // namespace BPrivate } // namespace BPrivate
const unsigned short* __ctype_b = BPrivate::gPosixClassInfo; const unsigned short* __ctype_b = &BPrivate::gPosixClassInfo[1];
const int* __ctype_tolower = BPrivate::gPosixToLowerMap; const int* __ctype_tolower = &BPrivate::gPosixToLowerMap[1];
const int* __ctype_toupper = BPrivate::gPosixToUpperMap; const int* __ctype_toupper = &BPrivate::gPosixToUpperMap[1];
+28 -16
View File
@@ -691,24 +691,24 @@ test_ctype(const char* locale, const unsigned short int classInfos[],
printf("ctype of %s locale\n", locale); printf("ctype of %s locale\n", locale);
int problemCount = 0; int problemCount = 0;
for (int i = 0; i < 256; ++i) { for (int i = -1; i < 256; ++i) {
unsigned short classInfo = determineFullClassInfo(i); unsigned short classInfo = determineFullClassInfo(i);
if (classInfo != classInfos[i]) { if (classInfo != classInfos[i + 1]) {
printf("\tPROBLEM: %d = %x (expected %x)\n", i, classInfo, printf("\tPROBLEM: ctype(%d) = %x (expected %x)\n", i, classInfo,
classInfos[i]); classInfos[i + 1]);
problemCount++; problemCount++;
} }
int lower = tolower(i); int lower = tolower(i);
if (lower != toLowerMap[i]) { if (lower != toLowerMap[i + 1]) {
printf("\tPROBLEM: tolower(%d) = %x (expected %x)\n", i, lower, printf("\tPROBLEM: tolower(%d) = %x (expected %x)\n", i, lower,
toLowerMap[i]); toLowerMap[i + 1]);
problemCount++; problemCount++;
} }
int upper = toupper(i); int upper = toupper(i);
if (upper != toUpperMap[i]) { if (upper != toUpperMap[i + 1]) {
printf("\tPROBLEM: toupper(%d) = %x (expected %x)\n", i, upper, printf("\tPROBLEM: toupper(%d) = %x (expected %x)\n", i, upper,
toUpperMap[i]); toUpperMap[i + 1]);
problemCount++; problemCount++;
} }
} }
@@ -722,7 +722,8 @@ test_ctype(const char* locale, const unsigned short int classInfos[],
void void
test_ctype() test_ctype()
{ {
const unsigned short int classInfos_posix[256] = { const unsigned short int classInfos_posix[257] = {
/* -1 */ 0, // neutral value
/* 0 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, /* 0 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl,
/* 8 */ _IScntrl, _ISblank|_IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl, _IScntrl, /* 8 */ _IScntrl, _ISblank|_IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl, _IScntrl,
/* 16 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, /* 16 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl,
@@ -756,7 +757,8 @@ test_ctype()
/* 240 */ 0, 0, 0, 0, 0, 0, 0, 0, /* 240 */ 0, 0, 0, 0, 0, 0, 0, 0,
/* 248 */ 0, 0, 0, 0, 0, 0, 0, 0, /* 248 */ 0, 0, 0, 0, 0, 0, 0, 0,
}; };
const int toLowerMap_posix[256] = { const int toLowerMap_posix[257] = {
/* -1 */ -1, // identity value
/* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, /* 0 */ 0, 1, 2, 3, 4, 5, 6, 7,
/* 8 */ 8, 9, 10, 11, 12, 13, 14, 15, /* 8 */ 8, 9, 10, 11, 12, 13, 14, 15,
/* 16 */ 16, 17, 18, 19, 20, 21, 22, 23, /* 16 */ 16, 17, 18, 19, 20, 21, 22, 23,
@@ -790,7 +792,8 @@ test_ctype()
/* 240 */ 240, 241, 242, 243, 244, 245, 246, 247, /* 240 */ 240, 241, 242, 243, 244, 245, 246, 247,
/* 248 */ 248, 249, 250, 251, 252, 253, 254, 255, /* 248 */ 248, 249, 250, 251, 252, 253, 254, 255,
}; };
const int toUpperMap_posix[256] = { const int toUpperMap_posix[257] = {
/* -1 */ -1, // identity value
/* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, /* 0 */ 0, 1, 2, 3, 4, 5, 6, 7,
/* 8 */ 8, 9, 10, 11, 12, 13, 14, 15, /* 8 */ 8, 9, 10, 11, 12, 13, 14, 15,
/* 16 */ 16, 17, 18, 19, 20, 21, 22, 23, /* 16 */ 16, 17, 18, 19, 20, 21, 22, 23,
@@ -826,7 +829,8 @@ test_ctype()
}; };
test_ctype("POSIX", classInfos_posix, toLowerMap_posix, toUpperMap_posix); test_ctype("POSIX", classInfos_posix, toLowerMap_posix, toUpperMap_posix);
const unsigned short int classInfos_de[256] = { const unsigned short int classInfos_de[257] = {
/* -1 */ 0, // neutral value
/* 0 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, /* 0 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl,
/* 8 */ _IScntrl, _ISblank|_IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl, _IScntrl, /* 8 */ _IScntrl, _ISblank|_IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl, _IScntrl,
/* 16 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, /* 16 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl,
@@ -860,7 +864,8 @@ test_ctype()
/* 240 */ _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph, /* 240 */ _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph,
/* 248 */ _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, /* 248 */ _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower, _ISprint|_ISgraph|_ISalnum|_ISalpha|_ISlower,
}; };
const int toLowerMap_de[256] = { const int toLowerMap_de[257] = {
/* -1 */ -1, // identity value
/* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, /* 0 */ 0, 1, 2, 3, 4, 5, 6, 7,
/* 8 */ 8, 9, 10, 11, 12, 13, 14, 15, /* 8 */ 8, 9, 10, 11, 12, 13, 14, 15,
/* 16 */ 16, 17, 18, 19, 20, 21, 22, 23, /* 16 */ 16, 17, 18, 19, 20, 21, 22, 23,
@@ -894,7 +899,8 @@ test_ctype()
/* 240 */ 240, 241, 242, 243, 244, 245, 246, 247, /* 240 */ 240, 241, 242, 243, 244, 245, 246, 247,
/* 248 */ 248, 249, 250, 251, 252, 253, 254, 255, /* 248 */ 248, 249, 250, 251, 252, 253, 254, 255,
}; };
const int toUpperMap_de[256] = { const int toUpperMap_de[257] = {
/* -1 */ -1, // identity value
/* 0 */ 0, 1, 2, 3, 4, 5, 6, 7, /* 0 */ 0, 1, 2, 3, 4, 5, 6, 7,
/* 8 */ 8, 9, 10, 11, 12, 13, 14, 15, /* 8 */ 8, 9, 10, 11, 12, 13, 14, 15,
/* 16 */ 16, 17, 18, 19, 20, 21, 22, 23, /* 16 */ 16, 17, 18, 19, 20, 21, 22, 23,
@@ -930,7 +936,8 @@ test_ctype()
}; };
test_ctype("de_DE.ISO8859-1", classInfos_de, toLowerMap_de, toUpperMap_de); test_ctype("de_DE.ISO8859-1", classInfos_de, toLowerMap_de, toUpperMap_de);
const unsigned short int classInfos_utf8[256] = { const unsigned short int classInfos_utf8[257] = {
/* -1 */ 0, // neutral value
/* 0 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, /* 0 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl,
/* 8 */ _IScntrl, _ISblank|_IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl, _IScntrl, /* 8 */ _IScntrl, _ISblank|_IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl|_ISspace, _IScntrl, _IScntrl,
/* 16 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, /* 16 */ _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl, _IScntrl,
@@ -1014,9 +1021,14 @@ test_wctype(const char* locale, const wchar_t* text,
printf("wctype of %s locale\n", locale); printf("wctype of %s locale\n", locale);
int problemCount = 0; int problemCount = 0;
unsigned short classInfo = determineWideFullClassInfo(WEOF);
if (classInfo != 0) {
printf("\tPROBLEM: classinfo for WEOF = %x (expected 0)\n", classInfo);
problemCount++;
}
wint_t wc = *text; wint_t wc = *text;
for (int i = 0; i < 48; wc = *++text, ++i) { for (int i = 0; i < 48; wc = *++text, ++i) {
unsigned short classInfo = determineWideFullClassInfo(wc); classInfo = determineWideFullClassInfo(wc);
if (wc != wcs[i]) { if (wc != wcs[i]) {
printf("\tPROBLEM: wc for char #%d = %x (expected %x)\n", i, wc, printf("\tPROBLEM: wc for char #%d = %x (expected %x)\n", i, wc,
wcs[i]); wcs[i]);