Skip to content

Commit 4266e34

Browse files
miss-islingtonvstinnerencukou
authored
[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 2fcb0e2) Co-authored-by: Victor Stinner <vstinner@python.org> Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent f63df37 commit 4266e34

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

Doc/c-api/bytearray.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ Byte Array Objects
1212
1313
This subtype of :c:type:`PyObject` represents a Python bytearray object.
1414

15+
.. impl-detail::
16+
17+
The internal buffer of :c:type:`PyByteArrayObject` always includes an
18+
extra trailing null byte for compatibility with null terminated C
19+
strings. This extra byte is not counted in :c:func:`PyByteArray_Size`
20+
nor in the *len* arguments of the functions below.
1521

1622
.. c:var:: PyTypeObject PyByteArray_Type
1723

Doc/c-api/bytes.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ Bytes Objects
88
These functions raise :exc:`TypeError` when expecting a bytes parameter and
99
called with a non-bytes parameter.
1010

11+
.. impl-detail::
12+
13+
The internal buffer of :c:type:`PyBytesObject` always includes an extra
14+
trailing null byte for compatibility with null terminated C strings.
15+
This extra byte is not counted in :c:func:`PyBytes_Size` nor in the
16+
various *length* and *size* arguments of the functions below.
17+
1118
.. index:: pair: object; bytes
1219

1320

0 commit comments

Comments
 (0)