@@ -69,6 +69,8 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
69
69
in _PyUnicode_ClearInterned(). */
70
70
/* #define INTERNED_STATS 1 */
71
71
72
+ #define INTERNED_DICT () \
73
+ _PyRuntime.global_objects.interned
72
74
73
75
/*[clinic input]
74
76
class str "PyObject *" "&PyUnicode_Type"
@@ -191,16 +193,6 @@ extern "C" {
191
193
# define OVERALLOCATE_FACTOR 4
192
194
#endif
193
195
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
-
204
196
/* Forward declaration */
205
197
static inline int
206
198
_PyUnicodeWriter_WriteCharInline (_PyUnicodeWriter * writer , Py_UCS4 ch );
@@ -1523,7 +1515,7 @@ unicode_dealloc(PyObject *unicode)
1523
1515
_Py_FatalRefcountError ("deallocating an Unicode singleton" );
1524
1516
}
1525
1517
#endif
1526
-
1518
+ PyObject * interned = INTERNED_DICT ();
1527
1519
if (PyUnicode_CHECK_INTERNED (unicode )) {
1528
1520
/* Revive the dead object temporarily. PyDict_DelItem() removes two
1529
1521
references (key and value) which were ignored by
@@ -14657,12 +14649,14 @@ PyUnicode_InternInPlace(PyObject **p)
14657
14649
return ;
14658
14650
}
14659
14651
14652
+ PyObject * interned = INTERNED_DICT ();
14660
14653
if (interned == NULL ) {
14661
14654
interned = PyDict_New ();
14662
14655
if (interned == NULL ) {
14663
14656
PyErr_Clear (); /* Don't leave an exception */
14664
14657
return ;
14665
14658
}
14659
+ INTERNED_DICT () = interned ;
14666
14660
}
14667
14661
14668
14662
PyObject * t = PyDict_SetDefault (interned , s , s );
@@ -14713,6 +14707,7 @@ _PyUnicode_ClearInterned(PyInterpreterState *interp)
14713
14707
return ;
14714
14708
}
14715
14709
14710
+ PyObject * interned = INTERNED_DICT ();
14716
14711
if (interned == NULL ) {
14717
14712
return ;
14718
14713
}
@@ -14748,7 +14743,7 @@ _PyUnicode_ClearInterned(PyInterpreterState *interp)
14748
14743
#endif
14749
14744
14750
14745
PyDict_Clear (interned );
14751
- Py_CLEAR (interned );
14746
+ Py_CLEAR (INTERNED_DICT () );
14752
14747
}
14753
14748
14754
14749
@@ -15155,7 +15150,7 @@ _PyUnicode_EnableLegacyWindowsFSEncoding(void)
15155
15150
static inline int
15156
15151
unicode_is_finalizing (void )
15157
15152
{
15158
- return (interned == NULL );
15153
+ return (INTERNED_DICT () == NULL );
15159
15154
}
15160
15155
#endif
15161
15156
@@ -15197,7 +15192,7 @@ _PyUnicode_Fini(PyInterpreterState *interp)
15197
15192
15198
15193
if (_Py_IsMainInterpreter (interp )) {
15199
15194
// _PyUnicode_ClearInterned() must be called before _PyUnicode_Fini()
15200
- assert (interned == NULL );
15195
+ assert (INTERNED_DICT () == NULL );
15201
15196
// bpo-47182: force a unicodedata CAPI capsule re-import on
15202
15197
// subsequent initialization of main interpreter.
15203
15198
ucnhash_capi = NULL ;
0 commit comments