From 9ae141ea3a7142e4affb7c7945663839fd0b9977 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 9 Sep 2026 22:00:37 +0200 Subject: [PATCH 1/3] gh-156939: Document that PyBytesObject ends with a NUL byte --- Doc/c-api/bytes.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/c-api/bytes.rst b/Doc/c-api/bytes.rst index ff68ecafcda4d08..c6f038409e1d499 100644 --- a/Doc/c-api/bytes.rst +++ b/Doc/c-api/bytes.rst @@ -8,6 +8,10 @@ Bytes Objects These functions raise :exc:`TypeError` when expecting a bytes parameter and called with a non-bytes parameter. +.. impl-detail:: + A :c:type:`PyBytesObject` allocates an extra trailing NUL byte for + compatibility with NUL terminated C strings. + .. index:: pair: object; bytes From 7a2b992f81c9cc3e1b2c7ccf8f4828a0b50898d2 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 9 Sep 2026 22:09:31 +0200 Subject: [PATCH 2/3] Don't add the note as an implementation detail --- Doc/c-api/bytes.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/bytes.rst b/Doc/c-api/bytes.rst index c6f038409e1d499..ba719f9648d19de 100644 --- a/Doc/c-api/bytes.rst +++ b/Doc/c-api/bytes.rst @@ -8,9 +8,9 @@ Bytes Objects These functions raise :exc:`TypeError` when expecting a bytes parameter and called with a non-bytes parameter. -.. impl-detail:: - A :c:type:`PyBytesObject` allocates an extra trailing NUL byte for - compatibility with NUL terminated C strings. +A :c:type:`PyBytesObject` allocates an extra trailing NUL byte for +compatibility with NUL terminated C strings. It is not counted in +:c:func:`PyBytes_Size` length. .. index:: pair: object; bytes From 65550b742c7d3d0a0e23cff3972bf2bc7893b032 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 9 Sep 2026 22:12:20 +0200 Subject: [PATCH 3/3] Replace NUL with null For consistency with the page. --- Doc/c-api/bytes.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/bytes.rst b/Doc/c-api/bytes.rst index ba719f9648d19de..9fd4284f0035042 100644 --- a/Doc/c-api/bytes.rst +++ b/Doc/c-api/bytes.rst @@ -8,8 +8,8 @@ Bytes Objects These functions raise :exc:`TypeError` when expecting a bytes parameter and called with a non-bytes parameter. -A :c:type:`PyBytesObject` allocates an extra trailing NUL byte for -compatibility with NUL terminated C strings. It is not counted in +A :c:type:`PyBytesObject` allocates an extra trailing null byte for +compatibility with null terminated C strings. It is not counted in :c:func:`PyBytes_Size` length. .. index:: pair: object; bytes