From 8ba47146111d714c7b61825d43b52311d9be366d Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sat, 26 Aug 2023 04:05:17 +0200 Subject: [PATCH] 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. --- Include/cpython/abstract.h | 10 ------ Include/internal/pycore_abstract.h | 7 +++++ Modules/_io/_iomodule.c | 1 + Modules/_io/clinic/bufferedio.c.h | 3 +- Modules/_io/clinic/bytesio.c.h | 3 +- Modules/_io/clinic/fileio.c.h | 3 +- Modules/_io/clinic/iobase.c.h | 3 +- Modules/_io/clinic/stringio.c.h | 3 +- Modules/_io/clinic/textio.c.h | 3 +- Modules/_io/clinic/winconsoleio.c.h | 3 +- Modules/_sre/clinic/sre.c.h | 3 +- Modules/clinic/_bisectmodule.c.h | 3 +- Modules/clinic/_bz2module.c.h | 3 +- Modules/clinic/_collectionsmodule.c.h | 3 +- Modules/clinic/_elementtree.c.h | 3 +- Modules/clinic/_hashopenssl.c.h | 3 +- Modules/clinic/_lzmamodule.c.h | 3 +- Modules/clinic/_operator.c.h | 3 +- Modules/clinic/_ssl.c.h | 3 +- Modules/clinic/_struct.c.h | 3 +- Modules/clinic/_testclinic.c.h | 3 +- Modules/clinic/_testclinic_depr.c.h | 3 +- Modules/clinic/arraymodule.c.h | 3 +- Modules/clinic/gcmodule.c.h | 3 +- Modules/clinic/itertoolsmodule.c.h | 3 +- Modules/clinic/posixmodule.c.h | 3 +- Modules/clinic/zlibmodule.c.h | 3 +- Modules/mathmodule.c | 1 + Modules/mmapmodule.c | 1 + Modules/posixmodule.c | 1 + Objects/clinic/bytearrayobject.c.h | 3 +- Objects/clinic/bytesobject.c.h | 3 +- Objects/clinic/listobject.c.h | 3 +- Objects/clinic/longobject.c.h | 3 +- Objects/clinic/unicodeobject.c.h | 3 +- Objects/floatobject.c | 1 + Objects/stringlib/clinic/transmogrify.h.h | 3 +- Python/clinic/_warnings.c.h | 3 +- Python/getargs.c | 1 + Tools/c-analyzer/c_parser/preprocessor/gcc.py | 31 ++++++------------- Tools/clinic/clinic.py | 3 ++ 41 files changed, 88 insertions(+), 62 deletions(-) diff --git a/Include/cpython/abstract.h b/Include/cpython/abstract.h index dd924dfd3d8..1f495f19df2 100644 --- a/Include/cpython/abstract.h +++ b/Include/cpython/abstract.h @@ -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); diff --git a/Include/internal/pycore_abstract.h b/Include/internal/pycore_abstract.h index 2733d8102e5..3cc0afac4bd 100644 --- a/Include/internal/pycore_abstract.h +++ b/Include/internal/pycore_abstract.h @@ -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 } diff --git a/Modules/_io/_iomodule.c b/Modules/_io/_iomodule.c index f56654227f1..0762e26a36c 100644 --- a/Modules/_io/_iomodule.c +++ b/Modules/_io/_iomodule.c @@ -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() diff --git a/Modules/_io/clinic/bufferedio.c.h b/Modules/_io/clinic/bufferedio.c.h index b9b42cf3428..32c4a4e177c 100644 --- a/Modules/_io/clinic/bufferedio.c.h +++ b/Modules/_io/clinic/bufferedio.c.h @@ -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]*/ diff --git a/Modules/_io/clinic/bytesio.c.h b/Modules/_io/clinic/bytesio.c.h index 52c9c2c5ecb..b5cdd0802b8 100644 --- a/Modules/_io/clinic/bytesio.c.h +++ b/Modules/_io/clinic/bytesio.c.h @@ -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]*/ diff --git a/Modules/_io/clinic/fileio.c.h b/Modules/_io/clinic/fileio.c.h index 9f5198d45ab..7b63e36b503 100644 --- a/Modules/_io/clinic/fileio.c.h +++ b/Modules/_io/clinic/fileio.c.h @@ -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]*/ diff --git a/Modules/_io/clinic/iobase.c.h b/Modules/_io/clinic/iobase.c.h index a539125a2a8..f582b9d2c71 100644 --- a/Modules/_io/clinic/iobase.c.h +++ b/Modules/_io/clinic/iobase.c.h @@ -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]*/ diff --git a/Modules/_io/clinic/stringio.c.h b/Modules/_io/clinic/stringio.c.h index d0acfdb4bf3..dbe1833a90e 100644 --- a/Modules/_io/clinic/stringio.c.h +++ b/Modules/_io/clinic/stringio.c.h @@ -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]*/ diff --git a/Modules/_io/clinic/textio.c.h b/Modules/_io/clinic/textio.c.h index d653cc87ae3..03d5facedfb 100644 --- a/Modules/_io/clinic/textio.c.h +++ b/Modules/_io/clinic/textio.c.h @@ -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]*/ diff --git a/Modules/_io/clinic/winconsoleio.c.h b/Modules/_io/clinic/winconsoleio.c.h index cd3348dc122..53f971e37c1 100644 --- a/Modules/_io/clinic/winconsoleio.c.h +++ b/Modules/_io/clinic/winconsoleio.c.h @@ -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]*/ diff --git a/Modules/_sre/clinic/sre.c.h b/Modules/_sre/clinic/sre.c.h index a303a557ca5..1846f175b45 100644 --- a/Modules/_sre/clinic/sre.c.h +++ b/Modules/_sre/clinic/sre.c.h @@ -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]*/ diff --git a/Modules/clinic/_bisectmodule.c.h b/Modules/clinic/_bisectmodule.c.h index 7944f5219b0..62ce0fc8172 100644 --- a/Modules/clinic/_bisectmodule.c.h +++ b/Modules/clinic/_bisectmodule.c.h @@ -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]*/ diff --git a/Modules/clinic/_bz2module.c.h b/Modules/clinic/_bz2module.c.h index 6ad2db3ce1d..7c4d57b5fec 100644 --- a/Modules/clinic/_bz2module.c.h +++ b/Modules/clinic/_bz2module.c.h @@ -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]*/ diff --git a/Modules/clinic/_collectionsmodule.c.h b/Modules/clinic/_collectionsmodule.c.h index 3882d069216..b96502d3cf4 100644 --- a/Modules/clinic/_collectionsmodule.c.h +++ b/Modules/clinic/_collectionsmodule.c.h @@ -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]*/ diff --git a/Modules/clinic/_elementtree.c.h b/Modules/clinic/_elementtree.c.h index a0bc751ca21..78e456b6a43 100644 --- a/Modules/clinic/_elementtree.c.h +++ b/Modules/clinic/_elementtree.c.h @@ -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]*/ diff --git a/Modules/clinic/_hashopenssl.c.h b/Modules/clinic/_hashopenssl.c.h index fb61a444018..0ea192eac2d 100644 --- a/Modules/clinic/_hashopenssl.c.h +++ b/Modules/clinic/_hashopenssl.c.h @@ -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]*/ diff --git a/Modules/clinic/_lzmamodule.c.h b/Modules/clinic/_lzmamodule.c.h index 017b24f765e..ceb75399157 100644 --- a/Modules/clinic/_lzmamodule.c.h +++ b/Modules/clinic/_lzmamodule.c.h @@ -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]*/ diff --git a/Modules/clinic/_operator.c.h b/Modules/clinic/_operator.c.h index b68e6e0144a..18b0b920b0d 100644 --- a/Modules/clinic/_operator.c.h +++ b/Modules/clinic/_operator.c.h @@ -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]*/ diff --git a/Modules/clinic/_ssl.c.h b/Modules/clinic/_ssl.c.h index 81712617bee..6ab8e3ee436 100644 --- a/Modules/clinic/_ssl.c.h +++ b/Modules/clinic/_ssl.c.h @@ -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]*/ diff --git a/Modules/clinic/_struct.c.h b/Modules/clinic/_struct.c.h index c3cf179ed4c..a8233644478 100644 --- a/Modules/clinic/_struct.c.h +++ b/Modules/clinic/_struct.c.h @@ -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]*/ diff --git a/Modules/clinic/_testclinic.c.h b/Modules/clinic/_testclinic.c.h index 3c04c41599c..94c4b5a1221 100644 --- a/Modules/clinic/_testclinic.c.h +++ b/Modules/clinic/_testclinic.c.h @@ -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]*/ diff --git a/Modules/clinic/_testclinic_depr.c.h b/Modules/clinic/_testclinic_depr.c.h index 71cb972b951..7b9d8971efb 100644 --- a/Modules/clinic/_testclinic_depr.c.h +++ b/Modules/clinic/_testclinic_depr.c.h @@ -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]*/ diff --git a/Modules/clinic/arraymodule.c.h b/Modules/clinic/arraymodule.c.h index 5e957013ad0..8bdfcc62bef 100644 --- a/Modules/clinic/arraymodule.c.h +++ b/Modules/clinic/arraymodule.c.h @@ -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]*/ diff --git a/Modules/clinic/gcmodule.c.h b/Modules/clinic/gcmodule.c.h index 0ea5b40cfb7..290a8aaa272 100644 --- a/Modules/clinic/gcmodule.c.h +++ b/Modules/clinic/gcmodule.c.h @@ -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]*/ diff --git a/Modules/clinic/itertoolsmodule.c.h b/Modules/clinic/itertoolsmodule.c.h index 32278bf715a..6555bd495b2 100644 --- a/Modules/clinic/itertoolsmodule.c.h +++ b/Modules/clinic/itertoolsmodule.c.h @@ -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]*/ diff --git a/Modules/clinic/posixmodule.c.h b/Modules/clinic/posixmodule.c.h index 4b85519b532..e80bbff6b51 100644 --- a/Modules/clinic/posixmodule.c.h +++ b/Modules/clinic/posixmodule.c.h @@ -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]*/ diff --git a/Modules/clinic/zlibmodule.c.h b/Modules/clinic/zlibmodule.c.h index 3d71536c846..1debe2ae989 100644 --- a/Modules/clinic/zlibmodule.c.h +++ b/Modules/clinic/zlibmodule.c.h @@ -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]*/ diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c index 0d238c086ac..d929dcf65a7 100644 --- a/Modules/mathmodule.c +++ b/Modules/mathmodule.c @@ -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() diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 5c131570123..44d5b268e1b 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -23,6 +23,7 @@ #endif #include +#include "pycore_abstract.h" // _Py_convert_optional_to_ssize_t() #include "pycore_bytesobject.h" // _PyBytes_Find() #include "pycore_fileutils.h" // _Py_stat_struct diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index cffa401d2ce..8eb25fc2424 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -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() diff --git a/Objects/clinic/bytearrayobject.c.h b/Objects/clinic/bytearrayobject.c.h index ecb08a86c2a..f091fc7afbd 100644 --- a/Objects/clinic/bytearrayobject.c.h +++ b/Objects/clinic/bytearrayobject.c.h @@ -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]*/ diff --git a/Objects/clinic/bytesobject.c.h b/Objects/clinic/bytesobject.c.h index 904ff07e97c..66db76dbbb4 100644 --- a/Objects/clinic/bytesobject.c.h +++ b/Objects/clinic/bytesobject.c.h @@ -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]*/ diff --git a/Objects/clinic/listobject.c.h b/Objects/clinic/listobject.c.h index e3d6ffa9f76..a41ed3e4b04 100644 --- a/Objects/clinic/listobject.c.h +++ b/Objects/clinic/listobject.c.h @@ -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]*/ diff --git a/Objects/clinic/longobject.c.h b/Objects/clinic/longobject.c.h index d37e44f2f33..3ecef1f0fd5 100644 --- a/Objects/clinic/longobject.c.h +++ b/Objects/clinic/longobject.c.h @@ -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]*/ diff --git a/Objects/clinic/unicodeobject.c.h b/Objects/clinic/unicodeobject.c.h index 7edb4bc7609..56b64087d66 100644 --- a/Objects/clinic/unicodeobject.c.h +++ b/Objects/clinic/unicodeobject.c.h @@ -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]*/ diff --git a/Objects/floatobject.c b/Objects/floatobject.c index 6a0c2e033e3..1c5078bdda6 100644 --- a/Objects/floatobject.c +++ b/Objects/floatobject.c @@ -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() diff --git a/Objects/stringlib/clinic/transmogrify.h.h b/Objects/stringlib/clinic/transmogrify.h.h index 1e0df0958d6..d1adda4e979 100644 --- a/Objects/stringlib/clinic/transmogrify.h.h +++ b/Objects/stringlib/clinic/transmogrify.h.h @@ -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]*/ diff --git a/Python/clinic/_warnings.c.h b/Python/clinic/_warnings.c.h index b39e412a7d6..1a01416e736 100644 --- a/Python/clinic/_warnings.c.h +++ b/Python/clinic/_warnings.c.h @@ -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]*/ diff --git a/Python/getargs.c b/Python/getargs.c index 809b2d4ef17..fdc144488c9 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -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() diff --git a/Tools/c-analyzer/c_parser/preprocessor/gcc.py b/Tools/c-analyzer/c_parser/preprocessor/gcc.py index de9a2484de8..55cc2d37e1e 100644 --- a/Tools/c-analyzer/c_parser/preprocessor/gcc.py +++ b/Tools/c-analyzer/c_parser/preprocessor/gcc.py @@ -3,26 +3,14 @@ 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( diff --git a/Tools/clinic/clinic.py b/Tools/clinic/clinic.py index e622d254ee8..70ec18f726e 100755 --- a/Tools/clinic/clinic.py +++ b/Tools/clinic/clinic.py @@ -3795,8 +3795,11 @@ def converter_init(self, *, accept: TypeSet = {int}) -> None: 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}")