diff options
author | jdemeyer <jdemeyer@cage.ugent.be> | 2018-09-19 10:06:20 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2018-09-19 10:06:20 (GMT) |
commit | e89de7398718f6e68848b6340830aeb90b7d582c (patch) | |
tree | b8b0e00f2ab2ae1e7b4438b954f59273b31748af /Python | |
parent | b3b8cb419e496629873fa7dda82a01863f58617a (diff) | |
download | cpython-e89de7398718f6e68848b6340830aeb90b7d582c.zip cpython-e89de7398718f6e68848b6340830aeb90b7d582c.tar.gz cpython-e89de7398718f6e68848b6340830aeb90b7d582c.tar.bz2 |
bpo-34125: Enable profiling of method_descriptor in all cases (GH-8416)
`list.append([], None)` was profiled but `list.append([], None, **{})` was not profiled.
Enable profiling for later case.
https://bugs.python.org/issue34125
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ceval.c | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 4a82bd3..d0f9915 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -4642,15 +4642,39 @@ call_function(PyObject ***pp_stack, Py_ssize_t oparg, PyObject *kwnames) static PyObject * do_call_core(PyObject *func, PyObject *callargs, PyObject *kwdict) { + PyObject *result; + if (PyCFunction_Check(func)) { - PyObject *result; PyThreadState *tstate = PyThreadState_GET(); C_TRACE(result, PyCFunction_Call(func, callargs, kwdict)); return result; } - else { - return PyObject_Call(func, callargs, kwdict); + else if (Py_TYPE(func) == &PyMethodDescr_Type) { + PyThreadState *tstate = PyThreadState_GET(); + Py_ssize_t nargs = PyTuple_GET_SIZE(callargs); + if (nargs > 0 && tstate->use_tracing) { + /* We need to create a temporary bound method as argument + for profiling. + + If nargs == 0, then this cannot work because we have no + "self". In any case, the call itself would raise + TypeError (foo needs an argument), so we just skip + profiling. */ + PyObject *self = PyTuple_GET_ITEM(callargs, 0); + func = Py_TYPE(func)->tp_descr_get(func, self, (PyObject*)Py_TYPE(self)); + if (func == NULL) { + return NULL; + } + + C_TRACE(result, _PyCFunction_FastCallDict(func, + &PyTuple_GET_ITEM(callargs, 1), + nargs - 1, + kwdict)); + Py_DECREF(func); + return result; + } } + return PyObject_Call(func, callargs, kwdict); } /* Extract a slice index from a PyLong or an object with the |