Message223682
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. |
|
Date |
User |
Action |
Args |
2014-07-22 19:12:25 | skrah | set | recipients:
+ skrah, pitrou, scoder, benjamin.peterson, stutzbach, hynek, dw, serhiy.storchaka, kmike |
2014-07-22 19:12:25 | skrah | set | messageid: <1406056345.51.0.763225261303.issue22003@psf.upfronthosting.co.za> |
2014-07-22 19:12:25 | skrah | link | issue22003 messages |
2014-07-22 19:12:25 | skrah | create | |
|