summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-07-21 16:58:35 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2018-07-21 16:58:35 (GMT)
commit7638eb892a50d101fe06342da180f0ab63a0b334 (patch)
tree417897747cd2a8047c0b8469fa3d1e800248672b /Python
parent25326dea8b907fdd2bf087baab3c31b617438f2e (diff)
downloadcpython-7638eb892a50d101fe06342da180f0ab63a0b334.zip
cpython-7638eb892a50d101fe06342da180f0ab63a0b334.tar.gz
cpython-7638eb892a50d101fe06342da180f0ab63a0b334.tar.bz2
bpo-34126: Fix crashes while profiling invalid calls. (GH-8300) (GH-8371)
(cherry picked from commit 56868f940e0cc0b35d33c0070107ff3bed2d8766) Co-authored-by: jdemeyer <jdemeyer@cage.ugent.be>
Diffstat (limited to 'Python')
-rw-r--r--Python/ceval.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 86cb4cd..600147b 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4555,10 +4555,16 @@ call_function(PyObject ***pp_stack, Py_ssize_t oparg, PyObject *kwnames)
}
else if (Py_TYPE(func) == &PyMethodDescr_Type) {
PyThreadState *tstate = PyThreadState_GET();
- if (tstate->use_tracing && tstate->c_profilefunc) {
- // We need to create PyCFunctionObject for tracing.
- PyMethodDescrObject *descr = (PyMethodDescrObject*)func;
- func = PyCFunction_NewEx(descr->d_method, stack[0], NULL);
+ 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 = stack[0];
+ func = Py_TYPE(func)->tp_descr_get(func, self, (PyObject*)Py_TYPE(self));
if (func == NULL) {
return NULL;
}