@@ -75,7 +75,6 @@ typedef struct {
75
75
* kind = PyUnicode_1BYTE_KIND
76
76
* compact = 1
77
77
* ascii = 1
78
- * ready = 1
79
78
* (length is the length of the utf8)
80
79
* (data starts just after the structure)
81
80
* (since ASCII is decoded from UTF-8, the utf8 string are the data)
@@ -87,20 +86,18 @@ typedef struct {
87
86
* kind = PyUnicode_1BYTE_KIND, PyUnicode_2BYTE_KIND or
88
87
PyUnicode_4BYTE_KIND
89
88
* compact = 1
90
- * ready = 1
91
89
* ascii = 0
92
90
* utf8 is not shared with data
93
91
* utf8_length = 0 if utf8 is NULL
94
92
* (data starts just after the structure)
95
93
96
- - legacy string, ready :
94
+ - legacy string:
97
95
98
96
* structure = PyUnicodeObject structure
99
97
* test: !PyUnicode_IS_COMPACT(op)
100
98
* kind = PyUnicode_1BYTE_KIND, PyUnicode_2BYTE_KIND or
101
99
PyUnicode_4BYTE_KIND
102
100
* compact = 0
103
- * ready = 1
104
101
* data.any is not NULL
105
102
* utf8 is shared and utf8_length = length with data.any if ascii = 1
106
103
* utf8_length = 0 if utf8 is NULL
@@ -158,14 +155,9 @@ typedef struct {
158
155
and the kind is PyUnicode_1BYTE_KIND. If ascii is set and compact is
159
156
set, use the PyASCIIObject structure. */
160
157
unsigned int ascii :1 ;
161
- /* The ready flag indicates whether the object layout is initialized
162
- completely. This means that this is either a compact object, or
163
- the data pointer is filled out. The bit is redundant, and helps
164
- to minimize the test in PyUnicode_IS_READY(). */
165
- unsigned int ready :1 ;
166
158
/* Padding to ensure that PyUnicode_DATA() is always aligned to
167
159
4 bytes (see issue #19537 on m68k). */
168
- unsigned int :24 ;
160
+ unsigned int :25 ;
169
161
} state ;
170
162
} PyASCIIObject ;
171
163
@@ -223,10 +215,9 @@ static inline unsigned int PyUnicode_CHECK_INTERNED(PyObject *op) {
223
215
# define PyUnicode_CHECK_INTERNED (op ) PyUnicode_CHECK_INTERNED(_PyObject_CAST(op))
224
216
#endif
225
217
226
- /* Fast check to determine whether an object is ready. Equivalent to:
227
- PyUnicode_IS_COMPACT(op) || _PyUnicodeObject_CAST(op)->data.any */
218
+ /* For backward compatibility */
228
219
static inline unsigned int PyUnicode_IS_READY (PyObject * op ) {
229
- return _PyASCIIObject_CAST ( op ) -> state . ready ;
220
+ return 1 ;
230
221
}
231
222
#if !defined(Py_LIMITED_API ) || Py_LIMITED_API + 0 < 0x030b0000
232
223
# define PyUnicode_IS_READY (op ) PyUnicode_IS_READY(_PyObject_CAST(op))
@@ -236,7 +227,6 @@ static inline unsigned int PyUnicode_IS_READY(PyObject *op) {
236
227
string may be compact (PyUnicode_IS_COMPACT_ASCII) or not, but must be
237
228
ready. */
238
229
static inline unsigned int PyUnicode_IS_ASCII (PyObject * op ) {
239
- assert (PyUnicode_IS_READY (op ));
240
230
return _PyASCIIObject_CAST (op )-> state .ascii ;
241
231
}
242
232
#if !defined(Py_LIMITED_API ) || Py_LIMITED_API + 0 < 0x030b0000
@@ -270,8 +260,7 @@ enum PyUnicode_Kind {
270
260
271
261
/* Return one of the PyUnicode_*_KIND values defined above. */
272
262
#define PyUnicode_KIND (op ) \
273
- (assert(PyUnicode_IS_READY(op)), \
274
- _PyASCIIObject_CAST(op)->state.kind)
263
+ (_PyASCIIObject_CAST(op)->state.kind)
275
264
276
265
/* Return a void pointer to the raw unicode buffer. */
277
266
static inline void * _PyUnicode_COMPACT_DATA (PyObject * op ) {
@@ -307,11 +296,8 @@ static inline void* PyUnicode_DATA(PyObject *op) {
307
296
#define PyUnicode_2BYTE_DATA (op ) _Py_STATIC_CAST(Py_UCS2*, PyUnicode_DATA(op))
308
297
#define PyUnicode_4BYTE_DATA (op ) _Py_STATIC_CAST(Py_UCS4*, PyUnicode_DATA(op))
309
298
310
- /* Returns the length of the unicode string. The caller has to make sure that
311
- the string has it's canonical representation set before calling
312
- this function. Call PyUnicode_(FAST_)Ready to ensure that. */
299
+ /* Returns the length of the unicode string. */
313
300
static inline Py_ssize_t PyUnicode_GET_LENGTH (PyObject * op ) {
314
- assert (PyUnicode_IS_READY (op ));
315
301
return _PyASCIIObject_CAST (op )-> length ;
316
302
}
317
303
#if !defined(Py_LIMITED_API ) || Py_LIMITED_API + 0 < 0x030b0000
@@ -366,7 +352,6 @@ static inline Py_UCS4 PyUnicode_READ(unsigned int kind,
366
352
cache kind and use PyUnicode_READ instead. */
367
353
static inline Py_UCS4 PyUnicode_READ_CHAR (PyObject * unicode , Py_ssize_t index )
368
354
{
369
- assert (PyUnicode_IS_READY (unicode ));
370
355
unsigned int kind = PyUnicode_KIND (unicode );
371
356
if (kind == PyUnicode_1BYTE_KIND ) {
372
357
return PyUnicode_1BYTE_DATA (unicode )[index ];
@@ -387,7 +372,6 @@ static inline Py_UCS4 PyUnicode_READ_CHAR(PyObject *unicode, Py_ssize_t index)
387
372
than iterating over the string. */
388
373
static inline Py_UCS4 PyUnicode_MAX_CHAR_VALUE (PyObject * op )
389
374
{
390
- assert (PyUnicode_IS_READY (op ));
391
375
if (PyUnicode_IS_ASCII (op )) {
392
376
return 0x7fU ;
393
377
}
@@ -419,13 +403,9 @@ PyAPI_FUNC(PyObject*) PyUnicode_New(
419
403
Py_UCS4 maxchar /* maximum code point value in the string */
420
404
);
421
405
422
- /* PyUnicode_READY() does less work than _PyUnicode_Ready() in the best
423
- case. If the canonical representation is not yet set, it will still call
424
- _PyUnicode_Ready().
425
- Returns 0 on success and -1 on errors. */
406
+ /* For backward compatibility */
426
407
static inline int PyUnicode_READY (PyObject * op )
427
408
{
428
- assert (PyUnicode_IS_READY (op ));
429
409
return 0 ;
430
410
}
431
411
#if !defined(Py_LIMITED_API ) || Py_LIMITED_API + 0 < 0x030b0000
@@ -574,8 +554,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
574
554
575
555
Return 0 on success, raise an exception and return -1 on error. */
576
556
#define _PyUnicodeWriter_PrepareKind (WRITER , KIND ) \
577
- (assert((KIND) != PyUnicode_WCHAR_KIND), \
578
- (KIND) <= (WRITER)->kind \
557
+ ((KIND) <= (WRITER)->kind \
579
558
? 0 \
580
559
: _PyUnicodeWriter_PrepareKindInternal((WRITER), (KIND)))
581
560
0 commit comments