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().
This commit is contained in:
Victor Stinner 2023-09-01 18:36:53 +02:00 committed by GitHub
parent 03c5a68568
commit 578ebc5d5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 36 deletions

View file

@ -11,11 +11,11 @@ PyOS_mystrnicmp(const char *s1, const char *s2, Py_ssize_t size)
return 0;
p1 = (const unsigned char *)s1;
p2 = (const unsigned char *)s2;
for (; (--size > 0) && *p1 && *p2 && (tolower(*p1) == tolower(*p2));
for (; (--size > 0) && *p1 && *p2 && (Py_TOLOWER(*p1) == Py_TOLOWER(*p2));
p1++, p2++) {
;
}
return tolower(*p1) - tolower(*p2);
return Py_TOLOWER(*p1) - Py_TOLOWER(*p2);
}
int
@ -23,8 +23,8 @@ PyOS_mystricmp(const char *s1, const char *s2)
{
const unsigned char *p1 = (const unsigned char *)s1;
const unsigned char *p2 = (const unsigned char *)s2;
for (; *p1 && *p2 && (tolower(*p1) == tolower(*p2)); p1++, p2++) {
for (; *p1 && *p2 && (Py_TOLOWER(*p1) == Py_TOLOWER(*p2)); p1++, p2++) {
;
}
return (tolower(*p1) - tolower(*p2));
return (Py_TOLOWER(*p1) - Py_TOLOWER(*p2));
}