Skip to content

Commit ab64130

Browse files
gh-132250: Clear error in lsprof callback when method descriptor raises an excep… (#132251)
1 parent efd8aca commit ab64130

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
@@ -671,6 +671,7 @@ PyObject* get_cfunc_from_callable(PyObject* callable, PyObject* self_arg, PyObje
671671
PyObject *meth = Py_TYPE(callable)->tp_descr_get(
672672
callable, self_arg, (PyObject*)Py_TYPE(self_arg));
673673
if (meth == NULL) {
674+
PyErr_Clear();
674675
return NULL;
675676
}
676677
if (PyCFunction_Check(meth)) {

0 commit comments

Comments
 (0)