-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-110892: Return NULL for PyTrace_RETURN events caused by an exception
#110909
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few suggestions for names
Python/legacy_tracing.c
Outdated
| } | ||
|
|
||
| static PyObject * | ||
| sys_profile_func3( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.