This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pitrou
Recipients gumpy, pitrou
Date 2008-12-04.12:25:40
SpamBayes Score 0.002338695
Marked as misclassified No
Message-id <1228393543.18.0.876505915924.issue4509@psf.upfronthosting.co.za>
In-reply-to
Content
It's not a memoryview bug, but a bytearray oddity. The bytearray uses a
variable-sized buffer underneath, and it tries to minimize the number of
reallocations when changing the object length through some simple
heuristics. Therefore, a bytearray has both a logical size (the one
which is seen from Python, e.g. len()) and a physical size (which can be
greater than the logical size, due to those heuristics).

The bug here is that the bytearray only prohibits changing the physical
size, not the logical size when there is a buffer pointing to it. This
also explains the "\00" you are witnessing at the 5th byte when calling
tobytes() on the memoryview object: it is the end-of-string marker which
has been inserted when changing the logical size.
History
Date User Action Args
2008-12-04 12:25:43pitrousetrecipients: + pitrou, gumpy
2008-12-04 12:25:43pitrousetmessageid: <1228393543.18.0.876505915924.issue4509@psf.upfronthosting.co.za>
2008-12-04 12:25:42pitroulinkissue4509 messages
2008-12-04 12:25:40pitroucreate