Python 3.2 hash() return value is arch dependant

Python 3.2 hash() function will now return a 64bit value when run on a 64bit
architecture, where as previously, it would always return a 32bit value.
Modified the code to use the now Py_hash_t typedef and for Python versions
less than 3.2, hard code Py_hash_t to long and Py_uhash_t to unsigned long.
This commit is contained in:
Jason Erickson 2011-02-18 23:57:25 -07:00
parent 4fdc22451e
commit 4bc47d47a5
2 changed files with 11 additions and 2 deletions

View File

@ -189,10 +189,10 @@ exit:
} }
long Py_hash_t
notify_hash(NotifyObject *self) notify_hash(NotifyObject *self)
{ {
long rv = -1L; Py_hash_t rv = -1L;
PyObject *tself = NULL; PyObject *tself = NULL;
/* if self == a tuple, then their hashes are the same. */ /* if self == a tuple, then their hashes are the same. */

View File

@ -54,6 +54,15 @@
#define CONV_CODE_PY_SSIZE_T "n" #define CONV_CODE_PY_SSIZE_T "n"
#endif #endif
/* hash() return size changed around version 3.2a4 on 64bit platforms. Before
* this, the return size was always a long, regardless of arch. ~3.2
* introduced the Py_hash_t & Py_uhash_t typedefs with the resulting sizes
* based upon arch. */
#if PY_VERSION_HEX < 0x030200A4
typedef long Py_hash_t;
typedef unsigned long Py_uhash_t;
#endif
/* Macros defined in Python 2.6 */ /* Macros defined in Python 2.6 */
#ifndef Py_REFCNT #ifndef Py_REFCNT
#define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt) #define Py_REFCNT(ob) (((PyObject*)(ob))->ob_refcnt)