Repository navigation
gh-157710: Add more asserts to internal PyUnicode operations #159033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,7 @@ extern "C" { | |||||||
| #include "pycore_fileutils.h" // _Py_error_handler | ||||||||
| #include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI | ||||||||
| #include "pycore_runtime.h" // _Py_LATIN1_CHR() | ||||||||
| #include "pycore_pyatomic_ft_wrappers.h" // FT_ATOMIC_LOAD_PTR_ACQUIRE | ||||||||
|
|
||||||||
|
|
||||||||
| // Maximum code point of Unicode 6.0: 0x10ffff (1,114,111). | ||||||||
|
|
@@ -108,6 +109,11 @@ _PyUnicode_EnsureUnicode(PyObject *obj) | |||||||
| return 0; | ||||||||
| } | ||||||||
|
|
||||||||
| static inline char* _PyUnicode_UTF8(PyObject *op) | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| { | ||||||||
| return FT_ATOMIC_LOAD_PTR_ACQUIRE(_PyCompactUnicodeObject_CAST(op)->utf8); | ||||||||
| } | ||||||||
|
|
||||||||
| #ifndef NDEBUG | ||||||||
| static inline int | ||||||||
| _PyUnicodeWriter_CanWrite(_PyUnicodeWriter *writer) | ||||||||
|
|
@@ -125,6 +131,9 @@ _PyUnicodeWriter_CanWrite(_PyUnicodeWriter *writer) | |||||||
| assert(PyUnstable_Unicode_GET_CACHED_HASH(buffer) == -1); | ||||||||
| assert(!PyUnicode_CHECK_INTERNED(buffer)); | ||||||||
| assert(!_Py_IsImmortal(buffer)); | ||||||||
| assert(PyUnicode_IS_COMPACT_ASCII(buffer) | ||||||||
| || _PyUnicode_UTF8(buffer) == NULL | ||||||||
| || _PyUnicode_UTF8(buffer) == PyUnicode_DATA(buffer)); | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would prefer moving
|
||||||||
| return 1; | ||||||||
| } | ||||||||
| #endif | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: you might write the test as "make sure that it's not a compact ASCII string":
It's just a minor coding style suggestion, feel free to ignore it.