-
-
Notifications
You must be signed in to change notification settings - Fork 30.8k
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
gh-110892: Return NULL for PyTrace_RETURN
events caused by an exception
#110909
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
@@ -59,6 +59,16 @@ 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
@@ -173,6 +183,16 @@ sys_trace_func3( | |||
return call_trace_func(self, Py_None); | |||
} | |||
|
|||
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
NULL
ifPyTrace_RETURN
is caused by an exception.For both
PyEval_SetProfile
andPyEval_SetTrace
, we should simply sendNULL
forPY_MONITORING_EVENT_PY_UNWIND
event.call_trampoline
will convertNULL
toPy_None
before calling Python profile/trace function.Another
arg
related issue was fixed - we should always sendNone
as arg toPyTrace_CALL
event (or the correspodingcall
event for sys.setprofile), but currently in_PyEval_SetProfile
,sys_profile_func3
is used as callback forPY_MONITORING_EVENT_PY_THROW
(okay I wrote it, sorry about that), andsys_profile_func3
usesarg[2]
as thearg
to trace function, which is different thansys_trace_func3
which usesNone
. (Wow that's a bit confusing!)I made it clear the original callback actually uses
arg[2]
and madesys_profile_func3
similar tosys_trace_func3
- they all useNone
now.The test framework of
test_sys_setprofile
is also modified a bit to check args.