Message223682
| Author |
skrah |
| Recipients |
benjamin.peterson, dw, hynek, kmike, pitrou, scoder, serhiy.storchaka, skrah, stutzbach |
| Date |
2014年07月22日.19:12:25 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1406056345.51.0.763225261303.issue22003@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Actually we have an extra safety net in memory_hash() apart from
the readonly check: We also check if the underlying object is
hashable.
This might be applicable here, too. Unfortunately mmap objects
*are* hashable, leading to some funny results:
>>> import mmap
>>> with open("hello.txt", "wb") as f:
... f.write(b"xxxxx\n")
...
6
>>> f = open("hello.txt", "r+b")
>>> mm = mmap.mmap(f.fileno(), 0, prot=mmap.PROT_READ)
>>> x = memoryview(mm)
>>> hash(mm)
-9223363309538046107
>>> hash(x)
-3925142568057840789
>>> x.tolist()
[120, 120, 120, 120, 120, 10]
>>>
>>> with open("hello.txt", "wb") as g:
... g.write(b"yyy\n")
...
4
>>> hash(mm)
-9223363309538046107
>>> hash(x)
-3925142568057840789
>>> x.tolist()
[121, 121, 121, 10, 0, 0]
memoryview (rightfully) assumes that hashable objects are immutable
and caches the first hash.
I'm not sure why mmap objects are hashable, it looks like a bug
to me. |
|