Index: Python/ceval.c =================================================================== --- Python/ceval.c (revision 85765) +++ Python/ceval.c (working copy) @@ -2102,7 +2102,7 @@ /* Inline the PyDict_GetItem() calls. WARNING: this is an extreme speed hack. Do not try this at home. */ - Py_hash_t hash = ((PyUnicodeObject *)w)->hash; + Py_ssize_t hash = ((PyUnicodeObject *)w)->hash; if (hash != -1) { PyDictObject *d; PyDictEntry *e; Index: Python/bltinmodule.c =================================================================== --- Python/bltinmodule.c (revision 85765) +++ Python/bltinmodule.c (working copy) @@ -1148,7 +1148,7 @@ static PyObject * builtin_hash(PyObject *self, PyObject *v) { - Py_hash_t x; + Py_ssize_t x; x = PyObject_Hash(v); if (x == -1) Index: Python/sysmodule.c =================================================================== --- Python/sysmodule.c (revision 85765) +++ Python/sysmodule.c (working copy) @@ -567,9 +567,9 @@ if (hash_info == NULL) return NULL; PyStructSequence_SET_ITEM(hash_info, field++, - PyLong_FromLong(8*sizeof(Py_hash_t))); + PyLong_FromLong(8*sizeof(Py_ssize_t))); PyStructSequence_SET_ITEM(hash_info, field++, - PyLong_FromLong(_PyHASH_MODULUS)); + PyLong_FromSsize_t(_PyHASH_MODULUS)); PyStructSequence_SET_ITEM(hash_info, field++, PyLong_FromLong(_PyHASH_INF)); PyStructSequence_SET_ITEM(hash_info, field++, Index: Include/datetime.h =================================================================== --- Include/datetime.h (revision 85765) +++ Include/datetime.h (working copy) @@ -34,7 +34,7 @@ typedef struct { PyObject_HEAD - Py_hash_t hashcode; /* -1 when unknown */ + Py_ssize_t hashcode; /* -1 when unknown */ int days; /* -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS */ int seconds; /* 0 <= seconds < 24*3600 is invariant */ int microseconds; /* 0 <= microseconds < 1000000 is invariant */ @@ -51,7 +51,7 @@ */ #define _PyTZINFO_HEAD \ PyObject_HEAD \ - Py_hash_t hashcode; \ + Py_ssize_t hashcode; \ char hastzinfo; /* boolean flag */ /* No _PyDateTime_BaseTZInfo is allocated; it's just to have something Index: Include/pyport.h =================================================================== --- Include/pyport.h (revision 85765) +++ Include/pyport.h (working copy) @@ -135,7 +135,7 @@ #else #define _PyHASH_BITS 31 #endif -#define _PyHASH_MODULUS ((1UL << _PyHASH_BITS) - 1) +#define _PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1) #define _PyHASH_INF 314159 #define _PyHASH_NAN 0 #define _PyHASH_IMAG 1000003UL @@ -177,9 +177,6 @@ # error "Python needs a typedef for Py_ssize_t in pyport.h." #endif -/* Py_hash_t is the same size as a pointer. */ -typedef Py_ssize_t Py_hash_t; - /* Largest possible value of size_t. SIZE_MAX is part of C99, so it might be defined on some platforms. If it is not defined, (size_t)-1 is a portable Index: Include/dictobject.h =================================================================== --- Include/dictobject.h (revision 85765) +++ Include/dictobject.h (working copy) @@ -49,7 +49,7 @@ typedef struct { /* Cached hash code of me_key. */ - Py_hash_t me_hash; + Py_ssize_t me_hash; PyObject *me_key; PyObject *me_value; } PyDictEntry; @@ -81,7 +81,7 @@ * setitem calls. */ PyDictEntry *ma_table; - PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, Py_hash_t hash); + PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, Py_ssize_t hash); PyDictEntry ma_smalltable[PyDict_MINSIZE]; }; @@ -113,14 +113,14 @@ PyAPI_FUNC(int) PyDict_Next( PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value); PyAPI_FUNC(int) _PyDict_Next( - PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash); + PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_ssize_t *hash); PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp); PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp); PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp); PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp); PyAPI_FUNC(PyObject *) PyDict_Copy(PyObject *mp); PyAPI_FUNC(int) PyDict_Contains(PyObject *mp, PyObject *key); -PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, Py_hash_t hash); +PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, Py_ssize_t hash); PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused); PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp); PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp); Index: Include/unicodeobject.h =================================================================== --- Include/unicodeobject.h (revision 85765) +++ Include/unicodeobject.h (working copy) @@ -372,7 +372,7 @@ PyObject_HEAD Py_ssize_t length; /* Length of raw Unicode data in buffer */ Py_UNICODE *str; /* Raw Unicode buffer */ - Py_hash_t hash; /* Hash value; -1 if not set */ + Py_ssize_t hash; /* Hash value; -1 if not set */ int state; /* != 0 if interned. In this case the two * references from the dictionary to this object * are *not* counted in ob_refcnt. */ Index: Include/object.h =================================================================== --- Include/object.h (revision 85765) +++ Include/object.h (working copy) @@ -275,7 +275,7 @@ typedef int (*setattrfunc)(PyObject *, char *, PyObject *); typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *); typedef PyObject *(*reprfunc)(PyObject *); -typedef Py_hash_t (*hashfunc)(PyObject *); +typedef Py_ssize_t (*hashfunc)(PyObject *); typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int); typedef PyObject *(*getiterfunc) (PyObject *); typedef PyObject *(*iternextfunc) (PyObject *); @@ -440,8 +440,8 @@ PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *); PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *, PyObject *, PyObject *); -PyAPI_FUNC(Py_hash_t) PyObject_Hash(PyObject *); -PyAPI_FUNC(Py_hash_t) PyObject_HashNotImplemented(PyObject *); +PyAPI_FUNC(Py_ssize_t) PyObject_Hash(PyObject *); +PyAPI_FUNC(Py_ssize_t) PyObject_HashNotImplemented(PyObject *); PyAPI_FUNC(int) PyObject_IsTrue(PyObject *); PyAPI_FUNC(int) PyObject_Not(PyObject *); PyAPI_FUNC(int) PyCallable_Check(PyObject *); @@ -470,8 +470,8 @@ PyAPI_FUNC(void) Py_ReprLeave(PyObject *); /* Helpers for hash functions */ -PyAPI_FUNC(Py_hash_t) _Py_HashDouble(double); -PyAPI_FUNC(Py_hash_t) _Py_HashPointer(void*); +PyAPI_FUNC(Py_ssize_t) _Py_HashDouble(double); +PyAPI_FUNC(Py_ssize_t) _Py_HashPointer(void*); /* Helper for passing objects to printf and the like */ #define PyObject_REPR(obj) _PyUnicode_AsString(PyObject_Repr(obj)) Index: Include/weakrefobject.h =================================================================== --- Include/weakrefobject.h (revision 85765) +++ Include/weakrefobject.h (working copy) @@ -27,7 +27,7 @@ /* A cache for wr_object's hash code. As usual for hashes, this is -1 * if the hash code isn't known yet. */ - Py_hash_t hash; + Py_ssize_t hash; /* If wr_object is weakly referenced, wr_object has a doubly-linked NULL- * terminated list of weak references to it. These are the list pointers. Index: Include/bytesobject.h =================================================================== --- Include/bytesobject.h (revision 85765) +++ Include/bytesobject.h (working copy) @@ -29,7 +29,7 @@ typedef struct { PyObject_VAR_HEAD - Py_hash_t ob_shash; + Py_ssize_t ob_shash; char ob_sval[1]; /* Invariants: Index: Include/setobject.h =================================================================== --- Include/setobject.h (revision 85765) +++ Include/setobject.h (working copy) @@ -23,7 +23,7 @@ typedef struct { /* Cached hash code of the key. */ - Py_hash_t hash; + Py_ssize_t hash; PyObject *key; } setentry; @@ -50,10 +50,10 @@ * saves repeated runtime null-tests. */ setentry *table; - setentry *(*lookup)(PySetObject *so, PyObject *key, Py_hash_t hash); + setentry *(*lookup)(PySetObject *so, PyObject *key, Py_ssize_t hash); setentry smalltable[PySet_MINSIZE]; - Py_hash_t hash; /* only used by frozenset objects */ + Py_ssize_t hash; /* only used by frozenset objects */ PyObject *weakreflist; /* List of weak references */ }; @@ -90,7 +90,7 @@ PyAPI_FUNC(int) PySet_Contains(PyObject *anyset, PyObject *key); PyAPI_FUNC(int) PySet_Discard(PyObject *set, PyObject *key); PyAPI_FUNC(int) PySet_Add(PyObject *set, PyObject *key); -PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash); +PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_ssize_t *hash); PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set); PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable); Index: Objects/complexobject.c =================================================================== --- Objects/complexobject.c (revision 85765) +++ Objects/complexobject.c (working copy) @@ -394,15 +394,15 @@ return complex_format(v, 0, 'r'); } -static Py_hash_t +static Py_ssize_t complex_hash(PyComplexObject *v) { - unsigned long hashreal, hashimag, combined; - hashreal = (unsigned long)_Py_HashDouble(v->cval.real); - if (hashreal == (unsigned long)-1) + size_t hashreal, hashimag, combined; + hashreal = (size_t)_Py_HashDouble(v->cval.real); + if (hashreal == (size_t)-1) return -1; - hashimag = (unsigned long)_Py_HashDouble(v->cval.imag); - if (hashimag == (unsigned long)-1) + hashimag = (size_t)_Py_HashDouble(v->cval.imag); + if (hashimag == (size_t)-1) return -1; /* Note: if the imaginary part is 0, hashimag is 0 now, * so the following returns hashreal unchanged. This is @@ -411,9 +411,9 @@ * hash(x + 0*j) must equal hash(x). */ combined = hashreal + _PyHASH_IMAG * hashimag; - if (combined == (unsigned long)-1) - combined = (unsigned long)-2; - return (Py_hash_t)combined; + if (combined == (size_t)-1) + combined = (size_t)-2; + return (Py_ssize_t)combined; } /* This macro may return! */ Index: Objects/codeobject.c =================================================================== --- Objects/codeobject.c (revision 85765) +++ Objects/codeobject.c (working copy) @@ -417,10 +417,10 @@ return res; } -static Py_hash_t +static Py_ssize_t code_hash(PyCodeObject *co) { - Py_hash_t h, h0, h1, h2, h3, h4, h5, h6; + Py_ssize_t h, h0, h1, h2, h3, h4, h5, h6; h0 = PyObject_Hash(co->co_name); if (h0 == -1) return -1; h1 = PyObject_Hash(co->co_code); Index: Objects/object.c =================================================================== --- Objects/object.c (revision 85765) +++ Objects/object.c (working copy) @@ -687,12 +687,12 @@ */ -Py_hash_t +Py_ssize_t _Py_HashDouble(double v) { int e, sign; double m; - unsigned long x, y; + size_t x, y; if (!Py_IS_FINITE(v)) { if (Py_IS_INFINITY(v)) @@ -716,7 +716,7 @@ x = ((x << 28) & _PyHASH_MODULUS) | x >> (_PyHASH_BITS - 28); m *= 268435456.0; /* 2**28 */ e -= 28; - y = (unsigned long)m; /* pull out integer part */ + y = (size_t)m; /* pull out integer part */ m -= y; x += y; if (x >= _PyHASH_MODULUS) @@ -728,26 +728,26 @@ x = ((x << e) & _PyHASH_MODULUS) | x >> (_PyHASH_BITS - e); x = x * sign; - if (x == (unsigned long)-1) - x = (unsigned long)-2; - return (Py_hash_t)x; + if (x == (size_t)-1) + x = (size_t)-2; + return (Py_ssize_t)x; } -Py_hash_t +Py_ssize_t _Py_HashPointer(void *p) { - Py_hash_t x; + Py_ssize_t x; size_t y = (size_t)p; /* bottom 3 or 4 bits are likely to be 0; rotate y by 4 to avoid excessive hash collisions for dicts and sets */ y = (y >> 4) | (y << (8 * SIZEOF_VOID_P - 4)); - x = (Py_hash_t)y; + x = (Py_ssize_t)y; if (x == -1) x = -2; return x; } -Py_hash_t +Py_ssize_t PyObject_HashNotImplemented(PyObject *v) { PyErr_Format(PyExc_TypeError, "unhashable type: '%.200s'", @@ -755,7 +755,7 @@ return -1; } -Py_hash_t +Py_ssize_t PyObject_Hash(PyObject *v) { PyTypeObject *tp = Py_TYPE(v); Index: Objects/methodobject.c =================================================================== --- Objects/methodobject.c (revision 85765) +++ Objects/methodobject.c (working copy) @@ -224,10 +224,10 @@ return res; } -static Py_hash_t +static Py_ssize_t meth_hash(PyCFunctionObject *a) { - Py_hash_t x, y; + Py_ssize_t x, y; if (a->m_self == NULL) x = 0; else { Index: Objects/typeobject.c =================================================================== --- Objects/typeobject.c (revision 85765) +++ Objects/typeobject.c (working copy) @@ -4314,14 +4314,14 @@ wrap_hashfunc(PyObject *self, PyObject *args, void *wrapped) { hashfunc func = (hashfunc)wrapped; - long res; + Py_ssize_t res; if (!check_num_args(args, 0)) return NULL; res = (*func)(self); if (res == -1 && PyErr_Occurred()) return NULL; - return PyLong_FromLong(res); + return PyLong_FromSsize_t(res); } static PyObject * @@ -4918,7 +4918,7 @@ } } -static Py_hash_t +static Py_ssize_t slot_tp_hash(PyObject *self) { PyObject *func, *res; @@ -4946,14 +4946,14 @@ "__hash__ method should return an integer"); return -1; } - /* Transform the PyLong `res` to a Py_hash_t `h`. For an existing + /* Transform the PyLong `res` to a Py_ssize_t `h`. For an existing hashable Python object x, hash(x) will always lie within the range of - Py_hash_t. Therefore our transformation must preserve values that + Py_ssize_t. Therefore our transformation must preserve values that already lie within this range, to ensure that if x.__hash__() returns hash(y) then hash(x) == hash(y). */ h = PyLong_AsSsize_t(res); if (h == -1 && PyErr_Occurred()) { - /* res was not within the range of a Py_hash_t, so we're free to + /* res was not within the range of a Py_ssize_t, so we're free to use any sufficiently bit-mixing transformation; long.__hash__ will do nicely. */ PyErr_Clear(); Index: Objects/dictobject.c =================================================================== --- Objects/dictobject.c (revision 85765) +++ Objects/dictobject.c (working copy) @@ -148,7 +148,7 @@ /* forward declarations */ static PyDictEntry * -lookdict_unicode(PyDictObject *mp, PyObject *key, Py_hash_t hash); +lookdict_unicode(PyDictObject *mp, PyObject *key, Py_ssize_t hash); #ifdef SHOW_CONVERSION_COUNTS static long created = 0L; @@ -318,7 +318,7 @@ PyDictEntry*. */ static PyDictEntry * -lookdict(PyDictObject *mp, PyObject *key, register Py_hash_t hash) +lookdict(PyDictObject *mp, PyObject *key, register Py_ssize_t hash) { register size_t i; register size_t perturb; @@ -407,7 +407,7 @@ * This is valuable because dicts with only unicode keys are very common. */ static PyDictEntry * -lookdict_unicode(PyDictObject *mp, PyObject *key, register Py_hash_t hash) +lookdict_unicode(PyDictObject *mp, PyObject *key, register Py_ssize_t hash) { register size_t i; register size_t perturb; @@ -527,7 +527,7 @@ Returns -1 if an error occurred, or 0 on success. */ static int -insertdict(register PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value) +insertdict(register PyDictObject *mp, PyObject *key, Py_ssize_t hash, PyObject *value) { PyObject *old_value; register PyDictEntry *ep; @@ -571,7 +571,7 @@ is responsible for incref'ing `key` and `value`. */ static void -insertdict_clean(register PyDictObject *mp, PyObject *key, Py_hash_t hash, +insertdict_clean(register PyDictObject *mp, PyObject *key, Py_ssize_t hash, PyObject *value) { register size_t i; @@ -712,7 +712,7 @@ PyObject * PyDict_GetItem(PyObject *op, PyObject *key) { - Py_hash_t hash; + Py_ssize_t hash; PyDictObject *mp = (PyDictObject *)op; PyDictEntry *ep; PyThreadState *tstate; @@ -762,7 +762,7 @@ PyObject * PyDict_GetItemWithError(PyObject *op, PyObject *key) { - Py_hash_t hash; + Py_ssize_t hash; PyDictObject*mp = (PyDictObject *)op; PyDictEntry *ep; @@ -795,7 +795,7 @@ PyDict_SetItem(register PyObject *op, PyObject *key, PyObject *value) { register PyDictObject *mp; - register Py_hash_t hash; + register Py_ssize_t hash; register Py_ssize_t n_used; if (!PyDict_Check(op)) { @@ -841,7 +841,7 @@ PyDict_DelItem(PyObject *op, PyObject *key) { register PyDictObject *mp; - register Py_hash_t hash; + register Py_ssize_t hash; register PyDictEntry *ep; PyObject *old_value, *old_key; @@ -987,7 +987,7 @@ /* Internal version of PyDict_Next that returns a hash value in addition to the key and value.*/ int -_PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue, Py_hash_t *phash) +_PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue, Py_ssize_t *phash) { register Py_ssize_t i; register Py_ssize_t mask; @@ -1127,7 +1127,7 @@ dict_subscript(PyDictObject *mp, register PyObject *key) { PyObject *v; - Py_hash_t hash; + Py_ssize_t hash; PyDictEntry *ep; assert(mp->ma_table != NULL); if (!PyUnicode_CheckExact(key) || @@ -1321,7 +1321,7 @@ PyObject *oldvalue; Py_ssize_t pos = 0; PyObject *key; - Py_hash_t hash; + Py_ssize_t hash; if (dictresize(mp, Py_SIZE(seq))) return NULL; @@ -1339,7 +1339,7 @@ PyDictObject *mp = (PyDictObject *)d; Py_ssize_t pos = 0; PyObject *key; - Py_hash_t hash; + Py_ssize_t hash; if (dictresize(mp, PySet_GET_SIZE(seq))) return NULL; @@ -1731,7 +1731,7 @@ static PyObject * dict_contains(register PyDictObject *mp, PyObject *key) { - Py_hash_t hash; + Py_ssize_t hash; PyDictEntry *ep; if (!PyUnicode_CheckExact(key) || @@ -1752,7 +1752,7 @@ PyObject *key; PyObject *failobj = Py_None; PyObject *val = NULL; - Py_hash_t hash; + Py_ssize_t hash; PyDictEntry *ep; if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &failobj)) @@ -1781,7 +1781,7 @@ PyObject *key; PyObject *failobj = Py_None; PyObject *val = NULL; - Py_hash_t hash; + Py_ssize_t hash; PyDictEntry *ep; if (!PyArg_UnpackTuple(args, "setdefault", 1, 2, &key, &failobj)) @@ -1817,7 +1817,7 @@ static PyObject * dict_pop(PyDictObject *mp, PyObject *args) { - Py_hash_t hash; + Py_ssize_t hash; PyDictEntry *ep; PyObject *old_value, *old_key; PyObject *key, *deflt = NULL; @@ -1863,7 +1863,7 @@ static PyObject * dict_popitem(PyDictObject *mp) { - Py_hash_t i = 0; + Py_ssize_t i = 0; PyDictEntry *ep; PyObject *res; @@ -2038,7 +2038,7 @@ int PyDict_Contains(PyObject *op, PyObject *key) { - Py_hash_t hash; + Py_ssize_t hash; PyDictObject *mp = (PyDictObject *)op; PyDictEntry *ep; @@ -2054,7 +2054,7 @@ /* Internal version of PyDict_Contains used when the hash value is already known */ int -_PyDict_Contains(PyObject *op, PyObject *key, Py_hash_t hash) +_PyDict_Contains(PyObject *op, PyObject *key, Py_ssize_t hash) { PyDictObject *mp = (PyDictObject *)op; PyDictEntry *ep; Index: Objects/weakrefobject.c =================================================================== --- Objects/weakrefobject.c (revision 85765) +++ Objects/weakrefobject.c (working copy) @@ -139,7 +139,7 @@ } -static Py_hash_t +static Py_ssize_t weakref_hash(PyWeakReference *self) { if (self->hash != -1) Index: Objects/unicodeobject.c =================================================================== --- Objects/unicodeobject.c (revision 85765) +++ Objects/unicodeobject.c (working copy) @@ -7559,12 +7559,12 @@ /* Believe it or not, this produces the same value for ASCII strings as string_hash(). */ -static Py_hash_t +static Py_ssize_t unicode_hash(PyUnicodeObject *self) { Py_ssize_t len; Py_UNICODE *p; - Py_hash_t x; + Py_ssize_t x; if (self->hash != -1) return self->hash; Index: Objects/tupleobject.c =================================================================== --- Objects/tupleobject.c (revision 85765) +++ Objects/tupleobject.c (working copy) @@ -312,13 +312,13 @@ 1330111, 1412633, 1165069, 1247599, 1495177, 1577699 */ -static Py_hash_t +static Py_ssize_t tuplehash(PyTupleObject *v) { - register Py_hash_t x, y; + register Py_ssize_t x, y; register Py_ssize_t len = Py_SIZE(v); register PyObject **p; - long mult = 1000003L; + Py_ssize_t mult = 1000003L; x = 0x345678L; p = v->ob_item; while (--len >= 0) { @@ -326,8 +326,7 @@ if (y == -1) return -1; x = (x ^ y) * mult; - /* the cast might truncate len; that doesn't change hash stability */ - mult += (long)(82520L + len + len); + mult += 82520L + len + len; } x += 97531L; if (x == -1) Index: Objects/descrobject.c =================================================================== --- Objects/descrobject.c (revision 85765) +++ Objects/descrobject.c (working copy) @@ -916,10 +916,10 @@ return v; } -static Py_hash_t +static Py_ssize_t wrapper_hash(wrapperobject *wp) { - Py_hash_t x, y; + Py_ssize_t x, y; x = _Py_HashPointer(wp->descr); if (x == -1) return -1; Index: Objects/bytesobject.c =================================================================== --- Objects/bytesobject.c (revision 85765) +++ Objects/bytesobject.c (working copy) @@ -868,12 +868,12 @@ return result; } -static Py_hash_t +static Py_ssize_t bytes_hash(PyBytesObject *a) { register Py_ssize_t len; register unsigned char *p; - register Py_hash_t x; + register Py_ssize_t x; if (a->ob_shash != -1) return a->ob_shash; Index: Objects/setobject.c =================================================================== --- Objects/setobject.c (revision 85765) +++ Objects/setobject.c (working copy) @@ -75,7 +75,7 @@ */ static setentry * -set_lookkey(PySetObject *so, PyObject *key, register Py_hash_t hash) +set_lookkey(PySetObject *so, PyObject *key, register Py_ssize_t hash) { register Py_ssize_t i; register size_t perturb; @@ -157,7 +157,7 @@ * see if the comparison altered the table. */ static setentry * -set_lookkey_unicode(PySetObject *so, PyObject *key, register Py_hash_t hash) +set_lookkey_unicode(PySetObject *so, PyObject *key, register Py_ssize_t hash) { register Py_ssize_t i; register size_t perturb; @@ -211,7 +211,7 @@ Eats a reference to key. */ static int -set_insert_key(register PySetObject *so, PyObject *key, Py_hash_t hash) +set_insert_key(register PySetObject *so, PyObject *key, Py_ssize_t hash) { register setentry *entry; typedef setentry *(*lookupfunc)(PySetObject *, PyObject *, long); @@ -248,7 +248,7 @@ is responsible for incref'ing `key`. */ static void -set_insert_clean(register PySetObject *so, PyObject *key, Py_hash_t hash) +set_insert_clean(register PySetObject *so, PyObject *key, Py_ssize_t hash) { register size_t i; register size_t perturb; @@ -381,7 +381,7 @@ static int set_add_key(register PySetObject *so, PyObject *key) { - register Py_hash_t hash; + register Py_ssize_t hash; register Py_ssize_t n_used; if (!PyUnicode_CheckExact(key) || @@ -426,7 +426,7 @@ static int set_discard_key(PySetObject *so, PyObject *key) { - register Py_hash_t hash; + register Py_ssize_t hash; register setentry *entry; PyObject *old_key; @@ -675,7 +675,7 @@ static int set_contains_key(PySetObject *so, PyObject *key) { - Py_hash_t hash; + Py_ssize_t hash; setentry *entry; if (!PyUnicode_CheckExact(key) || @@ -761,11 +761,11 @@ return 0; } -static Py_hash_t +static Py_ssize_t frozenset_hash(PyObject *self) { PySetObject *so = (PySetObject *)self; - Py_hash_t h, hash = 1927868237L; + Py_ssize_t h, hash = 1927868237L; setentry *entry; Py_ssize_t pos = 0; @@ -926,7 +926,7 @@ if (PyDict_CheckExact(other)) { PyObject *value; Py_ssize_t pos = 0; - Py_hash_t hash; + Py_ssize_t hash; Py_ssize_t dictsize = PyDict_Size(other); /* Do one big resize at the start, rather than @@ -1285,7 +1285,7 @@ while ((key = PyIter_Next(it)) != NULL) { int rv; setentry entry; - Py_hash_t hash = PyObject_Hash(key); + Py_ssize_t hash = PyObject_Hash(key); if (hash == -1) { Py_DECREF(it); @@ -1442,7 +1442,7 @@ while ((key = PyIter_Next(it)) != NULL) { int rv; setentry entry; - Py_hash_t hash = PyObject_Hash(key); + Py_ssize_t hash = PyObject_Hash(key); if (hash == -1) { Py_DECREF(key); @@ -1641,7 +1641,7 @@ if (PyDict_CheckExact(other)) { PyObject *value; int rv; - Py_hash_t hash; + Py_ssize_t hash; while (_PyDict_Next(other, &pos, &key, &value, &hash)) { setentry an_entry; @@ -2308,7 +2308,7 @@ } int -_PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash) +_PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_ssize_t *hash) { setentry *entry; @@ -2363,7 +2363,7 @@ Py_ssize_t i; PyObject *elem=NULL, *dup=NULL, *t, *f, *dup2, *x; PyObject *ob = (PyObject *)so; - Py_hash_t hash; + Py_ssize_t hash; PyObject *str; /* Verify preconditions */ Index: Objects/longobject.c =================================================================== --- Objects/longobject.c (revision 85765) +++ Objects/longobject.c (working copy) @@ -2552,10 +2552,10 @@ return v; } -static Py_hash_t +static Py_ssize_t long_hash(PyLongObject *v) { - unsigned long x; + size_t x; Py_ssize_t i; int sign; @@ -2604,9 +2604,9 @@ x -= _PyHASH_MODULUS; } x = x * sign; - if (x == (unsigned long)-1) - x = (unsigned long)-2; - return (Py_hash_t)x; + if (x == (size_t)-1) + x = (size_t)-2; + return (Py_ssize_t)x; } Index: Objects/floatobject.c =================================================================== --- Objects/floatobject.c (revision 85765) +++ Objects/floatobject.c (working copy) @@ -522,7 +522,7 @@ return Py_NotImplemented; } -static Py_hash_t +static Py_ssize_t float_hash(PyFloatObject *v) { return _Py_HashDouble(v->ob_fval); Index: Objects/classobject.c =================================================================== --- Objects/classobject.c (revision 85765) +++ Objects/classobject.c (working copy) @@ -263,10 +263,10 @@ return result; } -static Py_hash_t +static Py_ssize_t method_hash(PyMethodObject *a) { - Py_hash_t x, y; + Py_ssize_t x, y; if (a->im_self == NULL) x = PyObject_Hash(Py_None); else Index: Doc/c-api/object.rst =================================================================== --- Doc/c-api/object.rst (revision 85765) +++ Doc/c-api/object.rst (working copy) @@ -247,7 +247,7 @@ *NULL* on failure. -.. c:function:: Py_hash_t PyObject_Hash(PyObject *o) +.. c:function:: Py_ssize_t PyObject_Hash(PyObject *o) .. index:: builtin: hash @@ -256,18 +256,21 @@ .. versionchanged:: 3.2 - The return type is now Py_hash_t. This is a signed integer the same size - as Py_ssize_t. + The return type is now Py_ssize_t. -.. c:function:: Py_hash_t PyObject_HashNotImplemented(PyObject *o) +.. c:function:: Py_ssize_t PyObject_HashNotImplemented(PyObject *o) Set a :exc:`TypeError` indicating that ``type(o)`` is not hashable and return ``-1``. This function receives special treatment when stored in a ``tp_hash`` slot, allowing a type to explicitly indicate to the interpreter that it is not hashable. + .. versionchanged:: 3.2 + The return type is now Py_ssize_t. + + .. c:function:: int PyObject_IsTrue(PyObject *o) Returns ``1`` if the object *o* is considered to be true, and ``0`` otherwise. Index: Doc/c-api/typeobj.rst =================================================================== --- Doc/c-api/typeobj.rst (revision 85765) +++ Doc/c-api/typeobj.rst (working copy) @@ -307,7 +307,7 @@ :func:`hash`. The signature is the same as for :c:func:`PyObject_Hash`; it must return a - value of the type Py_hash_t. The value ``-1`` should not be returned as a + value of the type Py_ssize_t. The value ``-1`` should not be returned as a normal return value; when an error occurs during the computation of the hash value, the function should set an exception and return ``-1``. Index: Modules/_datetimemodule.c =================================================================== --- Modules/_datetimemodule.c (revision 85765) +++ Modules/_datetimemodule.c (working copy) @@ -1843,7 +1843,7 @@ static PyObject *delta_getstate(PyDateTime_Delta *self); -static Py_hash_t +static Py_ssize_t delta_hash(PyDateTime_Delta *self) { if (self->hashcode == -1) { @@ -2777,11 +2777,11 @@ /* Borrowed from stringobject.c, originally it was string_hash() */ -static Py_hash_t +static Py_ssize_t generic_hash(unsigned char *data, int len) { register unsigned char *p; - register Py_hash_t x; + register Py_ssize_t x; p = (unsigned char *) data; x = *p << 7; @@ -2797,7 +2797,7 @@ static PyObject *date_getstate(PyDateTime_Date *self); -static Py_hash_t +static Py_ssize_t date_hash(PyDateTime_Date *self) { if (self->hashcode == -1) @@ -3246,7 +3246,7 @@ return delta_richcompare(self->offset, other->offset, op); } -static Py_hash_t +static Py_ssize_t timezone_hash(PyDateTime_TimeZone *self) { return delta_hash((PyDateTime_Delta *)self->offset); @@ -3751,7 +3751,7 @@ return result; } -static Py_hash_t +static Py_ssize_t time_hash(PyDateTime_Time *self) { if (self->hashcode == -1) { @@ -4640,7 +4640,7 @@ return result; } -static Py_hash_t +static Py_ssize_t datetime_hash(PyDateTime_DateTime *self) { if (self->hashcode == -1) { Index: Modules/_pickle.c =================================================================== --- Modules/_pickle.c (revision 85765) +++ Modules/_pickle.c (working copy) @@ -486,7 +486,7 @@ size_t mask = (size_t)self->mt_mask; PyMemoEntry *table = self->mt_table; PyMemoEntry *entry; - Py_hash_t hash = (Py_hash_t)key >> 3; + Py_ssize_t hash = (Py_ssize_t)key >> 3; i = hash & mask; entry = &table[i]; Index: Modules/_ctypes/_ctypes.c =================================================================== --- Modules/_ctypes/_ctypes.c (revision 85765) +++ Modules/_ctypes/_ctypes.c (working copy) @@ -2478,7 +2478,7 @@ /* * CData objects are mutable, so they cannot be hashable! */ -static Py_hash_t +static Py_ssize_t PyCData_nohash(PyObject *self) { PyErr_SetString(PyExc_TypeError, "unhashable type"); Index: Modules/_sqlite/row.c =================================================================== --- Modules/_sqlite/row.c (revision 85765) +++ Modules/_sqlite/row.c (working copy) @@ -166,7 +166,7 @@ return PyObject_GetIter(self->data); } -static Py_hash_t pysqlite_row_hash(pysqlite_Row *self) +static Py_ssize_t pysqlite_row_hash(pysqlite_Row *self) { return PyObject_Hash(self->description) ^ PyObject_Hash(self->data); }