libc++: support newlib's ctype

Summary: Newlib supports ctype differently from other platforms, this patch teaches libc++ about yet another platform that does ctype differently.

Reviewers: jroelofs

Subscribers: cfe-commits, danalbert, EricWF, jvoung, jfb, mclow.lists

Differential Revision: http://reviews.llvm.org/D7888

llvm-svn: 230557
This commit is contained in:
JF Bastien 2015-02-25 22:16:46 +00:00
parent 6801be3354
commit e9401f61c2
2 changed files with 23 additions and 7 deletions

View File

@ -354,15 +354,15 @@ public:
static const mask xdigit = _HEX;
static const mask blank = _BLANK;
#elif defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) || defined(__NetBSD__) || defined(__ANDROID__)
#ifdef __APPLE__
# ifdef __APPLE__
typedef __uint32_t mask;
#elif defined(__FreeBSD__)
# elif defined(__FreeBSD__)
typedef unsigned long mask;
#elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
# elif defined(__EMSCRIPTEN__) || defined(__NetBSD__)
typedef unsigned short mask;
#elif defined(__ANDROID__)
# elif defined(__ANDROID__)
typedef unsigned char mask;
#endif
# endif
static const mask space = _CTYPE_S;
static const mask print = _CTYPE_R;
static const mask cntrl = _CTYPE_C;
@ -394,7 +394,20 @@ public:
static const mask punct = _ISPUNCT;
static const mask xdigit = _ISXDIGIT;
static const mask blank = _ISBLANK;
#else // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__ || __EMSCRIPTEN__ || __sun__
#elif defined(_NEWLIB_VERSION)
// Same type as Newlib's _ctype_ array in newlib/libc/include/ctype.h.
typedef char mask;
static const mask space = _S;
static const mask print = _P | _U | _L | _N | _B;
static const mask cntrl = _C;
static const mask upper = _U;
static const mask lower = _L;
static const mask alpha = _U | _L;
static const mask digit = _N;
static const mask punct = _P;
static const mask xdigit = _X | _N;
static const mask blank = _B;
#else
typedef unsigned long mask;
static const mask space = 1<<0;
static const mask print = 1<<1;
@ -406,7 +419,7 @@ public:
static const mask punct = 1<<7;
static const mask xdigit = 1<<8;
static const mask blank = 1<<9;
#endif // __GLIBC__ || _WIN32 || __APPLE__ || __FreeBSD__
#endif
static const mask alnum = alpha | digit;
static const mask graph = alnum | punct;

View File

@ -1033,6 +1033,9 @@ ctype<char>::classic_table() _NOEXCEPT
// going to end up dereferencing it later...
#elif defined(__EMSCRIPTEN__)
return *__ctype_b_loc();
#elif defined(_NEWLIB_VERSION)
// Newlib has a 257-entry table in ctype_.c, where (char)0 starts at [1].
return _ctype_ + 1;
#elif defined(_AIX)
return (const unsigned int *)__lc_ctype_ptr->obj->mask;
#elif defined(__ANDROID__)