Skip to content

Commit 10fe658

Browse files
[3.13] gh-132250: Clear error in lsprof callback when method descriptor raises an excep… (GH-132251) (#132281)
gh-132250: Clear error in lsprof callback when method descriptor raises an excep… (GH-132251) (cherry picked from commit ab64130) Co-authored-by: Tian Gao <[email protected]>
1 parent 67ebb39 commit 10fe658

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Lib/test/test_cprofile.py

+8
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ def test_throw(self):
139139
self.assertEqual(cc, 1)
140140
self.assertEqual(nc, 1)
141141

142+
def test_bad_descriptor(self):
143+
# gh-132250
144+
# cProfile should not crash when the profiler callback fails to locate
145+
# the actual function of a method.
146+
with self.profilerclass() as prof:
147+
with self.assertRaises(TypeError):
148+
bytes.find(str())
149+
142150

143151
class TestCommandLine(unittest.TestCase):
144152
def test_sort(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed the :exc:`SystemError` in :mod:`cProfile` when locating the actual C function of a method raises an exception.

Modules/_lsprof.c

+1
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,7 @@ PyObject* get_cfunc_from_callable(PyObject* callable, PyObject* self_arg, PyObje
652652
PyObject *meth = Py_TYPE(callable)->tp_descr_get(
653653
callable, self_arg, (PyObject*)Py_TYPE(self_arg));
654654
if (meth == NULL) {
655+
PyErr_Clear();
655656
return NULL;
656657
}
657658
if (PyCFunction_Check(meth)) {

0 commit comments

Comments
 (0)