Commit e699e5a2 authored by Victor Stinner's avatar Victor Stinner

Issue #18408: Don't check unicode consistency in _PyUnicode_HAS_UTF8_MEMORY()

and _PyUnicode_HAS_WSTR_MEMORY() macros

These macros are called in unicode_dealloc(), whereas the unicode object can be
"inconsistent" if the creation of the object failed.

For example, when unicode_subtype_new() fails on a memory allocation,
_PyUnicode_CheckConsistency() fails with an assertion error because data is
NULL.
parent 3de58698
...@@ -122,16 +122,14 @@ extern "C" { ...@@ -122,16 +122,14 @@ extern "C" {
/* true if the Unicode object has an allocated UTF-8 memory block /* true if the Unicode object has an allocated UTF-8 memory block
(not shared with other data) */ (not shared with other data) */
#define _PyUnicode_HAS_UTF8_MEMORY(op) \ #define _PyUnicode_HAS_UTF8_MEMORY(op) \
(assert(_PyUnicode_CHECK(op)), \ ((!PyUnicode_IS_COMPACT_ASCII(op) \
(!PyUnicode_IS_COMPACT_ASCII(op) \
&& _PyUnicode_UTF8(op) \ && _PyUnicode_UTF8(op) \
&& _PyUnicode_UTF8(op) != PyUnicode_DATA(op))) && _PyUnicode_UTF8(op) != PyUnicode_DATA(op)))
/* true if the Unicode object has an allocated wstr memory block /* true if the Unicode object has an allocated wstr memory block
(not shared with other data) */ (not shared with other data) */
#define _PyUnicode_HAS_WSTR_MEMORY(op) \ #define _PyUnicode_HAS_WSTR_MEMORY(op) \
(assert(_PyUnicode_CHECK(op)), \ ((_PyUnicode_WSTR(op) && \
(_PyUnicode_WSTR(op) && \
(!PyUnicode_IS_READY(op) || \ (!PyUnicode_IS_READY(op) || \
_PyUnicode_WSTR(op) != PyUnicode_DATA(op)))) _PyUnicode_WSTR(op) != PyUnicode_DATA(op))))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment