summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-07-21 20:27:52 (GMT)
committerGitHub <noreply@github.com>2023-07-21 20:27:52 (GMT)
commit957f14d0decb7aa5723d5ed8c4d16abad40547b0 (patch)
tree0b3f7f8b79f86f3c8fe1b7bbcd3a856634f99dea
parentffc7678f4683a63180c1321334c76e9b3e09b0a5 (diff)
downloadcpython-957f14d0decb7aa5723d5ed8c4d16abad40547b0.zip
cpython-957f14d0decb7aa5723d5ed8c4d16abad40547b0.tar.gz
cpython-957f14d0decb7aa5723d5ed8c4d16abad40547b0.tar.bz2
[3.12] gh-105699: Fix a Crasher Related to a Deprecated Global Variable (gh-106923) (#106964)
gh-105699: Fix a Crasher Related to a Deprecated Global Variable (gh-106923) There was a slight race in _Py_ClearFileSystemEncoding() (when called from _Py_SetFileSystemEncoding()), between freeing the value and setting the variable to NULL, which occasionally caused crashes when multiple isolated interpreters were used. (Notably, I saw at least 10 different, seemingly unrelated spooky-action-at-a-distance, ways this crashed. Yay, free threading!) We avoid the problem by only setting the global variables with the main interpreter (i.e. runtime init). (cherry picked from commit 0ba07b2108d4763273f3fb85544dde34c5acd40a) Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2023-07-20-12-21-37.gh-issue-105699.08ywGV.rst4
-rw-r--r--Objects/unicodeobject.c11
2 files changed, 11 insertions, 4 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-07-20-12-21-37.gh-issue-105699.08ywGV.rst b/Misc/NEWS.d/next/Core and Builtins/2023-07-20-12-21-37.gh-issue-105699.08ywGV.rst
new file mode 100644
index 0000000..8231271
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2023-07-20-12-21-37.gh-issue-105699.08ywGV.rst
@@ -0,0 +1,4 @@
+Python no longer crashes due to an infrequent race in setting
+``Py_FileSystemDefaultEncoding`` and ``Py_FileSystemDefaultEncodeErrors``
+(both deprecated), when simultaneously initializing two isolated
+subinterpreters. Now they are only set during runtime initialization.
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index a0be857..cd196f5 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -15177,10 +15177,13 @@ init_fs_codec(PyInterpreterState *interp)
/* Set Py_FileSystemDefaultEncoding and Py_FileSystemDefaultEncodeErrors
global configuration variables. */
- if (_Py_SetFileSystemEncoding(fs_codec->encoding,
- fs_codec->errors) < 0) {
- PyErr_NoMemory();
- return -1;
+ if (_Py_IsMainInterpreter(interp)) {
+
+ if (_Py_SetFileSystemEncoding(fs_codec->encoding,
+ fs_codec->errors) < 0) {
+ PyErr_NoMemory();
+ return -1;
+ }
}
return 0;
}