mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
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 commitb5047fd019in 2004 for MacOSX and FreeBSD. * Test removed by commit52ddaefb6bin 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 commitfb1f68ed7c(in 2001).
This commit is contained in:
parent
1796c191b4
commit
03c4080c71
22 changed files with 86 additions and 114 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue