https://github.com/python/cpython/commit/10fe658f34a7b4d1bd07882fe5f76204d69977e9
commit: 10fe658f34a7b4d1bd07882fe5f76204d69977e9
branch: 3.13
author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com>
committer: gaogaotiantian <gaogaotiant...@hotmail.com>
date: 2025-04-08T17:19:40-04:00
summary:

[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 ab64130b572424695bf072f7608a536997dce14f)

Co-authored-by: Tian Gao <gaogaotiant...@hotmail.com>

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 084f8b162270b8..f23f254c0aa0db 100644
--- a/Modules/_lsprof.c
+++ b/Modules/_lsprof.c
@@ -652,6 +652,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

Reply via email to