-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-93274: Expose receiving vectorcall in the Limited API #95717
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
00be261
ec3991f
8270404
5fc5996
cb9b79a
535cac7
37e57d3
1a6255d
15ad183
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,3 @@ | ||
API for implementing vectorcall (:c:data:`Py_TPFLAGS_HAVE_VECTORCALL`, | ||
:c:func:`PyVectorcall_NARGS` and :c:func:`PyVectorcall_Call`) was added to | ||
the limited API and stable ABI. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
#include "Python.h" | ||
|
||
int _PyTestCapi_Init_Vectorcall(PyObject *module); | ||
int _PyTestCapi_Init_VectorcallLimited(PyObject *module); | ||
int _PyTestCapi_Init_Heaptype(PyObject *module); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#define Py_LIMITED_API 0x030c0000 // 3.12 | ||
#include "parts.h" | ||
#include "structmember.h" // PyMemberDef | ||
|
||
/* Test Vectorcall in the limited API */ | ||
|
||
PyObject * | ||
LimitedVectorCallClass_tpcall(PyObject *self, PyObject *args, PyObject *kwargs) { | ||
return PyUnicode_FromString("tp_call called"); | ||
} | ||
|
||
PyObject * | ||
LimitedVectorCallClass_vectorcall(PyObject *callable, | ||
PyObject *const *args, | ||
size_t nargsf, | ||
PyObject *kwnames) { | ||
return PyUnicode_FromString("vectorcall called"); | ||
} | ||
|
||
static PyObject * | ||
LimitedVectorCallClass_new(PyTypeObject *tp, PyTypeObject *a, PyTypeObject *kw) | ||
{ | ||
PyObject *self = ((allocfunc)PyType_GetSlot(tp, Py_tp_alloc))(tp, 0); | ||
if (!self) { | ||
return NULL; | ||
} | ||
*(vectorcallfunc*)((char*)self + sizeof(PyObject)) = ( | ||
LimitedVectorCallClass_vectorcall); | ||
return self; | ||
} | ||
|
||
PyMemberDef LimitedVectorCallClass_members[] = { | ||
{"__vectorcalloffset__", T_PYSSIZET, sizeof(PyObject), READONLY}, | ||
{NULL} | ||
}; | ||
|
||
PyType_Slot LimitedVectorallClass_slots[] = { | ||
{Py_tp_new, LimitedVectorCallClass_new}, | ||
{Py_tp_call, LimitedVectorCallClass_tpcall}, | ||
{Py_tp_members, LimitedVectorCallClass_members}, | ||
{0}, | ||
}; | ||
|
||
PyType_Spec LimitedVectorCallClass_spec = { | ||
.name = "_testcapi.LimitedVectorCallClass", | ||
.basicsize = (int)(sizeof(PyObject) + sizeof(vectorcallfunc)), | ||
.flags = Py_TPFLAGS_DEFAULT | ||
| Py_TPFLAGS_HAVE_VECTORCALL | ||
| Py_TPFLAGS_BASETYPE, | ||
.slots = LimitedVectorallClass_slots, | ||
}; | ||
|
||
static PyMethodDef TestMethods[] = { | ||
{NULL}, | ||
}; | ||
|
||
int | ||
_PyTestCapi_Init_VectorcallLimited(PyObject *m) { | ||
if (PyModule_AddFunctions(m, TestMethods) < 0) { | ||
return -1; | ||
} | ||
|
||
PyObject *LimitedVectorCallClass = PyType_FromModuleAndSpec( | ||
m, &LimitedVectorCallClass_spec, NULL); | ||
if (!LimitedVectorCallClass) { | ||
return -1; | ||
} | ||
if (PyModule_AddType(m, (PyTypeObject *)LimitedVectorCallClass) < 0) { | ||
return -1; | ||
} | ||
|
||
return 0; | ||
} |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1047,3 +1047,11 @@ _PyStack_UnpackDict_Free(PyObject *const *stack, Py_ssize_t nargs, | |||||
PyMem_Free((PyObject **)stack - 1); | ||||||
Py_DECREF(kwnames); | ||||||
} | ||||||
|
||||||
// Export for the stable ABI | ||||||
#undef PyVectorcall_NARGS(n) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
Py_ssize_t | ||||||
PyVectorcall_NARGS(size_t n) | ||||||
{ | ||||||
return _PyVectorcall_NARGS(n); | ||||||
} |
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.