This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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.
History
Date User Action Args
2014-07-22 19:12:25skrahsetrecipients: + skrah, pitrou, scoder, benjamin.peterson, stutzbach, hynek, dw, serhiy.storchaka, kmike
2014-07-22 19:12:25skrahsetmessageid: <1406056345.51.0.763225261303.issue22003@psf.upfronthosting.co.za>
2014-07-22 19:12:25skrahlinkissue22003 messages
2014-07-22 19:12:25skrahcreate