]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-105699: Use a _Py_hashtable_t for the PyModuleDef Cache (gh-106974)
authorEric Snow <ericsnowcurrently@gmail.com>
Fri, 28 Jul 2023 20:39:08 +0000 (14:39 -0600)
committerGitHub <noreply@github.com>
Fri, 28 Jul 2023 20:39:08 +0000 (14:39 -0600)
commit8ba4df91ae60833723d8d3b9afeb2b642f7176d5
treec9e659951582121e0f08d97ca075825c58ab65a5
parent55ed85e49c16b1dc5470a8a893869261f6356c99
gh-105699: Use a _Py_hashtable_t for the PyModuleDef Cache (gh-106974)

This fixes a crasher due to a race condition, triggered infrequently when two isolated (own GIL) subinterpreters simultaneously initialize their sys or builtins modules.  The crash happened due the combination of the "detached" thread state we were using and the "last holder" logic we use for the GIL.  It turns out it's tricky to use the same thread state for different threads.  Who could have guessed?

We solve the problem by eliminating the one object we were still sharing between interpreters.  We replace it with a low-level hashtable, using the "raw" allocator to avoid tying it to the main interpreter.

We also remove the accommodations for "detached" thread states, which were a dubious idea to start with.
Include/internal/pycore_import.h
Include/internal/pycore_pystate.h
Include/internal/pycore_runtime_init.h
Python/import.c
Python/pystate.c