Rev 4741: (jam) Work around a bug in pyrex 0.9.8.5 and 64-bit wrt hash() in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Wed Oct 14 04:40:38 BST 2009


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 4741 [merge]
revision-id: pqm at pqm.ubuntu.com-20091014034034-f9ncw9kq6pr3je1j
parent: pqm at pqm.ubuntu.com-20091014025311-tj3yzazgt722aj2c
parent: john at arbash-meinel.com-20091013164443-b92lnyiir2ucyguj
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2009-10-14 04:40:34 +0100
message:
  (jam) Work around a bug in pyrex 0.9.8.5 and 64-bit wrt hash()
modified:
  bzrlib/_simple_set_pyx.pyx     _static_tuple_intern-20091002053806-sid67p8spedru51w-1
=== modified file 'bzrlib/_simple_set_pyx.pyx'
--- a/bzrlib/_simple_set_pyx.pyx	2009-10-12 16:48:36 +0000
+++ b/bzrlib/_simple_set_pyx.pyx	2009-10-13 16:44:43 +0000
@@ -37,6 +37,9 @@
 
     PyTypeObject *Py_TYPE(PyObject *)
     int PyObject_IsTrue(PyObject *)
+    # Note: *Don't* use hash(), Pyrex 0.9.8.5 thinks it returns an 'int', and
+    #       thus silently truncates to 32-bits on 64-bit machines.
+    long PyObject_Hash(PyObject *) except -1
         
     void *PyMem_Malloc(size_t nbytes)
     void PyMem_Free(void *)
@@ -61,11 +64,7 @@
 
     if this == other:
         return 1
-    other_hash = Py_TYPE(other).tp_hash(other)
-    if other_hash == -1:
-        # Even though other successfully hashed in the past, it seems to have
-        # changed its mind, and failed this time, so propogate the failure.
-        return -1
+    other_hash = PyObject_Hash(other)
     if other_hash != this_hash:
         return 0
 
@@ -203,9 +202,7 @@
         mask = self._mask
         table = self._table
 
-        the_hash = Py_TYPE(key).tp_hash(key)
-        if the_hash == -1:
-            return -1
+        the_hash = PyObject_Hash(key)
         i = the_hash
         for n_lookup from 0 <= n_lookup <= <size_t>mask: # Don't loop forever
             slot = &table[i & mask]
@@ -458,13 +455,14 @@
     cdef long key_hash
     cdef PyObject **table, **slot, *cur, **free_slot, *py_key
 
-    # hash is a signed long(), we are using an offset at unsigned size_t
-    key_hash = hash(key)
+    py_key = <PyObject *>key
+    # Note: avoid using hash(obj) because of a bug w/ pyrex 0.9.8.5 and 64-bit
+    #       (it treats hash() as returning an 'int' rather than a 'long')
+    key_hash = PyObject_Hash(py_key)
     i = <size_t>key_hash
     mask = self._mask
     table = self._table
     free_slot = NULL
-    py_key = <PyObject *>key
     for n_lookup from 0 <= n_lookup <= <size_t>mask: # Don't loop forever
         slot = &table[i & mask]
         cur = slot[0]




More information about the bazaar-commits mailing list