summaryrefslogtreecommitdiffstats
path: root/Objects/unicodeobject.c
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2023-03-23 00:30:04 (GMT)
committerGitHub <noreply@github.com>2023-03-23 00:30:04 (GMT)
commit87be8d95228ee95de9045cf2952311d20dc5de45 (patch)
tree2f7172f22aaae687b17a04de208d79b757f68a7f /Objects/unicodeobject.c
parent8709697292c67254ba836d7e88d1eba08c4a351a (diff)
downloadcpython-87be8d95228ee95de9045cf2952311d20dc5de45.zip
cpython-87be8d95228ee95de9045cf2952311d20dc5de45.tar.gz
cpython-87be8d95228ee95de9045cf2952311d20dc5de45.tar.bz2
gh-100227: Make the Global Interned Dict Safe for Isolated Interpreters (gh-102925)
This is effectively two changes. The first (the bulk of the change) is where we add _Py_AddToGlobalDict() (and _PyRuntime.cached_objects.main_tstate, etc.). The second (much smaller) change is where we update PyUnicode_InternInPlace() to use _Py_AddToGlobalDict() instead of calling PyDict_SetDefault() directly. Basically, _Py_AddToGlobalDict() is a wrapper around PyDict_SetDefault() that should be used whenever we need to add a value to a runtime-global dict object (in the few cases where we are leaving the container global rather than moving it to PyInterpreterState, e.g. the interned strings dict). _Py_AddToGlobalDict() does all the necessary work to make sure the target global dict is shared safely between isolated interpreters. This is especially important as we move the obmalloc state to each interpreter (gh-101660), as well as, potentially, the GIL (PEP 684). https://github.com/python/cpython/issues/100227
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r--Objects/unicodeobject.c13
1 files changed, 4 insertions, 9 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index b9fb531..891a655 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -14609,16 +14609,11 @@ PyUnicode_InternInPlace(PyObject **p)
}
PyObject *interned = get_interned_dict();
- assert(interned != NULL);
-
- PyObject *t = PyDict_SetDefault(interned, s, s);
- if (t == NULL) {
- PyErr_Clear();
- return;
- }
-
+ PyObject *t = _Py_AddToGlobalDict(interned, s, s);
if (t != s) {
- Py_SETREF(*p, Py_NewRef(t));
+ if (t != NULL) {
+ Py_SETREF(*p, Py_NewRef(t));
+ }
return;
}