Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-98586: Add vector call APIs to the Limited API#98587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
7acde4068e17a9993452935685b0550df59ba419298d05d912c893e07968a8372169aaFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Added the methods :c:func:`PyObject_Vectorcall` and | ||
| :c:func:`PyObject_VectorcallMethod` to the :ref:`Limited API <stable>` along | ||
| with the auxiliary macro constant :c:macro:`PY_VECTORCALL_ARGUMENTS_OFFSET`. | ||
| The availability of these functions enables more efficient :PEP:`590` vector | ||
| calls from binary extension modules that avoid argument boxing/unboxing | ||
| overheads. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -32,6 +32,105 @@ LimitedVectorCallClass_new(PyTypeObject *tp, PyTypeObject *a, PyTypeObject *kw) | ||
| return self; | ||
| } | ||
| static PyObject * | ||
| call_vectorcall(PyObject* self, PyObject *callable) | ||
| { | ||
| PyObject *args[3] ={NULL, NULL, NULL }; | ||
| PyObject *kwname = NULL, *kwnames = NULL, *result = NULL; | ||
| args[1] = PyUnicode_FromString("foo"); | ||
| if (!args[1]){ | ||
| goto leave; | ||
| } | ||
| args[2] = PyUnicode_FromString("bar"); | ||
| if (!args[2]){ | ||
| goto leave; | ||
| } | ||
| kwname = PyUnicode_InternFromString("baz"); | ||
| if (!kwname){ | ||
| goto leave; | ||
| } | ||
| kwnames = PyTuple_New(1); | ||
| if (!kwnames){ | ||
| goto leave; | ||
| } | ||
| if (PyTuple_SetItem(kwnames, 0, kwname)){ | ||
| goto leave; | ||
| } | ||
| result = PyObject_Vectorcall( | ||
| callable, | ||
| args + 1, | ||
| 1 | PY_VECTORCALL_ARGUMENTS_OFFSET, | ||
| kwnames | ||
| ); | ||
| leave: | ||
| Py_XDECREF(args[1]); | ||
| Py_XDECREF(args[2]); | ||
| Py_XDECREF(kwnames); | ||
| return result; | ||
| } | ||
| static PyObject * | ||
| call_vectorcall_method(PyObject* self, PyObject *callable) | ||
| { | ||
| PyObject *args[3] ={NULL, NULL, NULL }; | ||
| PyObject *name = NULL, *kwname = NULL, | ||
| *kwnames = NULL, *result = NULL; | ||
| name = PyUnicode_FromString("f"); | ||
| if (!name){ | ||
| goto leave; | ||
| } | ||
| args[0] = callable; | ||
| args[1] = PyUnicode_FromString("foo"); | ||
encukou marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| if (!args[1]){ | ||
| goto leave; | ||
| } | ||
| args[2] = PyUnicode_FromString("bar"); | ||
| if (!args[2]){ | ||
| goto leave; | ||
| } | ||
| kwname = PyUnicode_InternFromString("baz"); | ||
| if (!kwname){ | ||
| goto leave; | ||
| } | ||
| kwnames = PyTuple_New(1); | ||
| if (!kwnames){ | ||
| goto leave; | ||
| } | ||
| if (PyTuple_SetItem(kwnames, 0, kwname)){ | ||
| goto leave; | ||
| } | ||
| result = PyObject_VectorcallMethod( | ||
| name, | ||
| args, | ||
| 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, | ||
| kwnames | ||
| ); | ||
| leave: | ||
| Py_XDECREF(name); | ||
| Py_XDECREF(args[1]); | ||
| Py_XDECREF(args[2]); | ||
| Py_XDECREF(kwnames); | ||
| return result; | ||
| } | ||
| static PyMemberDef LimitedVectorCallClass_members[] ={ | ||
| {"__vectorcalloffset__", T_PYSSIZET, sizeof(PyObject), READONLY}, | ||
| {NULL} | ||
| @@ -54,10 +153,8 @@ static PyType_Spec LimitedVectorCallClass_spec ={ | ||
| }; | ||
| static PyMethodDef TestMethods[] ={ | ||
| /* Add module methods here. | ||
| * (Empty list left here as template/example, since using | ||
| * PyModule_AddFunctions isn't very common.) | ||
| */ | ||
| {"call_vectorcall", call_vectorcall, METH_O}, | ||
| {"call_vectorcall_method", call_vectorcall_method, METH_O}, | ||
| {NULL}, | ||
| }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.