Author jonathanunderwood
Recipients jonathanunderwood
Date 2017-12-27.15:17:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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.
Date User Action Args
2017-12-27 15:17:14jonathanunderwoodsetrecipients: + jonathanunderwood
2017-12-27 15:17:14jonathanunderwoodsetmessageid: <>
2017-12-27 15:17:14jonathanunderwoodlinkissue32431 messages
2017-12-27 15:17:13jonathanunderwoodcreate