From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Mon, 20 Jan 2025 16:06:18 +0000 (+0100) Subject: [3.12] Docs C API: Clarify what happens when null bytes are passed to `PyUnicode_AsUT... X-Git-Tag: v3.12.9~49 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e6cb31a098a5036519fe270b4d73b2b0e8e774ba;p=thirdparty%2FPython%2Fcpython.git [3.12] Docs C API: Clarify what happens when null bytes are passed to `PyUnicode_AsUTF8` (GH-127458) (#129081) 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 9b49569ad271..f2263610f6fa 100644 --- a/Doc/c-api/unicode.rst +++ b/Doc/c-api/unicode.rst @@ -1032,6 +1032,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