This is the mail archive of the newlib@sourceware.org mailing list for the newlib 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]

Re: [PATCH/RFA] Fix ctype table and isblank


Looks good. Thanks.

-- Jeff J.

Corinna Vinschen wrote:
On Apr 8 21:48, Corinna Vinschen wrote:
Hi guys,

On Apr 8 15:22, Jeff Johnston wrote:
Wizards' Guild wrote:
[...]
#define isalpha(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L))
#define isupper(c) (((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L))==_U)
#define islower(c) (((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L))==_L)
[...]
After studying the iswXX behavior some more, I am convinced that
Corinna's revised isblank (with the hardcoded tab test) proposal is
indeed correct. Of course it must go in a gcc-specific macro; other
compilers would presumably get the library version always.
Thanks Mike. I prefer this to my suggestion. Corinna, if you're ok with this and use an intermediate for the isblank macro with your tab test, it can be checked in.
Yes, I'm fine with that idea. I'll implement that in the next couple
of days. I have to revisit the ISO and Windows tables. AFAICS, only
the Arabic and Hebrew tables should be affected by the upper/lowercase
problem but I'm not quite sure.

First cut. It doesn't change any of the extended tables, but the general idea is already implemented. I'll change the tables in a second step.

Ok to checkin?


Corinna



* libc/ctype/ctype_.c (_CTYPE_DATA_0_127): Remove _B flag from TAB. * libc/ctype/isblank.c (isblank): Special case TAB. * libc/ctype/islower.c (islower): Check explicitely for _L flag only in (_U|_L). * libc/ctype/isupper.c (isupper): Ditto, but check for _U flag. * libc/include/ctype.h (islower): Same in macro. (isupper): Ditto. (isblank): Special case TAB. Redefine macro for GCC only.


Index: libc/ctype/ctype_.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/ctype/ctype_.c,v
retrieving revision 1.8
diff -u -p -r1.8 ctype_.c
--- libc/ctype/ctype_.c 2 Apr 2009 07:53:12 -0000 1.8
+++ libc/ctype/ctype_.c 8 Apr 2009 20:01:22 -0000
@@ -39,7 +39,7 @@ static char sccsid[] = "@(#)ctype_.c 5.6
#define _CTYPE_DATA_0_127 \
_C, _C, _C, _C, _C, _C, _C, _C, \
- _C, _B|_C|_S, _C|_S, _C|_S, _C|_S, _C|_S, _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, \
Index: libc/ctype/isblank.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/ctype/isblank.c,v
retrieving revision 1.3
diff -u -p -r1.3 isblank.c
--- libc/ctype/isblank.c 26 Mar 2009 09:45:11 -0000 1.3
+++ libc/ctype/isblank.c 8 Apr 2009 20:01:22 -0000
@@ -37,5 +37,5 @@ No supporting OS subroutines are require
int
_DEFUN(isblank,(c),int c)
{
- return(__ctype_ptr__[c+1] & _B);
+ return ((__ctype_ptr__[c+1] & _B) || (c == '\t'));
}
Index: libc/ctype/islower.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/ctype/islower.c,v
retrieving revision 1.3
diff -u -p -r1.3 islower.c
--- libc/ctype/islower.c 21 Jul 2008 21:28:34 -0000 1.3
+++ libc/ctype/islower.c 8 Apr 2009 20:01:22 -0000
@@ -38,6 +38,6 @@ No supporting OS subroutines are require
int
_DEFUN(islower,(c),int c)
{
- return(__ctype_ptr__[c+1] & _L);
+ return ((__ctype_ptr__[c+1] & (_U|_L)) == _L);
}
Index: libc/ctype/isupper.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/ctype/isupper.c,v
retrieving revision 1.3
diff -u -p -r1.3 isupper.c
--- libc/ctype/isupper.c 21 Jul 2008 21:28:34 -0000 1.3
+++ libc/ctype/isupper.c 8 Apr 2009 20:01:22 -0000
@@ -38,6 +38,6 @@ No supporting OS subroutines are require
int
_DEFUN(isupper,(c),int c)
{
- return(__ctype_ptr__[c+1] & _U);
+ return ((__ctype_ptr__[c+1] & (_U|_L)) == _U);
}
Index: libc/include/ctype.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/ctype.h,v
retrieving revision 1.16
diff -u -p -r1.16 ctype.h
--- libc/include/ctype.h 2 Apr 2009 07:53:12 -0000 1.16
+++ libc/include/ctype.h 8 Apr 2009 20:01:22 -0000
@@ -46,8 +46,8 @@ extern __IMPORT char *__ctype_ptr__;
#ifndef __cplusplus
#define isalpha(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L))
-#define isupper(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_U)
-#define islower(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_L)
+#define isupper(c) (((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L))==_U)
+#define islower(c) (((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L))==_L)
#define isdigit(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_N)
#define isxdigit(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_X|_N))
#define isspace(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_S)
@@ -57,8 +57,10 @@ extern __IMPORT char *__ctype_ptr__;
#define isgraph(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_P|_U|_L|_N))
#define iscntrl(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_C)
-#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L
-#define isblank(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_B)
+#if defined(__GNUC__) && \
+ (!defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L)
+#define isblank(c) \
+ __extension__ ({ int __c = (c); ((__ctype_ptr__)[(unsigned)((__c)+1)]&_B) || (__c) == '\t';})
#endif




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