@@ -1900,25 +1900,29 @@ unicode_dealloc(PyObject *unicode)
1900
1900
case SSTATE_INTERNED_MORTAL :
1901
1901
/* revive dead object temporarily for DelItem */
1902
1902
Py_REFCNT (unicode ) = 3 ;
1903
- if (PyDict_DelItem (interned , unicode ) != 0 )
1904
- Py_FatalError (
1905
- "deletion of interned string failed" );
1903
+ if (PyDict_DelItem (interned , unicode ) != 0 ) {
1904
+ _PyErr_WriteUnraisableMsg ("deletion of interned string failed" ,
1905
+ NULL );
1906
+ }
1906
1907
break ;
1907
1908
1908
1909
case SSTATE_INTERNED_IMMORTAL :
1909
- Py_FatalError ( "Immortal interned string died. " );
1910
- /* fall through */
1910
+ _PyObject_ASSERT_FAILED_MSG ( unicode , "Immortal interned string died" );
1911
+ break ;
1911
1912
1912
1913
default :
1913
- Py_FatalError ( "Inconsistent interned string state." );
1914
+ Py_UNREACHABLE ( );
1914
1915
}
1915
1916
1916
- if (_PyUnicode_HAS_WSTR_MEMORY (unicode ))
1917
+ if (_PyUnicode_HAS_WSTR_MEMORY (unicode )) {
1917
1918
PyObject_DEL (_PyUnicode_WSTR (unicode ));
1918
- if (_PyUnicode_HAS_UTF8_MEMORY (unicode ))
1919
+ }
1920
+ if (_PyUnicode_HAS_UTF8_MEMORY (unicode )) {
1919
1921
PyObject_DEL (_PyUnicode_UTF8 (unicode ));
1920
- if (!PyUnicode_IS_COMPACT (unicode ) && _PyUnicode_DATA_ANY (unicode ))
1922
+ }
1923
+ if (!PyUnicode_IS_COMPACT (unicode ) && _PyUnicode_DATA_ANY (unicode )) {
1921
1924
PyObject_DEL (_PyUnicode_DATA_ANY (unicode ));
1925
+ }
1922
1926
1923
1927
Py_TYPE (unicode )-> tp_free (unicode );
1924
1928
}
@@ -15401,14 +15405,10 @@ PyUnicode_InternFromString(const char *cp)
15401
15405
static void
15402
15406
unicode_release_interned (void )
15403
15407
{
15404
- PyObject * keys ;
15405
- PyObject * s ;
15406
- Py_ssize_t i , n ;
15407
- Py_ssize_t immortal_size = 0 , mortal_size = 0 ;
15408
-
15409
- if (interned == NULL || !PyDict_Check (interned ))
15408
+ if (interned == NULL || !PyDict_Check (interned )) {
15410
15409
return ;
15411
- keys = PyDict_Keys (interned );
15410
+ }
15411
+ PyObject * keys = PyDict_Keys (interned );
15412
15412
if (keys == NULL || !PyList_Check (keys )) {
15413
15413
PyErr_Clear ();
15414
15414
return ;
@@ -15419,30 +15419,35 @@ unicode_release_interned(void)
15419
15419
rather, we give them their stolen references back, and then clear
15420
15420
and DECREF the interned dict. */
15421
15421
15422
- n = PyList_GET_SIZE (keys );
15422
+ Py_ssize_t n = PyList_GET_SIZE (keys );
15423
15423
#ifdef INTERNED_STATS
15424
15424
fprintf (stderr , "releasing %" PY_FORMAT_SIZE_T "d interned strings\n" ,
15425
15425
n );
15426
+
15427
+ Py_ssize_t immortal_size = 0 , mortal_size = 0 ;
15426
15428
#endif
15427
- for (i = 0 ; i < n ; i ++ ) {
15428
- s = PyList_GET_ITEM (keys , i );
15429
+ for (Py_ssize_t i = 0 ; i < n ; i ++ ) {
15430
+ PyObject * s = PyList_GET_ITEM (keys , i );
15429
15431
if (PyUnicode_READY (s ) == -1 ) {
15430
15432
Py_UNREACHABLE ();
15431
15433
}
15432
15434
switch (PyUnicode_CHECK_INTERNED (s )) {
15433
- case SSTATE_NOT_INTERNED :
15434
- /* XXX Shouldn't happen */
15435
- break ;
15436
15435
case SSTATE_INTERNED_IMMORTAL :
15437
15436
Py_REFCNT (s ) += 1 ;
15437
+ #ifdef INTERNED_STATS
15438
15438
immortal_size += PyUnicode_GET_LENGTH (s );
15439
+ #endif
15439
15440
break ;
15440
15441
case SSTATE_INTERNED_MORTAL :
15441
15442
Py_REFCNT (s ) += 2 ;
15443
+ #ifdef INTERNED_STATS
15442
15444
mortal_size += PyUnicode_GET_LENGTH (s );
15445
+ #endif
15443
15446
break ;
15447
+ case SSTATE_NOT_INTERNED :
15448
+ /* fall through */
15444
15449
default :
15445
- Py_FatalError ( "Inconsistent interned string state." );
15450
+ Py_UNREACHABLE ( );
15446
15451
}
15447
15452
_PyUnicode_STATE (s ).interned = SSTATE_NOT_INTERNED ;
15448
15453
}
0 commit comments