@@ -55,7 +55,7 @@ Calls are made through a function pointer taking the following parameters:
55
55
* ``PyObject *callable ``: The called object
56
56
* ``Py_ssize_t n ``: The number of arguments plus the optional flag ``PY_VECTORCALL_ARGUMENTS_OFFSET `` (see below)
57
57
* ``PyObject *const *args ``: A vector of arguments
58
- * ``PyTupleObject *kwnames ``: A tuple of the names of the named arguments.
58
+ * ``PyObject *kwnames ``: Either `` NULL `` or a non-empty tuple of the names of the keyword arguments
59
59
60
60
This is implemented by the function pointer type:
61
61
``typedef PyObject *(*vectorcallfunc)(PyObject *callable, Py_ssize_t n, PyObject *const *args, PyObject *kwnames); ``
@@ -99,11 +99,13 @@ The call
99
99
The call takes the form ``((vectorcallfunc)(((char *)o)+offset))(o, n, args, kwnames) `` where
100
100
``offset `` is ``Py_TYPE(o)->tp_vectorcall_offset ``.
101
101
The caller is responsible for creating the ``kwnames `` tuple and ensuring that there are no duplicates in it.
102
+ For efficiently dealing with the common case of no keywords,
103
+ ``kwnames `` must be ``NULL `` if there are no keyword arguments.
102
104
103
105
``n `` is the number of postional arguments plus possibly the ``PY_VECTORCALL_ARGUMENTS_OFFSET `` flag.
104
106
105
107
PY_VECTORCALL_ARGUMENTS_OFFSET
106
- ------------------------------
108
+ ---------------------
107
109
108
110
The flag ``PY_VECTORCALL_ARGUMENTS_OFFSET `` should be added to ``n ``
109
111
if the callee is allowed to temporarily change ``args[-1] ``.
@@ -131,8 +133,8 @@ The following functions or macros are added to the C API:
131
133
Calls ``obj `` with the given arguments.
132
134
Note that ``nargs `` may include the flag ``PY_VECTORCALL_ARGUMENTS_OFFSET ``.
133
135
The actual number of positional arguments is given by ``PyVectorcall_NARGS(nargs) ``.
134
- The argument ``keywords `` is a tuple of keyword names or ``NULL ``.
135
- An empty tuple has the same effect as passing ``NULL ``.
136
+ The argument ``keywords `` is either a dict, a tuple of keyword names or ``NULL ``.
137
+ An empty dict or empty tuple has the same effect as passing ``NULL ``.
136
138
This uses either the vectorcall protocol or ``tp_call `` internally;
137
139
if neither is supported, an exception is raised.
138
140
@@ -149,7 +151,7 @@ New ``METH_VECTORCALL`` flag
149
151
----------------------------
150
152
151
153
A new constant ``METH_VECTORCALL `` is added for specifying ``PyMethodDef `` structs.
152
- It means that the C function has the type ``PyObject *(*call) (PyObject *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwname) ``.
154
+ It means that the C function has the signature ``vectorcallfunc ``.
153
155
This should be the preferred flag for new functions, as this avoids a wrapper function.
154
156
155
157
**NOTE **: the numerical value of ``METH_VECTORCALL `` is unspecified
@@ -205,7 +207,7 @@ The ``PyMethodDef`` protocol and Argument Clinic
205
207
206
208
Argument Clinic [4 ]_ automatically generates wrapper functions around lower-level callables, providing safe unboxing of primitive types and
207
209
other safety checks.
208
- Argument Clinic could be extended to generate wrapper objects conforming to the new `` vectorcall `` protocol .
210
+ Argument Clinic could be extended to generate wrapper objects with the `` METH_VECTORCALL `` signature .
209
211
This will allow execution to flow from the caller to the Argument Clinic generated wrapper and
210
212
thence to the hand-written code with only a single indirection.
211
213
0 commit comments