]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Revert r61969 which added casts to Py_CHARMASK to avoid compiler warnings.
authorNeal Norwitz <nnorwitz@gmail.com>
Fri, 28 Mar 2008 04:58:51 +0000 (04:58 +0000)
committerNeal Norwitz <nnorwitz@gmail.com>
Fri, 28 Mar 2008 04:58:51 +0000 (04:58 +0000)
Rather than sprinkle casts throughout the code, change Py_CHARMASK to
always cast it's result to an unsigned char.  This should ensure we
do the right thing when accessing an array with the result.

Include/Python.h
Include/bytes_methods.h
Objects/longobject.c
Objects/unicodeobject.c
Parser/tokenizer.c
Python/mystrtoul.c

index a5e28539c0e017f1cdc333492f8b449197764464..4cffda3fd8bd411d5b7a91895f64fa02044ca6ea 100644 (file)
@@ -148,7 +148,7 @@ PyAPI_FUNC(PyObject*) _Py_Mangle(PyObject *p, PyObject *name);
 #ifdef __CHAR_UNSIGNED__
 #define Py_CHARMASK(c)         (c)
 #else
-#define Py_CHARMASK(c)         ((c) & 0xff)
+#define Py_CHARMASK(c)         ((unsigned char)((c) & 0xff))
 #endif
 
 #include "pyfpe.h"
index a05e11f433dcea28f00a05a8d78716d4f800a924..59873f29a0737849688b935990e0a3b7406e8da2 100644 (file)
@@ -44,13 +44,13 @@ extern const char _Py_swapcase__doc__[];
 
 extern const unsigned int _Py_ctype_table[256];
 
-#define ISLOWER(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_LOWER)
-#define ISUPPER(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_UPPER)
-#define ISALPHA(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_ALPHA)
-#define ISDIGIT(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_DIGIT)
-#define ISXDIGIT(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_XDIGIT)
-#define ISALNUM(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_ALNUM)
-#define ISSPACE(c) (_Py_ctype_table[(unsigned)Py_CHARMASK(c)] & FLAG_SPACE)
+#define ISLOWER(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_LOWER)
+#define ISUPPER(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_UPPER)
+#define ISALPHA(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_ALPHA)
+#define ISDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_DIGIT)
+#define ISXDIGIT(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_XDIGIT)
+#define ISALNUM(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_ALNUM)
+#define ISSPACE(c) (_Py_ctype_table[Py_CHARMASK(c)] & FLAG_SPACE)
 
 #undef islower
 #define islower(c) undefined_islower(c)
index 0fd699c0bb65211b20070ac47f67391bb800352d..2e13d6141f17f83164b345a30ec8a6e006fab054 100644 (file)
@@ -1397,7 +1397,7 @@ long_from_binary_base(char **str, int base)
                n >>= 1;
        /* n <- total # of bits needed, while setting p to end-of-string */
        n = 0;
-       while (_PyLong_DigitValue[(unsigned)Py_CHARMASK(*p)] < base)
+       while (_PyLong_DigitValue[Py_CHARMASK(*p)] < base)
                ++p;
        *str = p;
        /* n <- # of Python digits needed, = ceiling(n/PyLong_SHIFT). */
@@ -1418,7 +1418,7 @@ long_from_binary_base(char **str, int base)
        bits_in_accum = 0;
        pdigit = z->ob_digit;
        while (--p >= start) {
-               int k = _PyLong_DigitValue[(unsigned)Py_CHARMASK(*p)];
+               int k = _PyLong_DigitValue[Py_CHARMASK(*p)];
                assert(k >= 0 && k < base);
                accum |= (twodigits)(k << bits_in_accum);
                bits_in_accum += bits_per_char;
@@ -1609,7 +1609,7 @@ digit beyond the first.
 
                /* Find length of the string of numeric characters. */
                scan = str;
-               while (_PyLong_DigitValue[(unsigned)Py_CHARMASK(*scan)] < base)
+               while (_PyLong_DigitValue[Py_CHARMASK(*scan)] < base)
                        ++scan;
 
                /* Create a long object that can contain the largest possible
@@ -1635,10 +1635,10 @@ digit beyond the first.
                /* Work ;-) */
                while (str < scan) {
                        /* grab up to convwidth digits from the input string */
-                       c = (digit)_PyLong_DigitValue[(unsigned)Py_CHARMASK(*str++)];
+                       c = (digit)_PyLong_DigitValue[Py_CHARMASK(*str++)];
                        for (i = 1; i < convwidth && str != scan; ++i, ++str) {
                                c = (twodigits)(c *  base +
-                                       _PyLong_DigitValue[(unsigned)Py_CHARMASK(*str)]);
+                                       _PyLong_DigitValue[Py_CHARMASK(*str)]);
                                assert(c < PyLong_BASE);
                        }
 
index 317d03bc1c83e10d4d8fcfe5a1c8895996ce9310..c5acd1b43ca54bbc7fa18b57e3de4f63e0487129 100644 (file)
@@ -480,13 +480,13 @@ PyObject *PyUnicode_FromStringAndSize(const char *u, Py_ssize_t size)
        /* Single characters are shared when using this constructor.
            Restrict to ASCII, since the input must be UTF-8. */
        if (size == 1 && Py_CHARMASK(*u) < 128) {
-           unicode = unicode_latin1[(unsigned)Py_CHARMASK(*u)];
+           unicode = unicode_latin1[Py_CHARMASK(*u)];
            if (!unicode) {
                unicode = _PyUnicode_New(1);
                if (!unicode)
                    return NULL;
                unicode->str[0] = Py_CHARMASK(*u);
-               unicode_latin1[(unsigned)Py_CHARMASK(*u)] = unicode;
+               unicode_latin1[Py_CHARMASK(*u)] = unicode;
            }
            Py_INCREF(unicode);
            return (PyObject *)unicode;
index 799db20543fc5421e02e98a899d07b2f842724d1..29fb1142917e145327ae5e4522ca289c53aa7d45 100644 (file)
@@ -27,14 +27,6 @@ extern char *PyOS_Readline(FILE *, FILE *, char *);
 /* Don't ever change this -- it would break the portability of Python code */
 #define TABSIZE 8
 
-/* Convert a possibly signed character to a nonnegative int */
-/* XXX This assumes characters are 8 bits wide */
-#ifdef __CHAR_UNSIGNED__
-#define Py_CHARMASK(c)         (c)
-#else
-#define Py_CHARMASK(c)         ((c) & 0xff)
-#endif
-
 /* Forward */
 static struct tok_state *tok_new(void);
 static int tok_nextc(struct tok_state *tok);
index 3d9a28dbf899617a56bb39916dad6ea6bb924fe0..ebd468c6d7a79bdc805badef9c49d142c7474060 100644 (file)
@@ -109,7 +109,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
                        ++str;
                        if (*str == 'x' || *str == 'X') {
                                /* there must be at least one digit after 0x */
-                               if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 16) {
+                               if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 16) {
                                        if (ptr)
                                                *ptr = str;
                                        return 0;
@@ -118,7 +118,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
                                base = 16;
                        } else if (*str == 'o' || *str == 'O') {
                                /* there must be at least one digit after 0o */
-                               if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 8) {
+                               if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 8) {
                                        if (ptr)
                                                *ptr = str;
                                        return 0;
@@ -127,7 +127,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
                                base = 8;
                        } else if (*str == 'b' || *str == 'B') {
                                /* there must be at least one digit after 0b */
-                               if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 2) {
+                               if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 2) {
                                        if (ptr)
                                                *ptr = str;
                                        return 0;
@@ -147,7 +147,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
                        ++str;
                        if (*str == 'b' || *str == 'B') {
                                /* there must be at least one digit after 0b */
-                               if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 2) {
+                               if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 2) {
                                        if (ptr)
                                                *ptr = str;
                                        return 0;
@@ -162,7 +162,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
                        ++str;
                        if (*str == 'o' || *str == 'O') {
                                /* there must be at least one digit after 0o */
-                               if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 8) {
+                               if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 8) {
                                        if (ptr)
                                                *ptr = str;
                                        return 0;
@@ -177,7 +177,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
                        ++str;
                        if (*str == 'x' || *str == 'X') {
                                /* there must be at least one digit after 0x */
-                               if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 16) {
+                               if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 16) {
                                        if (ptr)
                                                *ptr = str;
                                        return 0;
@@ -203,7 +203,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
        ovlimit = digitlimit[base];
 
        /* do the conversion until non-digit character encountered */
-       while ((c = _PyLong_DigitValue[(unsigned)Py_CHARMASK(*str)]) < base) {
+       while ((c = _PyLong_DigitValue[Py_CHARMASK(*str)]) < base) {
                if (ovlimit > 0) /* no overflow check required */
                        result = result * base + c;
                else { /* requires overflow check */
@@ -240,7 +240,7 @@ PyOS_strtoul(register char *str, char **ptr, int base)
 overflowed:
        if (ptr) {
                /* spool through remaining digit characters */
-               while (_PyLong_DigitValue[(unsigned)Py_CHARMASK(*str)] < base)
+               while (_PyLong_DigitValue[Py_CHARMASK(*str)] < base)
                        ++str;
                *ptr = str;
        }