Author serhiy.storchaka
Recipients jonathanunderwood, r.david.murray, serhiy.storchaka
Date 2017-12-27.17:14:57
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1514394897.69.0.213398074469.issue32431@psf.upfronthosting.co.za>
In-reply-to
Content
Much C code implies that bytes are null terminated. For example bytes-to-number converters and most functions that accept bytes as file path. Changing just the compare logic will not help.

The documented way of changing the size of the bytes object is _PyBytes_Resize(). But since this is a private function the only way of resizing the bytes object using public functions is creating a new object with PyBytes_FromStringAndSize(). If the new size is 0, it will return a singleton, thus this is a fast and memory efficient way.

Using the Py_SIZE() macro with the bytes object is not even documented. We should either document this way with its caveats (for example misusing it can lead to inefficient use of memory), or admit that this is working with internal representation which we shouldn't encourage.
History
Date User Action Args
2017-12-27 17:14:57serhiy.storchakasetrecipients: + serhiy.storchaka, r.david.murray, jonathanunderwood
2017-12-27 17:14:57serhiy.storchakasetmessageid: <1514394897.69.0.213398074469.issue32431@psf.upfronthosting.co.za>
2017-12-27 17:14:57serhiy.storchakalinkissue32431 messages
2017-12-27 17:14:57serhiy.storchakacreate