[Checkins] CVS: Products/Ape/lib/apelib/zodb3 - storage.py:1.18

Christian Zagrodnick cz at gocept.com
Wed Oct 18 09:01:38 EDT 2006


Update of /cvs-repository/Products/Ape/lib/apelib/zodb3
In directory cvs.zope.org:/tmp/cvs-serv6816

Modified Files:
	storage.py 
Log Message:
fixed the hash64 function for 64 bit machines

the hash64 maps all hash result into an unsigned 32-bit integer which did break on 64bit machines because the python hash has doubled in size.


=== Products/Ape/lib/apelib/zodb3/storage.py 1.17 => 1.18 ===
--- Products/Ape/lib/apelib/zodb3/storage.py:1.17	Wed Jan 12 01:53:42 2005
+++ Products/Ape/lib/apelib/zodb3/storage.py	Wed Oct 18 09:01:36 2006
@@ -87,10 +87,16 @@
     def hash64(self, value):
         """Returns an 8-byte hash value.
         """
-        v = hash(value)
-        if v < 0:
+        if v < -2L ** 32:
+            v += 2L ** 64
+        elif v < 0:
             # Treat the hash as an unsigned 32-bit integer
             v += 2L ** 32
+        if v > 2L ** 32:
+            v = v / 2 ** 32
+
+        assert v >= 0 and v <= 2L ** 32
+
         h = '%08x' % v
         if h == HASH0:
             # Avoid the special zero hash.



More information about the Checkins mailing list