Skip to content

C API: Fix PyUnicodeWriter_WriteUTF8() and PyUnicodeWriter_Format() error handling #158439

Closed

Description

@vstinner

If PyUnicodeWriter_WriteUTF8() or PyUnicodeWriter_Format() fails, the writer should remain valid and usable for further writes. These functions can change the buffer kind to support write larger character. But if these functions fail, PyUnicodeWriter_Finish() may need to change the buffer kind to use the most efficient storage for the final string.

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Sep 29, 2026
  2. added 5 commits that reference this issue on Sep 29, 2026
  3. vstinner commented on Sep 29, 2026

    @vstinner
    MemberAuthor

    The fix in the main branch changes the _PyUnicodeWriter structure (to add a new recheck_maxchar member). The structure is private but exposed in the public C API. I prefer to leave the code as it is in 3.14 and 3.15 branches: it's too risky to change the ABI. So I close the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions