summaryrefslogtreecommitdiffstats
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorjdemeyer <jdemeyer@cage.ugent.be>2018-07-21 08:30:59 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2018-07-21 08:30:59 (GMT)
commit56868f940e0cc0b35d33c0070107ff3bed2d8766 (patch)
treecf89ed80def829ba86fee5c2c2db623db134fc34 /Python/ceval.c
parenta692efe4733f98831cb51a9683877b152f754d14 (diff)
downloadcpython-56868f940e0cc0b35d33c0070107ff3bed2d8766.zip
cpython-56868f940e0cc0b35d33c0070107ff3bed2d8766.tar.gz
cpython-56868f940e0cc0b35d33c0070107ff3bed2d8766.tar.bz2
bpo-34126: Fix crashes while profiling invalid calls. (GH-8300)
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 90ad591..465e030 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -4566,10 +4566,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;
}