File tree Expand file tree Collapse file tree 7 files changed +22
-20
lines changed
Filter options
Expand file tree Collapse file tree 7 files changed +22
-20
lines changed
Original file line number Diff line number Diff line change @@ -135,7 +135,7 @@ Used in: PY_LONG_LONG
135
135
#else
136
136
#define _PyHASH_BITS 31
137
137
#endif
138
- #define _PyHASH_MODULUS ((1UL << _PyHASH_BITS) - 1)
138
+ #define _PyHASH_MODULUS (((size_t)1 << _PyHASH_BITS) - 1)
139
139
#define _PyHASH_INF 314159
140
140
#define _PyHASH_NAN 0
141
141
#define _PyHASH_IMAG 1000003UL
@@ -179,6 +179,8 @@ typedef Py_intptr_t Py_ssize_t;
179
179
180
180
/* Py_hash_t is the same size as a pointer. */
181
181
typedef Py_ssize_t Py_hash_t ;
182
+ /* Py_uhash_t is the unsigned equivalent needed to calculate numeric hash. */
183
+ typedef size_t Py_uhash_t ;
182
184
183
185
/* Largest possible value of size_t.
184
186
SIZE_MAX is part of C99, so it might be defined on some
Original file line number Diff line number Diff line change @@ -397,12 +397,12 @@ complex_repr(PyComplexObject *v)
397
397
static Py_hash_t
398
398
complex_hash (PyComplexObject * v )
399
399
{
400
- unsigned long hashreal , hashimag , combined ;
401
- hashreal = (unsigned long )_Py_HashDouble (v -> cval .real );
402
- if (hashreal == (unsigned long )-1 )
400
+ Py_uhash_t hashreal , hashimag , combined ;
401
+ hashreal = (Py_uhash_t )_Py_HashDouble (v -> cval .real );
402
+ if (hashreal == (Py_uhash_t )- 1 )
403
403
return -1 ;
404
- hashimag = (unsigned long )_Py_HashDouble (v -> cval .imag );
405
- if (hashimag == (unsigned long )-1 )
404
+ hashimag = (Py_uhash_t )_Py_HashDouble (v -> cval .imag );
405
+ if (hashimag == (Py_uhash_t )- 1 )
406
406
return -1 ;
407
407
/* Note: if the imaginary part is 0, hashimag is 0 now,
408
408
* so the following returns hashreal unchanged. This is
@@ -411,8 +411,8 @@ complex_hash(PyComplexObject *v)
411
411
* hash(x + 0*j) must equal hash(x).
412
412
*/
413
413
combined = hashreal + _PyHASH_IMAG * hashimag ;
414
- if (combined == (unsigned long )-1 )
415
- combined = (unsigned long )-2 ;
414
+ if (combined == (Py_uhash_t )- 1 )
415
+ combined = (Py_uhash_t )- 2 ;
416
416
return (Py_hash_t )combined ;
417
417
}
418
418
Original file line number Diff line number Diff line change @@ -2555,7 +2555,7 @@ long_richcompare(PyObject *self, PyObject *other, int op)
2555
2555
static Py_hash_t
2556
2556
long_hash (PyLongObject * v )
2557
2557
{
2558
- unsigned long x ;
2558
+ Py_uhash_t x ;
2559
2559
Py_ssize_t i ;
2560
2560
int sign ;
2561
2561
@@ -2604,8 +2604,8 @@ long_hash(PyLongObject *v)
2604
2604
x -= _PyHASH_MODULUS ;
2605
2605
}
2606
2606
x = x * sign ;
2607
- if (x == (unsigned long )-1 )
2608
- x = (unsigned long )-2 ;
2607
+ if (x == (Py_uhash_t )- 1 )
2608
+ x = (Py_uhash_t )- 2 ;
2609
2609
return (Py_hash_t )x ;
2610
2610
}
2611
2611
Original file line number Diff line number Diff line change @@ -692,7 +692,7 @@ _Py_HashDouble(double v)
692
692
{
693
693
int e , sign ;
694
694
double m ;
695
- unsigned long x , y ;
695
+ Py_uhash_t x , y ;
696
696
697
697
if (!Py_IS_FINITE (v )) {
698
698
if (Py_IS_INFINITY (v ))
@@ -716,7 +716,7 @@ _Py_HashDouble(double v)
716
716
x = ((x << 28 ) & _PyHASH_MODULUS ) | x >> (_PyHASH_BITS - 28 );
717
717
m *= 268435456.0 ; /* 2**28 */
718
718
e -= 28 ;
719
- y = (unsigned long )m ; /* pull out integer part */
719
+ y = (Py_uhash_t )m ; /* pull out integer part */
720
720
m -= y ;
721
721
x += y ;
722
722
if (x >= _PyHASH_MODULUS )
@@ -728,8 +728,8 @@ _Py_HashDouble(double v)
728
728
x = ((x << e ) & _PyHASH_MODULUS ) | x >> (_PyHASH_BITS - e );
729
729
730
730
x = x * sign ;
731
- if (x == (unsigned long )-1 )
732
- x = (unsigned long )-2 ;
731
+ if (x == (Py_uhash_t )- 1 )
732
+ x = (Py_uhash_t )- 2 ;
733
733
return (Py_hash_t )x ;
734
734
}
735
735
Original file line number Diff line number Diff line change @@ -318,7 +318,7 @@ tuplehash(PyTupleObject *v)
318
318
register Py_hash_t x , y ;
319
319
register Py_ssize_t len = Py_SIZE (v );
320
320
register PyObject * * p ;
321
- long mult = 1000003L ;
321
+ Py_hash_t mult = 1000003L ;
322
322
x = 0x345678L ;
323
323
p = v -> ob_item ;
324
324
while (-- len >= 0 ) {
@@ -327,7 +327,7 @@ tuplehash(PyTupleObject *v)
327
327
return -1 ;
328
328
x = (x ^ y ) * mult ;
329
329
/* the cast might truncate len; that doesn't change hash stability */
330
- mult += (long )(82520L + len + len );
330
+ mult += (Py_hash_t )(82520L + len + len );
331
331
}
332
332
x += 97531L ;
333
333
if (x == -1 )
Original file line number Diff line number Diff line change @@ -4314,14 +4314,14 @@ static PyObject *
4314
4314
wrap_hashfunc (PyObject * self , PyObject * args , void * wrapped )
4315
4315
{
4316
4316
hashfunc func = (hashfunc )wrapped ;
4317
- long res ;
4317
+ Py_hash_t res ;
4318
4318
4319
4319
if (!check_num_args (args , 0 ))
4320
4320
return NULL ;
4321
4321
res = (* func )(self );
4322
4322
if (res == -1 && PyErr_Occurred ())
4323
4323
return NULL ;
4324
- return PyLong_FromLong (res );
4324
+ return PyLong_FromSsize_t (res );
4325
4325
}
4326
4326
4327
4327
static PyObject *
Original file line number Diff line number Diff line change @@ -569,7 +569,7 @@ get_hash_info(void)
569
569
PyStructSequence_SET_ITEM (hash_info , field ++ ,
570
570
PyLong_FromLong (8 * sizeof (Py_hash_t )));
571
571
PyStructSequence_SET_ITEM (hash_info , field ++ ,
572
- PyLong_FromLong (_PyHASH_MODULUS ));
572
+ PyLong_FromSsize_t (_PyHASH_MODULUS ));
573
573
PyStructSequence_SET_ITEM (hash_info , field ++ ,
574
574
PyLong_FromLong (_PyHASH_INF ));
575
575
PyStructSequence_SET_ITEM (hash_info , field ++ ,
You can’t perform that action at this time.
0 commit comments