Skip to content

Commit 7f7f274

Browse files
committed
use Py_CHARMASK
1 parent 760dd10 commit 7f7f274

5 files changed

Lines changed: 27 additions & 22 deletions

File tree

‎Modules/regexmodule.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3535
#include "modsupport.h"
3636

3737
#include "regexpr.h"
38-
#include "ctype.h"
38+
#include <ctype.h>
3939

4040
static object *RegexError; /* Exception */
4141

@@ -433,7 +433,7 @@ symcomp(pattern, gdict)
433433
++o; /* eat the '>' */
434434
break;
435435
}
436-
if (!isalnum(*o) && *o != '_') {
436+
if (!isalnum(Py_CHARMASK(*o)) && *o != '_') {
437437
o = backtrack;
438438
break;
439439
}

‎Modules/stropmodule.c‎

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ strop_split(self, args)
4141
{
4242
int len, i, j, err;
4343
char *s;
44-
char c;
4544
object *list, *item;
4645

4746
if (!getargs(args, "s#", &s, &len))
@@ -52,13 +51,11 @@ strop_split(self, args)
5251

5352
i = 0;
5453
while (i < len) {
55-
while (i < len &&
56-
((c = s[i]), isspace(c))) {
54+
while (i < len && isspace(Py_CHARMASK(s[i]))) {
5755
i = i+1;
5856
}
5957
j = i;
60-
while (i < len &&
61-
!((c = s[i]), isspace(c))) {
58+
while (i < len && isspace(Py_CHARMASK(s[i]))) {
6259
i = i+1;
6360
}
6461
if (j < i) {
@@ -269,20 +266,19 @@ strop_strip(self, args)
269266
{
270267
char *s;
271268
int len, i, j;
272-
char c;
273269

274270
if (!getargs(args, "s#", &s, &len))
275271
return NULL;
276272

277273
i = 0;
278-
while (i < len && ((c = s[i]), isspace(c))) {
274+
while (i < len && isspace(Py_CHARMASK(s[i]))) {
279275
i++;
280276
}
281277

282278
j = len;
283279
do {
284280
j--;
285-
} while (j >= i && ((c = s[j]), isspace(c)));
281+
} while (j >= i && isspace(Py_CHARMASK(s[i])));
286282
j++;
287283

288284
if (i == 0 && j == len) {
@@ -312,7 +308,7 @@ strop_lower(self, args)
312308
s_new = getstringvalue(new);
313309
changed = 0;
314310
for (i = 0; i < n; i++) {
315-
char c = *s++;
311+
int c = Py_CHARMASK(*s++);
316312
if (isupper(c)) {
317313
changed = 1;
318314
*s_new = tolower(c);
@@ -347,7 +343,7 @@ strop_upper(self, args)
347343
s_new = getstringvalue(new);
348344
changed = 0;
349345
for (i = 0; i < n; i++) {
350-
char c = *s++;
346+
int c = Py_CHARMASK(*s++);
351347
if (islower(c)) {
352348
changed = 1;
353349
*s_new = toupper(c);
@@ -382,7 +378,7 @@ strop_swapcase(self, args)
382378
s_new = getstringvalue(new);
383379
changed = 0;
384380
for (i = 0; i < n; i++) {
385-
char c = *s++;
381+
int c = Py_CHARMASK(*s++);
386382
if (islower(c)) {
387383
changed = 1;
388384
*s_new = toupper(c);
@@ -530,7 +526,7 @@ initstrop()
530526

531527
/* Create 'whitespace' object */
532528
n = 0;
533-
for (c = 1; c < 256; c++) {
529+
for (c = 0; c < 256; c++) {
534530
if (isspace(c))
535531
buf[n++] = c;
536532
}
@@ -541,7 +537,7 @@ initstrop()
541537
}
542538
/* Create 'lowercase' object */
543539
n = 0;
544-
for (c = 1; c < 256; c++) {
540+
for (c = 0; c < 256; c++) {
545541
if (islower(c))
546542
buf[n++] = c;
547543
}
@@ -553,7 +549,7 @@ initstrop()
553549

554550
/* Create 'uppercase' object */
555551
n = 0;
556-
for (c = 1; c < 256; c++) {
552+
for (c = 0; c < 256; c++) {
557553
if (isupper(c))
558554
buf[n++] = c;
559555
}

‎Python/ceval.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,8 @@ eval_code(co, globals, locals, owner, arg)
753753
/* XXX move into writeobject() ? */
754754
char *s = getstringvalue(v);
755755
int len = getstringsize(v);
756-
if (len > 0 && isspace(s[len-1]) &&
756+
if (len > 0 &&
757+
isspace(Py_CHARMASK(s[len-1])) &&
757758
s[len-1] != ' ')
758759
softspace(w, 0);
759760
}

‎Python/compile.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,12 @@ parsestr(s)
608608
*p++ = c;
609609
break;
610610
case 'x':
611-
if (isxdigit(*s)) {
611+
if (isxdigit(Py_CHARMASK(*s))) {
612612
sscanf(s, "%x", &c);
613613
*p++ = c;
614614
do {
615615
s++;
616-
} while (isxdigit(*s));
616+
} while (isxdigit(Py_CHARMASK(*s)));
617617
break;
618618
}
619619
/* FALLTHROUGH */

‎Python/mystrtoul.c‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
2626
#include "config.h"
2727
#endif
2828

29+
/* Convert a possibly signed character to a nonnegative int */
30+
/* XXX This assumes characters are 8 bits wide */
31+
#ifdef __CHAR_UNSIGNED__
32+
#define Py_CHARMASK(c) (c)
33+
#else
34+
#define Py_CHARMASK(c) ((c) & 0xff)
35+
#endif
36+
2937
#include "rename2.h"
3038

3139
/* strtol and strtoul, renamed to avoid conflicts */
@@ -70,7 +78,7 @@ int base;
7078
}
7179

7280
/* skip leading white space */
73-
while (*str && isspace(*str))
81+
while (*str && isspace(Py_CHARMASK(*str)))
7482
str++;
7583

7684
/* check for leading 0 or 0x for auto-base or base 16 */
@@ -99,7 +107,7 @@ int base;
99107
}
100108

101109
/* do the conversion */
102-
while (c = *str)
110+
while (c = Py_CHARMASK(*str))
103111
{
104112
if (isdigit(c) && c - '0' < base)
105113
c -= '0';
@@ -143,7 +151,7 @@ int base;
143151
long result;
144152
char sign;
145153

146-
while (*str && isspace(*str))
154+
while (*str && isspace(Py_CHARMASK(*str)))
147155
str++;
148156

149157
sign = *str;

0 commit comments

Comments
 (0)