[3.11] gh-113566: Fix asyncio segfault during interpreter finalization (#113578)

https://github.com/python/cpython/commit/8938495120612122e3519f002104a8322bd... commit: 8938495120612122e3519f002104a8322bd864ff branch: 3.11 author: Guido van Rossum <guido@python.org> committer: gvanrossum <gvanrossum@gmail.com> date: 2023-12-29T21:06:32-08:00 summary: [3.11] gh-113566: Fix asyncio segfault during interpreter finalization (#113578) files: A Misc/NEWS.d/next/Core and Builtins/2023-12-29-16-55-12.gh-issue-113566.grGQEg.rst M 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 index 00000000000000..7c22afad446990 --- /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 b2fef017050b22..a92feebcdbc4ac 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("<Future at %p>", fut); + } return PyObject_CallOneArg(asyncio_future_repr_func, (PyObject *)fut); }
participants (1)
-
gvanrossum