https://github.com/python/cpython/commit/ab64130b572424695bf072f7608a536997dce14f commit: ab64130b572424695bf072f7608a536997dce14f branch: main author: Tian Gao <gaogaotiant...@hotmail.com> committer: gaogaotiantian <gaogaotiant...@hotmail.com> date: 2025-04-08T13:36:47-04:00 summary:
gh-132250: Clear error in lsprof callback when method descriptor raises an excep… (#132251) files: A Misc/NEWS.d/next/Library/2025-04-08-01-55-11.gh-issue-132250.APBFCw.rst M Lib/test/test_cprofile.py M Modules/_lsprof.c diff --git a/Lib/test/test_cprofile.py b/Lib/test/test_cprofile.py index 65720871d5c5f0..b46edf66bf09f8 100644 --- a/Lib/test/test_cprofile.py +++ b/Lib/test/test_cprofile.py @@ -139,6 +139,14 @@ def test_throw(self): self.assertEqual(cc, 1) self.assertEqual(nc, 1) + def test_bad_descriptor(self): + # gh-132250 + # cProfile should not crash when the profiler callback fails to locate + # the actual function of a method. + with self.profilerclass() as prof: + with self.assertRaises(TypeError): + bytes.find(str()) + class TestCommandLine(unittest.TestCase): def test_sort(self): diff --git a/Misc/NEWS.d/next/Library/2025-04-08-01-55-11.gh-issue-132250.APBFCw.rst b/Misc/NEWS.d/next/Library/2025-04-08-01-55-11.gh-issue-132250.APBFCw.rst new file mode 100644 index 00000000000000..b49528867c2ef3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-04-08-01-55-11.gh-issue-132250.APBFCw.rst @@ -0,0 +1 @@ +Fixed the :exc:`SystemError` in :mod:`cProfile` when locating the actual C function of a method raises an exception. diff --git a/Modules/_lsprof.c b/Modules/_lsprof.c index 379f9869f2fe09..626c176715bdac 100644 --- a/Modules/_lsprof.c +++ b/Modules/_lsprof.c @@ -671,6 +671,7 @@ PyObject* get_cfunc_from_callable(PyObject* callable, PyObject* self_arg, PyObje PyObject *meth = Py_TYPE(callable)->tp_descr_get( callable, self_arg, (PyObject*)Py_TYPE(self_arg)); if (meth == NULL) { + PyErr_Clear(); return NULL; } if (PyCFunction_Check(meth)) { _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com