@@ -257,7 +257,8 @@ _PyUnicode_InternedSize_Immortal(void)
257
257
// value, to help detect bugs in optimizations.
258
258
259
259
while (PyDict_Next (dict , & pos , & key , & value )) {
260
- if (_Py_IsImmortal (key )) {
260
+ assert (PyUnicode_CHECK_INTERNED (key ) != SSTATE_INTERNED_IMMORTAL_STATIC );
261
+ if (PyUnicode_CHECK_INTERNED (key ) == SSTATE_INTERNED_IMMORTAL ) {
261
262
count ++ ;
262
263
}
263
264
}
@@ -691,10 +692,14 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
691
692
692
693
/* Check interning state */
693
694
#ifdef Py_DEBUG
695
+ // Note that we do not check `_Py_IsImmortal(op)`, since stable ABI
696
+ // extensions can make immortal strings mortal (but with a high enough
697
+ // refcount).
698
+ // The other way is extremely unlikely (worth a potential failed assertion
699
+ // in a debug build), so we do check `!_Py_IsImmortal(op)`.
694
700
switch (PyUnicode_CHECK_INTERNED (op )) {
695
701
case SSTATE_NOT_INTERNED :
696
702
if (ascii -> state .statically_allocated ) {
697
- CHECK (_Py_IsImmortal (op ));
698
703
// This state is for two exceptions:
699
704
// - strings are currently checked before they're interned
700
705
// - the 256 one-latin1-character strings
@@ -710,11 +715,9 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
710
715
break ;
711
716
case SSTATE_INTERNED_IMMORTAL :
712
717
CHECK (!ascii -> state .statically_allocated );
713
- CHECK (_Py_IsImmortal (op ));
714
718
break ;
715
719
case SSTATE_INTERNED_IMMORTAL_STATIC :
716
720
CHECK (ascii -> state .statically_allocated );
717
- CHECK (_Py_IsImmortal (op ));
718
721
break ;
719
722
default :
720
723
Py_UNREACHABLE ();
@@ -1899,7 +1902,8 @@ unicode_write_cstr(PyObject *unicode, Py_ssize_t index,
1899
1902
static PyObject *
1900
1903
get_latin1_char (Py_UCS1 ch )
1901
1904
{
1902
- return Py_NewRef (LATIN1 (ch ));
1905
+ PyObject * o = LATIN1 (ch );
1906
+ return o ;
1903
1907
}
1904
1908
1905
1909
static PyObject *
@@ -15015,7 +15019,7 @@ intern_common(PyInterpreterState *interp, PyObject *s /* stolen */,
15015
15019
{
15016
15020
PyObject * r = (PyObject * )_Py_hashtable_get (INTERNED_STRINGS , s );
15017
15021
if (r != NULL ) {
15018
- assert (_Py_IsImmortal (r ));
15022
+ assert (_PyUnicode_STATE (r ). statically_allocated );
15019
15023
assert (r != s ); // r must be statically_allocated; s is not
15020
15024
Py_DECREF (s );
15021
15025
return Py_NewRef (r );
0 commit comments