@@ -247,7 +247,8 @@ _PyUnicode_InternedSize_Immortal(void)
247
247
// value, to help detect bugs in optimizations.
248
248
249
249
while (PyDict_Next (dict , & pos , & key , & value )) {
250
- if (_Py_IsImmortal (key )) {
250
+ assert (PyUnicode_CHECK_INTERNED (key ) != SSTATE_INTERNED_IMMORTAL_STATIC );
251
+ if (PyUnicode_CHECK_INTERNED (key ) == SSTATE_INTERNED_IMMORTAL ) {
251
252
count ++ ;
252
253
}
253
254
}
@@ -683,10 +684,14 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
683
684
684
685
/* Check interning state */
685
686
#ifdef Py_DEBUG
687
+ // Note that we do not check `_Py_IsImmortal(op)`, since stable ABI
688
+ // extensions can make immortal strings mortal (but with a high enough
689
+ // refcount).
690
+ // The other way is extremely unlikely (worth a potential failed assertion
691
+ // in a debug build), so we do check `!_Py_IsImmortal(op)`.
686
692
switch (PyUnicode_CHECK_INTERNED (op )) {
687
693
case SSTATE_NOT_INTERNED :
688
694
if (ascii -> state .statically_allocated ) {
689
- CHECK (_Py_IsImmortal (op ));
690
695
// This state is for two exceptions:
691
696
// - strings are currently checked before they're interned
692
697
// - the 256 one-latin1-character strings
@@ -702,11 +707,9 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
702
707
break ;
703
708
case SSTATE_INTERNED_IMMORTAL :
704
709
CHECK (!ascii -> state .statically_allocated );
705
- CHECK (_Py_IsImmortal (op ));
706
710
break ;
707
711
case SSTATE_INTERNED_IMMORTAL_STATIC :
708
712
CHECK (ascii -> state .statically_allocated );
709
- CHECK (_Py_IsImmortal (op ));
710
713
break ;
711
714
default :
712
715
Py_UNREACHABLE ();
@@ -1899,7 +1902,6 @@ static PyObject*
1899
1902
get_latin1_char (Py_UCS1 ch )
1900
1903
{
1901
1904
PyObject * o = LATIN1 (ch );
1902
- assert (_Py_IsImmortal (o ));
1903
1905
return o ;
1904
1906
}
1905
1907
@@ -15049,7 +15051,6 @@ intern_static(PyInterpreterState *interp, PyObject *s /* stolen */)
15049
15051
assert (s != NULL );
15050
15052
assert (_PyUnicode_CHECK (s ));
15051
15053
assert (_PyUnicode_STATE (s ).statically_allocated );
15052
- assert (_Py_IsImmortal (s ));
15053
15054
15054
15055
switch (PyUnicode_CHECK_INTERNED (s )) {
15055
15056
case SSTATE_NOT_INTERNED :
@@ -15190,7 +15191,7 @@ intern_common(PyInterpreterState *interp, PyObject *s /* stolen */,
15190
15191
{
15191
15192
PyObject * r = (PyObject * )_Py_hashtable_get (INTERNED_STRINGS , s );
15192
15193
if (r != NULL ) {
15193
- assert (_Py_IsImmortal (r ));
15194
+ assert (_PyUnicode_STATE (r ). statically_allocated );
15194
15195
assert (r != s ); // r must be statically_allocated; s is not
15195
15196
Py_DECREF (s );
15196
15197
return Py_NewRef (r );
0 commit comments