@@ -114,11 +114,6 @@ NOTE: In the interpreter's initialization phase, some globals are currently
114114# define _PyUnicode_CHECK (op ) PyUnicode_Check(op)
115115#endif
116116
117- static inline char * _PyUnicode_UTF8 (PyObject * op )
118- {
119- return FT_ATOMIC_LOAD_PTR_ACQUIRE (_PyCompactUnicodeObject_CAST (op )-> utf8 );
120- }
121-
122117static inline char * PyUnicode_UTF8 (PyObject * op )
123118{
124119 assert (_PyUnicode_CHECK (op ));
@@ -175,15 +170,6 @@ static inline int _PyUnicode_SHARE_UTF8(PyObject *op)
175170 return (_PyUnicode_UTF8 (op ) == PyUnicode_DATA (op ));
176171}
177172
178- /* true if the Unicode object has an allocated UTF-8 memory block
179- (not shared with other data) */
180- static inline int _PyUnicode_HAS_UTF8_MEMORY (PyObject * op )
181- {
182- return (!PyUnicode_IS_COMPACT_ASCII (op )
183- && _PyUnicode_UTF8 (op ) != NULL
184- && _PyUnicode_UTF8 (op ) != PyUnicode_DATA (op ));
185- }
186-
187173
188174#define LATIN1 _Py_LATIN1_CHR
189175
@@ -1251,34 +1237,32 @@ const void *_PyUnicode_data(void *unicode_raw) {
12511237 printf ("compact %d\n" , PyUnicode_IS_COMPACT (unicode ));
12521238 printf ("compact ascii %d\n" , PyUnicode_IS_COMPACT_ASCII (unicode ));
12531239 printf ("ascii op %p\n" , (void * )(_PyASCIIObject_CAST (unicode ) + 1 ));
1254- printf ("compact op %p\n" , (void * )(_PyCompactUnicodeObject_CAST (unicode ) + 1 ));
1255- printf ("compact data %p\n" , _PyUnicode_COMPACT_DATA (unicode ));
1240+ if (!PyUnicode_IS_COMPACT_ASCII (unicode )) {
1241+ printf ("compact op %p\n" , (void * )(_PyCompactUnicodeObject_CAST (unicode ) + 1 ));
1242+ printf ("compact data %p\n" , _PyUnicode_COMPACT_DATA (unicode ));
1243+ }
12561244 return PyUnicode_DATA (unicode );
12571245}
12581246
12591247void
12601248_PyUnicode_Dump (PyObject * op )
12611249{
12621250 PyASCIIObject * ascii = _PyASCIIObject_CAST (op );
1263- PyCompactUnicodeObject * compact = _PyCompactUnicodeObject_CAST (op );
1264- PyUnicodeObject * unicode = _PyUnicodeObject_CAST (op );
1265- const void * data ;
12661251
1267- if (ascii -> state .compact )
1268- {
1269- if (ascii -> state .ascii )
1270- data = (ascii + 1 );
1271- else
1272- data = (compact + 1 );
1273- }
1274- else
1275- data = unicode -> data .any ;
1276- printf ("%s: len=%zu, " , unicode_kind_name (op ), ascii -> length );
1252+ printf ("%s: len=%zu" , unicode_kind_name (op ), ascii -> length );
12771253
12781254 if (!ascii -> state .ascii ) {
1279- printf ("utf8=%p (%zu)" , (void * )compact -> utf8 , compact -> utf8_length );
1255+ PyCompactUnicodeObject * compact = _PyCompactUnicodeObject_CAST (op );
1256+ if (compact -> utf8 == NULL ) {
1257+ printf (", utf8=NULL" );
1258+ }
1259+ else {
1260+ printf (", utf8=%p" , (void * )compact -> utf8 );
1261+ }
1262+ printf (" (%zu)" , compact -> utf8_length );
12801263 }
1281- printf (", data=%p\n" , data );
1264+ printf (", data=%p\n" , PyUnicode_DATA (op ));
1265+ fflush (stdout );
12821266}
12831267#endif
12841268
@@ -1767,6 +1751,9 @@ _PyUnicode_IsModifiable(PyObject *unicode)
17671751 return 0 ;
17681752 if (PyUnicode_CHECK_INTERNED (unicode ))
17691753 return 0 ;
1754+ if (_PyUnicode_HAS_UTF8_MEMORY (unicode )) {
1755+ return 0 ;
1756+ }
17701757#ifdef Py_DEBUG
17711758 /* singleton refcount is greater than 1 */
17721759 assert (!unicode_is_singleton (unicode ));
0 commit comments