]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] Docs C API: Clarify what happens when null bytes are passed to `PyUnicode_AsUT...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 20 Jan 2025 16:06:18 +0000 (17:06 +0100)
committerGitHub <noreply@github.com>
Mon, 20 Jan 2025 16:06:18 +0000 (16:06 +0000)
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 <zintensitydev@gmail.com>
Co-authored-by: Stan U. <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Tomas R. <tomas.roun8@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
Doc/c-api/unicode.rst

index 9b49569ad271b0344d4e640d4b79faa373e7f50d..f2263610f6fa76509d6457f16dc98a9db3376506 100644 (file)
@@ -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 <https://en.wikipedia.org/wiki/Null_character>`_ 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