[3.8] bpo-36974: separate vectorcall functions for each calling convention (GH-13781) by jdemeyer · Pull Request #14782 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 0 additions & 3 deletions Include/descrobject.h
5 changes: 0 additions & 5 deletions Include/methodobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ PyAPI_FUNC(PyObject *) _PyCFunction_FastCallDict(PyObject *func,
PyObject *const *args,
Py_ssize_t nargs,
PyObject *kwargs);

PyAPI_FUNC(PyObject *) _PyCFunction_Vectorcall(PyObject *func,
PyObject *const *stack,
size_t nargsf,
PyObject *kwnames);
#endif

struct PyMethodDef {
Expand Down
2 changes: 2 additions & 0 deletions Lib/test/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,8 @@ def __call__(self, *args):
return super().__call__(*args)

calls += [
(dict.update, ({},), {"key":True}, None),
({}.update, ({},), {"key":True}, None),
(MethodDescriptorHeap(), (0,), {}, True),
(MethodDescriptorOverridden(), (0,), {}, 'new'),
(MethodDescriptorSuper(), (0,), {}, True),
Expand Down
8 changes: 4 additions & 4 deletions Lib/test/test_gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,10 +850,10 @@ def test_pycfunction(self):
# called, so test a variety of calling conventions.
for py_name, py_args, c_name, expected_frame_number in (
('gmtime', '', 'time_gmtime', 1), # METH_VARARGS
('len', '[]', 'builtin_len', 2), # METH_O
('locals', '', 'builtin_locals', 2), # METH_NOARGS
('iter', '[]', 'builtin_iter', 2), # METH_FASTCALL
('sorted', '[]', 'builtin_sorted', 2), # METH_FASTCALL|METH_KEYWORDS
('len', '[]', 'builtin_len', 1), # METH_O
('locals', '', 'builtin_locals', 1), # METH_NOARGS
('iter', '[]', 'builtin_iter', 1), # METH_FASTCALL
('sorted', '[]', 'builtin_sorted', 1), # METH_FASTCALL|METH_KEYWORDS
):
with self.subTest(c_name):
cmd = ('from time import gmtime\n' # (not always needed)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Implemented separate vectorcall functions for every calling convention of
builtin functions and methods. This improves performance for calls.
21 changes: 1 addition & 20 deletions Objects/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *kwargs)
Py_DECREF(kwnames);
}

return result;
return _Py_CheckFunctionResult(callable, result, NULL);
}


Expand Down Expand Up @@ -723,25 +723,6 @@ _PyMethodDef_RawFastCallKeywords(PyMethodDef *method, PyObject *self,
}


PyObject *
_PyCFunction_Vectorcall(PyObject *func,
PyObject *const *args, size_t nargsf,
PyObject *kwnames)
{
PyObject *result;

assert(func != NULL);
assert(PyCFunction_Check(func));
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);

result = _PyMethodDef_RawFastCallKeywords(((PyCFunctionObject*)func)->m_ml,
PyCFunction_GET_SELF(func),
args, nargs, kwnames);
result = _Py_CheckFunctionResult(func, result, NULL);
return result;
}


static PyObject *
cfunction_call_varargs(PyObject *func, PyObject *args, PyObject *kwargs)
{
Expand Down
246 changes: 196 additions & 50 deletions Objects/descrobject.c
Loading