summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorBrett Simmers <swtaarrs@users.noreply.github.com>2024-05-02 22:25:36 (GMT)
committerGitHub <noreply@github.com>2024-05-02 22:25:36 (GMT)
commitf8290df63f1fd970dfd6bbfdc9a86341a9f97d05 (patch)
tree295dd866e9306b1d8ed7eda44872fd1d151b391d /Objects/unicodeobject.c
parent4e2caf2aa046bf80e87e9b858837bb527459a034 (diff)
downloadcpython-f8290df63f1fd970dfd6bbfdc9a86341a9f97d05.zip
cpython-f8290df63f1fd970dfd6bbfdc9a86341a9f97d05.tar.gz
cpython-f8290df63f1fd970dfd6bbfdc9a86341a9f97d05.tar.bz2
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.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 2c259b7..67b1282 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -15441,7 +15441,11 @@ init_fs_encoding(PyThreadState *tstate)
PyStatus
_PyUnicode_InitEncodings(PyThreadState *tstate)
{
- PyStatus status = init_fs_encoding(tstate);
+ PyStatus status = _PyCodec_InitRegistry(tstate->interp);
+ if (_PyStatus_EXCEPTION(status)) {
+ return status;
+ }
+ status = init_fs_encoding(tstate);
if (_PyStatus_EXCEPTION(status)) {
return status;
}