]
)
+ # Test CALL_FUNCTION_EX
+ events = []
+ sys.setprofile(lambda frame, event, args: events.append(event))
+ # Not important, we only want to trigger INSTRUMENTED_CALL_KW
+ args = (1,)
+ m = B().f
+ m(*args, key=lambda x: 0)
+ sys.setprofile(None)
+ # The last c_call is the call to sys.setprofile
+ # INSTRUMENTED_CALL_FUNCTION_EX has different behavior than the other
+ # instrumented call bytecodes, it does not unpack the callable before
+ # calling it. This is probably not ideal because it's not consistent,
+ # but at least we get a consistent call stack (no unmatched c_call).
+ self.assertEqual(
+ events,
+ ['call', 'return',
+ 'call', 'return',
+ 'c_call'
+ ]
+ )
+
if __name__ == "__main__":
unittest.main()
Py_DECREF(meth);
return res;
}
- else if (Py_TYPE(callable) == &PyMethod_Type) {
- // CALL instruction will grab the function from the method,
- // so if the function is a C function, the return event will
- // be emitted. However, CALL event happens before CALL
- // instruction, so we need to handle this case here.
- PyObject* func = PyMethod_GET_FUNCTION(callable);
- if (func == NULL) {
- return NULL;
- }
- if (PyCFunction_Check(func)) {
- return call_profile_func(self, func);
- }
- }
Py_RETURN_NONE;
}