https://github.com/python/cpython/commit/2327e118aeba38b796a6b6afc1e980852d660250
commit: 2327e118aeba38b796a6b6afc1e980852d660250
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: vstinner <[email protected]>
date: 2026-09-15T14:53:08+02:00
summary:

[3.14] gh-156939: Document that PyBytesObject ends with a NUL byte (GH-157236) 
(#157551)

gh-156939: Document that PyBytesObject ends with a NUL byte (GH-157236)

Document as an implementation detail that PyBytesObject and ByteArrayObject end
with a NUL byte.
(cherry picked from commit 2fcb0e27d959345151750b756af79054c3230531)

Co-authored-by: Victor Stinner <[email protected]>
Co-authored-by: Petr Viktorin <[email protected]>

files:
M Doc/c-api/bytearray.rst
M Doc/c-api/bytes.rst

diff --git a/Doc/c-api/bytearray.rst b/Doc/c-api/bytearray.rst
index 2b36da997d42956..8f3cb2d63cb3c82 100644
--- a/Doc/c-api/bytearray.rst
+++ b/Doc/c-api/bytearray.rst
@@ -12,6 +12,12 @@ Byte Array Objects
 
    This subtype of :c:type:`PyObject` represents a Python bytearray object.
 
+   .. impl-detail::
+
+      The internal buffer of :c:type:`PyByteArrayObject` always includes an
+      extra trailing null byte for compatibility with null terminated C
+      strings.  This extra byte is not counted in :c:func:`PyByteArray_Size`
+      nor in the *len* arguments of the functions below.
 
 .. c:var:: PyTypeObject PyByteArray_Type
 
diff --git a/Doc/c-api/bytes.rst b/Doc/c-api/bytes.rst
index b90d030719eca5b..4be86cfabe3eab1 100644
--- a/Doc/c-api/bytes.rst
+++ b/Doc/c-api/bytes.rst
@@ -8,6 +8,13 @@ Bytes Objects
 These functions raise :exc:`TypeError` when expecting a bytes parameter and
 called with a non-bytes parameter.
 
+.. impl-detail::
+
+   The internal buffer of :c:type:`PyBytesObject` always includes an extra
+   trailing null byte for compatibility with null terminated C strings.
+   This extra byte is not counted in :c:func:`PyBytes_Size` nor in the
+   various *length* and *size* arguments of the functions below.
+
 .. index:: pair: object; bytes
 
 

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to