[issue32431] Two bytes objects of zero length don't compare equal

Xiang Zhang report at bugs.python.org
Thu Feb 8 01:30:20 EST 2018


Xiang Zhang <angwerzx at 126.com> added the comment:

In my mind I don't think here is any problem. The code

val = PyBytes_FromStringAndSize (NULL, 20);
Py_SIZE(val) = 0;

doesn't create a zero length bytes object. A resizing I think should always means reorganizing the internal representation, including changing the size attribute. Using Py_SIZE won't trigger a full resizing. The code is not resizing but just breaks the internal representation and then leads to bugs. In C level, if you want, it's easy to muck Python objects. And exposing that much implementation details in documentation seems unnecessary.

----------
nosy: +xiang.zhang

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32431>
_______________________________________


More information about the Python-bugs-list mailing list