Skip to content
Prev Previous commit
Next Next commit
Always use the main interpreter when possibly resizing the interned d…
…ict.
  • Loading branch information
ericsnowcurrently committed Mar 20, 2023
commit 5d6e1b955684a60dbc0db7941fa8e490c842c96e
16 changes: 14 additions & 2 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -14617,14 +14617,26 @@ store_interned(PyObject *obj)
PyObject *interned = get_interned_dict();
assert(interned != NULL);

// XXX Swap to the main interpreter.
/* Swap to the main interpreter, if necessary. */
PyThreadState *oldts = NULL;
if (!_Py_IsMainInterpreter(_PyInterpreterState_GET())) {
PyThreadState *main_tstate = get_interned_tstate();
if (main_tstate == NULL) {
return NULL;
}
oldts = PyThreadState_Swap(main_tstate);
assert(oldts != NULL);
}

PyObject *t = PyDict_SetDefault(interned, obj, obj);
if (t == NULL) {
PyErr_Clear();
}

// XXX Swap back.
/* Swap back. */
if (oldts != NULL) {
PyThreadState_Swap(oldts);
}

return t;
}
Expand Down