diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-12-27 10:19:19 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-12-27 10:19:19 +0000 |
commit | cf578c75a521e1f35a9f07ca04c0cd678209c79f (patch) | |
tree | 03cf31e8d7db0d0fcdf8384278e672bf437dc423 /libc | |
parent | 7779fe81082b7521e537b02cdf71f88aff3de358 (diff) |
ctype: remove some trivial macros from ctype.h;
remove __tolower and __toupper (they existed only in SOME configs!);
remove usages of _tolower (some of them clearly buggy) from uclibc code;
add a few more -U<define> options to unifdef pass over installed headers;
document it on docs/wchar_and_locale.txt
text data bss dec hex filename
- 514963 2727 15396 533086 8225e lib/libuClibc-0.9.30-svn.so
+ 514888 2727 15396 533011 82213 lib/libuClibc-0.9.30-svn.so
Diffstat (limited to 'libc')
-rw-r--r-- | libc/misc/ctype/ctype.c | 6 | ||||
-rw-r--r-- | libc/misc/regex/regcomp.c | 2 | ||||
-rw-r--r-- | libc/misc/regex/regex.c | 4 | ||||
-rw-r--r-- | libc/misc/regex/regex_internal.c | 4 | ||||
-rw-r--r-- | libc/misc/regex/regex_old.c | 2 | ||||
-rw-r--r-- | libc/misc/wctype/_wctype.c | 25 | ||||
-rw-r--r-- | libc/stdlib/_strtod.c | 28 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/bits/uClibc_ctype.h | 144 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/bits/uClibc_locale.h | 38 | ||||
-rw-r--r-- | libc/sysdeps/linux/common/bits/uClibc_touplow.h | 4 |
10 files changed, 120 insertions, 137 deletions
diff --git a/libc/misc/ctype/ctype.c b/libc/misc/ctype/ctype.c index 8c99d004c..8d20a39cf 100644 --- a/libc/misc/ctype/ctype.c +++ b/libc/misc/ctype/ctype.c @@ -319,7 +319,8 @@ int tolower_l(int c, __locale_t l) return __UCLIBC_CTYPE_IN_TO_DOMAIN(c) ? l->__ctype_tolower[c] : c; } libc_hidden_def(tolower_l) -weak_alias (tolower_l, __tolower_l) +//remove after 0.9.31. See ctype.h for why. +//weak_alias (tolower_l, __tolower_l) #endif /**********************************************************************/ @@ -366,7 +367,8 @@ int toupper_l(int c, __locale_t l) return __UCLIBC_CTYPE_IN_TO_DOMAIN(c) ? l->__ctype_toupper[c] : c; } libc_hidden_def(toupper_l) -weak_alias (toupper_l, __toupper_l) +//remove after 0.9.31. See ctype.h for why. +//weak_alias (toupper_l, __toupper_l) #endif /**********************************************************************/ diff --git a/libc/misc/regex/regcomp.c b/libc/misc/regex/regcomp.c index 720214161..0c348a48d 100644 --- a/libc/misc/regex/regcomp.c +++ b/libc/misc/regex/regcomp.c @@ -281,7 +281,7 @@ re_set_fastmap (char *fastmap, int icase, int ch) { fastmap[ch] = 1; if (icase) - fastmap[__tolower (ch)] = 1; + fastmap[tolower (ch)] = 1; } /* Helper function for re_compile_fastmap. diff --git a/libc/misc/regex/regex.c b/libc/misc/regex/regex.c index bc2e502f6..fa46f635f 100644 --- a/libc/misc/regex/regex.c +++ b/libc/misc/regex/regex.c @@ -38,10 +38,6 @@ # define __wctype wctype # endif # include <ctype.h> -# ifdef __UCLIBC_HAS_CTYPE_TABLES__ -# define __toupper toupper -# define __tolower tolower -# endif #endif /* Make sure noone compiles this code with a C++ compiler. */ diff --git a/libc/misc/regex/regex_internal.c b/libc/misc/regex/regex_internal.c index c6685528d..493985217 100644 --- a/libc/misc/regex/regex_internal.c +++ b/libc/misc/regex/regex_internal.c @@ -289,7 +289,7 @@ build_wcs_upper_buffer (re_string_t *pstr) { /* In case of a singlebyte character. */ pstr->mbs[byte_idx] - = __toupper (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]); + = toupper (pstr->raw_mbs[pstr->raw_mbs_idx + byte_idx]); /* The next step uses the assumption that wchar_t is encoded ASCII-safe: all ASCII values can be converted like this. */ pstr->wcs[byte_idx] = (wchar_t) pstr->mbs[byte_idx]; @@ -523,7 +523,7 @@ build_upper_buffer (re_string_t *pstr) if (BE (pstr->trans != NULL, 0)) ch = pstr->trans[ch]; if (islower (ch)) - pstr->mbs[char_idx] = __toupper (ch); + pstr->mbs[char_idx] = toupper (ch); else pstr->mbs[char_idx] = ch; } diff --git a/libc/misc/regex/regex_old.c b/libc/misc/regex/regex_old.c index af1af50a6..bdc298a3e 100644 --- a/libc/misc/regex/regex_old.c +++ b/libc/misc/regex/regex_old.c @@ -226,7 +226,7 @@ char *realloc (); # ifdef _tolower # define TOLOWER(c) _tolower(c) # else -# define TOLOWER(c) __tolower(c) +# define TOLOWER(c) tolower(c) # endif # ifndef NULL diff --git a/libc/misc/wctype/_wctype.c b/libc/misc/wctype/_wctype.c index c3303d247..c6f536d91 100644 --- a/libc/misc/wctype/_wctype.c +++ b/libc/misc/wctype/_wctype.c @@ -701,23 +701,20 @@ libc_hidden_def(iswctype) /* Minimal support for C/POSIX locale. */ -#ifndef _tolower -#warning _tolower is undefined! -#define _tolower(c) tolower(c) -#endif -#ifndef _toupper -#warning _toupper is undefined! -#define _toupper(c) toupper(c) -#endif - wint_t towctrans(wint_t wc, wctrans_t desc) { - if (((unsigned int)(desc - _CTYPE_tolower)) - <= (_CTYPE_toupper - _CTYPE_tolower) - ) { + if ((unsigned int)(desc - _CTYPE_tolower) <= (_CTYPE_toupper - _CTYPE_tolower)) { /* Transliteration is either tolower or toupper. */ - if (((__uwchar_t) wc) <= 0x7f) { - return (desc == _CTYPE_tolower) ? _tolower(wc) : _toupper(wc); +// I think it's wrong: _toupper(c) assumes that c is a *lowercase* *letter* - +// it is defined as ((c) ^ 0x20)! +// if ((__uwchar_t) wc <= 0x7f) { +// return (desc == _CTYPE_tolower) ? _tolower(wc) : _toupper(wc); +// } + __uwchar_t c = wc | 0x20; /* lowercase if it's a letter */ + if (c >= 'a' && c <= 'z') { + if (desc == _CTYPE_toupper) + c &= ~0x20; /* uppercase */ + return c; } } else { __set_errno(EINVAL); /* Invalid transliteration. */ diff --git a/libc/stdlib/_strtod.c b/libc/stdlib/_strtod.c index aac5b811b..d531d1b54 100644 --- a/libc/stdlib/_strtod.c +++ b/libc/stdlib/_strtod.c @@ -36,7 +36,7 @@ */ /**********************************************************************/ -/* OPTIONS */ +/* OPTIONS */ /**********************************************************************/ /* Defined if we want to recognize "nan", "inf", and "infinity". (C99) */ @@ -79,7 +79,7 @@ #define _STRTOD_ZERO_CHECK 1 /**********************************************************************/ -/* Don't change anything that follows. */ +/* Don't change anything that follows. */ /**********************************************************************/ #ifdef _STRTOD_ERRNO @@ -107,23 +107,22 @@ #include <locale.h> #ifdef __UCLIBC_HAS_WCHAR__ - -#include <wchar.h> -#include <wctype.h> -#include <bits/uClibc_uwchar.h> +# include <wchar.h> +# include <wctype.h> +# include <bits/uClibc_uwchar.h> /* libc_hidden_proto(iswspace) */ #endif #ifdef __UCLIBC_HAS_XLOCALE__ -#include <xlocale.h> +# include <xlocale.h> /* libc_hidden_proto(iswspace_l) */ -#endif /* __UCLIBC_HAS_XLOCALE__ */ +#endif /* Handle _STRTOD_HEXADECIMAL_FLOATS via uClibc config now. */ #undef _STRTOD_HEXADECIMAL_FLOATS #ifdef __UCLIBC_HAS_HEXADECIMAL_FLOATS__ -#define _STRTOD_HEXADECIMAL_FLOATS 1 -#endif /* __UCLIBC_HAS_HEXADECIMAL_FLOATS__ */ +# define _STRTOD_HEXADECIMAL_FLOATS 1 +#endif /**********************************************************************/ @@ -348,16 +347,11 @@ __fpmax_t attribute_hidden __XL_NPP(__strtofpmax)(const Wchar *str, Wchar **endp static const char nan_inf_str[] = "\05nan\0\012infinity\0\05inf\0"; int i = 0; -#ifdef __UCLIBC_HAS_LOCALE__ - /* Avoid tolower problems for INFINITY in the tr_TR locale. (yuk)*/ -#undef _tolower -#define _tolower(C) ((C)|0x20) -#endif /* __UCLIBC_HAS_LOCALE__ */ - do { /* Unfortunately, we have no memcasecmp(). */ int j = 0; - while (_tolower(pos[j]) == nan_inf_str[i+1+j]) { + /* | 0x20 is a cheap lowercasing (valid for ASCII letters and numbers only) */ + while (pos[j] | 0x20 == nan_inf_str[i+1+j]) { ++j; if (!nan_inf_str[i+1+j]) { number = i / 0.; diff --git a/libc/sysdeps/linux/common/bits/uClibc_ctype.h b/libc/sysdeps/linux/common/bits/uClibc_ctype.h index 3c07b5799..04185cc58 100644 --- a/libc/sysdeps/linux/common/bits/uClibc_ctype.h +++ b/libc/sysdeps/linux/common/bits/uClibc_ctype.h @@ -39,7 +39,7 @@ #include "uClibc_charclass.h" -#else /* !__UCLIBC_GEN_LOCALE */ +#else /* Define some ctype macros valid for the C/POSIX locale. */ @@ -86,7 +86,7 @@ : (((unsigned int)((c) - 0x21)) <= (0x7e - 0x21)))) #define __C_isgraph(c) \ ((sizeof(c) == sizeof(char)) \ - ? (((unsigned int)((c) - 0x21)) <= (0x7e - 0x21)) \ + ? (((unsigned char)((c) - 0x21)) <= (0x7e - 0x21)) \ : (((unsigned int)((c) - 0x21)) <= (0x7e - 0x21))) #define __C_tolower(c) (__C_isupper(c) ? ((c) | 0x20) : (c)) @@ -119,27 +119,18 @@ extern int toascii(int c) __THROW; #endif #if defined _LIBC && (defined NOT_IN_libc || defined IS_IN_libc) -/* isdigit() is really locale-invariant, so provide some small fast macros. - * These are uClibc-specific. */ -#define __isdigit_char(C) (((unsigned char)((C) - '0')) <= 9) -#define __isdigit_int(C) (((unsigned int)((C) - '0')) <= 9) +/* These are uClibc-specific. */ +# define __isdigit_char(c) ((unsigned char)((c) - '0') <= 9) +# define __isdigit_int(c) ((unsigned int)((c) - '0') <= 9) #endif -/* Next, some ctype macros which are valid for all supported locales. */ -/* WARNING: isspace and isblank need to be reverified if more 8-bit codesets - * are added!!! But isdigit and isxdigit are always valid. */ - -/* #define __isspace(c) __C_isspace(c) */ -/* #define __isblank(c) __C_isblank(c) */ - -/* #define __isdigit(c) __C_isdigit(c) */ -/* #define __isxdigit(c) __C_isxdigit(c) */ - /* Now some non-ansi/iso c99 macros. */ #define __isascii(c) (((c) & ~0x7f) == 0) #define __toascii(c) ((c) & 0x7f) +/* Works correctly *only* on lowercase letters! */ #define _toupper(c) ((c) ^ 0x20) +/* Works correctly *only* on letters (of any case) and numbers */ #define _tolower(c) ((c) | 0x20) __END_DECLS @@ -147,70 +138,73 @@ __END_DECLS /**********************************************************************/ #ifdef __GNUC__ -#define __body_C_macro(f,args) __C_ ## f args - -#define __body(f,c) \ - (__extension__ ({ \ - int __res; \ - if (sizeof(c) > sizeof(char)) { \ - int __c = (c); \ - __res = __body_C_macro(f,(__c)); \ - } else { \ - unsigned char __c = (c); \ - __res = __body_C_macro(f,(__c)); \ - } \ - __res; \ - })) - -#define __isspace(c) __body(isspace,c) -#define __isblank(c) __body(isblank,c) -#define __isdigit(c) __body(isdigit,c) -#define __isxdigit(c) __body(isxdigit,c) -#define __iscntrl(c) __body(iscntrl,c) -#define __isalpha(c) __body(isalpha,c) -#define __isalnum(c) __body(isalnum,c) -#define __isprint(c) __body(isprint,c) -#define __islower(c) __body(islower,c) -#define __isupper(c) __body(isupper,c) -#define __ispunct(c) __body(ispunct,c) -#define __isgraph(c) __body(isgraph,c) - -#define __tolower(c) __body(tolower,c) -#define __toupper(c) __body(toupper,c) - -#if !defined __NO_CTYPE && !defined __cplusplus - -#define isspace(c) __isspace(c) -#define isblank(c) __isblank(c) -#define isdigit(c) __isdigit(c) -#define isxdigit(c) __isxdigit(c) -#define iscntrl(c) __iscntrl(c) -#define isalpha(c) __isalpha(c) -#define isalnum(c) __isalnum(c) -#define isprint(c) __isprint(c) -#define islower(c) __islower(c) -#define isupper(c) __isupper(c) -#define ispunct(c) __ispunct(c) -#define isgraph(c) __isgraph(c) - -#define tolower(c) __tolower(c) -#define toupper(c) __toupper(c) - -#endif +# define __body_C_macro(f,args) __C_ ## f args + +# define __body(f,c) \ +(__extension__ ({ \ + int __res; \ + if (sizeof(c) > sizeof(char)) { \ + int __c = (c); \ + __res = __body_C_macro(f,(__c)); \ + } else { \ + unsigned char __c = (c); \ + __res = __body_C_macro(f,(__c)); \ + } \ + __res; \ +})) + +# define __isspace(c) __body(isspace,c) +# define __isblank(c) __body(isblank,c) +# define __isdigit(c) __body(isdigit,c) +# define __isxdigit(c) __body(isxdigit,c) +# define __iscntrl(c) __body(iscntrl,c) +# define __isalpha(c) __body(isalpha,c) +# define __isalnum(c) __body(isalnum,c) +# define __isprint(c) __body(isprint,c) +# define __islower(c) __body(islower,c) +# define __isupper(c) __body(isupper,c) +# define __ispunct(c) __body(ispunct,c) +# define __isgraph(c) __body(isgraph,c) + +//locale-aware ctype.h has no __tolower, why stub locale +//tries to have it? remove after 0.9.31 +//# define __tolower(c) __body(tolower,c) +//# define __toupper(c) __body(toupper,c) + +# if !defined __NO_CTYPE && !defined __cplusplus + +# define isspace(c) __isspace(c) +# define isblank(c) __isblank(c) +# define isdigit(c) __isdigit(c) +# define isxdigit(c) __isxdigit(c) +# define iscntrl(c) __iscntrl(c) +# define isalpha(c) __isalpha(c) +# define isalnum(c) __isalnum(c) +# define isprint(c) __isprint(c) +# define islower(c) __islower(c) +# define isupper(c) __isupper(c) +# define ispunct(c) __ispunct(c) +# define isgraph(c) __isgraph(c) + +# define tolower(c) __body(tolower,c) +# define toupper(c) __body(toupper,c) + +# endif #else /* !_GNUC__ */ -#if !defined __NO_CTYPE && !defined __cplusplus +# if !defined __NO_CTYPE && !defined __cplusplus -/* These macros should be safe from side effects. */ -#define isdigit(c) __C_isdigit(c) -#define isalpha(c) __C_isalpha(c) -#define isprint(c) __C_isprint(c) -#define islower(c) __C_islower(c) -#define isupper(c) __C_isupper(c) -#define isgraph(c) __C_isgraph(c) +/* These macros should be safe from side effects! + * (not all __C_xxx macros are) */ +# define isdigit(c) __C_isdigit(c) +# define isalpha(c) __C_isalpha(c) +# define isprint(c) __C_isprint(c) +# define islower(c) __C_islower(c) +# define isupper(c) __C_isupper(c) +# define isgraph(c) __C_isgraph(c) -#endif +# endif #endif /* __GNUC__ */ /**********************************************************************/ diff --git a/libc/sysdeps/linux/common/bits/uClibc_locale.h b/libc/sysdeps/linux/common/bits/uClibc_locale.h index 0ac12578e..532ab8244 100644 --- a/libc/sysdeps/linux/common/bits/uClibc_locale.h +++ b/libc/sysdeps/linux/common/bits/uClibc_locale.h @@ -334,42 +334,42 @@ extern int __locale_mbrtowc_l(wchar_t *__restrict dst, extern __locale_t __curlocale_var; -#ifdef __UCLIBC_HAS_THREADS__ +# ifdef __UCLIBC_HAS_THREADS__ extern __locale_t __curlocale(void) __THROW __attribute__ ((__const__)); extern __locale_t __curlocale_set(__locale_t newloc); -#define __UCLIBC_CURLOCALE (__curlocale()) -#define __UCLIBC_CURLOCALE_DATA (*__curlocale()) +# define __UCLIBC_CURLOCALE (__curlocale()) +# define __UCLIBC_CURLOCALE_DATA (*__curlocale()) -#else /* __UCLIBC_HAS_THREADS__ */ +# else -#define __UCLIBC_CURLOCALE (__curlocale_var) -#define __UCLIBC_CURLOCALE_DATA (*__curlocale_var) +# define __UCLIBC_CURLOCALE (__curlocale_var) +# define __UCLIBC_CURLOCALE_DATA (*__curlocale_var) -#endif /* __UCLIBC_HAS_THREADS__ */ +# endif #elif defined(__UCLIBC_HAS_LOCALE__) -#define __UCLIBC_CURLOCALE (__global_locale) -#define __UCLIBC_CURLOCALE_DATA (*__global_locale) +# define __UCLIBC_CURLOCALE (__global_locale) +# define __UCLIBC_CURLOCALE_DATA (*__global_locale) #endif /**********************************************************************/ #if defined(__UCLIBC_HAS_XLOCALE__) && defined(__UCLIBC_DO_XLOCALE) -#define __XL_NPP(N) N ## _l -#define __LOCALE_PARAM , __locale_t locale_arg -#define __LOCALE_ARG , locale_arg -#define __LOCALE_PTR locale_arg +# define __XL_NPP(N) N ## _l +# define __LOCALE_PARAM , __locale_t locale_arg +# define __LOCALE_ARG , locale_arg +# define __LOCALE_PTR locale_arg -#else /* defined(__UCLIBC_HAS_XLOCALE__) && defined(__UCLIBC_DO_XLOCALE) */ +#else -#define __XL_NPP(N) N -#define __LOCALE_PARAM -#define __LOCALE_ARG -#define __LOCALE_PTR __UCLIBC_CURLOCALE +# define __XL_NPP(N) N +# define __LOCALE_PARAM +# define __LOCALE_ARG +# define __LOCALE_PTR __UCLIBC_CURLOCALE -#endif /* defined(__UCLIBC_HAS_XLOCALE__) && defined(__UCLIBC_DO_XLOCALE) */ +#endif /**********************************************************************/ #endif /* !defined(__LOCALE_C_ONLY) */ diff --git a/libc/sysdeps/linux/common/bits/uClibc_touplow.h b/libc/sysdeps/linux/common/bits/uClibc_touplow.h index 28d4e2f48..a65d61342 100644 --- a/libc/sysdeps/linux/common/bits/uClibc_touplow.h +++ b/libc/sysdeps/linux/common/bits/uClibc_touplow.h @@ -43,13 +43,13 @@ typedef __int16_t __ctype_touplow_t; #define __UCLIBC_CTYPE_B_TBL_OFFSET 128 #define __UCLIBC_CTYPE_TO_TBL_OFFSET 128 -#else /* __UCLIBC_HAS_CTYPE_SIGNED__ */ +#else typedef unsigned char __ctype_touplow_t; #define __UCLIBC_CTYPE_B_TBL_OFFSET 1 #define __UCLIBC_CTYPE_TO_TBL_OFFSET 0 -#endif /* __UCLIBC_HAS_CTYPE_SIGNED__ */ +#endif #endif /* _UCLIBC_TOUPLOW_H */ |