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 Eric Blake on 4/24/2009 6:27 AM:
> 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.
Would it also be okay to apply this? The idea is that on cygwin, even
though we must call the function to support particular locales, we can
still be nice and warn about invalid uses of toupper((char)ch). Or is
there a simple test for when __ctype_ptr__ represents the C locale, in
which case rewriting this test would allow avoiding the function call for
apps that only care about the C locale?
__extension__ ({ __typeof__ (__c) __x = (__c); \
__ctype_ptr__ == <WHAT> \
? isupper(__x) ? (__x - 'A' + 'a') : __x \
: (isupper) (__x);})
2009-04-24 Eric Blake <ebb9@byu.net>
Allow gcc warning for toupper even with extended charsets.
* libc/include/ctype.h (toupper, tolower)
[_MB_EXTENDED_CHARSETS_ISO]: Allow gcc warning when called with
'char' even when we must call the function for correct behavior.
- --
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
iEYEARECAAYFAknxs2QACgkQ84KuGfSFAYAO/wCfS9LeLF48kz25cg99StxP08wz
gCYAn3HzJJQP0f2Q5NpigTFnwq/C8LT5
=G9vv
-----END PGP SIGNATURE-----
Index: libc/include/ctype.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/ctype.h,v
retrieving revision 1.19
diff -u -p -r1.19 ctype.h
--- libc/include/ctype.h 24 Apr 2009 12:27:36 -0000 1.19
+++ libc/include/ctype.h 24 Apr 2009 12:38:40 -0000
@@ -71,14 +71,25 @@ extern __IMPORT char *__ctype_ptr__;
/* Non-gcc versions will get the library versions, and will be
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) \
+# if defined(__GNUC__)
+# if !defined (_MB_EXTENDED_CHARSETS_ISO) && !defined (_MB_EXTENDED_CHARSETS_WINDOWS)
+# define toupper(__c) \
__extension__ ({ __typeof__ (__c) __x = (__c); \
islower(__x) ? (__x - 'a' + 'A') : __x;})
-# define tolower(__c) \
+# define tolower(__c) \
__extension__ ({ __typeof__ (__c) __x = (__c); \
isupper(__x) ? (__x - 'A' + 'a') : __x;})
-#endif
+# else /* !_MB_EXTENDED_CHARSETS* */
+/* Allow a gcc warning if the user passed 'char', but defer to the
+ function. */
+# define toupper(__c) \
+ __extension__ ({ __typeof__ (__c) __x = (__c); \
+ (void) __ctype_ptr__[__x]; (toupper) (__x);})
+# define tolower(__c) \
+ __extension__ ({ __typeof__ (__c) __x = (__c); \
+ (void) __ctype_ptr__[__x]; (tolower) (__x);})
+# endif /* !_MB_EXTENDED_CHARSETS* */
+# endif /* __GNUC__ */
#endif /* !__cplusplus */
#ifndef __STRICT_ANSI__