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
This commit is contained in:
Victor Stinner 2023-10-17 14:30:31 +02:00 committed by GitHub
parent 054f496bd4
commit be5e8a0103
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
166 changed files with 511 additions and 229 deletions

View file

@ -1,6 +1,7 @@
/* Cell object implementation */
#include "Python.h"
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
#include "pycore_object.h"
PyObject *

View file

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
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=94b9b5f492b5fed6 input=a9049054013a1b77]*/
/*[clinic end generated code: output=fc2b9ccabe0e6782 input=a9049054013a1b77]*/

View file

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

View file

@ -2,6 +2,8 @@
preserve
[clinic start generated code]*/
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
PyDoc_STRVAR(method___reduce____doc__,
"__reduce__($self, /)\n"
"--\n"
@ -80,4 +82,4 @@ instancemethod_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
/*[clinic end generated code: output=a0d17bad3b0734d9 input=a9049054013a1b77]*/
/*[clinic end generated code: output=5a5e3f2d0726f189 input=a9049054013a1b77]*/

View file

@ -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(code_new__doc__,
"code(argcount, posonlyargcount, kwonlyargcount, nlocals, stacksize,\n"
@ -463,4 +464,4 @@ code__varname_from_oparg(PyCodeObject *self, PyObject *const *args, Py_ssize_t n
exit:
return return_value;
}
/*[clinic end generated code: output=b9ccfbfabe1a5f46 input=a9049054013a1b77]*/
/*[clinic end generated code: output=d604263a3ca72a0f input=a9049054013a1b77]*/

View file

@ -6,6 +6,7 @@ preserve
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_modsupport.h" // _PyArg_BadArgument()
PyDoc_STRVAR(complex_conjugate__doc__,
"conjugate($self, /)\n"
@ -156,4 +157,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=002c74f8a33b6697 input=a9049054013a1b77]*/
/*[clinic end generated code: output=04e6261649967b30 input=a9049054013a1b77]*/

View file

@ -6,6 +6,7 @@ preserve
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
static PyObject *
mappingproxy_new_impl(PyTypeObject *type, PyObject *mapping);
@ -166,4 +167,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=a97dc44d12f9f9b6 input=a9049054013a1b77]*/
/*[clinic end generated code: output=a4664ccf3da10f5a input=a9049054013a1b77]*/

View file

@ -2,6 +2,8 @@
preserve
[clinic start generated code]*/
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
PyDoc_STRVAR(dict_fromkeys__doc__,
"fromkeys($type, iterable, value=None, /)\n"
"--\n"
@ -191,4 +193,4 @@ dict___reversed__(PyDictObject *self, PyObject *Py_UNUSED(ignored))
{
return dict___reversed___impl(self);
}
/*[clinic end generated code: output=582766ac0154c8bf input=a9049054013a1b77]*/
/*[clinic end generated code: output=17c3c4cf9a9b95a7 input=a9049054013a1b77]*/

View file

@ -6,6 +6,7 @@ preserve
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
PyDoc_STRVAR(enum_new__doc__,
"enumerate(iterable, start=0)\n"
@ -106,4 +107,4 @@ reversed_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
exit:
return return_value;
}
/*[clinic end generated code: output=661b29708f501d19 input=a9049054013a1b77]*/
/*[clinic end generated code: output=5c48a9a482a52e91 input=a9049054013a1b77]*/

View file

@ -2,6 +2,8 @@
preserve
[clinic start generated code]*/
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
PyDoc_STRVAR(float_is_integer__doc__,
"is_integer($self, /)\n"
"--\n"
@ -316,4 +318,4 @@ float___format__(PyObject *self, PyObject *arg)
exit:
return return_value;
}
/*[clinic end generated code: output=eb093cc601cc5426 input=a9049054013a1b77]*/
/*[clinic end generated code: output=c79743c8551c30d9 input=a9049054013a1b77]*/

View file

@ -6,6 +6,7 @@ preserve
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
PyDoc_STRVAR(func_new__doc__,
"function(code, globals, name=None, argdefs=None, closure=None)\n"
@ -103,4 +104,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=b2d676ff51c992d0 input=a9049054013a1b77]*/
/*[clinic end generated code: output=ff7b995500d2bee6 input=a9049054013a1b77]*/

View file

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
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=e2d9f4092498a5ca input=a9049054013a1b77]*/
/*[clinic end generated code: output=5dea9dd3bb219a7f input=a9049054013a1b77]*/

View file

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
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=009a537ab558763c input=a9049054013a1b77]*/
/*[clinic end generated code: output=7e6e57246e55911f input=a9049054013a1b77]*/

View file

@ -6,6 +6,7 @@ preserve
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
PyDoc_STRVAR(memoryview__doc__,
"memoryview(object)\n"
@ -412,4 +413,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=7ebdadda3b0fcd35 input=a9049054013a1b77]*/
/*[clinic end generated code: output=7e76a09106921ba2 input=a9049054013a1b77]*/

View file

@ -6,6 +6,7 @@ preserve
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
PyDoc_STRVAR(module___init____doc__,
"module(name, doc=None)\n"
@ -73,4 +74,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=9d3d7854d17a033c input=a9049054013a1b77]*/
/*[clinic end generated code: output=e8a71bfbed774c15 input=a9049054013a1b77]*/

View file

@ -6,6 +6,7 @@ preserve
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
PyDoc_STRVAR(OrderedDict_fromkeys__doc__,
"fromkeys($type, /, iterable, value=None)\n"
@ -331,4 +332,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=6d7ae9fb552c6108 input=a9049054013a1b77]*/
/*[clinic end generated code: output=eff78d2a3f9379bd input=a9049054013a1b77]*/

View file

@ -6,6 +6,7 @@ preserve
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
static PyObject *
structseq_new_impl(PyTypeObject *type, PyObject *arg, PyObject *dict);
@ -61,4 +62,4 @@ skip_optional_pos:
exit:
return return_value;
}
/*[clinic end generated code: output=2f88fe2a6f5c13a8 input=a9049054013a1b77]*/
/*[clinic end generated code: output=5bf39b3f06a34ce4 input=a9049054013a1b77]*/

View file

@ -2,6 +2,8 @@
preserve
[clinic start generated code]*/
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
PyDoc_STRVAR(tuple_index__doc__,
"index($self, value, start=0, stop=sys.maxsize, /)\n"
"--\n"
@ -112,4 +114,4 @@ tuple___getnewargs__(PyTupleObject *self, PyObject *Py_UNUSED(ignored))
{
return tuple___getnewargs___impl(self);
}
/*[clinic end generated code: output=7c5d9d12e0cf6a83 input=a9049054013a1b77]*/
/*[clinic end generated code: output=a6a9abba5d121f4c input=a9049054013a1b77]*/

View file

@ -2,6 +2,8 @@
preserve
[clinic start generated code]*/
#include "pycore_modsupport.h" // _PyArg_BadArgument()
PyDoc_STRVAR(type___instancecheck____doc__,
"__instancecheck__($self, instance, /)\n"
"--\n"
@ -260,4 +262,4 @@ object___dir__(PyObject *self, PyObject *Py_UNUSED(ignored))
{
return object___dir___impl(self);
}
/*[clinic end generated code: output=943f639f264362d9 input=a9049054013a1b77]*/
/*[clinic end generated code: output=b56c87f9cace1921 input=a9049054013a1b77]*/

View file

@ -6,6 +6,7 @@ preserve
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_modsupport.h" // _PyArg_UnpackKeywordsWithVararg()
PyDoc_STRVAR(typevar_new__doc__,
"typevar(name, *constraints, bound=None, covariant=False,\n"
@ -590,4 +591,4 @@ skip_optional_kwonly:
exit:
return return_value;
}
/*[clinic end generated code: output=027fb8cbef6e5015 input=a9049054013a1b77]*/
/*[clinic end generated code: output=5a582d9d89ad787b input=a9049054013a1b77]*/

View file

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

View file

@ -6,6 +6,7 @@
#include "pycore_ceval.h" // _Py_EnterRecursiveCallTstate()
#include "pycore_emscripten_trampoline.h" // descr_set_trampoline_call(), descr_get_trampoline_call()
#include "pycore_descrobject.h" // _PyMethodWrapper_Type
#include "pycore_modsupport.h" // _PyArg_UnpackStack()
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_tuple.h" // _PyTuple_ITEMS()

View file

@ -8,10 +8,11 @@
#include <stdbool.h>
#include "pycore_abstract.h" // _PyObject_RealIsSubclass()
#include "pycore_ceval.h" // _Py_EnterRecursiveCall
#include "pycore_pyerrors.h" // struct _PyErr_SetRaisedException
#include "pycore_exceptions.h" // struct _Py_exc_state
#include "pycore_initconfig.h"
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
#include "pycore_object.h"
#include "pycore_pyerrors.h" // struct _PyErr_SetRaisedException
#include "osdefs.h" // SEP

View file

@ -3,6 +3,7 @@
#include "Python.h"
#include "pycore_ceval.h" // _PyEval_BuiltinsFromGlobals()
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#include "pycore_pyerrors.h" // _PyErr_Occurred()

View file

@ -2,6 +2,7 @@
#include "Python.h"
#include "pycore_ceval.h" // _PyEval_GetBuiltin()
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
#include "pycore_object.h"
#include "pycore_unionobject.h" // _Py_union_type_or, _PyGenericAlias_Check

View file

@ -7,6 +7,7 @@
#include "pycore_ceval.h" // _PyEval_EvalFrame()
#include "pycore_frame.h" // _PyInterpreterFrame
#include "pycore_genobject.h" // struct _Py_async_gen_state
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
#include "pycore_object.h" // _PyObject_GC_UNTRACK()
#include "pycore_pyerrors.h" // _PyErr_ClearExcState()
#include "pycore_pystate.h" // _PyThreadState_GET()

View file

@ -1,12 +1,12 @@
// namespace object implementation
#include "Python.h"
#include "pycore_modsupport.h" // _PyArg_NoPositional()
#include "pycore_namespace.h" // _PyNamespace_Type
#include <stddef.h> // offsetof()
typedef struct {
PyObject_HEAD
PyObject *ns_dict;

View file

@ -16,6 +16,7 @@ this type and there is exactly one in existence.
#include "Python.h"
#include "pycore_abstract.h" // _PyIndex_Check()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_modsupport.h" // _PyArg_NoKeywords()
#include "pycore_object.h" // _PyObject_GC_TRACK()

View file

@ -7,6 +7,7 @@ preserve
# include "pycore_runtime.h" // _Py_ID()
#endif
#include "pycore_abstract.h" // _PyNumber_Index()
#include "pycore_modsupport.h" // _PyArg_UnpackKeywords()
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=39cd1ee983137188 input=a9049054013a1b77]*/
/*[clinic end generated code: output=b409bdf9ab68d5a6 input=a9049054013a1b77]*/

View file

@ -9,11 +9,11 @@
#include "Python.h"
#include "pycore_dict.h" // _PyDict_Pop()
#include "pycore_tuple.h" // _PyTuple_FromArray()
#include "pycore_object.h" // _PyObject_GC_TRACK()
#include "pycore_structseq.h" // PyStructSequence_InitType()
#include "pycore_initconfig.h" // _PyStatus_OK()
#include "pycore_modsupport.h" // _PyArg_NoPositional()
#include "pycore_object.h" // _PyObject_GC_TRACK()
#include "pycore_structseq.h" // PyStructSequence_InitType()
#include "pycore_tuple.h" // _PyTuple_FromArray()
static const char visible_length_key[] = "n_sequence_fields";
static const char real_length_key[] = "n_fields";