From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Mon, 20 Jan 2025 16:04:53 +0000 (+0100) Subject: [3.13] Docs C API: Clarify what happens when null bytes are passed to `PyUnicode_AsUT... X-Git-Tag: v3.13.2~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=22e9faf08a4b2a90c62c3486d1183839132d4231;p=thirdparty%2FPython%2Fcpython.git [3.13] Docs C API: Clarify what happens when null bytes are passed to `PyUnicode_AsUTF8` (GH-127458) (#129080) Docs C API: Clarify what happens when null bytes are passed to `PyUnicode_AsUTF8` (GH-127458) (cherry picked from commit e792f4bc2e712bb6e2143599d2b88dd339de83e6) Co-authored-by: Peter Bierma Co-authored-by: Stan U. <89152624+StanFromIreland@users.noreply.github.com> Co-authored-by: Tomas R. Co-authored-by: Victor Stinner --- diff --git a/Doc/c-api/unicode.rst b/Doc/c-api/unicode.rst index 305929809689..22e134c9f08e 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -1054,6 +1054,15 @@ These are the UTF-8 codec APIs: As :c:func:`PyUnicode_AsUTF8AndSize`, but does not store the size. + .. warning:: + + This function does not have any special behavior for + `null characters `_ embedded within + *unicode*. As a result, strings containing null characters will remain in the returned + string, which some C functions might interpret as the end of the string, leading to + truncation. If truncation is an issue, it is recommended to use :c:func:`PyUnicode_AsUTF8AndSize` + instead. + .. versionadded:: 3.3 .. versionchanged:: 3.7