summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-11-11 19:11:15 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-11-11 19:11:15 (GMT)
commitf2985650a00f4aae6803cef1d2082385edad1824 (patch)
treed280de488079e9b729dc49e6b210410f80dc074d
parent05bc966490be9bfe62d906af7fa574547669dbc6 (diff)
parent37bfa4e7ec5df1528aa208150933a3fc54508cf9 (diff)
downloadcpython-f2985650a00f4aae6803cef1d2082385edad1824.zip
cpython-f2985650a00f4aae6803cef1d2082385edad1824.tar.gz
cpython-f2985650a00f4aae6803cef1d2082385edad1824.tar.bz2
Add a test for hashing of unaligned memory buffers (from issue #16427).
-rw-r--r--Lib/test/test_hash.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_hash.py b/Lib/test/test_hash.py
index 0776779..d1ddc76 100644
--- a/Lib/test/test_hash.py
+++ b/Lib/test/test_hash.py
@@ -45,6 +45,16 @@ class HashEqualityTestCase(unittest.TestCase):
self.same_hash(int(1.23e300), float(1.23e300))
self.same_hash(float(0.5), complex(0.5, 0.0))
+ def test_unaligned_buffers(self):
+ # The hash function for bytes-like objects shouldn't have
+ # alignment-dependent results (example in issue #16427).
+ b = b"123456789abcdefghijklmnopqrstuvwxyz" * 128
+ for i in range(16):
+ for j in range(16):
+ aligned = b[i:128+j]
+ unaligned = memoryview(b)[i:128+j]
+ self.assertEqual(hash(aligned), hash(unaligned))
+
_default_hash = object.__hash__
class DefaultHash(object): pass