Mercurial > cpython-lru_cache-weakref
diff Objects/bufferobject.c @ 31639:047148089c35 legacy-trunk
Document one of the many problems with the buffer object.
| author | Neil Schemenauer <nascheme@enme.ucalgary.ca> |
|---|---|
| date | Thu, 11 Mar 2004 01:00:44 +0000 |
| parents | 0d53ecf22d91 |
| children | 42f8820686c9 |
line wrap: on
line diff
--- a/Objects/bufferobject.c Thu Mar 11 00:44:54 2004 +0000 +++ b/Objects/bufferobject.c Thu Mar 11 01:00:44 2004 +0000 @@ -228,10 +228,17 @@ if ( self->b_hash != -1 ) 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 ) { - /* ### use different wording, since this is conditional? */ - PyErr_SetString(PyExc_TypeError, "unhashable type"); + PyErr_SetString(PyExc_TypeError, + "writable buffers are not hashable"); return -1; }
