From becd7a967f36248e0090010fbd04885170df3e7a Mon Sep 17 00:00:00 2001 From: Serhiy Storchaka Date: Thu, 19 Mar 2026 10:23:01 +0200 Subject: [PATCH] gh-146143: Fix the PyUnicodeWriter_WriteUCS4() signature (GH-146144) It now accepts a 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 7e9346ea9f7..3a9b34b5922 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 631a6570658..ea91f4158eb 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 00000000000..930d90ff9a2 --- /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 a pointer to a constant buffer +of ``Py_UCS4``. diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index dd2482ca653..d51a95c69a9 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;