]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-153419: Fix several issues around bytearray __init__ (#153498)
authorSteve Stagg <stestagg@gmail.com>
Fri, 24 Jul 2026 15:25:11 +0000 (16:25 +0100)
committerGitHub <noreply@github.com>
Fri, 24 Jul 2026 15:25:11 +0000 (15:25 +0000)
commitd5c1b29658063d1ef9d66515d8e4cb9929126be7
treed0db333d6f703f79b0d46ebbb263d6487ac283a1
parentd24d9d0f1d1177cd6f130a4bd59c1c267a0f8d1f
gh-153419: Fix several issues around bytearray __init__ (#153498)

Introduce a bytearray_new() function to ensure that
ob_bytes_object is always set on a bytearray.

Resizing a bytearray to 0 length now explicitly sets
the ob_bytes_object to the empty constant immortal.

Add a check in the 'bytearray init from string'
fast path to ensure there are no active exports.

This fixes asserts/crashes on the following:
 - bytearray(1).__init__()
 - bytearray().__new__(bytearray).append(1)
 - a = bytearray(); b = memoryview(a); a.__init__('x', 'ascii')

Co-authored-by: Cody Maloney <cmaloney@users.noreply.github.com>
Lib/test/test_bytes.py
Misc/NEWS.d/next/Core_and_Builtins/2026-07-11-01-17-57.gh-issue-153419.U8HJOJ.rst [new file with mode: 0644]
Objects/bytearrayobject.c
Objects/bytesobject.c