Skip to content

Commit 24c74be

Browse files
author
Victor Stinner
committed
PyUnicode_IS_ASCII() macro ensures that the string is ready
It has no sense to check if a not ready string is ASCII or not.
1 parent c4b4954 commit 24c74be

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

‎Include/unicodeobject.h‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -424,10 +424,12 @@ PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type;
424424
#define SSTATE_INTERNED_IMMORTAL 2
425425

426426
/* Return true if the string contains only ASCII characters, or 0 if not. The
427-
string may be compact (PyUnicode_IS_COMPACT_ASCII) or not. No type checks
428-
or Ready calls are performed. */
429-
#define PyUnicode_IS_ASCII(op) \
430-
(((PyASCIIObject*)op)->state.ascii)
427+
string may be compact (PyUnicode_IS_COMPACT_ASCII) or not, but must be
428+
ready. */
429+
#define PyUnicode_IS_ASCII(op) \
430+
(assert(PyUnicode_Check(op)), \
431+
assert(PyUnicode_IS_READY(op)), \
432+
((PyASCIIObject*)op)->state.ascii)
431433

432434
/* Return true if the string is compact or 0 if not.
433435
No type checks or Ready calls are performed. */
@@ -437,7 +439,7 @@ PyAPI_DATA(PyTypeObject) PyUnicodeIter_Type;
437439
/* Return true if the string is a compact ASCII string (use PyASCIIObject
438440
structure), or 0 if not. No type checks or Ready calls are performed. */
439441
#define PyUnicode_IS_COMPACT_ASCII(op) \
440-
(PyUnicode_IS_ASCII(op) && PyUnicode_IS_COMPACT(op))
442+
(((PyASCIIObject*)op)->state.ascii && PyUnicode_IS_COMPACT(op))
441443

442444
enum PyUnicode_Kind {
443445
/* String contains only wstr byte characters. This is only possible

0 commit comments

Comments
 (0)