gh-106320: Remove private AC converter functions (#108505)

Move these private functions to the internal C API
(pycore_abstract.h):

* _Py_convert_optional_to_ssize_t()
* _PyNumber_Index()

Argument Clinic now emits #include "pycore_abstract.h" when these
functions are used.

The parser of the c-analyzer tool now uses a list of files which use
the limited C API, rather than a list of files using the internal C
API.
This commit is contained in:
Victor Stinner 2023-08-26 04:05:17 +02:00 committed by GitHub
parent 6353c21b78
commit 8ba4714611
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 88 additions and 62 deletions

View File

@ -53,13 +53,3 @@ PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject *o, Py_ssize_t);
need to be corrected for a negative index. */
#define PySequence_ITEM(o, i)\
( Py_TYPE(o)->tp_as_sequence->sq_item((o), (i)) )
/* === Mapping protocol ================================================= */
// Convert Python int to Py_ssize_t. Do nothing if the argument is None.
// Cannot be moved to the internal C API: used by Argument Clinic.
PyAPI_FUNC(int) _Py_convert_optional_to_ssize_t(PyObject *, void *);
// Same as PyNumber_Index but can return an instance of a subclass of int.
// Cannot be moved to the internal C API: used by Argument Clinic.
PyAPI_FUNC(PyObject *) _PyNumber_Index(PyObject *o);

View File

@ -47,6 +47,13 @@ extern int _PyObject_RealIsInstance(PyObject *inst, PyObject *cls);
extern int _PyObject_RealIsSubclass(PyObject *derived, PyObject *cls);
// Convert Python int to Py_ssize_t. Do nothing if the argument is None.
// Export for '_bisect' shared extension.
PyAPI_FUNC(int) _Py_convert_optional_to_ssize_t(PyObject *, void *);
// Same as PyNumber_Index() but can return an instance of a subclass of int.
// Export for 'math' shared extension.
PyAPI_FUNC(PyObject*) _PyNumber_Index(PyObject *o);
#ifdef __cplusplus
}

View File

@ -8,6 +8,7 @@
*/
#include "Python.h"
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_initconfig.h" // _PyStatus_OK()
#include "pycore_pystate.h" // _PyInterpreterState_GET()

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_io__BufferedIOBase_readinto__doc__,
"readinto($self, buffer, /)\n"
@ -1098,4 +1099,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=e5b335441452653d input=a9049054013a1b77]*/
/*[clinic end generated code: output=768c3a3a3deabcb4 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
PyDoc_STRVAR(_io_BytesIO_readable__doc__,
"readable($self, /)\n"
@ -538,4 +539,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=8d4e7651002e14c6 input=a9049054013a1b77]*/
/*[clinic end generated code: output=6b1219bda0619e2a input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
PyDoc_STRVAR(_io_FileIO_close__doc__,
"close($self, /)\n"
@ -536,4 +537,4 @@ _io_FileIO_isatty(fileio *self, PyObject *Py_UNUSED(ignored))
#ifndef _IO_FILEIO_TRUNCATE_METHODDEF
#define _IO_FILEIO_TRUNCATE_METHODDEF
#endif /* !defined(_IO_FILEIO_TRUNCATE_METHODDEF) */
/*[clinic end generated code: output=65b9a5cc96d193b6 input=a9049054013a1b77]*/
/*[clinic end generated code: output=3a3c6ed7e5e78063 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
PyDoc_STRVAR(_io__IOBase_seek__doc__,
"seek($self, offset, whence=os.SEEK_SET, /)\n"
@ -436,4 +437,4 @@ _io__RawIOBase_readall(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return _io__RawIOBase_readall_impl(self);
}
/*[clinic end generated code: output=0f064cfd54e3c1a5 input=a9049054013a1b77]*/
/*[clinic end generated code: output=ec741e0961671a86 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
PyDoc_STRVAR(_io_StringIO_getvalue__doc__,
"getvalue($self, /)\n"
@ -367,4 +368,4 @@ _io_StringIO_seekable(stringio *self, PyObject *Py_UNUSED(ignored))
{
return _io_StringIO_seekable_impl(self);
}
/*[clinic end generated code: output=6f55dc1454aeb507 input=a9049054013a1b77]*/
/*[clinic end generated code: output=09d4056cc8c4aae4 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
PyDoc_STRVAR(_io__TextIOBase_detach__doc__,
"detach($self, /)\n"
@ -975,4 +976,4 @@ _io_TextIOWrapper_close(textio *self, PyObject *Py_UNUSED(ignored))
{
return _io_TextIOWrapper_close_impl(self);
}
/*[clinic end generated code: output=29b945b24287dd0c input=a9049054013a1b77]*/
/*[clinic end generated code: output=c3a8eb2591be1bf7 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
#if defined(HAVE_WINDOWS_CONSOLE_IO)
@ -465,4 +466,4 @@ _io__WindowsConsoleIO_isatty(winconsoleio *self, PyObject *Py_UNUSED(ignored))
#ifndef _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
#define _IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF
#endif /* !defined(_IO__WINDOWSCONSOLEIO_ISATTY_METHODDEF) */
/*[clinic end generated code: output=235393758365c229 input=a9049054013a1b77]*/
/*[clinic end generated code: output=0cdb16d95f1c7dac input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_sre_getcodesize__doc__,
"getcodesize($module, /)\n"
@ -1460,4 +1461,4 @@ _sre_SRE_Scanner_search(ScannerObject *self, PyTypeObject *cls, PyObject *const
}
return _sre_SRE_Scanner_search_impl(self, cls);
}
/*[clinic end generated code: output=6b84e62c87238f0e input=a9049054013a1b77]*/
/*[clinic end generated code: output=b8cf77f05e44d08c input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_bisect_bisect_right__doc__,
"bisect_right($module, /, a, x, lo=0, hi=None, *, key=None)\n"
@ -433,4 +434,4 @@ skip_optional_kwonly:
exit:
return return_value;
}
/*[clinic end generated code: output=5a7fa64bf9b262f3 input=a9049054013a1b77]*/
/*[clinic end generated code: output=839fdddeacdc2ecb input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_bz2_BZ2Compressor_compress__doc__,
"compress($self, data, /)\n"
@ -241,4 +242,4 @@ _bz2_BZ2Decompressor(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
/*[clinic end generated code: output=431fd0fc40f019d1 input=a9049054013a1b77]*/
/*[clinic end generated code: output=40706688f92642b4 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_collections__count_elements__doc__,
"_count_elements($module, mapping, iterable, /)\n"
@ -75,4 +76,4 @@ tuplegetter_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
/*[clinic end generated code: output=00e516317d2b8bed input=a9049054013a1b77]*/
/*[clinic end generated code: output=d83188040656ad7c input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_elementtree_Element_append__doc__,
"append($self, subelement, /)\n"
@ -1218,4 +1219,4 @@ skip_optional:
exit:
return return_value;
}
/*[clinic end generated code: output=40767b1a98e54b60 input=a9049054013a1b77]*/
/*[clinic end generated code: output=0a34620406b95eb0 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(EVP_copy__doc__,
"copy($self, /)\n"
@ -1851,4 +1852,4 @@ exit:
#ifndef _HASHLIB_SCRYPT_METHODDEF
#define _HASHLIB_SCRYPT_METHODDEF
#endif /* !defined(_HASHLIB_SCRYPT_METHODDEF) */
/*[clinic end generated code: output=b339e255db698147 input=a9049054013a1b77]*/
/*[clinic end generated code: output=cfad8d5e904a4917 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_lzma_LZMACompressor_compress__doc__,
"compress($self, data, /)\n"
@ -338,4 +339,4 @@ exit:
return return_value;
}
/*[clinic end generated code: output=aaf225a5d15d3e75 input=a9049054013a1b77]*/
/*[clinic end generated code: output=f1a001f5f489c372 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_operator_truth__doc__,
"truth($module, a, /)\n"
@ -1492,4 +1493,4 @@ _operator__compare_digest(PyObject *module, PyObject *const *args, Py_ssize_t na
exit:
return return_value;
}
/*[clinic end generated code: output=227cbcfed44f736e input=a9049054013a1b77]*/
/*[clinic end generated code: output=72bc63a775937245 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(_ssl__SSLSocket_do_handshake__doc__,
"do_handshake($self, /)\n"
@ -1542,4 +1543,4 @@ exit:
#ifndef _SSL_ENUM_CRLS_METHODDEF
#define _SSL_ENUM_CRLS_METHODDEF
#endif /* !defined(_SSL_ENUM_CRLS_METHODDEF) */
/*[clinic end generated code: output=4c9f00c62f0825d2 input=a9049054013a1b77]*/
/*[clinic end generated code: output=6e2eb86330f3f9b8 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(Struct__doc__,
"Struct(format)\n"
@ -451,4 +452,4 @@ exit:
return return_value;
}
/*[clinic end generated code: output=f3d6e06f80368998 input=a9049054013a1b77]*/
/*[clinic end generated code: output=9b48aeaa86898ec5 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_long.h" // _PyLong_UnsignedShort_Converter()
PyDoc_STRVAR(test_empty_function__doc__,
@ -3070,4 +3071,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=41f439aab0cb809d input=a9049054013a1b77]*/
/*[clinic end generated code: output=a652e6b1787d3346 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_long.h" // _PyLong_UnsignedShort_Converter()
PyDoc_STRVAR(depr_star_new__doc__,
@ -2392,4 +2393,4 @@ depr_multi(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *
exit:
return return_value;
}
/*[clinic end generated code: output=22b59d92d517a8ec input=a9049054013a1b77]*/
/*[clinic end generated code: output=464aeba97e482f5c input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(array_array___copy____doc__,
"__copy__($self, /)\n"
@ -674,4 +675,4 @@ PyDoc_STRVAR(array_arrayiterator___setstate____doc__,
#define ARRAY_ARRAYITERATOR___SETSTATE___METHODDEF \
{"__setstate__", (PyCFunction)array_arrayiterator___setstate__, METH_O, array_arrayiterator___setstate____doc__},
/*[clinic end generated code: output=db417f5677a25eaa input=a9049054013a1b77]*/
/*[clinic end generated code: output=ab24c7a40a41c2e1 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
PyDoc_STRVAR(gc_enable__doc__,
"enable($module, /)\n"
@ -424,4 +425,4 @@ gc_get_freeze_count(PyObject *module, PyObject *Py_UNUSED(ignored))
exit:
return return_value;
}
/*[clinic end generated code: output=16003cfbc66ada39 input=a9049054013a1b77]*/
/*[clinic end generated code: output=fe89ce0b90a1067d input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(batched_new__doc__,
"batched(iterable, n)\n"
@ -913,4 +914,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=111cbd102c2a23c9 input=a9049054013a1b77]*/
/*[clinic end generated code: output=20999801c7349d2c input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_fileutils.h" // _PyLong_FileDescriptor_Converter()
#include "pycore_long.h" // _PyLong_UnsignedInt_Converter()
@ -11992,4 +11993,4 @@ exit:
#ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
#endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
/*[clinic end generated code: output=ff0e50316f4ed71a input=a9049054013a1b77]*/
/*[clinic end generated code: output=1b34619e5f65adc2 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(zlib_compress__doc__,
"compress($module, data, /, level=Z_DEFAULT_COMPRESSION, wbits=MAX_WBITS)\n"
@ -1129,4 +1130,4 @@ exit:
#ifndef ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
#define ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF
#endif /* !defined(ZLIB_DECOMPRESS___DEEPCOPY___METHODDEF) */
/*[clinic end generated code: output=3eccb3f7265d53ba input=a9049054013a1b77]*/
/*[clinic end generated code: output=d574a79aa47c9969 input=a9049054013a1b77]*/

View File

@ -57,6 +57,7 @@ raised for division by zero and mod by zero.
#endif
#include "Python.h"
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_bitutils.h" // _Py_bit_length()
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_long.h" // _PyLong_GetZero()

View File

@ -23,6 +23,7 @@
#endif
#include <Python.h>
#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t()
#include "pycore_bytesobject.h" // _PyBytes_Find()
#include "pycore_fileutils.h" // _Py_stat_struct

View File

@ -12,6 +12,7 @@
#ifdef __VXWORKS__
# include "pycore_bitutils.h" // _Py_popcount32()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_call.h" // _PyObject_CallNoArgs()
#include "pycore_ceval.h" // _PyEval_ReInitThreads()
#include "pycore_fileutils.h" // _Py_closerange()

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
static int
bytearray___init___impl(PyByteArrayObject *self, PyObject *arg,
@ -1284,4 +1285,4 @@ bytearray_sizeof(PyByteArrayObject *self, PyObject *Py_UNUSED(ignored))
{
return bytearray_sizeof_impl(self);
}
/*[clinic end generated code: output=cb94d7ac45f0a4b7 input=a9049054013a1b77]*/
/*[clinic end generated code: output=d388e9027b333f00 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(bytes___bytes____doc__,
"__bytes__($self, /)\n"
@ -1060,4 +1061,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=f4e85363c79c64d3 input=a9049054013a1b77]*/
/*[clinic end generated code: output=9da56b6c04914e18 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(list_insert__doc__,
"insert($self, index, object, /)\n"
@ -383,4 +384,4 @@ list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored))
{
return list___reversed___impl(self);
}
/*[clinic end generated code: output=2ca109d8acc775bc input=a9049054013a1b77]*/
/*[clinic end generated code: output=537a17b562c57505 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
static PyObject *
long_new_impl(PyTypeObject *type, PyObject *x, PyObject *obase);
@ -475,4 +476,4 @@ int_is_integer(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return int_is_integer_impl(self);
}
/*[clinic end generated code: output=75ed306fff493ba1 input=a9049054013a1b77]*/
/*[clinic end generated code: output=ea9c87ea532dadbe input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(EncodingMap_size__doc__,
"size($self, /)\n"
@ -1504,4 +1505,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=2e1e1b136ef1b681 input=a9049054013a1b77]*/
/*[clinic end generated code: output=a64776a3ea1c970c input=a9049054013a1b77]*/

View File

@ -4,6 +4,7 @@
for any kind of float exception without losing portability. */
#include "Python.h"
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_dtoa.h" // _Py_dg_dtoa()
#include "pycore_floatobject.h" // _PyFloat_FormatAdvancedWriter()
#include "pycore_initconfig.h" // _PyStatus_OK()

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(stringlib_expandtabs__doc__,
"expandtabs($self, /, tabsize=8)\n"
@ -278,4 +279,4 @@ stringlib_zfill(PyObject *self, PyObject *arg)
exit:
return return_value;
}
/*[clinic end generated code: output=00e34c03331699fe input=a9049054013a1b77]*/
/*[clinic end generated code: output=a0338b2d41671b17 input=a9049054013a1b77]*/

View File

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
PyDoc_STRVAR(warnings_warn__doc__,
"warn($module, /, message, category=None, stacklevel=1, source=None, *,\n"
@ -243,4 +244,4 @@ warnings_filters_mutated(PyObject *module, PyObject *Py_UNUSED(ignored))
{
return warnings_filters_mutated_impl(module);
}
/*[clinic end generated code: output=0e2b367a662bf51b input=a9049054013a1b77]*/
/*[clinic end generated code: output=c8a6dc1403fba1d5 input=a9049054013a1b77]*/

View File

@ -2,6 +2,7 @@
/* New getargs implementation */
#include "Python.h"
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_dict.h" // _PyDict_HasOnlyStringKeys()
#include "pycore_pylifecycle.h" // _PyArg_Fini
#include "pycore_tuple.h" // _PyTuple_ITEMS()

View File

@ -3,26 +3,14 @@ import re
from . import common as _common
# Modules/socketmodule.h uses pycore_time.h which needs the Py_BUILD_CORE
# macro. Usually it's defined by the C file which includes it.
# Other header files have a similar issue.
NEED_BUILD_CORE = {
# Header ".h" files
'cjkcodecs.h',
'multibytecodec.h',
'socketmodule.h',
# Argument Clinic ".c.h" header files
'_testclinic.c.h',
'_testclinic_depr.c.h',
'_winapi.c.h',
'fcntlmodule.c.h',
'overlapped.c.h',
'posixmodule.c.h',
'selectmodule.c.h',
'sha3module.c.h',
'termios.c.h',
}
# The following C files must not be built with Py_BUILD_CORE,
# because they use the limited C API.
USE_LIMITED_C_API = frozenset((
'_testcapimodule.c',
'_testclinic_limited.c',
'xxlimited.c',
'xxlimited_35.c',
))
TOOL = 'gcc'
@ -81,8 +69,9 @@ def preprocess(filename,
cwd = os.path.abspath(cwd or '.')
filename = _normpath(filename, cwd)
print(filename)
postargs = POST_ARGS
if os.path.basename(filename) in NEED_BUILD_CORE:
if os.path.basename(filename) not in USE_LIMITED_C_API:
postargs += ('-DPy_BUILD_CORE=1',)
text = _common.preprocess(

View File

@ -3795,8 +3795,11 @@ class Py_ssize_t_converter(CConverter):
if accept == {int}:
self.format_unit = 'n'
self.default_type = int
self.add_include('pycore_abstract.h', '_PyNumber_Index()')
elif accept == {int, NoneType}:
self.converter = '_Py_convert_optional_to_ssize_t'
self.add_include('pycore_abstract.h',
'_Py_convert_optional_to_ssize_t()')
else:
fail(f"Py_ssize_t_converter: illegal 'accept' argument {accept!r}")