FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-157710: Add more asserts to internal PyUnicode operations by encukou · Pull Request #159033 · python/cpython · GitHub

Repository navigation

gh-157710: Add more asserts to internal PyUnicode operations - #159033

Open
encukou wants to merge 6 commits into
python:mainfrom
encukou:more-unicode-protection
Open

encukou wants to merge 6 commits into
python:mainfrom
encukou:more-unicode-protection

Conversation

encukou commented Oct 8, 2026 •
edited by bedevere-app Bot
Loading

Copy link
Copy Markdown
Member

Add checks based on the review on #159028:

  • _Py*UnicodeObject_CAST macros assert they have the right bits for the shape
    (this means that _PyUnicode_UTF8 asserts it's not called on a compact ASCII object.)

  • _PyUnicode_IsModifiable & _PyUnicodeWriter_CanWrite assert that UTF-8 storage hasn't been allocated yet

  • Move _PyUnicode_UTF8 to the internal header for use in _PyUnicodeWriter_CanWrite

- `_Py*UnicodeObject_CAST` macros assert they have the right bits for the shape
- `_PyUnicode_IsModifiable` & `_PyUnicodeWriter_CanWrite` assert that
  UTF-8 storage hasn't been allocated yet
Comment thread Include/internal/pycore_unicodeobject.h Outdated
assert(!_Py_IsImmortal(buffer));
assert(PyUnicode_IS_COMPACT_ASCII(buffer)
|| _PyUnicode_UTF8(buffer) == NULL
|| _PyUnicode_UTF8(buffer) == PyUnicode_DATA(buffer));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I would prefer moving _PyUnicode_HAS_UTF8_MEMORY() static inline function to pycore_unicodeobject.h and just test:

assert(!_PyUnicode_HAS_UTF8_MEMORY(buffer);

Comment thread Include/cpython/unicodeobject.h Outdated
Comment thread Include/internal/pycore_unicodeobject.h Outdated
Co-authored-by: Victor Stinner <vstinner@python.org>

encukou commented Oct 9, 2026

Copy link
Copy Markdown
Member Author

Turns out I broke a private debug helper. Added a test so it doesn't happen again.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL