@@ -252,7 +252,8 @@ _PyUnicode_InternedSize_Immortal(void)
252
252
// value, to help detect bugs in optimizations.
253
253
254
254
while (PyDict_Next (dict , & pos , & key , & value )) {
255
- if (_Py_IsImmortal (key )) {
255
+ assert (PyUnicode_CHECK_INTERNED (key ) != SSTATE_INTERNED_IMMORTAL_STATIC );
256
+ if (PyUnicode_CHECK_INTERNED (key ) == SSTATE_INTERNED_IMMORTAL ) {
256
257
count ++ ;
257
258
}
258
259
}
@@ -688,10 +689,14 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
688
689
689
690
/* Check interning state */
690
691
#ifdef Py_DEBUG
692
+ // Note that we do not check `_Py_IsImmortal(op)`, since stable ABI
693
+ // extensions can make immortal strings mortal (but with a high enough
694
+ // refcount).
695
+ // The other way is extremely unlikely (worth a potential failed assertion
696
+ // in a debug build), so we do check `!_Py_IsImmortal(op)`.
691
697
switch (PyUnicode_CHECK_INTERNED (op )) {
692
698
case SSTATE_NOT_INTERNED :
693
699
if (ascii -> state .statically_allocated ) {
694
- CHECK (_Py_IsImmortal (op ));
695
700
// This state is for two exceptions:
696
701
// - strings are currently checked before they're interned
697
702
// - the 256 one-latin1-character strings
@@ -707,11 +712,9 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
707
712
break ;
708
713
case SSTATE_INTERNED_IMMORTAL :
709
714
CHECK (!ascii -> state .statically_allocated );
710
- CHECK (_Py_IsImmortal (op ));
711
715
break ;
712
716
case SSTATE_INTERNED_IMMORTAL_STATIC :
713
717
CHECK (ascii -> state .statically_allocated );
714
- CHECK (_Py_IsImmortal (op ));
715
718
break ;
716
719
default :
717
720
Py_UNREACHABLE ();
@@ -1867,7 +1870,6 @@ static PyObject*
1867
1870
get_latin1_char (Py_UCS1 ch )
1868
1871
{
1869
1872
PyObject * o = LATIN1 (ch );
1870
- assert (_Py_IsImmortal (o ));
1871
1873
return o ;
1872
1874
}
1873
1875
@@ -15352,7 +15354,6 @@ intern_static(PyInterpreterState *interp, PyObject *s /* stolen */)
15352
15354
assert (s != NULL );
15353
15355
assert (_PyUnicode_CHECK (s ));
15354
15356
assert (_PyUnicode_STATE (s ).statically_allocated );
15355
- assert (_Py_IsImmortal (s ));
15356
15357
15357
15358
switch (PyUnicode_CHECK_INTERNED (s )) {
15358
15359
case SSTATE_NOT_INTERNED :
@@ -15493,7 +15494,7 @@ intern_common(PyInterpreterState *interp, PyObject *s /* stolen */,
15493
15494
{
15494
15495
PyObject * r = (PyObject * )_Py_hashtable_get (INTERNED_STRINGS , s );
15495
15496
if (r != NULL ) {
15496
- assert (_Py_IsImmortal (r ));
15497
+ assert (_PyUnicode_STATE (r ). statically_allocated );
15497
15498
assert (r != s ); // r must be statically_allocated; s is not
15498
15499
Py_DECREF (s );
15499
15500
return Py_NewRef (r );
0 commit comments