From 8938495120612122e3519f002104a8322bd864ff Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 29 Dec 2023 21:06:32 -0800 Subject: [PATCH] [3.11] gh-113566: Fix asyncio segfault during interpreter finalization (#113578) --- .../2023-12-29-16-55-12.gh-issue-113566.grGQEg.rst | 2 ++ Modules/_asynciomodule.c | 3 +++ 2 files changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-12-29-16-55-12.gh-issue-113566.grGQEg.rst 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 index 000000000000..7c22afad4469 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-12-29-16-55-12.gh-issue-113566.grGQEg.rst @@ -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. diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index b2fef017050b..a92feebcdbc4 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -1377,6 +1377,9 @@ static PyObject * FutureObj_repr(FutureObj *fut) { ENSURE_FUTURE_ALIVE(fut) + if (asyncio_future_repr_func == NULL) { + return PyUnicode_FromFormat("", fut); + } return PyObject_CallOneArg(asyncio_future_repr_func, (PyObject *)fut); } -- 2.47.3