Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-91049: Introduce set vectorcall field API for PyFunctionObject#92257

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
Show all changes
26 commits
Select commitHold shift + click to select a range
9cf96ec
Enable setting vectorcall field on PyFunctionObjects
May 3, 2022
282e3dc
check if vectorcall is nondefault before inlining call
May 3, 2022
edcdcf1
📜🤖 Added by blurb_it.
blurb-it[bot]May 3, 2022
debf5a9
Apply suggestions from code review
adphrostMay 3, 2022
473d18d
addressed comments
May 3, 2022
76e8c9d
added to docs
May 3, 2022
3337459
Merge branch 'main' into pyfunctionobject-set-vectorcall-field
Jun 16, 2022
1543f44
updated doc with fix by itamaro
Jun 16, 2022
08082bd
formatting
Jun 16, 2022
ed93327
removed doc from 3.11
Jun 16, 2022
24ffd30
remove lines from 3.11
Jun 16, 2022
89cb4b2
Apply review feedback from vstinner and markshannon
itamaroJun 21, 2022
3387d4a
Merge branch 'main' into gh-91049-set-vectorcall
itamaroSep 2, 2022
b0cc28a
Merge branch 'main' into gh-91049-set-vectorcall
itamaroSep 5, 2022
99e4085
Add deopt on func version in LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN
itamaroSep 6, 2022
24353c8
write func version to cache keys version when specializing LOAD_ATTR_…
itamaroSep 6, 2022
60f7769
remove redundant argcount check in LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN …
itamaroSep 6, 2022
376ee75
Add missing periods in docs
itamaroSep 6, 2022
56ffc70
move warning comment to the function C API docs
itamaroSep 6, 2022
5340e87
Merge branch 'main' into pyfunctionobject-set-vectorcall-field
itamaroSep 6, 2022
a5e9d13
fix race with GH-96519 (removed func_version in LOAD_ATTR_GETATTRIBUT…
itamaroSep 6, 2022
12faf52
PEP-7 formatting
itamaroSep 7, 2022
6623470
Address review feedback
itamaroSep 7, 2022
9149f14
Add test for LOAD_ATTR specialization when overriding vectorcall of _…
itamaroSep 8, 2022
e732d7e
Improve setvectorcall + specialization testing
itamaroSep 8, 2022
84874fb
Merge branch 'main' into pyfunctionobject-set-vectorcall-field
itamaroSep 15, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
NextNext commit
Enable setting vectorcall field on PyFunctionObjects
  • Loading branch information
Andrew Frost committedMay 3, 2022
commit9cf96ec740fb59155d8842a2bc91f52c04beb22d
1 change: 1 addition & 0 deletionsInclude/cpython/funcobject.h
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -69,6 +69,7 @@ PyAPI_FUNC(PyObject *) PyFunction_GetGlobals(PyObject *);
PyAPI_FUNC(PyObject *) PyFunction_GetModule(PyObject *);
PyAPI_FUNC(PyObject *) PyFunction_GetDefaults(PyObject *);
PyAPI_FUNC(int) PyFunction_SetDefaults(PyObject *, PyObject *);
PyAPI_FUNC(int) PyFunction_SetVectorcall(PyFunctionObject *, vectorcallfunc);
PyAPI_FUNC(PyObject *) PyFunction_GetKwDefaults(PyObject *);
PyAPI_FUNC(int) PyFunction_SetKwDefaults(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyFunction_GetClosure(PyObject *);
Expand Down
8 changes: 8 additions & 0 deletionsLib/test/test_call.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -665,6 +665,14 @@ def __call__(self, *args):
self.assertEqual(expected, meth(*args1, **kwargs))
self.assertEqual(expected, wrapped(*args, **kwargs))

def test_setvectorcall(self):
from _testcapi import pyobject_setvectorcall
def f(num): return num + 1
arg = (10,)

assert f(*arg) is 11
pyobject_setvectorcall(f)
assert f(*arg) is None

class A:
def method_two_args(self, x, y):
Expand Down
21 changes: 21 additions & 0 deletionsModules/_testcapimodule.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5285,6 +5285,26 @@ test_pyobject_vectorcall(PyObject *self, PyObject *args)
}


static PyObject *
override_vectorcall(
PyObject *callable, PyObject *const *args, size_t nargsf, PyObject *kwnames) {
Py_RETURN_NONE;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Could you modify the test to return the string "overridden" instead of just returning None?

}

static PyObject *
test_pyobject_setvectorcall(PyObject *self, PyObject *args)
{
PyFunctionObject *func = NULL;
if (!PyArg_ParseTuple(args, "O", &func)) {
return NULL;
}
if(PyFunction_SetVectorcall(func, (vectorcallfunc)override_vectorcall) != 0) {
PyErr_SetString(PyExc_TypeError, "Something went wrong setting vectorcall field");
return NULL;
}
Py_RETURN_NONE;
}

static PyObject *
test_pyvectorcall_call(PyObject *self, PyObject *args)
{
Expand DownExpand Up@@ -6186,6 +6206,7 @@ static PyMethodDef TestMethods[] = {
{"pyobject_fastcall", test_pyobject_fastcall, METH_VARARGS},
{"pyobject_fastcalldict", test_pyobject_fastcalldict, METH_VARARGS},
{"pyobject_vectorcall", test_pyobject_vectorcall, METH_VARARGS},
{"pyobject_setvectorcall", test_pyobject_setvectorcall, METH_VARARGS},
{"pyvectorcall_call", test_pyvectorcall_call, METH_VARARGS},
{"stack_pointer", stack_pointer, METH_NOARGS},
#ifdef W_STOPCODE
Expand Down
11 changes: 11 additions & 0 deletionsObjects/funcobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -133,6 +133,9 @@ uint32_t _PyFunction_GetVersionForCurrentState(PyFunctionObject *func)
if (func->func_version != 0) {
return func->func_version;
}
if (func->vectorcall != _PyFunction_Vectorcall) {
return 0;
}
if (next_func_version == 0) {
return 0;
}
Expand DownExpand Up@@ -208,6 +211,14 @@ PyFunction_SetDefaults(PyObject *op, PyObject *defaults)
return 0;
}

int
PyFunction_SetVectorcall(PyFunctionObject *func, vectorcallfunc vectorcall)
{
func->func_version = 0;
func->vectorcall = vectorcall;
return 0;
}

PyObject *
PyFunction_GetKwDefaults(PyObject *op)
{
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp