Skip to content

gh-158439: Add _PyUnicodeWriter.recheck_maxchar - #158442

Merged
vstinner merged 1 commit into
python:mainfrom
vstinner:writer_recheck_maxchar
Sep 29, 2026
Merged

vstinner merged 1 commit into
python:mainfrom
vstinner:writer_recheck_maxchar

Conversation

@vstinner

@vstinner vstinner commented Sep 29, 2026 •

Copy link
Copy Markdown
Member

If PyUnicodeWriter_WriteUTF8() or PyUnicodeWriter_Format() fails, PyUnicodeWriter_Finish() now checks if the string uses the most efficient storage. Previously, PyUnicodeWriter_Finish() could return a string with an inefficient storage.

  • Add _PyUnicodeWriter.recheck_maxchar. PyUnicodeWriter_WriteUTF8() and PyUnicodeWriter_Format() now set recheck_maxchar to 1 on error.
  • Move error handling from caller to _PyUnicode_DecodeUTF8Writer().
  • PyUnicodeWriter_DecodeUTF8Stateful(): rename length parameter to size and rename string parameter to str.

If PyUnicodeWriter_WriteUTF8() or PyUnicodeWriter_Format() fails,
PyUnicodeWriter_Finish() now checks if the string uses the most
efficient storage. Previously, PyUnicodeWriter_Finish() could return
a string with an inefficient storage.

* Add _PyUnicodeWriter.recheck_maxchar. PyUnicodeWriter_WriteUTF8()
  and PyUnicodeWriter_Format() now set recheck_maxchar to 1 on error.
* Move error handling from caller to _PyUnicode_DecodeUTF8Writer().
* PyUnicodeWriter_DecodeUTF8Stateful(): rename length parameter to
  size and rename string parameter to str.
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34834583 | 📁 Comparing aef1317 against main (115c297)

  🔍 Preview build  

2 files changed
± c-api/unicode.html
± whatsnew/changelog.html

@vstinner
vstinner merged commit a0491c8 into python:main Sep 29, 2026
56 checks passed
@vstinner
vstinner deleted the writer_recheck_maxchar branch September 29, 2026 20:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant