diff options
author | Victor Stinner <vstinner@python.org> | 2023-10-17 12:30:31 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-17 12:30:31 (GMT) |
commit | be5e8a010341c4d2d28ef53a1baed402ee06466e (patch) | |
tree | 6372a45676c7d5b8d07c69b67e889bbaf8f307e1 /Modules/_testcapi | |
parent | 054f496bd45cf94eac4158fd60ac95ab5f8e45c4 (diff) | |
download | cpython-be5e8a010341c4d2d28ef53a1baed402ee06466e.zip cpython-be5e8a010341c4d2d28ef53a1baed402ee06466e.tar.gz cpython-be5e8a010341c4d2d28ef53a1baed402ee06466e.tar.bz2 |
gh-110964: Remove private _PyArg functions (#110966)
Move the following private functions and structures to
pycore_modsupport.h internal C API:
* _PyArg_BadArgument()
* _PyArg_CheckPositional()
* _PyArg_NoKeywords()
* _PyArg_NoPositional()
* _PyArg_ParseStack()
* _PyArg_ParseStackAndKeywords()
* _PyArg_Parser structure
* _PyArg_UnpackKeywords()
* _PyArg_UnpackKeywordsWithVararg()
* _PyArg_UnpackStack()
* _Py_ANY_VARARGS()
Changes:
* Python/getargs.h now includes pycore_modsupport.h to export
functions.
* clinic.py now adds pycore_modsupport.h when one of these functions
is used.
* Add pycore_modsupport.h includes when a C extension uses one of
these functions.
* Define Py_BUILD_CORE_MODULE in C extensions which now include
directly or indirectly (via code generated by Argument Clinic)
pycore_modsupport.h:
* _csv
* _curses_panel
* _dbm
* _gdbm
* _multiprocessing.posixshmem
* _sqlite.row
* _statistics
* grp
* resource
* syslog
* _testcapi: bad_get() no longer uses METH_FASTCALL calling
convention but METH_VARARGS. Replace _PyArg_UnpackStack() with
PyArg_ParseTuple().
* _testcapi: add PYTESTCAPI_NEED_INTERNAL_API macro which is defined
by _testcapi sub-modules which need the internal C API
(pycore_modsupport.h): exceptions.c, float.c, vectorcall.c,
watchers.c.
* Remove Include/cpython/modsupport.h header file.
Include/modsupport.h no longer includes the removed header file.
* Fix mypy clinic.py
Diffstat (limited to 'Modules/_testcapi')
-rw-r--r-- | Modules/_testcapi/clinic/exceptions.c.h | 3 | ||||
-rw-r--r-- | Modules/_testcapi/clinic/float.c.h | 4 | ||||
-rw-r--r-- | Modules/_testcapi/clinic/vectorcall.c.h | 4 | ||||
-rw-r--r-- | Modules/_testcapi/clinic/watchers.c.h | 4 | ||||
-rw-r--r-- | Modules/_testcapi/exceptions.c | 3 | ||||
-rw-r--r-- | Modules/_testcapi/float.c | 3 | ||||
-rw-r--r-- | Modules/_testcapi/parts.h | 30 | ||||
-rw-r--r-- | Modules/_testcapi/vectorcall.c | 3 | ||||
-rw-r--r-- | Modules/_testcapi/watchers.c | 3 |
9 files changed, 41 insertions, 16 deletions
diff --git a/Modules/_testcapi/clinic/exceptions.c.h b/Modules/_testcapi/clinic/exceptions.c.h index 39b5f8b..a797444 100644 --- a/Modules/_testcapi/clinic/exceptions.c.h +++ b/Modules/_testcapi/clinic/exceptions.c.h @@ -6,6 +6,7 @@ preserve # include "pycore_gc.h" // PyGC_Head # include "pycore_runtime.h" // _Py_ID() #endif +#include "pycore_modsupport.h" // _PyArg_CheckPositional() PyDoc_STRVAR(_testcapi_err_set_raised__doc__, "err_set_raised($module, exception, /)\n" @@ -455,4 +456,4 @@ _testcapi_unstable_exc_prep_reraise_star(PyObject *module, PyObject *const *args exit: return return_value; } -/*[clinic end generated code: output=ff19512450b3bbdb input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0b11ef105030a48e input=a9049054013a1b77]*/ diff --git a/Modules/_testcapi/clinic/float.c.h b/Modules/_testcapi/clinic/float.c.h index fb0931a..d5a00c8 100644 --- a/Modules/_testcapi/clinic/float.c.h +++ b/Modules/_testcapi/clinic/float.c.h @@ -2,6 +2,8 @@ preserve [clinic start generated code]*/ +#include "pycore_modsupport.h" // _PyArg_CheckPositional() + PyDoc_STRVAR(_testcapi_float_pack__doc__, "float_pack($module, size, d, le, /)\n" "--\n" @@ -79,4 +81,4 @@ _testcapi_float_unpack(PyObject *module, PyObject *const *args, Py_ssize_t nargs exit: return return_value; } -/*[clinic end generated code: output=50146051f1341cce input=a9049054013a1b77]*/ +/*[clinic end generated code: output=b43dfd3a77fe04ba input=a9049054013a1b77]*/ diff --git a/Modules/_testcapi/clinic/vectorcall.c.h b/Modules/_testcapi/clinic/vectorcall.c.h index 48688e9..c6049a4 100644 --- a/Modules/_testcapi/clinic/vectorcall.c.h +++ b/Modules/_testcapi/clinic/vectorcall.c.h @@ -2,6 +2,8 @@ preserve [clinic start generated code]*/ +#include "pycore_modsupport.h" // _PyArg_CheckPositional() + PyDoc_STRVAR(_testcapi_pyobject_fastcalldict__doc__, "pyobject_fastcalldict($module, func, func_args, kwargs, /)\n" "--\n" @@ -204,4 +206,4 @@ _testcapi_has_vectorcall_flag(PyObject *module, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=0667266b825ec9ec input=a9049054013a1b77]*/ +/*[clinic end generated code: output=210ae67caab177ba input=a9049054013a1b77]*/ diff --git a/Modules/_testcapi/clinic/watchers.c.h b/Modules/_testcapi/clinic/watchers.c.h index fd2ef60..ebd71d1 100644 --- a/Modules/_testcapi/clinic/watchers.c.h +++ b/Modules/_testcapi/clinic/watchers.c.h @@ -2,6 +2,8 @@ preserve [clinic start generated code]*/ +#include "pycore_modsupport.h" // _PyArg_CheckPositional() + PyDoc_STRVAR(_testcapi_watch_dict__doc__, "watch_dict($module, watcher_id, dict, /)\n" "--\n" @@ -189,4 +191,4 @@ _testcapi_set_func_kwdefaults_via_capi(PyObject *module, PyObject *const *args, exit: return return_value; } -/*[clinic end generated code: output=5ad5771d6b29dfb9 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=0e07ce7f295917a5 input=a9049054013a1b77]*/ diff --git a/Modules/_testcapi/exceptions.c b/Modules/_testcapi/exceptions.c index b54ce0c..e463e62 100644 --- a/Modules/_testcapi/exceptions.c +++ b/Modules/_testcapi/exceptions.c @@ -1,3 +1,6 @@ +// clinic/exceptions.c.h uses internal pycore_modsupport.h API +#define PYTESTCAPI_NEED_INTERNAL_API + #include "parts.h" #include "util.h" #include "clinic/exceptions.c.h" diff --git a/Modules/_testcapi/float.c b/Modules/_testcapi/float.c index cff53fb..2a7d979 100644 --- a/Modules/_testcapi/float.c +++ b/Modules/_testcapi/float.c @@ -1,3 +1,6 @@ +// clinic/float.c.h uses internal pycore_modsupport.h API +#define PYTESTCAPI_NEED_INTERNAL_API + #include "parts.h" #include "clinic/float.c.h" diff --git a/Modules/_testcapi/parts.h b/Modules/_testcapi/parts.h index acdba86..e5dbb9c 100644 --- a/Modules/_testcapi/parts.h +++ b/Modules/_testcapi/parts.h @@ -4,21 +4,27 @@ // Always enable assertions #undef NDEBUG -// The _testcapi extension tests the public C API: header files in Include/ and -// Include/cpython/ directories. The internal C API must not be tested by -// _testcapi: use _testinternalcapi for that. -// -// _testcapi C files can built with the Py_BUILD_CORE_BUILTIN macro defined if -// one of the Modules/Setup files asks to build _testcapi as "static" -// (gh-109723). -// -// The Visual Studio projects builds _testcapi with Py_BUILD_CORE_MODULE. -#undef Py_BUILD_CORE_MODULE -#undef Py_BUILD_CORE_BUILTIN +#ifdef PYTESTCAPI_NEED_INTERNAL_API +# ifndef Py_BUILD_CORE_BUILTIN +# define Py_BUILD_CORE_MODULE 1 +# endif +#else + // The _testcapi extension tests the public C API: header files in Include/ + // and Include/cpython/ directories. The internal C API must not be tested + // by _testcapi: use _testinternalcapi for that. + // + // _testcapi C files can built with the Py_BUILD_CORE_BUILTIN macro defined + // if one of the Modules/Setup files asks to build _testcapi as "static" + // (gh-109723). + // + // The Visual Studio projects builds _testcapi with Py_BUILD_CORE_MODULE. +# undef Py_BUILD_CORE_MODULE +# undef Py_BUILD_CORE_BUILTIN +#endif #include "Python.h" -#ifdef Py_BUILD_CORE +#if defined(Py_BUILD_CORE) && !defined(PYTESTCAPI_NEED_INTERNAL_API) # error "_testcapi must test the public Python C API, not the internal C API" #endif diff --git a/Modules/_testcapi/vectorcall.c b/Modules/_testcapi/vectorcall.c index 2b5110f..b30c5e8 100644 --- a/Modules/_testcapi/vectorcall.c +++ b/Modules/_testcapi/vectorcall.c @@ -1,3 +1,6 @@ +// clinic/vectorcall.c.h uses internal pycore_modsupport.h API +#define PYTESTCAPI_NEED_INTERNAL_API + #include "parts.h" #include "clinic/vectorcall.c.h" diff --git a/Modules/_testcapi/watchers.c b/Modules/_testcapi/watchers.c index 8a264bb..a763ff4 100644 --- a/Modules/_testcapi/watchers.c +++ b/Modules/_testcapi/watchers.c @@ -1,3 +1,6 @@ +// clinic/watchers.c.h uses internal pycore_modsupport.h API +#define PYTESTCAPI_NEED_INTERNAL_API + #include "parts.h" #include "clinic/watchers.c.h" |