Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 89cb4b2

Browse files
itamaroAndrew Frost
authored andcommitted
Apply review feedback from vstinner and markshannon
1 parent 24ffd30 commit 89cb4b2

5 files changed

Lines changed: 10 additions & 8 deletions

File tree

Doc/c-api/function.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ There are a few functions specific to Python functions.
8787
8888
Set the vectorcall field of a given function object *func*
8989
90+
.. versionadded:: 3.12
9091
9192
.. c:function:: PyObject* PyFunction_GetClosure(PyObject *op)
9293

Doc/whatsnew/3.12.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,9 @@ New Features
237237
(Contributed by Wenzel Jakob in :gh:`93012`.)
238238

239239
* Add new function :c:func:`PyFunction_SetVectorcall` to the C API
240-
which sets the vectorcall field of a given PyFunctionObject
240+
which sets the vectorcall field of a given :c:type:`PyFunctionObject`
241+
Warning: extensions using this API must preserve the behavior
242+
of the unaltered function!
241243
(Contributed by Andrew Frost in :gh:`92257`.)
242244

243245
Porting to Python 3.12

Lib/test/test_call.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ def f(num): return num + 1
673673
function_setvectorcall(f)
674674
# make sure specializer is triggered by running > 50 times
675675
for _ in range(51):
676-
self.assertIsNone(f(num))
676+
self.assertEqual("overridden", f(num))
677677

678678
class A:
679679
def method_two_args(self, x, y):
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
CPython extensions providing optimized execution of Python bytecode (like Cinder JIT and Pyjion)
2-
can benefit from being able to modify the vectorcall field on instances of PyFunctionObject to allow calling the optimized path (e.g. JIT-compiled) directly.
1+
Add new function :c:func:`PyFunction_SetVectorcall` to the C API
2+
which sets the vectorcall field of a given :c:type:`PyFunctionObject`
33

4-
This PR introduces an API call where vectorcall field can be modified like so:
5-
6-
`void PyFunction_SetVectorcall(PyFunctionObject *func, vectorcallfunc vectorcall);`
4+
Warning: extensions using this API must preserve the behavior
5+
of the unaltered function!

Modules/_testcapimodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5359,7 +5359,7 @@ test_pyobject_vectorcall(PyObject *self, PyObject *args)
53595359
static PyObject *
53605360
override_vectorcall(
53615361
PyObject *callable, PyObject *const *args, size_t nargsf, PyObject *kwnames) {
5362-
Py_RETURN_NONE;
5362+
return PyUnicode_FromString("overridden");
53635363
}
53645364

53655365
static PyObject *

0 commit comments

Comments
 (0)