[Python-checkins] cpython (3.3): Add a test for hashing of unaligned memory buffers (from issue #16427).

antoine.pitrou python-checkins at python.org
Sun Nov 11 20:12:05 CET 2012


http://hg.python.org/cpython/rev/797de1864fd9
changeset: 80401:797de1864fd9
branch: 3.3
parent: 80398:e75945ac0bed
user: Antoine Pitrou <solipsis at pitrou.net>
date: Sun Nov 11 20:10:48 2012 +0100
summary:
 Add a test for hashing of unaligned memory buffers (from issue #16427).
files:
 Lib/test/test_hash.py | 10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/Lib/test/test_hash.py b/Lib/test/test_hash.py
--- a/Lib/test/test_hash.py
+++ b/Lib/test/test_hash.py
@@ -45,6 +45,16 @@
 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
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /