[Pyrex] Bug wrt 64-bit and hash()

John Arbash Meinel john at arbash-meinel.com
Tue Oct 13 17:52:34 CEST 2009


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

It seems pyrex 0.9.8.5 has a bug with how it handles "hash()". I have
this code:

cdef long the_hash

the_hash = hash(my_object)

When I look at the source code generated, I see:

long __pyx_v_the_hash;
int __pyx_1;

__pyx_1 = PyObject_Hash(my_object); if (__pyx_1 == -1...)
__pyx_v_the_hash = __pyx_1;

The problem is that Pyrex is thinking that 'hash()' returns a 32-bit
'int', when it really returns a 64-bit 'long'. Which means that my hash
values are getting truncated.

I only noticed because I have other code that grabs the hash directly
from PyObject_Hash and/or Py_TYPE(obj).tp_hash(obj) which don't truncate
the value.


The basic fix seems like it would just be informing Pyrex that
"PyObject_Hash()" returns a 'long' and not an 'int'. I just checked and
cython 0.11.3 does use a 'long' temporary variable in this situation.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkrUokIACgkQJdeBCYSNAAP8/QCeJTBlP+gQziN0pp7zlEy0mcBS
s4YAoLSo5YGgX409aw4rb+48/5eCp7FQ
=7mvI
-----END PGP SIGNATURE-----



More information about the Pyrex mailing list