Skip to content

[3.14] gh-135429: Fix the argument mismatch in lsprof throw event (GH-135442) #135446

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

Merged
merged 1 commit into from
Jun 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions Lib/test/test_cprofile.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,22 @@ def test_throw(self):
"""
gh-106152
generator.throw() should trigger a call in cProfile
In the any() call below, there should be two entries for the generator:
* one for the call to __next__ which gets a True and terminates any
* one when the generator is garbage collected which will effectively
do a throw.
"""

def gen():
yield

pr = self.profilerclass()
pr.enable()
any(a == 1 for a in (1, 2))
g = gen()
try:
g.throw(SyntaxError)
except SyntaxError:
pass
pr.disable()
pr.create_stats()

for func, (cc, nc, _, _, _) in pr.stats.items():
if func[2] == "<genexpr>":
self.assertEqual(cc, 1)
self.assertEqual(nc, 1)
self.assertTrue(any("throw" in func[2] for func in pr.stats.keys())),

def test_bad_descriptor(self):
# gh-132250
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix the argument mismatch in ``_lsprof`` for ``PY_THROW`` event.
24 changes: 23 additions & 1 deletion Modules/_lsprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,27 @@ _lsprof_Profiler__pystart_callback_impl(ProfilerObject *self, PyObject *code,
Py_RETURN_NONE;
}

/*[clinic input]
_lsprof.Profiler._pythrow_callback

code: object
instruction_offset: object
exception: object
/

[clinic start generated code]*/

static PyObject *
_lsprof_Profiler__pythrow_callback_impl(ProfilerObject *self, PyObject *code,
PyObject *instruction_offset,
PyObject *exception)
/*[clinic end generated code: output=0a32988919dfb94c input=fd728fc2c074f5e6]*/
{
ptrace_enter_call((PyObject*)self, (void *)code, code);

Py_RETURN_NONE;
}

/*[clinic input]
_lsprof.Profiler._pyreturn_callback

Expand Down Expand Up @@ -747,7 +768,7 @@ static const struct {
} callback_table[] = {
{PY_MONITORING_EVENT_PY_START, "_pystart_callback"},
{PY_MONITORING_EVENT_PY_RESUME, "_pystart_callback"},
{PY_MONITORING_EVENT_PY_THROW, "_pystart_callback"},
{PY_MONITORING_EVENT_PY_THROW, "_pythrow_callback"},
{PY_MONITORING_EVENT_PY_RETURN, "_pyreturn_callback"},
{PY_MONITORING_EVENT_PY_YIELD, "_pyreturn_callback"},
{PY_MONITORING_EVENT_PY_UNWIND, "_pyreturn_callback"},
Expand Down Expand Up @@ -1002,6 +1023,7 @@ static PyMethodDef profiler_methods[] = {
_LSPROF_PROFILER_DISABLE_METHODDEF
_LSPROF_PROFILER_CLEAR_METHODDEF
_LSPROF_PROFILER__PYSTART_CALLBACK_METHODDEF
_LSPROF_PROFILER__PYTHROW_CALLBACK_METHODDEF
_LSPROF_PROFILER__PYRETURN_CALLBACK_METHODDEF
_LSPROF_PROFILER__CCALL_CALLBACK_METHODDEF
_LSPROF_PROFILER__CRETURN_CALLBACK_METHODDEF
Expand Down
35 changes: 34 additions & 1 deletion Modules/clinic/_lsprof.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading