Serhiy Storchaka <storchaka+cpyt...@gmail.com> added the comment:

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.

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32431>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to