From 371b76ef3e221248c7df49906014037c66292901 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Mon, 11 Jun 2001 19:25:59 +0000 Subject: 2001-06-11 Egor Duda * libc/ctype/ctype_.c: When compiled with gcc on platforms with signed char, make _ctype_[-128] ... _ctype[-1] refer to initialized memory region. Platform can define COMPACT_CTYPE to avoid allocation of the additional 128 bytes of data. Add pointer to _ctype_ array. Always initialize all _ctype_ array elements. --- newlib/ChangeLog | 9 ++++++ newlib/libc/ctype/ctype_.c | 78 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 71 insertions(+), 16 deletions(-) (limited to 'newlib') diff --git a/newlib/ChangeLog b/newlib/ChangeLog index 81b62e4..c568283 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,12 @@ +2001-06-11 Egor Duda + + * libc/ctype/ctype_.c: When compiled with gcc on platforms + with signed char, make _ctype_[-128] ... _ctype[-1] refer to + initialized memory region. Platform can define COMPACT_CTYPE + to avoid allocation of the additional 128 bytes of data. + Add pointer to _ctype_ array. Always initialize all _ctype_ + array elements. + 2001-06-08 Jonathan Larmour * libc/stdlib/mbtowc_r.c (_mbtowc_r): Avoid dereferencing diff --git a/newlib/libc/ctype/ctype_.c b/newlib/libc/ctype/ctype_.c index 45fcaa7..90a1694 100644 --- a/newlib/libc/ctype/ctype_.c +++ b/newlib/libc/ctype/ctype_.c @@ -37,26 +37,72 @@ static char sccsid[] = "@(#)ctype_.c 5.6 (Berkeley) 6/1/90"; #include +#define _CTYPE_DATA_0_127 \ + _C, _C, _C, _C, _C, _C, _C, _C, \ + _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C, \ + _C, _C, _C, _C, _C, _C, _C, _C, \ + _C, _C, _C, _C, _C, _C, _C, _C, \ + _S|_B, _P, _P, _P, _P, _P, _P, _P, \ + _P, _P, _P, _P, _P, _P, _P, _P, \ + _N, _N, _N, _N, _N, _N, _N, _N, \ + _N, _N, _P, _P, _P, _P, _P, _P, \ + _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, \ + _U, _U, _U, _U, _U, _U, _U, _U, \ + _U, _U, _U, _U, _U, _U, _U, _U, \ + _U, _U, _U, _P, _P, _P, _P, _P, \ + _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, \ + _L, _L, _L, _L, _L, _L, _L, _L, \ + _L, _L, _L, _L, _L, _L, _L, _L, \ + _L, _L, _L, _P, _P, _P, _P, _C + +#define _CTYPE_DATA_128_256 \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0, \ + 0, 0, 0, 0, 0, 0, 0, 0 + +#if defined(__GNUC__) && !defined(__CHAR_UNSIGNED__) && !defined(COMPACT_CTYPE) +#define ALLOW_NEGATIVE_CTYPE_INDEX +#endif + +#if defined(ALLOW_NEGATIVE_CTYPE_INDEX) +static _CONST char _ctype_b[128 + 256] = { + _CTYPE_DATA_128_256, + _CTYPE_DATA_0_127, + _CTYPE_DATA_128_256 +}; + +#if defined(__CYGWIN__) || defined(__CYGWIN32__) +extern _CONST char __declspec(dllexport) _ctype_[1 + 256] __attribute__ ((alias ("_ctype_b+127"))); +_CONST char __declspec(dllexport) *__ctype_ptr = _ctype_b + 128; +#else +extern _CONST char _ctype_[1 + 256] __attribute__ ((alias ("_ctype_b+127"))); +_CONST char *__ctype_ptr = _ctype_b + 128; +#endif + +#else /* !defined(ALLOW_NEGATIVE_CTYPE_INDEX) */ + #if defined(__CYGWIN__) || defined(__CYGWIN32__) _CONST char __declspec(dllexport) _ctype_[1 + 256] = { #else _CONST char _ctype_[1 + 256] = { #endif 0, - _C, _C, _C, _C, _C, _C, _C, _C, - _C, _C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _C, _C, - _C, _C, _C, _C, _C, _C, _C, _C, - _C, _C, _C, _C, _C, _C, _C, _C, - _S|_B, _P, _P, _P, _P, _P, _P, _P, - _P, _P, _P, _P, _P, _P, _P, _P, - _N, _N, _N, _N, _N, _N, _N, _N, - _N, _N, _P, _P, _P, _P, _P, _P, - _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, - _U, _U, _U, _U, _U, _U, _U, _U, - _U, _U, _U, _U, _U, _U, _U, _U, - _U, _U, _U, _P, _P, _P, _P, _P, - _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, - _L, _L, _L, _L, _L, _L, _L, _L, - _L, _L, _L, _L, _L, _L, _L, _L, - _L, _L, _L, _P, _P, _P, _P, _C + _CTYPE_DATA_0_127, + _CTYPE_DATA_128_256 }; + +_CONST char *__ctype_ptr = _ctype_ + 1; +#endif -- cgit v1.1