Conversation
_PyBytes_Resize() now creates a new bytes object if the hash value was already computed. bytes_resize_inplace() no longer sets the hash value to -1, since this function must not be called if the hash value was already computed.
|
Recently, issue gh-158219 was found in I propose to make a similar fix for cc @cmaloney @serhiy-storchaka Using the new Using I propose to change In Python 3.15, commit 32c2649 modified Currently, calling // gh-158219: The hash value must not be cached yet. Otherwise, it means
// that the bytes object was already used in Python somehow (ex: as a
// dictionary key).
assert(get_ob_shash((PyBytesObject *)self) == -1);I added this assertion when I fixed the bytearray bug: commit 969af80. |
|
Sadly, there is also a (...)
if (!_PyObject_IsUniquelyReferenced(unicode))
return 0;
if (PyUnicode_HASH(unicode) != -1)
return 0;
(...) |
Enhance also _PyBytes_Resize() tests.
cmaloney
left a comment
There was a problem hiding this comment.
High level I think this is reasonable. On vacation currently / can't review fully.
_PyBytes_Resize() now creates a new bytes object if the hash value was already computed.
bytes_resize_inplace() no longer sets the hash value to -1, since this function must not be called if the hash value was already computed.
PyBytesWriterimplementation #158585