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 jonathanunderwood
Recipients jonathanunderwood
Date 2017-12-27.15:17:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1514387834.13.0.213398074469.issue32431@psf.upfronthosting.co.za>
In-reply-to
Content
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 compare equal to b'' because the memory is not initialized, so the first two bytes won't be equal. Nonetheless, the Python interpreter does return b'' for print(repr(val)), so this behaviour is very confusing. To get the correct behaviour, one would have to initialize the memory:

val = PyBytes_FromStringAndSize (NULL, 20);
c = PyBytes_AS_STRING (val);
c[0] = '\0';
Py_SIZE(val) = 0;

However, it would be more sensible to fix the logic in bytes_compare_eq in my opinion. That function should return true for two zero length bytes objects, irrespective of the memory contents.
History
Date User Action Args
2017-12-27 15:17:14jonathanunderwoodsetrecipients: + jonathanunderwood
2017-12-27 15:17:14jonathanunderwoodsetmessageid: <1514387834.13.0.213398074469.issue32431@psf.upfronthosting.co.za>
2017-12-27 15:17:14jonathanunderwoodlinkissue32431 messages
2017-12-27 15:17:13jonathanunderwoodcreate