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..930d90ff9a2675 --- /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 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;