Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 85d09f5

Browse files
committedOct 24, 2022
expose more of the PEP-590 vector call API
1 parent b863b9c commit 85d09f5

File tree

7 files changed

+49
-21
lines changed

7 files changed

+49
-21
lines changed
 

‎Doc/data/stable_abi.dat

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Include/abstract.h

+24
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,30 @@ PyAPI_FUNC(Py_ssize_t) PyVectorcall_NARGS(size_t nargsf);
238238
"tuple" and keyword arguments "dict". "dict" may also be NULL */
239239
PyAPI_FUNC(PyObject *) PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *dict);
240240

241+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030C0000
242+
#define PY_VECTORCALL_ARGUMENTS_OFFSET \
243+
(_Py_STATIC_CAST(size_t, 1) << (8 * sizeof(size_t) - 1))
244+
245+
/* Perform a PEP 590-style vector call on 'callable' */
246+
PyAPI_FUNC(PyObject *) PyObject_Vectorcall(
247+
PyObject *callable,
248+
PyObject *const *args,
249+
size_t nargsf,
250+
PyObject *kwnames);
251+
252+
/* Same as PyObject_Vectorcall except that keyword arguments are passed as
253+
dict, which may be NULL if there are no keyword arguments. */
254+
PyAPI_FUNC(PyObject *) PyObject_VectorcallDict(
255+
PyObject *callable,
256+
PyObject *const *args,
257+
size_t nargsf,
258+
PyObject *kwargs);
259+
260+
/* Call the method 'name' on args[0] with arguments in args[1..nargsf-1]. */
261+
PyAPI_FUNC(PyObject *) PyObject_VectorcallMethod(
262+
PyObject *name, PyObject *const *args,
263+
size_t nargsf, PyObject *kwnames);
264+
#endif
241265

242266
/* Implemented elsewhere:
243267

‎Include/cpython/abstract.h

-21
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ PyAPI_FUNC(PyObject *) _PyObject_MakeTpCall(
5050
PyObject *const *args, Py_ssize_t nargs,
5151
PyObject *keywords);
5252

53-
#define PY_VECTORCALL_ARGUMENTS_OFFSET \
54-
(_Py_STATIC_CAST(size_t, 1) << (8 * sizeof(size_t) - 1))
55-
5653
// PyVectorcall_NARGS() is exported as a function for the stable ABI.
5754
// Here (when we are not using the stable ABI), the name is overridden to
5855
// call a static inline function for best performance.
@@ -65,12 +62,6 @@ _PyVectorcall_NARGS(size_t n)
6562

6663
PyAPI_FUNC(vectorcallfunc) PyVectorcall_Function(PyObject *callable);
6764

68-
PyAPI_FUNC(PyObject *) PyObject_Vectorcall(
69-
PyObject *callable,
70-
PyObject *const *args,
71-
size_t nargsf,
72-
PyObject *kwnames);
73-
7465
// Backwards compatibility aliases for API that was provisional in Python 3.8
7566
#define _PyObject_Vectorcall PyObject_Vectorcall
7667
#define _PyObject_VectorcallMethod PyObject_VectorcallMethod
@@ -80,14 +71,6 @@ PyAPI_FUNC(PyObject *) PyObject_Vectorcall(
8071
#define _PyObject_CallMethodNoArgs PyObject_CallMethodNoArgs
8172
#define _PyObject_CallMethodOneArg PyObject_CallMethodOneArg
8273

83-
/* Same as PyObject_Vectorcall except that keyword arguments are passed as
84-
dict, which may be NULL if there are no keyword arguments. */
85-
PyAPI_FUNC(PyObject *) PyObject_VectorcallDict(
86-
PyObject *callable,
87-
PyObject *const *args,
88-
size_t nargsf,
89-
PyObject *kwargs);
90-
9174
// Same as PyObject_Vectorcall(), except without keyword arguments
9275
PyAPI_FUNC(PyObject *) _PyObject_FastCall(
9376
PyObject *func,
@@ -96,10 +79,6 @@ PyAPI_FUNC(PyObject *) _PyObject_FastCall(
9679

9780
PyAPI_FUNC(PyObject *) PyObject_CallOneArg(PyObject *func, PyObject *arg);
9881

99-
PyAPI_FUNC(PyObject *) PyObject_VectorcallMethod(
100-
PyObject *name, PyObject *const *args,
101-
size_t nargsf, PyObject *kwnames);
102-
10382
static inline PyObject *
10483
PyObject_CallMethodNoArgs(PyObject *self, PyObject *name)
10584
{

‎Lib/test/test_stable_abi_ctypes.py

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Added the methods ``PyObject_Vectorcall``, ``PyObject_VectorcallDict`` and
2+
``PyObject_VectorcallMethod`` to the limited API along with the auxiliary
3+
macro constant ``PY_VECTORCALL_ARGUMENTS_OFFSET``.
4+
5+
The availability of these functions enables more efficient PEP-590 vector
6+
calls from binary extension modules that avoid argument boxing/unboxing
7+
overheads.

‎Misc/stable_abi.toml

+8
Original file line numberDiff line numberDiff line change
@@ -2293,3 +2293,11 @@
22932293
added = '3.12'
22942294
[typedef.vectorcallfunc]
22952295
added = '3.12'
2296+
[function.PyObject_Vectorcall]
2297+
added = '3.12'
2298+
[function.PyObject_VectorcallDict]
2299+
added = '3.12'
2300+
[function.PyObject_VectorcallMethod]
2301+
added = '3.12'
2302+
[macro.PY_VECTORCALL_ARGUMENTS_OFFSET]
2303+
added = '3.12'

‎PC/python3dll.c

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
Please sign in to comment.