This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: [PATCH/RFA] Distinguish between EOF and character with value 0xff
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
According to Jeff Johnston on 4/23/2009 12:05 PM:
>> I spent some time and actually tested my proposal. I've verified that
>> with the patch below, the assembly produced by isalpha(i) is identical
>> both before and after the patch under gcc 4.3.2. Meanwhile, 'gcc
>> -Wall' is now able to complain about isalpha((char)i) while staying
>> silent for isalpha((unsigned char)
>> i).
>>
>> OK to apply? (And pardon the fact that gmane botched the long lines.)
>>
>>
> Yes, please resend as an attachment, otherwise I can't apply it, and
> include Mike's suggestion as well.
Here's what I applied, including Mike's suggestion, and also fixing
toupper and tolower for those avoiding alternate code pages. Then I also
committed an obvious followup to be namespace clean, in case the user
#define's c.
2009-04-24 Eric Blake <ebb9@byu.net>
Be namespace clean in ctype.h.
* libc/include/ctype.h (_tolower, _toupper, isalpha, isupper)
(islower, isdigit, isxdigit, isspace, ispunct, isalnum)
(isprint, isgraph, iscntrl, isblank, toupper, tolower)
(isascii, toascii): Don't use 'c' as macro parameter name.
- --
Don't work too hard, make some time for fun as well!
Eric Blake ebb9@byu.net
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iEYEARECAAYFAknxsBoACgkQ84KuGfSFAYAK1wCgiCOwuLz1vkP1j9wNEFWB/TTb
gcEAn0FSAqFwZ5Hf6/uIBXCO7HsoKyxe
=aAEc
-----END PGP SIGNATURE-----
Index: libc/include/ctype.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/ctype.h,v
retrieving revision 1.17
diff -u -p -r1.17 ctype.h
--- libc/include/ctype.h 9 Apr 2009 10:37:58 -0000 1.17
+++ libc/include/ctype.h 24 Apr 2009 12:15:19 -0000
@@ -45,22 +45,26 @@ _CONST
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|_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)
-#define ispunct(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_P)
-#define isalnum(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L|_N))
-#define isprint(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_P|_U|_L|_N|_B))
-#define isgraph(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_P|_U|_L|_N))
-#define iscntrl(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_C)
+/* These macros are intentionally written in a manner that will trigger
+ a gcc -Wall warning if the user mistakenly passes a 'char' instead
+ of an int containing an 'unsigned char'. */
+#define isalpha(c) ((__ctype_ptr__+1)[c]&(_U|_L))
+#define isupper(c) (((__ctype_ptr__+1)[c]&(_U|_L))==_U)
+#define islower(c) (((__ctype_ptr__+1)[c]&(_U|_L))==_L)
+#define isdigit(c) ((__ctype_ptr__+1)[c]&_N)
+#define isxdigit(c) ((__ctype_ptr__+1)[c]&(_X|_N))
+#define isspace(c) ((__ctype_ptr__+1)[c]&_S)
+#define ispunct(c) ((__ctype_ptr__+1)[c]&_P)
+#define isalnum(c) ((__ctype_ptr__+1)[c]&(_U|_L|_N))
+#define isprint(c) ((__ctype_ptr__+1)[c]&(_P|_U|_L|_N|_B))
+#define isgraph(c) ((__ctype_ptr__+1)[c]&(_P|_U|_L|_N))
+#define iscntrl(c) ((__ctype_ptr__+1)[c]&_C)
#if defined(__GNUC__) && \
(!defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L)
#define isblank(c) \
- __extension__ ({ int __c = (c); ((__ctype_ptr__)[(unsigned)((__c)+1)]&_B) || (__c) == '\t';})
+ __extension__ ({ __typeof__ (c) __c = (c); \
+ ((__ctype_ptr__+1)[__c]&_B) || (__c) == '\t';})
#endif
@@ -69,9 +73,11 @@ extern __IMPORT char *__ctype_ptr__;
disabled if the system supports the extended character sets. */
# if defined(__GNUC__) && !defined (_MB_EXTENDED_CHARSETS_ISO) && !defined (_MB_EXTENDED_CHARSETS_WINDOWS)
# define toupper(c) \
- __extension__ ({ int __x = (c); islower(__x) ? (__x - 'a' + 'A') : __x;})
+ __extension__ ({ __typeof__ (c) __x = (c); \
+ islower(__x) ? (__x - 'a' + 'A') : __x;})
# define tolower(c) \
- __extension__ ({ int __x = (c); isupper(__x) ? (__x - 'A' + 'a') : __x;})
+ __extension__ ({ __typeof__ (c) __x = (c); \
+ isupper(__x) ? (__x - 'A' + 'a') : __x;})
#endif
#endif /* !__cplusplus */
Index: libc/include/ctype.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/ctype.h,v
retrieving revision 1.18
diff -u -p -r1.18 ctype.h
--- libc/include/ctype.h 24 Apr 2009 12:20:07 -0000 1.18
+++ libc/include/ctype.h 24 Apr 2009 12:26:34 -0000
@@ -26,8 +26,8 @@ int _EXFUN(isblank, (int __c));
#ifndef __STRICT_ANSI__
int _EXFUN(isascii, (int __c));
int _EXFUN(toascii, (int __c));
-#define _tolower(c) ((unsigned char)(c) - 'A' + 'a')
-#define _toupper(c) ((unsigned char)(c) - 'a' + 'A')
+#define _tolower(__c) ((unsigned char)(__c) - 'A' + 'a')
+#define _toupper(__c) ((unsigned char)(__c) - 'a' + 'A')
#endif
#define _U 01
@@ -48,23 +48,23 @@ extern __IMPORT char *__ctype_ptr__;
/* These macros are intentionally written in a manner that will trigger
a gcc -Wall warning if the user mistakenly passes a 'char' instead
of an int containing an 'unsigned char'. */
-#define isalpha(c) ((__ctype_ptr__+1)[c]&(_U|_L))
-#define isupper(c) (((__ctype_ptr__+1)[c]&(_U|_L))==_U)
-#define islower(c) (((__ctype_ptr__+1)[c]&(_U|_L))==_L)
-#define isdigit(c) ((__ctype_ptr__+1)[c]&_N)
-#define isxdigit(c) ((__ctype_ptr__+1)[c]&(_X|_N))
-#define isspace(c) ((__ctype_ptr__+1)[c]&_S)
-#define ispunct(c) ((__ctype_ptr__+1)[c]&_P)
-#define isalnum(c) ((__ctype_ptr__+1)[c]&(_U|_L|_N))
-#define isprint(c) ((__ctype_ptr__+1)[c]&(_P|_U|_L|_N|_B))
-#define isgraph(c) ((__ctype_ptr__+1)[c]&(_P|_U|_L|_N))
-#define iscntrl(c) ((__ctype_ptr__+1)[c]&_C)
+#define isalpha(__c) ((__ctype_ptr__+1)[__c]&(_U|_L))
+#define isupper(__c) (((__ctype_ptr__+1)[__c]&(_U|_L))==_U)
+#define islower(__c) (((__ctype_ptr__+1)[__c]&(_U|_L))==_L)
+#define isdigit(__c) ((__ctype_ptr__+1)[__c]&_N)
+#define isxdigit(__c) ((__ctype_ptr__+1)[__c]&(_X|_N))
+#define isspace(__c) ((__ctype_ptr__+1)[__c]&_S)
+#define ispunct(__c) ((__ctype_ptr__+1)[__c]&_P)
+#define isalnum(__c) ((__ctype_ptr__+1)[__c]&(_U|_L|_N))
+#define isprint(__c) ((__ctype_ptr__+1)[__c]&(_P|_U|_L|_N|_B))
+#define isgraph(__c) ((__ctype_ptr__+1)[__c]&(_P|_U|_L|_N))
+#define iscntrl(__c) ((__ctype_ptr__+1)[__c]&_C)
#if defined(__GNUC__) && \
(!defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L)
-#define isblank(c) \
- __extension__ ({ __typeof__ (c) __c = (c); \
- ((__ctype_ptr__+1)[__c]&_B) || (__c) == '\t';})
+#define isblank(__c) \
+ __extension__ ({ __typeof__ (__c) __x = (__c); \
+ ((__ctype_ptr__+1)[__x]&_B) || (__x) == '\t';})
#endif
@@ -72,18 +72,18 @@ extern __IMPORT char *__ctype_ptr__;
slightly slower. These macros are not NLS-aware so they are
disabled if the system supports the extended character sets. */
# if defined(__GNUC__) && !defined (_MB_EXTENDED_CHARSETS_ISO) && !defined (_MB_EXTENDED_CHARSETS_WINDOWS)
-# define toupper(c) \
- __extension__ ({ __typeof__ (c) __x = (c); \
+# define toupper(__c) \
+ __extension__ ({ __typeof__ (__c) __x = (__c); \
islower(__x) ? (__x - 'a' + 'A') : __x;})
-# define tolower(c) \
- __extension__ ({ __typeof__ (c) __x = (c); \
+# define tolower(__c) \
+ __extension__ ({ __typeof__ (__c) __x = (__c); \
isupper(__x) ? (__x - 'A' + 'a') : __x;})
#endif
#endif /* !__cplusplus */
#ifndef __STRICT_ANSI__
-#define isascii(c) ((unsigned)(c)<=0177)
-#define toascii(c) ((c)&0177)
+#define isascii(__c) ((unsigned)(__c)<=0177)
+#define toascii(__c) ((__c)&0177)
#endif
/* For C++ backward-compatibility only. */