summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2023-09-01 16:36:53 (GMT)
committerGitHub <noreply@github.com>2023-09-01 16:36:53 (GMT)
commit578ebc5d5fab2e5e0b87636361c6aeb8d2b287fa (patch)
tree36df000be6a6d903c51fe5db44e9cf93625cadeb /Modules
parent03c5a685689fd4891d01caff8da01096fcf73d5a (diff)
downloadcpython-578ebc5d5fab2e5e0b87636361c6aeb8d2b287fa.zip
cpython-578ebc5d5fab2e5e0b87636361c6aeb8d2b287fa.tar.gz
cpython-578ebc5d5fab2e5e0b87636361c6aeb8d2b287fa.tar.bz2
gh-108767: Replace ctype.h functions with pyctype.h functions (#108772)
Replace <ctype.h> locale dependent functions with Python "pyctype.h" locale independent functions: * Replace isalpha() with Py_ISALPHA(). * Replace isdigit() with Py_ISDIGIT(). * Replace isxdigit() with Py_ISXDIGIT(). * Replace tolower() with Py_TOLOWER(). Leave Modules/_sre/sre.c unchanged, it uses locale dependent functions on purpose. Include explicitly <ctype.h> in _decimal.c to get isascii().
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_decimal/_decimal.c1
-rw-r--r--Modules/_zoneinfo.c14
-rw-r--r--Modules/getaddrinfo.c4
3 files changed, 10 insertions, 9 deletions
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
index 585214c..b49ea3c 100644
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -35,6 +35,7 @@
#include "complexobject.h"
#include "mpdecimal.h"
+#include <ctype.h> // isascii()
#include <stdlib.h>
#include "docstrings.h"
diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c
index 09f5fd4..3f7b285 100644
--- a/Modules/_zoneinfo.c
+++ b/Modules/_zoneinfo.c
@@ -1701,7 +1701,7 @@ error:
static int
parse_uint(const char *const p, uint8_t *value)
{
- if (!isdigit(*p)) {
+ if (!Py_ISDIGIT(*p)) {
return -1;
}
@@ -1732,7 +1732,7 @@ parse_abbr(const char *const p, PyObject **abbr)
// '+' ) character, or the minus-sign ( '-' ) character. The std
// and dst fields in this case shall not include the quoting
// characters.
- if (!isalpha(buff) && !isdigit(buff) && buff != '+' &&
+ if (!Py_ISALPHA(buff) && !Py_ISDIGIT(buff) && buff != '+' &&
buff != '-') {
return -1;
}
@@ -1748,7 +1748,7 @@ parse_abbr(const char *const p, PyObject **abbr)
// In the unquoted form, all characters in these fields shall be
// alphabetic characters from the portable character set in the
// current locale.
- while (isalpha(*ptr)) {
+ while (Py_ISALPHA(*ptr)) {
ptr++;
}
str_end = ptr;
@@ -1802,7 +1802,7 @@ parse_tz_delta(const char *const p, long *total_seconds)
// The hour can be 1 or 2 numeric characters
for (size_t i = 0; i < 2; ++i) {
buff = *ptr;
- if (!isdigit(buff)) {
+ if (!Py_ISDIGIT(buff)) {
if (i == 0) {
return -1;
}
@@ -1830,7 +1830,7 @@ parse_tz_delta(const char *const p, long *total_seconds)
for (size_t j = 0; j < 2; ++j) {
buff = *ptr;
- if (!isdigit(buff)) {
+ if (!Py_ISDIGIT(buff)) {
return -1;
}
*(outputs[i]) *= 10;
@@ -1932,7 +1932,7 @@ parse_transition_rule(const char *const p, TransitionRuleType **out)
}
for (size_t i = 0; i < 3; ++i) {
- if (!isdigit(*ptr)) {
+ if (!Py_ISDIGIT(*ptr)) {
if (i == 0) {
return -1;
}
@@ -2007,7 +2007,7 @@ parse_transition_time(const char *const p, int8_t *hour, int8_t *minute,
uint8_t buff = 0;
for (size_t j = 0; j < 2; j++) {
- if (!isdigit(*ptr)) {
+ if (!Py_ISDIGIT(*ptr)) {
if (i == 0 && j > 0) {
break;
}
diff --git a/Modules/getaddrinfo.c b/Modules/getaddrinfo.c
index f1c28d7..6fb6062 100644
--- a/Modules/getaddrinfo.c
+++ b/Modules/getaddrinfo.c
@@ -51,7 +51,6 @@
#include <string.h>
#include <stdlib.h>
#include <stddef.h>
-#include <ctype.h>
#include <unistd.h>
#include "addrinfo.h"
@@ -228,8 +227,9 @@ str_isnumber(const char *p)
{
unsigned char *q = (unsigned char *)p;
while (*q) {
- if (! isdigit(*q))
+ if (!Py_ISDIGIT(*q)) {
return NO;
+ }
q++;
}
return YES;