Trigger gcc warning if isFoo macros are called with plain char.
* libc/include/ctype.h (isalpha, isupper, islower, isdigit) (isxdigit, isspace, ispunct, isalnum, isprint, isgraph) (iscntrl, isblank, toupper, tolower): Rewrite to let 'gcc -Wall' warn when user calls macro with a char argument.
This commit is contained in:
parent
5921804481
commit
1335bf3c5d
@ -1,3 +1,11 @@
|
|||||||
|
2009-04-24 Eric Blake <ebb9@byu.net>
|
||||||
|
|
||||||
|
Trigger gcc warning if isFoo macros are called with plain char.
|
||||||
|
* libc/include/ctype.h (isalpha, isupper, islower, isdigit)
|
||||||
|
(isxdigit, isspace, ispunct, isalnum, isprint, isgraph)
|
||||||
|
(iscntrl, isblank, toupper, tolower): Rewrite to let 'gcc -Wall'
|
||||||
|
warn when user calls macro with a char argument.
|
||||||
|
|
||||||
2009-04-23 Mike Burgess <wizardsguild@earthlink.net>
|
2009-04-23 Mike Burgess <wizardsguild@earthlink.net>
|
||||||
|
|
||||||
* libc/string/strcasecmp.c: Optimized rewrite.
|
* libc/string/strcasecmp.c: Optimized rewrite.
|
||||||
|
@ -45,22 +45,26 @@ _CONST
|
|||||||
extern __IMPORT char *__ctype_ptr__;
|
extern __IMPORT char *__ctype_ptr__;
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
#define isalpha(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L))
|
/* These macros are intentionally written in a manner that will trigger
|
||||||
#define isupper(c) (((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L))==_U)
|
a gcc -Wall warning if the user mistakenly passes a 'char' instead
|
||||||
#define islower(c) (((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L))==_L)
|
of an int containing an 'unsigned char'. */
|
||||||
#define isdigit(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_N)
|
#define isalpha(c) ((__ctype_ptr__+1)[c]&(_U|_L))
|
||||||
#define isxdigit(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_X|_N))
|
#define isupper(c) (((__ctype_ptr__+1)[c]&(_U|_L))==_U)
|
||||||
#define isspace(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_S)
|
#define islower(c) (((__ctype_ptr__+1)[c]&(_U|_L))==_L)
|
||||||
#define ispunct(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_P)
|
#define isdigit(c) ((__ctype_ptr__+1)[c]&_N)
|
||||||
#define isalnum(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_U|_L|_N))
|
#define isxdigit(c) ((__ctype_ptr__+1)[c]&(_X|_N))
|
||||||
#define isprint(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_P|_U|_L|_N|_B))
|
#define isspace(c) ((__ctype_ptr__+1)[c]&_S)
|
||||||
#define isgraph(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&(_P|_U|_L|_N))
|
#define ispunct(c) ((__ctype_ptr__+1)[c]&_P)
|
||||||
#define iscntrl(c) ((__ctype_ptr__)[(unsigned)((c)+1)]&_C)
|
#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__) && \
|
#if defined(__GNUC__) && \
|
||||||
(!defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L)
|
(!defined(__STRICT_ANSI__) || __STDC_VERSION__ >= 199901L)
|
||||||
#define isblank(c) \
|
#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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -69,9 +73,11 @@ extern __IMPORT char *__ctype_ptr__;
|
|||||||
disabled if the system supports the extended character sets. */
|
disabled if the system supports the extended character sets. */
|
||||||
# if defined(__GNUC__) && !defined (_MB_EXTENDED_CHARSETS_ISO) && !defined (_MB_EXTENDED_CHARSETS_WINDOWS)
|
# if defined(__GNUC__) && !defined (_MB_EXTENDED_CHARSETS_ISO) && !defined (_MB_EXTENDED_CHARSETS_WINDOWS)
|
||||||
# define toupper(c) \
|
# 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) \
|
# 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
|
||||||
#endif /* !__cplusplus */
|
#endif /* !__cplusplus */
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user