This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH, libstdc++-v3] Add newlib specific ctype_members.cc


Hi,

This patch fixes an issue in the ctype<wchar_t> implementation when the
newlib C library is used.

The generic version of ctype<wchar_t>::_M_convert_to_wmask() in
config/locale/generic/ctype_members.cc assumes that a character type
mask is either a bitmask with only 1 bit set or a bitwise-OR result of
other character type masks; for instance, as illustrated in the C++
Standard 2003 TC1 [lib.category.ctype]:

  enum mask { // numeric values are for exposition only.
    space=1<<0, print=1<<1, cntrl=1<<2, upper=1<<3, lower=1<<4,
    alpha=1<<5, digit=1<<6, punct=1<<7, xdigit=1<<8,
    alnum=alpha|digit, graph=alnum|punct
  };

The newlibc has a more compact character type mask definition; it uses
one byte only to represent the masks:

(newlib/libc/include/ctype.h)
    #define _U 01
    #define _L 02
    #define _N 04
    #define _S 010
    #define _P 020
    #define _C 040
    #define _X 0100
    #define _B 0200

(libstdc++-v3/config/os/newlib/ctype_base.h)
    typedef char mask;
    static const mask upper = _U;
    static const mask lower = _L;
    static const mask alpha = _U | _L;
    static const mask digit = _N;
    static const mask xdigit = _X | _N;
    static const mask space = _S;
    static const mask print = _P | _U | _L | _N | _B;
    static const mask graph = _P | _U | _L | _N;
    static const mask cntrl = _C;
    static const mask punct = _P;
    static const mask alnum = _U | _L | _N;

For _X and _B, the generic version of
ctype<wchar_t>::_M_convert_to_wmask() fails to obtain their
corresponding wmasks, while other ctype_members.cc variants at
config/locale/{gnu,darwin}/ are not capable in handling this case either.

Therefore, in this patch, a newlib specific ctype_members.cc is added
at config/locale/newlib/, and acinclude.m4 is modified to use the new
ctype_members.cc when with_newlib is enabled. The main difference in this
ctype_members.cc from the generic version is the addition of the special
handling of xdigit and print at the end of
ctype<wchar_t>::_M_convert_to_wmask().

With this patch the following test failure (when the C library is the
newlib C) will be fixed:
    libstdc++-v3/testsuite/22_locale/ctype/scan/wchar_t/1.cc.

The patch has passed the regression test with armv7-a arm-eabi on qemu.

Is it OK for trunk?

Thanks,
Yufeng


libstdc++-v3/ChangeLog
2011-06-06  Yufeng Zhang  <yufeng.zhang@arm.com>

        * config/locale/newlib/ctype_members.cc: New file.
        * acinclude.m4 (GLIBCXX_ENABLE_CLOCALE): Add a new C locale
        kind: newlib.  Configure to use the newlib specific
        ctype_members.cc when with_newlib is enabled.
        * configure: Regenerate.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]