}
else if (Py_TYPE(func) == &PyMethodDescr_Type) {
PyThreadState *tstate = PyThreadState_GET();
- C_TRACE(x, _PyMethodDescr_FastCallKeywords(func, stack, nargs, kwnames));
+ 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 (func == NULL) {
+ return NULL;
+ }
+ C_TRACE(x, _PyCFunction_FastCallKeywords(func, stack+1, nargs-1,
+ kwnames));
+ Py_DECREF(func);
+ }
+ else {
+ x = _PyMethodDescr_FastCallKeywords(func, stack, nargs, kwnames);
+ }
}
else {
if (PyMethod_Check(func) && PyMethod_GET_SELF(func) != NULL) {