diff options
author | Victor Stinner <vstinner@python.org> | 2023-09-03 16:54:27 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-03 16:54:27 (GMT) |
commit | 03c4080c71f49df9c219354b7b38b738917fd2ed (patch) | |
tree | 77e69accecd104ce8195741923605fa713a8bb5d /Modules | |
parent | 1796c191b43ed0787d83c07be7de8118fb10e8b0 (diff) | |
download | cpython-03c4080c71f49df9c219354b7b38b738917fd2ed.zip cpython-03c4080c71f49df9c219354b7b38b738917fd2ed.tar.gz cpython-03c4080c71f49df9c219354b7b38b738917fd2ed.tar.bz2 |
gh-108765: Python.h no longer includes <ctype.h> (#108831)
Remove <ctype.h> in C files which don't use it; only sre.c and
_decimal.c still use it.
Remove _PY_PORT_CTYPE_UTF8_ISSUE code from pyport.h:
* Code added by commit b5047fd01948ab108edcc1b3c2c901d915814cfd
in 2004 for MacOSX and FreeBSD.
* Test removed by commit 52ddaefb6bab1a74ecffe8519c02735794ebfbe1
in 2007, since Python str type now uses locale independent
functions like Py_ISALPHA() and Py_TOLOWER() and the Unicode
database.
Modules/_sre/sre.c replaces _PY_PORT_CTYPE_UTF8_ISSUE with new
functions: sre_isalnum(), sre_tolower(), sre_toupper().
Remove unused includes:
* _localemodule.c: remove <stdio.h>.
* getargs.c: remove <float.h>.
* dynload_win.c: remove <direct.h>, it no longer calls _getcwd()
since commit fb1f68ed7cc1536482d1debd70a53c5442135fe2 (in 2001).
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_localemodule.c | 34 | ||||
-rw-r--r-- | Modules/_sre/sre.c | 38 | ||||
-rw-r--r-- | Modules/_struct.c | 1 | ||||
-rw-r--r-- | Modules/_tkinter.c | 13 | ||||
-rw-r--r-- | Modules/_zoneinfo.c | 7 | ||||
-rw-r--r-- | Modules/pyexpat.c | 1 | ||||
-rw-r--r-- | Modules/timemodule.c | 7 |
7 files changed, 57 insertions, 44 deletions
diff --git a/Modules/_localemodule.c b/Modules/_localemodule.c index 1847a48..fe8e4c5 100644 --- a/Modules/_localemodule.c +++ b/Modules/_localemodule.c @@ -10,35 +10,25 @@ This software comes with no warranty. Use at your own risk. ******************************************************************/ #include "Python.h" -#include "pycore_fileutils.h" -#include "pycore_pymem.h" // _PyMem_Strdup - -#include <stdio.h> -#include <locale.h> -#include <string.h> -#include <ctype.h> +#include "pycore_fileutils.h" // _Py_GetLocaleconvNumeric() +#include "pycore_pymem.h" // _PyMem_Strdup() +#include <locale.h> // setlocale() +#include <string.h> // strlen() #ifdef HAVE_ERRNO_H -#include <errno.h> +# include <errno.h> // errno #endif - #ifdef HAVE_LANGINFO_H -#include <langinfo.h> +# include <langinfo.h> // nl_langinfo() #endif - #ifdef HAVE_LIBINTL_H -#include <libintl.h> -#endif - -#ifdef HAVE_WCHAR_H -#include <wchar.h> +# include <libintl.h> #endif - -#if defined(MS_WINDOWS) -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include <windows.h> +#ifdef MS_WINDOWS +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# include <windows.h> #endif PyDoc_STRVAR(locale__doc__, "Support for POSIX locales."); diff --git a/Modules/_sre/sre.c b/Modules/_sre/sre.c index 3872c36..07da5da 100644 --- a/Modules/_sre/sre.c +++ b/Modules/_sre/sre.c @@ -43,12 +43,40 @@ static const char copyright[] = #include "pycore_long.h" // _PyLong_GetZero() #include "pycore_moduleobject.h" // _PyModule_GetState() +#include "sre.h" // SRE_CODE -#include "sre.h" +#include <ctype.h> // tolower(), toupper(), isalnum() #define SRE_CODE_BITS (8 * sizeof(SRE_CODE)) -#include <ctype.h> +// On macOS, use the wide character ctype API using btowc() +#if defined(__APPLE__) +# define USE_CTYPE_WINT_T +#endif + +static int sre_isalnum(unsigned int ch) { +#ifdef USE_CTYPE_WINT_T + return (unsigned int)iswalnum(btowc((int)ch)); +#else + return (unsigned int)isalnum((int)ch); +#endif +} + +static unsigned int sre_tolower(unsigned int ch) { +#ifdef USE_CTYPE_WINT_T + return (unsigned int)towlower(btowc((int)ch)); +#else + return (unsigned int)tolower((int)ch); +#endif +} + +static unsigned int sre_toupper(unsigned int ch) { +#ifdef USE_CTYPE_WINT_T + return (unsigned int)towupper(btowc((int)ch)); +#else + return (unsigned int)toupper((int)ch); +#endif +} /* Defining this one controls tracing: * 0 -- disabled @@ -114,17 +142,17 @@ static unsigned int sre_lower_ascii(unsigned int ch) /* locale-specific character predicates */ /* !(c & ~N) == (c < N+1) for any unsigned c, this avoids * warnings when c's type supports only numbers < N+1 */ -#define SRE_LOC_IS_ALNUM(ch) (!((ch) & ~255) ? isalnum((ch)) : 0) +#define SRE_LOC_IS_ALNUM(ch) (!((ch) & ~255) ? sre_isalnum((ch)) : 0) #define SRE_LOC_IS_WORD(ch) (SRE_LOC_IS_ALNUM((ch)) || (ch) == '_') static unsigned int sre_lower_locale(unsigned int ch) { - return ((ch) < 256 ? (unsigned int)tolower((ch)) : ch); + return ((ch) < 256 ? (unsigned int)sre_tolower((ch)) : ch); } static unsigned int sre_upper_locale(unsigned int ch) { - return ((ch) < 256 ? (unsigned int)toupper((ch)) : ch); + return ((ch) < 256 ? (unsigned int)sre_toupper((ch)) : ch); } /* unicode-specific character predicates */ diff --git a/Modules/_struct.c b/Modules/_struct.c index be4c23a..1f8f9c4 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -12,7 +12,6 @@ #include "pycore_long.h" // _PyLong_AsByteArray() #include "pycore_moduleobject.h" // _PyModule_GetState() -#include <ctype.h> #include <stddef.h> // offsetof() /*[clinic input] diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index 663b411..f9a1864 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -26,15 +26,14 @@ Copyright (C) 1994 Steen Lumholt. #endif #include "Python.h" -#include <ctype.h> #ifdef MS_WINDOWS # include "pycore_fileutils.h" // _Py_stat() #endif -#include "pycore_long.h" +#include "pycore_long.h" // _PyLong_IsNegative() #ifdef MS_WINDOWS -#include <windows.h> +# include <windows.h> #endif #define CHECK_SIZE(size, elemsize) \ @@ -46,11 +45,11 @@ Copyright (C) 1994 Steen Lumholt. #define TCL_THREADS #ifdef TK_FRAMEWORK -#include <Tcl/tcl.h> -#include <Tk/tk.h> +# include <Tcl/tcl.h> +# include <Tk/tk.h> #else -#include <tcl.h> -#include <tk.h> +# include <tcl.h> +# include <tk.h> #endif #include "tkinter.h" diff --git a/Modules/_zoneinfo.c b/Modules/_zoneinfo.c index 3f7b285..eb4e522 100644 --- a/Modules/_zoneinfo.c +++ b/Modules/_zoneinfo.c @@ -6,11 +6,10 @@ #include "pycore_long.h" // _PyLong_GetOne() #include "pycore_pyerrors.h" // _PyErr_ChainExceptions1() -#include <ctype.h> -#include <stddef.h> -#include <stdint.h> +#include "datetime.h" // PyDateTime_TZInfo -#include "datetime.h" +#include <stddef.h> // offsetof() +#include <stdint.h> #include "clinic/_zoneinfo.c.h" /*[clinic input] diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c index 52dd06c..bd24523 100644 --- a/Modules/pyexpat.c +++ b/Modules/pyexpat.c @@ -7,7 +7,6 @@ #include "pycore_pyhash.h" // _Py_HashSecret #include "pycore_traceback.h" // _PyTraceback_Add() -#include <ctype.h> #include <stddef.h> // offsetof() #include "expat.h" #include "pyexpat.h" diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 4e55da7..a2b6652 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -6,22 +6,21 @@ #include "pycore_namespace.h" // _PyNamespace_New() #include "pycore_runtime.h" // _Py_ID() -#include <ctype.h> #include <time.h> // clock() #ifdef HAVE_SYS_TIMES_H -# include <sys/times.h> +# include <sys/times.h> // times() #endif #ifdef HAVE_SYS_TYPES_H # include <sys/types.h> #endif #if defined(HAVE_SYS_RESOURCE_H) -# include <sys/resource.h> +# include <sys/resource.h> // getrusage(RUSAGE_SELF) #endif #ifdef QUICKWIN # include <io.h> #endif #if defined(HAVE_PTHREAD_H) -# include <pthread.h> +# include <pthread.h> // pthread_getcpuclockid() #endif #if defined(_AIX) # include <sys/thread.h> |