[Python-checkins] cpython (merge 3.3 -> default): Issue #17173: Remove uses of locale-dependent C functions (isalpha() etc.) in

antoine.pitrou python-checkins at python.org
Sat Feb 9 23:29:11 CET 2013


http://hg.python.org/cpython/rev/10e59553a8de
changeset:   82112:10e59553a8de
parent:      82109:99795d711a40
parent:      82111:c08bcf5302ec
user:        Antoine Pitrou <solipsis at pitrou.net>
date:        Sat Feb 09 23:16:51 2013 +0100
summary:
  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), mpdecimal (needs to build without Python.h).

files:
  Misc/NEWS                  |  3 +++
  Modules/_struct.c          |  4 ++--
  Modules/binascii.c         |  2 +-
  Objects/longobject.c       |  4 ++--
  Python/ast.c               |  2 +-
  Python/dynload_aix.c       |  3 +--
  Python/formatter_unicode.c |  2 +-
  Python/getargs.c           |  6 +++---
  Python/mystrtoul.c         |  6 +++---
  9 files changed, 17 insertions(+), 15 deletions(-)


diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@
 Core and Builtins
 -----------------
 
+- Issue #17173: Remove uses of locale-dependent C functions (isalpha() etc.)
+  in the interpreter.
+
 - Issue #17137: When an Unicode string is resized, the internal wide character
   string (wstr) format is now cleared.
 
diff --git a/Modules/_struct.c b/Modules/_struct.c
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -1270,7 +1270,7 @@
     size = 0;
     len = 0;
     while ((c = *s++) != '\0') {
-        if (isspace(Py_CHARMASK(c)))
+        if (Py_ISSPACE(Py_CHARMASK(c)))
             continue;
         if ('0' <= c && c <= '9') {
             num = c - '0';
@@ -1335,7 +1335,7 @@
     s = fmt;
     size = 0;
     while ((c = *s++) != '\0') {
-        if (isspace(Py_CHARMASK(c)))
+        if (Py_ISSPACE(Py_CHARMASK(c)))
             continue;
         if ('0' <= c && c <= '9') {
             num = c - '0';
diff --git a/Modules/binascii.c b/Modules/binascii.c
--- a/Modules/binascii.c
+++ b/Modules/binascii.c
@@ -1135,7 +1135,7 @@
 static int
 to_int(int c)
 {
-    if (isdigit(c))
+    if (Py_ISDIGIT(c))
         return c - '0';
     else {
         if (Py_ISUPPER(c))
diff --git a/Objects/longobject.c b/Objects/longobject.c
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -2008,7 +2008,7 @@
                         "int() arg 2 must be >= 2 and <= 36");
         return NULL;
     }
-    while (*str != '\0' && isspace(Py_CHARMASK(*str)))
+    while (*str != '\0' && Py_ISSPACE(Py_CHARMASK(*str)))
         str++;
     if (*str == '+')
         ++str;
@@ -2252,7 +2252,7 @@
         goto onError;
     if (sign < 0)
         Py_SIZE(z) = -(Py_SIZE(z));
-    while (*str && isspace(Py_CHARMASK(*str)))
+    while (*str && Py_ISSPACE(Py_CHARMASK(*str)))
         str++;
     if (*str != '\0')
         goto onError;
diff --git a/Python/ast.c b/Python/ast.c
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -3761,7 +3761,7 @@
     int quote = Py_CHARMASK(*s);
     int rawmode = 0;
     int need_encoding;
-    if (isalpha(quote)) {
+    if (Py_ISALPHA(quote)) {
         while (!*bytesmode || !rawmode) {
             if (quote == 'b' || quote == 'B') {
                 quote = *++s;
diff --git a/Python/dynload_aix.c b/Python/dynload_aix.c
--- a/Python/dynload_aix.c
+++ b/Python/dynload_aix.c
@@ -4,7 +4,6 @@
 #include "Python.h"
 #include "importdl.h"
 
-#include <ctype.h>      /*  for isdigit()         */
 #include <errno.h>      /*  for global errno      */
 #include <string.h>     /*  for strerror()        */
 #include <stdlib.h>     /*  for malloc(), free()  */
@@ -141,7 +140,7 @@
             if (nerr == load_errtab[j].errNo && load_errtab[j].errstr)
             ERRBUF_APPEND(load_errtab[j].errstr);
         }
-        while (isdigit(Py_CHARMASK(*message[i]))) message[i]++ ;
+        while (Py_ISDIGIT(Py_CHARMASK(*message[i]))) message[i]++ ;
         ERRBUF_APPEND(message[i]);
         ERRBUF_APPEND("\n");
     }
diff --git a/Python/formatter_unicode.c b/Python/formatter_unicode.c
--- a/Python/formatter_unicode.c
+++ b/Python/formatter_unicode.c
@@ -401,7 +401,7 @@
 {
     Py_ssize_t remainder;
 
-    while (pos<end && isdigit(PyUnicode_READ_CHAR(s, pos)))
+    while (pos<end && Py_ISDIGIT(PyUnicode_READ_CHAR(s, pos)))
         ++pos;
     remainder = pos;
 
diff --git a/Python/getargs.c b/Python/getargs.c
--- a/Python/getargs.c
+++ b/Python/getargs.c
@@ -244,7 +244,7 @@
             if (level == 0) {
                 if (c == 'O')
                     max++;
-                else if (isalpha(Py_CHARMASK(c))) {
+                else if (Py_ISALPHA(Py_CHARMASK(c))) {
                     if (c != 'e') /* skip encoded */
                         max++;
                 } else if (c == '|')
@@ -336,7 +336,7 @@
         }
     }
 
-    if (*format != '\0' && !isalpha(Py_CHARMASK(*format)) &&
+    if (*format != '\0' && !Py_ISALPHA(Py_CHARMASK(*format)) &&
         *format != '(' &&
         *format != '|' && *format != ':' && *format != ';') {
         PyErr_Format(PyExc_SystemError,
@@ -429,7 +429,7 @@
         }
         else if (c == ':' || c == ';' || c == '\0')
             break;
-        else if (level == 0 && isalpha(Py_CHARMASK(c)))
+        else if (level == 0 && Py_ISALPHA(Py_CHARMASK(c)))
             n++;
     }
 
diff --git a/Python/mystrtoul.c b/Python/mystrtoul.c
--- a/Python/mystrtoul.c
+++ b/Python/mystrtoul.c
@@ -99,7 +99,7 @@
     register int ovlimit;       /* required digits to overflow */
 
     /* skip leading white space */
-    while (*str && isspace(Py_CHARMASK(*str)))
+    while (*str && Py_ISSPACE(Py_CHARMASK(*str)))
         ++str;
 
     /* check for leading 0b, 0o or 0x for auto-base or base 16 */
@@ -138,7 +138,7 @@
                 /* skip all zeroes... */
                 while (*str == '0')
                     ++str;
-                while (isspace(Py_CHARMASK(*str)))
+                while (Py_ISSPACE(Py_CHARMASK(*str)))
                     ++str;
                 if (ptr)
                     *ptr = str;
@@ -266,7 +266,7 @@
     unsigned long uresult;
     char sign;
 
-    while (*str && isspace(Py_CHARMASK(*str)))
+    while (*str && Py_ISSPACE(Py_CHARMASK(*str)))
         str++;
 
     sign = *str;

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list