]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-116738: Make `_codecs` module thread-safe (#117530)
authorBrett Simmers <swtaarrs@users.noreply.github.com>
Thu, 2 May 2024 22:25:36 +0000 (15:25 -0700)
committerGitHub <noreply@github.com>
Thu, 2 May 2024 22:25:36 +0000 (18:25 -0400)
commitf8290df63f1fd970dfd6bbfdc9a86341a9f97d05
tree295dd866e9306b1d8ed7eda44872fd1d151b391d
parent4e2caf2aa046bf80e87e9b858837bb527459a034
gh-116738: Make `_codecs` module thread-safe (#117530)

The module itself is a thin wrapper around calls to functions in
`Python/codecs.c`, so that's where the meaningful changes happened:

- Move codecs-related state that lives on `PyInterpreterState` to a
  struct declared in `pycore_codecs.h`.

- In free-threaded builds, add a mutex to `codecs_state` to synchronize
  operations on `search_path`. Because `search_path_mutex` is used as a
  normal mutex and not a critical section, we must be extremely careful
  with operations called while holding it.

- The codec registry is explicitly initialized as part of
  `_PyUnicode_InitEncodings` to simplify thread-safety.
Include/internal/pycore_codecs.h
Include/internal/pycore_interp.h
Objects/unicodeobject.c
Python/codecs.c
Python/pystate.c
Tools/c-analyzer/cpython/ignored.tsv