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

2020-10-21 Thread Inada Naoki
Change by Inada Naoki : -- resolution: -> not a bug stage: patch review -> resolved status: open -> closed ___ Python tracker ___ _

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

2018-02-07 Thread Xiang Zhang
Xiang Zhang 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 th

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

2017-12-27 Thread Jonathan Underwood
Jonathan Underwood added the comment: Actually the commentary at the top of bytesobject.c for PyBytes_FromStringAndSize says: "... If `str' is NULL then PyBytes_FromStringAndSize() will allocate `size+1' bytes (setting the last byte to the null terminating character)... " So, perhaps that's

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

2017-12-27 Thread Jonathan Underwood
Jonathan Underwood added the comment: Py_SIZE is actually precisely specified and documented[1] as it stands; I don't think a change there is needed. The usage I outlined is in line with that documentation, and many other uses of that macro in the cpython sources. The documentation issues are

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

2017-12-27 Thread R. David Murray
R. David Murray added the comment: I think what Py_SIZE "means" depends on the object type in the general case, not just this one, so documenting that it is mucking with the internal representation is probably the way to go. -- ___ Python tracker

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

2017-12-27 Thread Serhiy Storchaka
Serhiy Storchaka 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 _PyB

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

2017-12-27 Thread Jonathan Underwood
Change by Jonathan Underwood : -- keywords: +patch pull_requests: +4911 stage: -> patch review ___ Python tracker ___ ___ Python-bug

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

2017-12-27 Thread Jonathan Underwood
Jonathan Underwood added the comment: https://github.com/python/cpython/pull/5021 -- ___ Python tracker ___ ___ Python-bugs-list mai

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

2017-12-27 Thread R. David Murray
R. David Murray added the comment: My suspicion is that this behavior/code is left over from when the code was handling strings in python2, where strings were always null terminated and so the equal-bytes test would always pass. I don't think this is appropriate for bytes objects, so I think

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

2017-12-27 Thread Jonathan Underwood
New submission from Jonathan Underwood : With the current logic in Objects/bytesobject.c in the function bytes_compare_eq it can be the case that zero length bytes object object created in an extension module like this: val = PyBytes_FromStringAndSize (NULL, 20); Py_SIZE(val) = 0; won't compa