mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
GH-91049: Introduce set vectorcall field API for PyFunctionObject (GH-92257)
Co-authored-by: Andrew Frost <adfrost@fb.com> Co-authored-by: Itamar Ostricher <itamarost@gmail.com>
This commit is contained in:
parent
e37ac5fbb6
commit
a41ed975e8
9 changed files with 115 additions and 3 deletions
|
@ -102,6 +102,24 @@ test_pyobject_vectorcall(PyObject *self, PyObject *args)
|
|||
return PyObject_Vectorcall(func, stack, nargs, kwnames);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
override_vectorcall(PyObject *callable, PyObject *const *args, size_t nargsf,
|
||||
PyObject *kwnames)
|
||||
{
|
||||
return PyUnicode_FromString("overridden");
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
function_setvectorcall(PyObject *self, PyObject *func)
|
||||
{
|
||||
if (!PyFunction_Check(func)) {
|
||||
PyErr_SetString(PyExc_TypeError, "'func' must be a function");
|
||||
return NULL;
|
||||
}
|
||||
PyFunction_SetVectorcall((PyFunctionObject *)func, (vectorcallfunc)override_vectorcall);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
test_pyvectorcall_call(PyObject *self, PyObject *args)
|
||||
{
|
||||
|
@ -244,6 +262,7 @@ static PyMethodDef TestMethods[] = {
|
|||
{"pyobject_fastcall", test_pyobject_fastcall, METH_VARARGS},
|
||||
{"pyobject_fastcalldict", test_pyobject_fastcalldict, METH_VARARGS},
|
||||
{"pyobject_vectorcall", test_pyobject_vectorcall, METH_VARARGS},
|
||||
{"function_setvectorcall", function_setvectorcall, METH_O},
|
||||
{"pyvectorcall_call", test_pyvectorcall_call, METH_VARARGS},
|
||||
_TESTCAPI_MAKE_VECTORCALL_CLASS_METHODDEF
|
||||
_TESTCAPI_HAS_VECTORCALL_FLAG_METHODDEF
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue