-
-
Notifications
You must be signed in to change notification settings - Fork 34.1k
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
Changes from 6 commits
7acde40
68e17a9
9934529
35685b0
550df59
ba41929
8d05d91
2c893e0
7968a83
72169aa
File filter
Filter by extension
Conversations
Jump to
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.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| 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,73 @@ LimitedVectorCallClass_new(PyTypeObject *tp, PyTypeObject *a, PyTypeObject *kw) | |
| return self; | ||
| } | ||
|
|
||
| static PyObject *call_vectorcall(PyObject* self, PyObject *callable) { | ||
| PyObject *args[3], *kwname, *kwnames; | ||
|
|
||
| args[0] = NULL; | ||
| args[1] = PyUnicode_FromString("foo"); | ||
| args[2] = PyUnicode_FromString("bar"); | ||
wjakob marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| kwname = PyUnicode_InternFromString("baz"); | ||
| kwnames = PyTuple_New(1); | ||
|
|
||
| if (!args[1] || !args[2] || !kwname || !kwnames || | ||
| PyTuple_SetItem(kwnames, 0, kwname)) | ||
| { | ||
| Py_XDECREF(args[1]); | ||
| Py_XDECREF(args[2]); | ||
| Py_XDECREF(kwnames); | ||
| return NULL; | ||
| } | ||
|
|
||
| PyObject *result = PyObject_Vectorcall( | ||
| callable, | ||
| args + 1, | ||
| 1 | PY_VECTORCALL_ARGUMENTS_OFFSET, | ||
| kwnames | ||
| ); | ||
|
|
||
| Py_DECREF(args[1]); | ||
| Py_DECREF(args[2]); | ||
| Py_DECREF(kwnames); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| static PyObject *call_vectorcall_method(PyObject* self, PyObject *callable) { | ||
wjakob marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| PyObject *name, *args[3], *kwname, *kwnames; | ||
|
|
||
| name = PyUnicode_FromString("f"); | ||
| args[0] = callable; | ||
| args[1] = PyUnicode_FromString("foo"); | ||
encukou marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| args[2] = PyUnicode_FromString("bar"); | ||
| kwname = PyUnicode_InternFromString("baz"); | ||
| kwnames = PyTuple_New(1); | ||
|
|
||
| if (!name || !args[1] || !args[2] || !kwname || !kwnames || | ||
| PyTuple_SetItem(kwnames, 0, kwname)) | ||
| { | ||
| Py_XDECREF(name); | ||
| Py_XDECREF(args[1]); | ||
| Py_XDECREF(args[2]); | ||
| Py_XDECREF(kwnames); | ||
| return NULL; | ||
| } | ||
|
|
||
| PyObject *result = PyObject_VectorcallMethod( | ||
| name, | ||
| args, | ||
| 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, | ||
| kwnames | ||
| ); | ||
|
|
||
| Py_DECREF(name); | ||
| Py_DECREF(args[1]); | ||
| Py_DECREF(args[2]); | ||
| Py_DECREF(kwnames); | ||
|
|
||
| return result; | ||
| } | ||
|
|
||
| static PyMemberDef LimitedVectorCallClass_members[] = { | ||
| {"__vectorcalloffset__", T_PYSSIZET, sizeof(PyObject), READONLY}, | ||
| {NULL} | ||
|
|
@@ -58,6 +125,8 @@ static PyMethodDef TestMethods[] = { | |
| * (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.