gh-104469: Convert_testcapi/vectorcall.c to use AC (gh-106557)

This commit is contained in:
littlebutt's workshop 2023-07-09 12:08:18 +00:00 committed by GitHub
parent 8cb6f9761e
commit d137c2cae2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 140 additions and 25 deletions

View file

@ -4,6 +4,10 @@
#include "structmember.h" // PyMemberDef
#include <stddef.h> // offsetof
/*[clinic input]
module _testcapi
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=6361033e795369fc]*/
/* Test PEP 590 - Vectorcall */
@ -25,18 +29,22 @@ fastcall_args(PyObject *args, PyObject ***stack, Py_ssize_t *nargs)
return 0;
}
/*[clinic input]
_testcapi.pyobject_fastcalldict
func: object
func_args: object
kwargs: object
/
[clinic start generated code]*/
static PyObject *
test_pyobject_fastcalldict(PyObject *self, PyObject *args)
_testcapi_pyobject_fastcalldict_impl(PyObject *module, PyObject *func,
PyObject *func_args, PyObject *kwargs)
/*[clinic end generated code: output=35902ece94de4418 input=b9c0196ca7d5f9e4]*/
{
PyObject *func, *func_args, *kwargs;
PyObject **stack;
Py_ssize_t nargs;
if (!PyArg_ParseTuple(args, "OOO", &func, &func_args, &kwargs)) {
return NULL;
}
if (fastcall_args(func_args, &stack, &nargs) < 0) {
return NULL;
}
@ -52,17 +60,22 @@ test_pyobject_fastcalldict(PyObject *self, PyObject *args)
return PyObject_VectorcallDict(func, stack, nargs, kwargs);
}
/*[clinic input]
_testcapi.pyobject_vectorcall
func: object
func_args: object
kwnames: object
/
[clinic start generated code]*/
static PyObject *
test_pyobject_vectorcall(PyObject *self, PyObject *args)
_testcapi_pyobject_vectorcall_impl(PyObject *module, PyObject *func,
PyObject *func_args, PyObject *kwnames)
/*[clinic end generated code: output=ff77245bc6afe0d8 input=a0668dfef625764c]*/
{
PyObject *func, *func_args, *kwnames = NULL;
PyObject **stack;
Py_ssize_t nargs, nkw;
if (!PyArg_ParseTuple(args, "OOO", &func, &func_args, &kwnames)) {
return NULL;
}
if (fastcall_args(func_args, &stack, &nargs) < 0) {
return NULL;
}
@ -103,17 +116,19 @@ function_setvectorcall(PyObject *self, PyObject *func)
Py_RETURN_NONE;
}
/*[clinic input]
_testcapi.pyvectorcall_call
func: object
argstuple: object
kwargs: object = NULL
/
[clinic start generated code]*/
static PyObject *
test_pyvectorcall_call(PyObject *self, PyObject *args)
_testcapi_pyvectorcall_call_impl(PyObject *module, PyObject *func,
PyObject *argstuple, PyObject *kwargs)
/*[clinic end generated code: output=809046fe78511306 input=4376ee7cabd698ce]*/
{
PyObject *func;
PyObject *argstuple;
PyObject *kwargs = NULL;
if (!PyArg_ParseTuple(args, "OO|O", &func, &argstuple, &kwargs)) {
return NULL;
}
if (!PyTuple_Check(argstuple)) {
PyErr_SetString(PyExc_TypeError, "args must be a tuple");
return NULL;
@ -242,10 +257,10 @@ _testcapi_has_vectorcall_flag_impl(PyObject *module, PyTypeObject *type)
}
static PyMethodDef TestMethods[] = {
{"pyobject_fastcalldict", test_pyobject_fastcalldict, METH_VARARGS},
{"pyobject_vectorcall", test_pyobject_vectorcall, METH_VARARGS},
_TESTCAPI_PYOBJECT_FASTCALLDICT_METHODDEF
_TESTCAPI_PYOBJECT_VECTORCALL_METHODDEF
{"function_setvectorcall", function_setvectorcall, METH_O},
{"pyvectorcall_call", test_pyvectorcall_call, METH_VARARGS},
_TESTCAPI_PYVECTORCALL_CALL_METHODDEF
_TESTCAPI_MAKE_VECTORCALL_CLASS_METHODDEF
_TESTCAPI_HAS_VECTORCALL_FLAG_METHODDEF
{NULL},