]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.13] gh-120161: Fix a Crash in the _datetime Module (gh-120518)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Fri, 14 Jun 2024 19:54:46 +0000 (21:54 +0200)
committerGitHub <noreply@github.com>
Fri, 14 Jun 2024 19:54:46 +0000 (19:54 +0000)
commit18ea22a8306b5746da74d83a9db00dcc390bf092
tree234eece50eb1ddd9a564e69334c5de0b9033f9cd
parentda40fa35263893f78e75205c54fa3bcd24a64468
[3.13] gh-120161: Fix a Crash in the _datetime Module (gh-120518)

In gh-120009 I used an atexit hook to finalize the _datetime module's static types at interpreter shutdown.  However, atexit hooks are executed very early in finalization, which is a problem in the few cases where a subclass of one of those static types is still alive until the final GC collection.  The static builtin types don't have this probably because they are finalized toward the end, after the final GC collection.  To avoid the problem for _datetime, I have applied a similar approach here.

Also, credit goes to @mgorny and @neonene for the new tests.

FYI, I would have liked to take a slightly cleaner approach with managed static types, but wanted to get a smaller fix in first for the sake of backporting.  I'll circle back to the cleaner approach with a future change on the main branch.

(cherry picked from commit b2e71ff4f8fa5b7d8117dd8125137aee3d01f015, AKA gh-120182)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
Include/internal/pycore_typeobject.h
Lib/test/datetimetester.py
Misc/NEWS.d/next/Library/2024-06-06-17-24-43.gh-issue-120161.DahNXV.rst [new file with mode: 0644]
Modules/_datetimemodule.c
Objects/typeobject.c
Python/pylifecycle.c