@@ -69,6 +69,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
6969 in _PyUnicode_ClearInterned(). */
7070/* #define INTERNED_STATS 1 */
7171
72+ #define INTERNED_DICT () \
73+ _PyRuntime.global_objects.interned
7274
7375/*[clinic input]
7476class str "PyObject *" "&PyUnicode_Type"
@@ -191,16 +193,6 @@ extern "C" {
191193# define OVERALLOCATE_FACTOR 4
192194#endif
193195
194- /* This dictionary holds all interned unicode strings. Note that references
195- to strings in this dictionary are *not* counted in the string's ob_refcnt.
196- When the interned string reaches a refcnt of 0 the string deallocation
197- function will delete the reference from this dictionary.
198-
199- Another way to look at this is that to say that the actual reference
200- count of a string is: s->ob_refcnt + (s->state ? 2 : 0)
201- */
202- static PyObject * interned = NULL ;
203-
204196/* Forward declaration */
205197static inline int
206198_PyUnicodeWriter_WriteCharInline (_PyUnicodeWriter * writer , Py_UCS4 ch );
@@ -1523,7 +1515,7 @@ unicode_dealloc(PyObject *unicode)
15231515 _Py_FatalRefcountError ("deallocating an Unicode singleton" );
15241516 }
15251517#endif
1526-
1518+ PyObject * interned = INTERNED_DICT ();
15271519 if (PyUnicode_CHECK_INTERNED (unicode )) {
15281520 /* Revive the dead object temporarily. PyDict_DelItem() removes two
15291521 references (key and value) which were ignored by
@@ -14657,12 +14649,14 @@ PyUnicode_InternInPlace(PyObject **p)
1465714649 return ;
1465814650 }
1465914651
14652+ PyObject * interned = INTERNED_DICT ();
1466014653 if (interned == NULL ) {
1466114654 interned = PyDict_New ();
1466214655 if (interned == NULL ) {
1466314656 PyErr_Clear (); /* Don't leave an exception */
1466414657 return ;
1466514658 }
14659+ INTERNED_DICT () = interned ;
1466614660 }
1466714661
1466814662 PyObject * t = PyDict_SetDefault (interned , s , s );
@@ -14713,6 +14707,7 @@ _PyUnicode_ClearInterned(PyInterpreterState *interp)
1471314707 return ;
1471414708 }
1471514709
14710+ PyObject * interned = INTERNED_DICT ();
1471614711 if (interned == NULL ) {
1471714712 return ;
1471814713 }
@@ -14748,7 +14743,7 @@ _PyUnicode_ClearInterned(PyInterpreterState *interp)
1474814743#endif
1474914744
1475014745 PyDict_Clear (interned );
14751- Py_CLEAR (interned );
14746+ Py_CLEAR (INTERNED_DICT () );
1475214747}
1475314748
1475414749
@@ -15155,7 +15150,7 @@ _PyUnicode_EnableLegacyWindowsFSEncoding(void)
1515515150static inline int
1515615151unicode_is_finalizing (void )
1515715152{
15158- return (interned == NULL );
15153+ return (INTERNED_DICT () == NULL );
1515915154}
1516015155#endif
1516115156
@@ -15197,7 +15192,7 @@ _PyUnicode_Fini(PyInterpreterState *interp)
1519715192
1519815193 if (_Py_IsMainInterpreter (interp )) {
1519915194 // _PyUnicode_ClearInterned() must be called before _PyUnicode_Fini()
15200- assert (interned == NULL );
15195+ assert (INTERNED_DICT () == NULL );
1520115196 // bpo-47182: force a unicodedata CAPI capsule re-import on
1520215197 // subsequent initialization of main interpreter.
1520315198 ucnhash_capi = NULL ;
0 commit comments