diff options
author | Gustavo Niemeyer <gustavo@niemeyer.net> | 2004-02-14 00:31:13 (GMT) |
---|---|---|
committer | Gustavo Niemeyer <gustavo@niemeyer.net> | 2004-02-14 00:31:13 (GMT) |
commit | 601b963be0c8ada918045577648b6f77b8e49440 (patch) | |
tree | b2c44b374805248ea4cb94f4e985e5df35fec7f9 | |
parent | a6e436e4b4f94062f274746fc5d109e4203bf658 (diff) | |
download | cpython-601b963be0c8ada918045577648b6f77b8e49440.zip cpython-601b963be0c8ada918045577648b6f77b8e49440.tar.gz cpython-601b963be0c8ada918045577648b6f77b8e49440.tar.bz2 |
- Fixing annoying warnings.
-rw-r--r-- | Modules/_sre.c | 17 | ||||
-rw-r--r-- | Modules/sre.h | 4 |
2 files changed, 12 insertions, 9 deletions
diff --git a/Modules/_sre.c b/Modules/_sre.c index ee07342..45139bc 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -146,20 +146,21 @@ static char sre_char_lower[128] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, static unsigned int sre_lower(unsigned int ch) { - return ((ch) < 128 ? sre_char_lower[ch] : ch); + return ((ch) < 128 ? (unsigned int)sre_char_lower[ch] : ch); } /* locale-specific character predicates */ - -#define SRE_LOC_IS_DIGIT(ch) ((ch) < 256 ? isdigit((ch)) : 0) -#define SRE_LOC_IS_SPACE(ch) ((ch) < 256 ? isspace((ch)) : 0) +/* !(c & ~N) == (c < N+1) for any unsigned c, this avoids + * warnings when c's type supports only numbers < N+1 */ +#define SRE_LOC_IS_DIGIT(ch) (!((ch) & ~255) ? isdigit((ch)) : 0) +#define SRE_LOC_IS_SPACE(ch) (!((ch) & ~255) ? isspace((ch)) : 0) #define SRE_LOC_IS_LINEBREAK(ch) ((ch) == '\n') -#define SRE_LOC_IS_ALNUM(ch) ((ch) < 256 ? isalnum((ch)) : 0) +#define SRE_LOC_IS_ALNUM(ch) (!((ch) & ~255) ? isalnum((ch)) : 0) #define SRE_LOC_IS_WORD(ch) (SRE_LOC_IS_ALNUM((ch)) || (ch) == '_') static unsigned int sre_lower_locale(unsigned int ch) { - return ((ch) < 256 ? tolower((ch)) : ch); + return ((ch) < 256 ? (unsigned int)tolower((ch)) : ch); } /* unicode-specific character predicates */ @@ -484,7 +485,9 @@ SRE_CHARSET(SRE_CODE* set, SRE_CODE ch) set += count*16; } else { - if (ch < 65536) + /* !(c & ~N) == (c < N+1) for any unsigned c, this avoids + * warnings when c's type supports only numbers < N+1 */ + if (!(ch & ~65535)) block = ((unsigned char*)set)[ch >> 8]; else block = -1; diff --git a/Modules/sre.h b/Modules/sre.h index 452e77a..ba8500b 100644 --- a/Modules/sre.h +++ b/Modules/sre.h @@ -76,8 +76,8 @@ typedef struct { void* mark[SRE_MARK_SIZE]; /* dynamically allocated stuff */ char* data_stack; - int data_stack_size; - int data_stack_base; + unsigned int data_stack_size; + unsigned int data_stack_base; /* current repeat context */ SRE_REPEAT *repeat; /* hooks */ |