diff options
author | Benjamin Peterson <benjamin@python.org> | 2010-10-23 16:20:50 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2010-10-23 16:20:50 (GMT) |
commit | 8035bc5c048ff08f652649754eb8ea769337afa0 (patch) | |
tree | 82778e9f0242d5a26e4ceba5d5b85babde6c12cf /Objects | |
parent | 2b9af63b4f4757cccad70b76960cfe8c7b9e6a49 (diff) | |
download | cpython-8035bc5c048ff08f652649754eb8ea769337afa0.zip cpython-8035bc5c048ff08f652649754eb8ea769337afa0.tar.gz cpython-8035bc5c048ff08f652649754eb8ea769337afa0.tar.bz2 |
follow up to #9778: define and use an unsigned hash type
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/complexobject.c | 14 | ||||
-rw-r--r-- | Objects/longobject.c | 6 | ||||
-rw-r--r-- | Objects/object.c | 8 | ||||
-rw-r--r-- | Objects/tupleobject.c | 4 | ||||
-rw-r--r-- | Objects/typeobject.c | 4 |
5 files changed, 18 insertions, 18 deletions
diff --git a/Objects/complexobject.c b/Objects/complexobject.c index c4ced31..c47e0d3 100644 --- a/Objects/complexobject.c +++ b/Objects/complexobject.c @@ -397,12 +397,12 @@ complex_repr(PyComplexObject *v) static Py_hash_t complex_hash(PyComplexObject *v) { - unsigned long hashreal, hashimag, combined; - hashreal = (unsigned long)_Py_HashDouble(v->cval.real); - if (hashreal == (unsigned long)-1) + Py_uhash_t hashreal, hashimag, combined; + hashreal = (Py_uhash_t)_Py_HashDouble(v->cval.real); + if (hashreal == (Py_uhash_t)-1) return -1; - hashimag = (unsigned long)_Py_HashDouble(v->cval.imag); - if (hashimag == (unsigned long)-1) + hashimag = (Py_uhash_t)_Py_HashDouble(v->cval.imag); + if (hashimag == (Py_uhash_t)-1) return -1; /* Note: if the imaginary part is 0, hashimag is 0 now, * so the following returns hashreal unchanged. This is @@ -411,8 +411,8 @@ complex_hash(PyComplexObject *v) * hash(x + 0*j) must equal hash(x). */ combined = hashreal + _PyHASH_IMAG * hashimag; - if (combined == (unsigned long)-1) - combined = (unsigned long)-2; + if (combined == (Py_uhash_t)-1) + combined = (Py_uhash_t)-2; return (Py_hash_t)combined; } diff --git a/Objects/longobject.c b/Objects/longobject.c index cf7eb2c..b9ce388 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -2555,7 +2555,7 @@ long_richcompare(PyObject *self, PyObject *other, int op) static Py_hash_t long_hash(PyLongObject *v) { - unsigned long x; + Py_uhash_t x; Py_ssize_t i; int sign; @@ -2604,8 +2604,8 @@ long_hash(PyLongObject *v) x -= _PyHASH_MODULUS; } x = x * sign; - if (x == (unsigned long)-1) - x = (unsigned long)-2; + if (x == (Py_uhash_t)-1) + x = (Py_uhash_t)-2; return (Py_hash_t)x; } diff --git a/Objects/object.c b/Objects/object.c index 2f544ba..723e40e 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -692,7 +692,7 @@ _Py_HashDouble(double v) { int e, sign; double m; - unsigned long x, y; + Py_uhash_t x, y; if (!Py_IS_FINITE(v)) { if (Py_IS_INFINITY(v)) @@ -716,7 +716,7 @@ _Py_HashDouble(double v) 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 = (Py_uhash_t)m; /* pull out integer part */ m -= y; x += y; if (x >= _PyHASH_MODULUS) @@ -728,8 +728,8 @@ _Py_HashDouble(double v) x = ((x << e) & _PyHASH_MODULUS) | x >> (_PyHASH_BITS - e); x = x * sign; - if (x == (unsigned long)-1) - x = (unsigned long)-2; + if (x == (Py_uhash_t)-1) + x = (Py_uhash_t)-2; return (Py_hash_t)x; } diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c index c55ad65..390b670 100644 --- a/Objects/tupleobject.c +++ b/Objects/tupleobject.c @@ -318,7 +318,7 @@ tuplehash(PyTupleObject *v) register Py_hash_t x, y; register Py_ssize_t len = Py_SIZE(v); register PyObject **p; - long mult = 1000003L; + Py_hash_t mult = 1000003L; x = 0x345678L; p = v->ob_item; while (--len >= 0) { @@ -327,7 +327,7 @@ tuplehash(PyTupleObject *v) return -1; x = (x ^ y) * mult; /* the cast might truncate len; that doesn't change hash stability */ - mult += (long)(82520L + len + len); + mult += (Py_hash_t)(82520L + len + len); } x += 97531L; if (x == -1) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 2c1bf88..e0001db 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -4314,14 +4314,14 @@ static PyObject * wrap_hashfunc(PyObject *self, PyObject *args, void *wrapped) { hashfunc func = (hashfunc)wrapped; - long res; + Py_hash_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 * |