https://github.com/python/cpython/commit/4266e34bba13ae1930813e22f5e9c99fc868e920 commit: 4266e34bba13ae1930813e22f5e9c99fc868e920 branch: 3.13 author: Miss Islington (bot) <[email protected]> committer: vstinner <[email protected]> date: 2026-09-15T14:53:11+02:00 summary:
[3.13] gh-156939: Document that PyBytesObject ends with a NUL byte (GH-157236) (#157552) 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 9045689a6be5675..ad7f97ddddb32a7 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 72b5ec8f68ce5bb..d0aa04cd4f02581 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]
