]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-113566: Fix asyncio segfault during interpreter finalization (#113578)
authorGuido van Rossum <guido@python.org>
Sat, 30 Dec 2023 05:06:32 +0000 (21:06 -0800)
committerGitHub <noreply@github.com>
Sat, 30 Dec 2023 05:06:32 +0000 (21:06 -0800)
Misc/NEWS.d/next/Core and Builtins/2023-12-29-16-55-12.gh-issue-113566.grGQEg.rst [new file with mode: 0644]
Modules/_asynciomodule.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-12-29-16-55-12.gh-issue-113566.grGQEg.rst b/Misc/NEWS.d/next/Core and Builtins/2023-12-29-16-55-12.gh-issue-113566.grGQEg.rst
new file mode 100644 (file)
index 0000000..7c22afa
--- /dev/null
@@ -0,0 +1,2 @@
+Fix a 3.11-specific crash when the ``repr`` of a :class:`~asyncio.Future` is
+requested after the module has already been garbage-collected.
index b2fef017050b22e9c1bb62a575223ebf7421824d..a92feebcdbc4acb711a3c5940b32b3300f93b2df 100644 (file)
@@ -1377,6 +1377,9 @@ static PyObject *
 FutureObj_repr(FutureObj *fut)
 {
     ENSURE_FUTURE_ALIVE(fut)
+    if (asyncio_future_repr_func == NULL) {
+        return PyUnicode_FromFormat("<Future at %p>", fut);
+    }
     return PyObject_CallOneArg(asyncio_future_repr_func, (PyObject *)fut);
 }