since char is signed on some platforms and unsigned on others.
extern const unsigned int _Py_ctype_table[256];
-#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)
+#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)
#undef islower
#define islower(c) undefined_islower(c)
n >>= 1;
/* n <- total # of bits needed, while setting p to end-of-string */
n = 0;
- while (_PyLong_DigitValue[Py_CHARMASK(*p)] < base)
+ while (_PyLong_DigitValue[(unsigned)Py_CHARMASK(*p)] < base)
++p;
*str = p;
/* n <- # of Python digits needed, = ceiling(n/PyLong_SHIFT). */
bits_in_accum = 0;
pdigit = z->ob_digit;
while (--p >= start) {
- int k = _PyLong_DigitValue[Py_CHARMASK(*p)];
+ int k = _PyLong_DigitValue[(unsigned)Py_CHARMASK(*p)];
assert(k >= 0 && k < base);
accum |= (twodigits)(k << bits_in_accum);
bits_in_accum += bits_per_char;
/* Find length of the string of numeric characters. */
scan = str;
- while (_PyLong_DigitValue[Py_CHARMASK(*scan)] < base)
+ while (_PyLong_DigitValue[(unsigned)Py_CHARMASK(*scan)] < base)
++scan;
/* Create a long object that can contain the largest possible
/* Work ;-) */
while (str < scan) {
/* grab up to convwidth digits from the input string */
- c = (digit)_PyLong_DigitValue[Py_CHARMASK(*str++)];
+ c = (digit)_PyLong_DigitValue[(unsigned)Py_CHARMASK(*str++)];
for (i = 1; i < convwidth && str != scan; ++i, ++str) {
c = (twodigits)(c * base +
- _PyLong_DigitValue[Py_CHARMASK(*str)]);
+ _PyLong_DigitValue[(unsigned)Py_CHARMASK(*str)]);
assert(c < PyLong_BASE);
}
/* 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[Py_CHARMASK(*u)];
+ unicode = unicode_latin1[(unsigned)Py_CHARMASK(*u)];
if (!unicode) {
unicode = _PyUnicode_New(1);
if (!unicode)
return NULL;
unicode->str[0] = Py_CHARMASK(*u);
- unicode_latin1[Py_CHARMASK(*u)] = unicode;
+ unicode_latin1[(unsigned)Py_CHARMASK(*u)] = unicode;
}
Py_INCREF(unicode);
return (PyObject *)unicode;
++str;
if (*str == 'x' || *str == 'X') {
/* there must be at least one digit after 0x */
- if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 16) {
+ if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 16) {
if (ptr)
*ptr = str;
return 0;
base = 16;
} else if (*str == 'o' || *str == 'O') {
/* there must be at least one digit after 0o */
- if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 8) {
+ if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 8) {
if (ptr)
*ptr = str;
return 0;
base = 8;
} else if (*str == 'b' || *str == 'B') {
/* there must be at least one digit after 0b */
- if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 2) {
+ if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 2) {
if (ptr)
*ptr = str;
return 0;
++str;
if (*str == 'b' || *str == 'B') {
/* there must be at least one digit after 0b */
- if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 2) {
+ if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 2) {
if (ptr)
*ptr = str;
return 0;
++str;
if (*str == 'o' || *str == 'O') {
/* there must be at least one digit after 0o */
- if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 8) {
+ if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 8) {
if (ptr)
*ptr = str;
return 0;
++str;
if (*str == 'x' || *str == 'X') {
/* there must be at least one digit after 0x */
- if (_PyLong_DigitValue[Py_CHARMASK(str[1])] >= 16) {
+ if (_PyLong_DigitValue[(unsigned)Py_CHARMASK(str[1])] >= 16) {
if (ptr)
*ptr = str;
return 0;
ovlimit = digitlimit[base];
/* do the conversion until non-digit character encountered */
- while ((c = _PyLong_DigitValue[Py_CHARMASK(*str)]) < base) {
+ while ((c = _PyLong_DigitValue[(unsigned)Py_CHARMASK(*str)]) < base) {
if (ovlimit > 0) /* no overflow check required */
result = result * base + c;
else { /* requires overflow check */
overflowed:
if (ptr) {
/* spool through remaining digit characters */
- while (_PyLong_DigitValue[Py_CHARMASK(*str)] < base)
+ while (_PyLong_DigitValue[(unsigned)Py_CHARMASK(*str)] < base)
++str;
*ptr = str;
}