From 12e6e6142523dd29ffe0ff6b6de39dad317dd74d Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Wed, 18 Mar 2026 23:44:34 +0200 Subject: [PATCH 1/2] gh-146143: Fix the PyUnicodeWriter_WriteUCS4() signature It now accepts pointer to constant buffer of Py_UCS4. --- Doc/c-api/unicode.rst | 2 +- Include/cpython/unicodeobject.h | 2 +- .../next/C_API/2026-03-18-23-44-29.gh-issue-146143.pwIrJq.rst | 2 ++ Objects/unicodeobject.c | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/C_API/2026-03-18-23-44-29.gh-issue-146143.pwIrJq.rst diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 4845e0f300278d..3df9d14552e74a 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -1867,7 +1867,7 @@ object. On success, return ``0``. On error, set an exception, leave the writer unchanged, and return ``-1``. -.. c:function:: int PyUnicodeWriter_WriteUCS4(PyUnicodeWriter *writer, Py_UCS4 *str, Py_ssize_t size) +.. c:function:: int PyUnicodeWriter_WriteUCS4(PyUnicodeWriter *writer, const Py_UCS4 *str, Py_ssize_t size) Writer the UCS4 string *str* into *writer*. diff --git a/Include/cpython/unicodeobject.h b/Include/cpython/unicodeobject.h index 631a6570658410..ea91f4158eb392 100644 --- a/Include/cpython/unicodeobject.h +++ b/Include/cpython/unicodeobject.h @@ -496,7 +496,7 @@ PyAPI_FUNC(int) PyUnicodeWriter_WriteWideChar( Py_ssize_t size); PyAPI_FUNC(int) PyUnicodeWriter_WriteUCS4( PyUnicodeWriter *writer, - Py_UCS4 *str, + const Py_UCS4 *str, Py_ssize_t size); PyAPI_FUNC(int) PyUnicodeWriter_WriteStr( diff --git a/Misc/NEWS.d/next/C_API/2026-03-18-23-44-29.gh-issue-146143.pwIrJq.rst b/Misc/NEWS.d/next/C_API/2026-03-18-23-44-29.gh-issue-146143.pwIrJq.rst new file mode 100644 index 00000000000000..ef22cf653f4dcd --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2026-03-18-23-44-29.gh-issue-146143.pwIrJq.rst @@ -0,0 +1,2 @@ +:c:func:`PyUnicodeWriter_WriteUCS4` now accepts pointer to constant buffer +of ``Py_UCS4``. diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index dd2482ca653fb1..d51a95c69a93b3 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -2224,7 +2224,7 @@ _PyUnicode_FromUCS4(const Py_UCS4 *u, Py_ssize_t size) int PyUnicodeWriter_WriteUCS4(PyUnicodeWriter *pub_writer, - Py_UCS4 *str, + const Py_UCS4 *str, Py_ssize_t size) { _PyUnicodeWriter *writer = (_PyUnicodeWriter*)pub_writer; From df56cb834d68ae30c7ad9f1f704bc0f6404abb8d Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 19 Mar 2026 09:56:52 +0200 Subject: [PATCH 2/2] Apply suggestion from @vstinner Co-authored-by: Victor Stinner --- .../next/C_API/2026-03-18-23-44-29.gh-issue-146143.pwIrJq.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/C_API/2026-03-18-23-44-29.gh-issue-146143.pwIrJq.rst b/Misc/NEWS.d/next/C_API/2026-03-18-23-44-29.gh-issue-146143.pwIrJq.rst index ef22cf653f4dcd..930d90ff9a2675 100644 --- a/Misc/NEWS.d/next/C_API/2026-03-18-23-44-29.gh-issue-146143.pwIrJq.rst +++ b/Misc/NEWS.d/next/C_API/2026-03-18-23-44-29.gh-issue-146143.pwIrJq.rst @@ -1,2 +1,2 @@ -:c:func:`PyUnicodeWriter_WriteUCS4` now accepts pointer to constant buffer +:c:func:`PyUnicodeWriter_WriteUCS4` now accepts a pointer to a constant buffer of ``Py_UCS4``.