@@ -1181,18 +1181,23 @@ unicode_dealloc(register PyUnicodeObject *unicode)
11811181static int
11821182unicode_resizable (PyObject * unicode )
11831183{
1184+ Py_ssize_t len ;
11841185 if (Py_REFCNT (unicode ) != 1 )
11851186 return 0 ;
11861187 if (PyUnicode_CHECK_INTERNED (unicode ))
11871188 return 0 ;
11881189 if (unicode == unicode_empty )
11891190 return 0 ;
1190- if (PyUnicode_WSTR_LENGTH (unicode ) == 1 ) {
1191+ if (_PyUnicode_KIND (unicode ) == PyUnicode_WCHAR_KIND )
1192+ len = PyUnicode_WSTR_LENGTH (unicode );
1193+ else
1194+ len = PyUnicode_GET_LENGTH (unicode );
1195+ if (len == 1 ) {
11911196 Py_UCS4 ch ;
1192- if (PyUnicode_IS_COMPACT (unicode ))
1193- ch = PyUnicode_READ_CHAR (unicode , 0 );
1194- else
1197+ if (_PyUnicode_KIND (unicode ) == PyUnicode_WCHAR_KIND )
11951198 ch = _PyUnicode_WSTR (unicode )[0 ];
1199+ else
1200+ ch = PyUnicode_READ_CHAR (unicode , 0 );
11961201 if (ch < 256 && unicode_latin1 [ch ] == unicode )
11971202 return 0 ;
11981203 }
@@ -11969,12 +11974,9 @@ unicode__sizeof__(PyUnicodeObject *v)
1196911974 PyUnicode_CHARACTER_SIZE (v );
1197011975 }
1197111976 /* If the wstr pointer is present, account for it unless it is shared
11972- with the data pointer. Since PyUnicode_DATA will crash if the object
11973- is not ready, check whether it's either not ready (in which case the
11974- data is entirely in wstr) or if the data is not shared. */
11977+ with the data pointer. Check if the data is not shared. */
1197511978 if (_PyUnicode_WSTR (v ) &&
11976- (!PyUnicode_IS_READY (v ) ||
11977- (PyUnicode_DATA (v ) != _PyUnicode_WSTR (v ))))
11979+ (PyUnicode_DATA (v ) != _PyUnicode_WSTR (v )))
1197811980 size += (PyUnicode_WSTR_LENGTH (v ) + 1 ) * sizeof (wchar_t );
1197911981 if (_PyUnicode_HAS_UTF8_MEMORY (v ))
1198011982 size += PyUnicode_UTF8_LENGTH (v ) + 1 ;
0 commit comments