mirror of
https://github.com/python/cpython.git
synced 2025-09-28 03:13:48 +00:00
Document one of the many problems with the buffer object.
This commit is contained in:
parent
5e3a675b6d
commit
0eadcd9cbb
1 changed files with 9 additions and 2 deletions
|
@ -228,10 +228,17 @@ buffer_hash(PyBufferObject *self)
|
||||||
if ( self->b_hash != -1 )
|
if ( self->b_hash != -1 )
|
||||||
return self->b_hash;
|
return self->b_hash;
|
||||||
|
|
||||||
|
/* XXX potential bugs here, a readonly buffer does not imply that the
|
||||||
|
* underlying memory is immutable. b_readonly is a necessary but not
|
||||||
|
* sufficient condition for a buffer to be hashable. Perhaps it would
|
||||||
|
* be better to only allow hashing if the underlying object is known to
|
||||||
|
* be immutable (e.g. PyString_Check() is true). Another idea would
|
||||||
|
* be to call tp_hash on the underlying object and see if it raises
|
||||||
|
* an error. */
|
||||||
if ( !self->b_readonly )
|
if ( !self->b_readonly )
|
||||||
{
|
{
|
||||||
/* ### use different wording, since this is conditional? */
|
PyErr_SetString(PyExc_TypeError,
|
||||||
PyErr_SetString(PyExc_TypeError, "unhashable type");
|
"writable buffers are not hashable");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue