Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4de7457

Browse files
committed
Issue #17173: Remove uses of locale-dependent C functions (isalpha() etc.) in the interpreter.
I've left a couple of them in: zlib (third-party lib), getaddrinfo.c (doesn't include Python.h, and probably obsolete), _sre.c (legitimate use for the re.LOCALE flag).
1 parent b6ed173 commit 4de7457

11 files changed

Lines changed: 19 additions & 17 deletions

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #17173: Remove uses of locale-dependent C functions (isalpha() etc.)
14+
in the interpreter.
15+
1316
- Issue #17043: The unicode-internal decoder no longer read past the end of
1417
input buffer.
1518

Modules/_struct.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ prepare_s(PyStructObject *self)
11841184
size = 0;
11851185
len = 0;
11861186
while ((c = *s++) != '\0') {
1187-
if (isspace(Py_CHARMASK(c)))
1187+
if (Py_ISSPACE(Py_CHARMASK(c)))
11881188
continue;
11891189
if ('0' <= c && c <= '9') {
11901190
num = c - '0';
@@ -1249,7 +1249,7 @@ prepare_s(PyStructObject *self)
12491249
s = fmt;
12501250
size = 0;
12511251
while ((c = *s++) != '\0') {
1252-
if (isspace(Py_CHARMASK(c)))
1252+
if (Py_ISSPACE(Py_CHARMASK(c)))
12531253
continue;
12541254
if ('0' <= c && c <= '9') {
12551255
num = c - '0';

Modules/binascii.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ This function is also available as \"hexlify()\".");
10991099
static int
11001100
to_int(int c)
11011101
{
1102-
if (isdigit(c))
1102+
if (Py_ISDIGIT(c))
11031103
return c - '0';
11041104
else {
11051105
if (Py_ISUPPER(c))

Modules/posixmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ os2_formatmsg(char *msgbuf, int msglen, char *reason)
695695
if (strlen(msgbuf) > 0) { /* If Non-Empty Msg, Trim CRLF */
696696
char *lastc = &msgbuf[ strlen(msgbuf)-1 ];
697697

698-
while (lastc > msgbuf && isspace(Py_CHARMASK(*lastc)))
698+
while (lastc > msgbuf && Py_ISSPACE(Py_CHARMASK(*lastc)))
699699
*lastc-- = '\0'; /* Trim Trailing Whitespace (CRLF) */
700700
}
701701

Modules/socketmodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ set_error(void)
519519
/* If non-empty msg, trim CRLF */
520520
char *lastc = &outbuf[ strlen(outbuf)-1 ];
521521
while (lastc > outbuf &&
522-
isspace(Py_CHARMASK(*lastc))) {
522+
Py_ISSPACE(Py_CHARMASK(*lastc))) {
523523
/* Trim trailing whitespace (CRLF) */
524524
*lastc-- = '\0';
525525
}

Objects/longobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ PyLong_FromString(char *str, char **pend, int base)
18871887
"int() arg 2 must be >= 2 and <= 36");
18881888
return NULL;
18891889
}
1890-
while (*str != '\0' && isspace(Py_CHARMASK(*str)))
1890+
while (*str != '\0' && Py_ISSPACE(Py_CHARMASK(*str)))
18911891
str++;
18921892
if (*str == '+')
18931893
++str;
@@ -2131,7 +2131,7 @@ digit beyond the first.
21312131
goto onError;
21322132
if (sign < 0)
21332133
Py_SIZE(z) = -(Py_SIZE(z));
2134-
while (*str && isspace(Py_CHARMASK(*str)))
2134+
while (*str && Py_ISSPACE(Py_CHARMASK(*str)))
21352135
str++;
21362136
if (*str != '\0')
21372137
goto onError;

Objects/stringlib/formatter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ parse_number(STRINGLIB_CHAR *ptr, Py_ssize_t len,
414414
STRINGLIB_CHAR *end = ptr + len;
415415
STRINGLIB_CHAR *remainder;
416416

417-
while (ptr<end && isdigit(*ptr))
417+
while (ptr<end && Py_ISDIGIT(*ptr))
418418
++ptr;
419419
remainder = ptr;
420420

Python/ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3305,7 +3305,7 @@ parsestr(struct compiling *c, const node *n, int *bytesmode)
33053305
int quote = Py_CHARMASK(*s);
33063306
int rawmode = 0;
33073307
int need_encoding;
3308-
if (isalpha(quote)) {
3308+
if (Py_ISALPHA(quote)) {
33093309
if (quote == 'b' || quote == 'B') {
33103310
quote = *++s;
33113311
*bytesmode = 1;

Python/dynload_aix.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "Python.h"
55
#include "importdl.h"
66

7-
#include <ctype.h> /* for isdigit() */
87
#include <errno.h> /* for global errno */
98
#include <string.h> /* for strerror() */
109
#include <stdlib.h> /* for malloc(), free() */
@@ -144,7 +143,7 @@ aix_loaderror(const char *pathname)
144143
if (nerr == load_errtab[j].errNo && load_errtab[j].errstr)
145144
ERRBUF_APPEND(load_errtab[j].errstr);
146145
}
147-
while (isdigit(Py_CHARMASK(*message[i]))) message[i]++ ;
146+
while (Py_ISDIGIT(Py_CHARMASK(*message[i]))) message[i]++ ;
148147
ERRBUF_APPEND(message[i]);
149148
ERRBUF_APPEND("\n");
150149
}

Python/getargs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ vgetargs1(PyObject *args, const char *format, va_list *p_va, int flags)
288288
if (level == 0) {
289289
if (c == 'O')
290290
max++;
291-
else if (isalpha(Py_CHARMASK(c))) {
291+
else if (Py_ISALPHA(Py_CHARMASK(c))) {
292292
if (c != 'e') /* skip encoded */
293293
max++;
294294
} else if (c == '|')
@@ -378,7 +378,7 @@ vgetargs1(PyObject *args, const char *format, va_list *p_va, int flags)
378378
}
379379
}
380380

381-
if (*format != '\0' && !isalpha(Py_CHARMASK(*format)) &&
381+
if (*format != '\0' && !Py_ISALPHA(Py_CHARMASK(*format)) &&
382382
*format != '(' &&
383383
*format != '|' && *format != ':' && *format != ';') {
384384
PyErr_Format(PyExc_SystemError,
@@ -471,7 +471,7 @@ converttuple(PyObject *arg, const char **p_format, va_list *p_va, int flags,
471471
}
472472
else if (c == ':' || c == ';' || c == '\0')
473473
break;
474-
else if (level == 0 && isalpha(Py_CHARMASK(c)))
474+
else if (level == 0 && Py_ISALPHA(Py_CHARMASK(c)))
475475
n++;
476476
}
477477

0 commit comments

Comments
 (0)