@@ -286,37 +286,13 @@ hashtable_unicode_compare(const void *key1, const void *key2)
286286 }
287287}
288288
289- /* Return true if this interpreter should share the main interpreter's
290- intern_dict. That's important for interpreters which load basic
291- single-phase init extension modules (m_size == -1). There could be interned
292- immortal strings that are shared between interpreters, due to the
293- PyDict_Update(mdict, m_copy) call in import_find_extension().
294-
295- It's not safe to deallocate those strings until all interpreters that
296- potentially use them are freed. By storing them in the main interpreter, we
297- ensure they get freed after all other interpreters are freed.
298- */
299- static bool
300- has_shared_intern_dict (PyInterpreterState * interp )
301- {
302- PyInterpreterState * main_interp = _PyInterpreterState_Main ();
303- return interp != main_interp && interp -> feature_flags & Py_RTFLAGS_USE_MAIN_OBMALLOC ;
304- }
305-
306289static int
307290init_interned_dict (PyInterpreterState * interp )
308291{
309292 assert (get_interned_dict (interp ) == NULL );
310- PyObject * interned ;
311- if (has_shared_intern_dict (interp )) {
312- interned = get_interned_dict (_PyInterpreterState_Main ());
313- Py_INCREF (interned );
314- }
315- else {
316- interned = PyDict_New ();
317- if (interned == NULL ) {
318- return -1 ;
319- }
293+ PyObject * interned = interned = PyDict_New ();
294+ if (interned == NULL ) {
295+ return -1 ;
320296 }
321297 _Py_INTERP_CACHED_OBJECT (interp , interned_strings ) = interned ;
322298 return 0 ;
@@ -327,10 +303,7 @@ clear_interned_dict(PyInterpreterState *interp)
327303{
328304 PyObject * interned = get_interned_dict (interp );
329305 if (interned != NULL ) {
330- if (!has_shared_intern_dict (interp )) {
331- // only clear if the dict belongs to this interpreter
332- PyDict_Clear (interned );
333- }
306+ PyDict_Clear (interned );
334307 Py_DECREF (interned );
335308 _Py_INTERP_CACHED_OBJECT (interp , interned_strings ) = NULL ;
336309 }
@@ -15163,13 +15136,6 @@ _PyUnicode_ClearInterned(PyInterpreterState *interp)
1516315136 }
1516415137 assert (PyDict_CheckExact (interned ));
1516515138
15166- if (has_shared_intern_dict (interp )) {
15167- // the dict doesn't belong to this interpreter, skip the debug
15168- // checks on it and just clear the pointer to it
15169- clear_interned_dict (interp );
15170- return ;
15171- }
15172-
1517315139#ifdef INTERNED_STATS
1517415140 fprintf (stderr , "releasing %zd interned strings\n" ,
1517515141 PyDict_GET_SIZE (interned ));
@@ -15688,10 +15654,8 @@ _PyUnicode_Fini(PyInterpreterState *interp)
1568815654{
1568915655 struct _Py_unicode_state * state = & interp -> unicode ;
1569015656
15691- if (!has_shared_intern_dict (interp )) {
15692- // _PyUnicode_ClearInterned() must be called before _PyUnicode_Fini()
15693- assert (get_interned_dict (interp ) == NULL );
15694- }
15657+ // _PyUnicode_ClearInterned() must be called before _PyUnicode_Fini()
15658+ assert (get_interned_dict (interp ) == NULL );
1569515659
1569615660 _PyUnicode_FiniEncodings (& state -> fs_codec );
1569715661
0 commit comments