gh-110892: Return NULL for PyTrace_RETURN events caused by an exception#110909
gh-110892: Return NULL for PyTrace_RETURN events caused by an exception#110909markshannon merged 5 commits intopython:mainfrom
PyTrace_RETURN events caused by an exception#110909Conversation
markshannon
left a comment
There was a problem hiding this comment.
Looks good, just a few suggestions for names
Python/legacy_tracing.c
Outdated
| @@ -59,6 +59,16 @@ static PyObject * | |||
| sys_profile_func3( | |||
There was a problem hiding this comment.
I think this is now only used for throw events, so maybe rename it to sys_profile_throw?
There was a problem hiding this comment.
I always think the callbacks should have better names. I thought there are some naming conventions used here. I changed names of all the single-used callbacks to involve the event they are used for.
Python/legacy_tracing.c
Outdated
| } | ||
|
|
||
| static PyObject * | ||
| sys_profile_func3_args2( |
There was a problem hiding this comment.
Since this is only used for PyTrace_RETURN events, maybe rename it to sys_profile_return?
Python/legacy_tracing.c
Outdated
| } | ||
|
|
||
| static PyObject * | ||
| sys_trace_func3_null( |
There was a problem hiding this comment.
Likewise, rename this to sys_trace_return, and rename sys_trace_func3 to sys_trace_throw?
|
Thanks for this. Much appreciated. |
|
|
According to https://docs.python.org/3/c-api/init.html#c.Py_tracefunc, the C-level trace function should return
NULLifPyTrace_RETURNis caused by an exception.For both
PyEval_SetProfileandPyEval_SetTrace, we should simply sendNULLforPY_MONITORING_EVENT_PY_UNWINDevent.call_trampolinewill convertNULLtoPy_Nonebefore calling Python profile/trace function.Another
argrelated issue was fixed - we should always sendNoneas arg toPyTrace_CALLevent (or the correspodingcallevent for sys.setprofile), but currently in_PyEval_SetProfile,sys_profile_func3is used as callback forPY_MONITORING_EVENT_PY_THROW(okay I wrote it, sorry about that), andsys_profile_func3usesarg[2]as theargto trace function, which is different thansys_trace_func3which usesNone. (Wow that's a bit confusing!)I made it clear the original callback actually uses
arg[2]and madesys_profile_func3similar tosys_trace_func3- they all useNonenow.The test framework of
test_sys_setprofileis also modified a bit to check args.