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:
Eric Blake 2009-04-24 12:20:07 +00:00
parent 5921804481
commit 1335bf3c5d
2 changed files with 53 additions and 39 deletions

View File

@ -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.
@ -25,7 +33,7 @@
* libc/machine/moxie/Makefile.in: New file. * libc/machine/moxie/Makefile.in: New file.
* libc/machine/moxie/setjmp.S: New file. * libc/machine/moxie/setjmp.S: New file.
* libc/include/machine/setjmp.h (_JBLEN): Define for moxie. * libc/include/machine/setjmp.h (_JBLEN): Define for moxie.
* libc/include/machine/ieeefp.h: Add moxie support. * libc/include/machine/ieeefp.h: Add moxie support.
2009-04-22 Kazu Hirata <kazu@codesourcery.com> 2009-04-22 Kazu Hirata <kazu@codesourcery.com>
@ -440,7 +448,7 @@
fpclassify(), isfinite(), isinf(), isnan(), and isnormal(). fpclassify(), isfinite(), isinf(), isnan(), and isnormal().
* libm/common/s_nearbyint.c: Add nearbyint() and nearbyintf() * libm/common/s_nearbyint.c: Add nearbyint() and nearbyintf()
documentation. documentation.
* libm/common/Makefile.am: Add s_llround.c (src); sf_llround.c (fsrc); * libm/common/Makefile.am: Add s_llround.c (src); sf_llround.c (fsrc);
s_fdim.def, s_fma.def, s_fmax.def, s_fmin.def, s_fdim.def, s_fma.def, s_fmax.def, s_fmin.def,
s_logb.def, s_lrint.def, s_lround.def, s_nearbyint.def, s_remquo.def, s_logb.def, s_lrint.def, s_lround.def, s_nearbyint.def, s_remquo.def,
s_rint.def, s_round.def, s_signbit.def, s_trunc.def, and s_rint.def, s_round.def, s_signbit.def, s_trunc.def, and
@ -818,7 +826,7 @@
2009-02-26 Ralf Corsepius <ralf.corsepius@rtems.org> 2009-02-26 Ralf Corsepius <ralf.corsepius@rtems.org>
* libc/machine/lm32/configure.in: Let * libc/machine/lm32/configure.in: Let
AC_CONFIG_SRCDIR point to setjmp.S instead of setjmp.s AC_CONFIG_SRCDIR point to setjmp.S instead of setjmp.s
* libs/machine/lm32/configure: Regenerate. * libs/machine/lm32/configure: Regenerate.
@ -834,11 +842,11 @@
2009-02-25 Corinna Vinschen <corinna@vinschen.de> 2009-02-25 Corinna Vinschen <corinna@vinschen.de>
* libc/stdlib/mbtowc_r.c (_mbtowc_r): Remove conversion of 5 and 6 * libc/stdlib/mbtowc_r.c (_mbtowc_r): Remove conversion of 5 and 6
byte UTF-8 sequences since they are invalid in the Unicode standard. byte UTF-8 sequences since they are invalid in the Unicode standard.
Handle surrogate pairs in case of wchar_t == UTF-16. Handle surrogate pairs in case of wchar_t == UTF-16.
* libc/stdlib/wctomb_r.c (_wctomb_r): Don't convert invalid Unicode * libc/stdlib/wctomb_r.c (_wctomb_r): Don't convert invalid Unicode
wchar_t values beyond 0x10ffff into UTF-8 chars. Handle surrogate wchar_t values beyond 0x10ffff into UTF-8 chars. Handle surrogate
pairs in case of wchar_t == UTF-16. pairs in case of wchar_t == UTF-16.
2009-02-24 Kevin Buettner <kevinb@redhat.com> 2009-02-24 Kevin Buettner <kevinb@redhat.com>
@ -1016,7 +1024,7 @@
2008-12-12 Ralf Corsepius <ralf.corsepius@rtems.org> 2008-12-12 Ralf Corsepius <ralf.corsepius@rtems.org>
* libc/sys/rtems/crt0.c: Add stubs for getdents(), nanosleep(), * libc/sys/rtems/crt0.c: Add stubs for getdents(), nanosleep(),
_execve(), _exit(). _execve(), _exit().
2008-12-12 Ralf Corsepius <ralf.corsepius@rtems.org> 2008-12-12 Ralf Corsepius <ralf.corsepius@rtems.org>
@ -1171,7 +1179,7 @@
2008-11-27 Ralf Corsepius <ralf.corsepius@rtems.org> 2008-11-27 Ralf Corsepius <ralf.corsepius@rtems.org>
* libc/posix/telldir.c: Use #if !defined() instead of #ifndef * libc/posix/telldir.c: Use #if !defined() instead of #ifndef
to fix GCC warning. to fix GCC warning.
2008-11-27 Ken Werner <ken.werner@de.ibm.com> 2008-11-27 Ken Werner <ken.werner@de.ibm.com>
@ -1248,7 +1256,7 @@
2008-11-24 Joel Sherrill <joel.sherrill@oarcorp.com> 2008-11-24 Joel Sherrill <joel.sherrill@oarcorp.com>
* libc/posix/scandir.c: Fix memory leaks. * libc/posix/scandir.c: Fix memory leaks.
2008-11-24 Joel Sherrill <joel.sherrill@oarcorp.com> 2008-11-24 Joel Sherrill <joel.sherrill@oarcorp.com>
@ -1343,9 +1351,9 @@
2008-11-19 Ralf Corsepius <ralf.corsepius@rtems.org> 2008-11-19 Ralf Corsepius <ralf.corsepius@rtems.org>
* libc/include/sys/config.h: Don't put * libc/include/sys/config.h: Don't put
__ATTRIBUTE_IMPURE_PTR__ into .sdata section for mips-rtems. __ATTRIBUTE_IMPURE_PTR__ into .sdata section for mips-rtems.
2008-11-19 Ralf Corsepius <ralf.corsepius@rtems.org> 2008-11-19 Ralf Corsepius <ralf.corsepius@rtems.org>
* libc/posix/runetype.h: Add include of stddef.h and remove * libc/posix/runetype.h: Add include of stddef.h and remove
@ -1382,7 +1390,7 @@
2008-11-17 Joel Sherrill <joel.sherrill@oarcorp.com> 2008-11-17 Joel Sherrill <joel.sherrill@oarcorp.com>
* configure.host: RTEMS now uses posix subdirectory. * configure.host: RTEMS now uses posix subdirectory.
2008-11-17 Joel Sherrill <joel.sherrill@oarcorp.com> 2008-11-17 Joel Sherrill <joel.sherrill@oarcorp.com>
@ -1429,7 +1437,7 @@
* libc/include/glob.h: Ditto. * libc/include/glob.h: Ditto.
* libc/include/regex.h: Ditto. * libc/include/regex.h: Ditto.
* libc/include/wordexp.h: Ditto. * libc/include/wordexp.h: Ditto.
* libc/posix/Makefile.am: Add new files moved from * libc/posix/Makefile.am: Add new files moved from
libc/sys/linux/stdlib. libc/sys/linux/stdlib.
* libc/posix/Makefile.in: Regenerated. * libc/posix/Makefile.in: Regenerated.
* libc/posix/COPYRIGHT: New file moved from libc/sys/linux/stdlib. * libc/posix/COPYRIGHT: New file moved from libc/sys/linux/stdlib.
@ -1496,13 +1504,13 @@
2008-10-16 Joel Sherrill <joel.sherrill@oarcorp.com> 2008-10-16 Joel Sherrill <joel.sherrill@oarcorp.com>
* libc/include/sys/unistd.h: RTEMS follows standard for sync(). * libc/include/sys/unistd.h: RTEMS follows standard for sync().
2008-10-16 Joel Sherrill <joel.sherrill@oarcorp.com> 2008-10-16 Joel Sherrill <joel.sherrill@oarcorp.com>
* libc/include/time.h: Add CLOCK_MONOTONIC. * libc/include/time.h: Add CLOCK_MONOTONIC.
* libc/include/sys/features.h: Define * libc/include/sys/features.h: Define
_POSIX_MONOTONIC_CLOCK for RTEMS. _POSIX_MONOTONIC_CLOCK for RTEMS.
2008-10-15 Jeff Johnston <jjohnstn@redhat.com> 2008-10-15 Jeff Johnston <jjohnstn@redhat.com>
@ -1548,7 +1556,7 @@
2008-10-02 Jeff Johnston <jjohnstn@redhat.com> 2008-10-02 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/sys/reent.h[_REENT_SMALL](_REENT_INIT_RAND48): Add * libc/include/sys/reent.h[_REENT_SMALL](_REENT_INIT_RAND48): Add
initialization of _rand_next to 1. initialization of _rand_next to 1.
2008-09-29 Peter O'Gorman <pogma@thewrittenword.com> 2008-09-29 Peter O'Gorman <pogma@thewrittenword.com>
@ -1808,7 +1816,7 @@
* libc/sys/linux/dl/atomicity.h (exchange_and_add): Fix asm * libc/sys/linux/dl/atomicity.h (exchange_and_add): Fix asm
statement to use "m" instead of "0". statement to use "m" instead of "0".
(atomic_add): Ditto. (atomic_add): Ditto.
* libc/sys/linux/linuxthreads/spinlock.c (__pthread_release): Ditto. * libc/sys/linux/linuxthreads/spinlock.c (__pthread_release): Ditto.
* libc/sys/linux/net/getaddrinfo.c: Add limit.h include. * libc/sys/linux/net/getaddrinfo.c: Add limit.h include.
* libc/sys/linux/stdlib/glob.c: Ditto. * libc/sys/linux/stdlib/glob.c: Ditto.
@ -1913,20 +1921,20 @@
* libm/machine/spu/headers/cbrt.h: cbrt_factors[] declared. * libm/machine/spu/headers/cbrt.h: cbrt_factors[] declared.
* libm/machine/spu/headers/cbrtf.h: Likewise. * libm/machine/spu/headers/cbrtf.h: Likewise.
2008-09-01 Ken Werner <ken.werner@de.ibm.com> 2008-09-01 Ken Werner <ken.werner@de.ibm.com>
* libc/machine/spu/include/spu_timer.h: spu_timebase function added. * libc/machine/spu/include/spu_timer.h: spu_timebase function added.
* libc/machine/spu/spu_timebase.c: New file. * libc/machine/spu/spu_timebase.c: New file.
* libc/machine/spu/Makefile.am: Add new file. * libc/machine/spu/Makefile.am: Add new file.
* libc/machine/spu/Makefile.in: Regenerated. * libc/machine/spu/Makefile.in: Regenerated.
2008-08-28 Craig Howland <howland@LGSInnovations.com> 2008-08-28 Craig Howland <howland@LGSInnovations.com>
* libc/time/mktime.c (mktime): Fix tm_isdst value usage (allowing * libc/time/mktime.c (mktime): Fix tm_isdst value usage (allowing
any positive value from user (per std) rather than depending any positive value from user (per std) rather than depending
upon 1). upon 1).
2008-08-28 Corinna Vinschen <corinna@vinschen.de> 2008-08-28 Corinna Vinschen <corinna@vinschen.de>
* libc/stdlib/wcsrtombs.c (_wcsrtombs_r): Optimize condition * libc/stdlib/wcsrtombs.c (_wcsrtombs_r): Optimize condition
@ -1937,12 +1945,12 @@
* libc/libc.texinfo: Remove "LOCAL KLUGE" that prevents it * libc/libc.texinfo: Remove "LOCAL KLUGE" that prevents it
from building pdfs. from building pdfs.
* libm/libm.texinfo: Likewise. * libm/libm.texinfo: Likewise.
2008-08-27 Corinna Vinschen <corinna@vinschen.de> 2008-08-27 Corinna Vinschen <corinna@vinschen.de>
* libc/stdlib/wcsrtombs.c (_wcsrtombs_r): Fix condition for * libc/stdlib/wcsrtombs.c (_wcsrtombs_r): Fix condition for
accepting a converted character and continuing the loop. accepting a converted character and continuing the loop.
2008-07-24 Jeff Johnston <jjohnstn@redhat.com> 2008-07-24 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/ctype.h (_ctype_): Restore for C++ backward * libc/include/ctype.h (_ctype_): Restore for C++ backward
@ -2039,7 +2047,7 @@
* libc/machine/spu/sys/dirent.h: Add extern "C" specifier if C++. * libc/machine/spu/sys/dirent.h: Add extern "C" specifier if C++.
* libc/machine/spu/sys/sched.h: Likewise. * libc/machine/spu/sys/sched.h: Likewise.
* libc/machine/spu/sys/syscall.h: Likewise. * libc/machine/spu/sys/syscall.h: Likewise.
2008-06-16 Ken Werner <ken.werner@de.ibm.com> 2008-06-16 Ken Werner <ken.werner@de.ibm.com>
* libc/machine/spu/mk_syscalls: Provide .type and .size directives * libc/machine/spu/mk_syscalls: Provide .type and .size directives
@ -2055,7 +2063,7 @@
and .size directives. and .size directives.
* libc/machine/spu/setjmp.S (setjmp): Likewise. * libc/machine/spu/setjmp.S (setjmp): Likewise.
(longjmp): Likewise. (longjmp): Likewise.
2008-06-11 Jeff Johnston <jjohnstn@redhat.com> 2008-06-11 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/machine/_default_types.h: Fix GNUC check to * libc/include/machine/_default_types.h: Fix GNUC check to
@ -2081,7 +2089,7 @@
* libc/machine/spu/strcat.c: Return value fixed. * libc/machine/spu/strcat.c: Return value fixed.
* libc/machine/spu/strncat.c: Likewise. * libc/machine/spu/strncat.c: Likewise.
2008-05-28 Eric Blake <ebb9@byu.net> 2008-05-28 Eric Blake <ebb9@byu.net>
Fix bug in previous patch. Fix bug in previous patch.

View File

@ -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 */