mirror of https://github.com/python/cpython
make hashes always the size of pointers; introduce Py_hash_t #9778
This commit is contained in:
parent
6fb457526c
commit
8f67d0893f
|
@ -247,15 +247,20 @@ is considered sufficient for this determination.
|
||||||
*NULL* on failure.
|
*NULL* on failure.
|
||||||
|
|
||||||
|
|
||||||
.. c:function:: long PyObject_Hash(PyObject *o)
|
.. c:function:: Py_hash_t PyObject_Hash(PyObject *o)
|
||||||
|
|
||||||
.. index:: builtin: hash
|
.. index:: builtin: hash
|
||||||
|
|
||||||
Compute and return the hash value of an object *o*. On failure, return ``-1``.
|
Compute and return the hash value of an object *o*. On failure, return ``-1``.
|
||||||
This is the equivalent of the Python expression ``hash(o)``.
|
This is the equivalent of the Python expression ``hash(o)``.
|
||||||
|
|
||||||
|
.. versionchanged:: 3.2
|
||||||
|
|
||||||
.. c:function:: long PyObject_HashNotImplemented(PyObject *o)
|
The return type is now Py_hash_t. This is a signed integer the same size
|
||||||
|
as Py_ssize_t.
|
||||||
|
|
||||||
|
|
||||||
|
.. c:function:: Py_hash_t PyObject_HashNotImplemented(PyObject *o)
|
||||||
|
|
||||||
Set a :exc:`TypeError` indicating that ``type(o)`` is not hashable and return ``-1``.
|
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,
|
This function receives special treatment when stored in a ``tp_hash`` slot,
|
||||||
|
|
|
@ -306,10 +306,10 @@ type objects) *must* have the :attr:`ob_size` field.
|
||||||
An optional pointer to a function that implements the built-in function
|
An optional pointer to a function that implements the built-in function
|
||||||
:func:`hash`.
|
:func:`hash`.
|
||||||
|
|
||||||
The signature is the same as for :c:func:`PyObject_Hash`; it must return a C
|
The signature is the same as for :c:func:`PyObject_Hash`; it must return a
|
||||||
long. The value ``-1`` should not be returned as a normal return value; when an
|
value of the type Py_hash_t. The value ``-1`` should not be returned as a
|
||||||
error occurs during the computation of the hash value, the function should set
|
normal return value; when an error occurs during the computation of the hash
|
||||||
an exception and return ``-1``.
|
value, the function should set an exception and return ``-1``.
|
||||||
|
|
||||||
This field can be set explicitly to :c:func:`PyObject_HashNotImplemented` to
|
This field can be set explicitly to :c:func:`PyObject_HashNotImplemented` to
|
||||||
block inheritance of the hash method from a parent type. This is interpreted
|
block inheritance of the hash method from a parent type. This is interpreted
|
||||||
|
|
|
@ -29,7 +29,7 @@ functions should be applied to nil objects.
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_VAR_HEAD
|
PyObject_VAR_HEAD
|
||||||
long ob_shash;
|
Py_hash_t ob_shash;
|
||||||
char ob_sval[1];
|
char ob_sval[1];
|
||||||
|
|
||||||
/* Invariants:
|
/* Invariants:
|
||||||
|
|
|
@ -34,7 +34,7 @@ extern "C" {
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
long hashcode; /* -1 when unknown */
|
Py_hash_t hashcode; /* -1 when unknown */
|
||||||
int days; /* -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS */
|
int days; /* -MAX_DELTA_DAYS <= days <= MAX_DELTA_DAYS */
|
||||||
int seconds; /* 0 <= seconds < 24*3600 is invariant */
|
int seconds; /* 0 <= seconds < 24*3600 is invariant */
|
||||||
int microseconds; /* 0 <= microseconds < 1000000 is invariant */
|
int microseconds; /* 0 <= microseconds < 1000000 is invariant */
|
||||||
|
@ -51,7 +51,7 @@ typedef struct
|
||||||
*/
|
*/
|
||||||
#define _PyTZINFO_HEAD \
|
#define _PyTZINFO_HEAD \
|
||||||
PyObject_HEAD \
|
PyObject_HEAD \
|
||||||
long hashcode; \
|
Py_hash_t hashcode; \
|
||||||
char hastzinfo; /* boolean flag */
|
char hastzinfo; /* boolean flag */
|
||||||
|
|
||||||
/* No _PyDateTime_BaseTZInfo is allocated; it's just to have something
|
/* No _PyDateTime_BaseTZInfo is allocated; it's just to have something
|
||||||
|
|
|
@ -48,11 +48,8 @@ meaning otherwise.
|
||||||
#define PyDict_MINSIZE 8
|
#define PyDict_MINSIZE 8
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* Cached hash code of me_key. Note that hash codes are C longs.
|
/* Cached hash code of me_key. */
|
||||||
* We have to use Py_ssize_t instead because dict_popitem() abuses
|
Py_hash_t me_hash;
|
||||||
* me_hash to hold a search finger.
|
|
||||||
*/
|
|
||||||
Py_ssize_t me_hash;
|
|
||||||
PyObject *me_key;
|
PyObject *me_key;
|
||||||
PyObject *me_value;
|
PyObject *me_value;
|
||||||
} PyDictEntry;
|
} PyDictEntry;
|
||||||
|
@ -84,7 +81,7 @@ struct _dictobject {
|
||||||
* setitem calls.
|
* setitem calls.
|
||||||
*/
|
*/
|
||||||
PyDictEntry *ma_table;
|
PyDictEntry *ma_table;
|
||||||
PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, long hash);
|
PyDictEntry *(*ma_lookup)(PyDictObject *mp, PyObject *key, Py_hash_t hash);
|
||||||
PyDictEntry ma_smalltable[PyDict_MINSIZE];
|
PyDictEntry ma_smalltable[PyDict_MINSIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -116,14 +113,14 @@ PyAPI_FUNC(void) PyDict_Clear(PyObject *mp);
|
||||||
PyAPI_FUNC(int) PyDict_Next(
|
PyAPI_FUNC(int) PyDict_Next(
|
||||||
PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value);
|
PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value);
|
||||||
PyAPI_FUNC(int) _PyDict_Next(
|
PyAPI_FUNC(int) _PyDict_Next(
|
||||||
PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, long *hash);
|
PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash);
|
||||||
PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp);
|
PyAPI_FUNC(PyObject *) PyDict_Keys(PyObject *mp);
|
||||||
PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp);
|
PyAPI_FUNC(PyObject *) PyDict_Values(PyObject *mp);
|
||||||
PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp);
|
PyAPI_FUNC(PyObject *) PyDict_Items(PyObject *mp);
|
||||||
PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp);
|
PyAPI_FUNC(Py_ssize_t) PyDict_Size(PyObject *mp);
|
||||||
PyAPI_FUNC(PyObject *) PyDict_Copy(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);
|
||||||
PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, long hash);
|
PyAPI_FUNC(int) _PyDict_Contains(PyObject *mp, PyObject *key, Py_hash_t hash);
|
||||||
PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
|
PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
|
||||||
PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);
|
PyAPI_FUNC(void) _PyDict_MaybeUntrack(PyObject *mp);
|
||||||
PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp);
|
PyAPI_FUNC(int) _PyDict_HasOnlyStringKeys(PyObject *mp);
|
||||||
|
|
|
@ -275,7 +275,7 @@ typedef PyObject *(*getattrofunc)(PyObject *, PyObject *);
|
||||||
typedef int (*setattrfunc)(PyObject *, char *, PyObject *);
|
typedef int (*setattrfunc)(PyObject *, char *, PyObject *);
|
||||||
typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *);
|
typedef int (*setattrofunc)(PyObject *, PyObject *, PyObject *);
|
||||||
typedef PyObject *(*reprfunc)(PyObject *);
|
typedef PyObject *(*reprfunc)(PyObject *);
|
||||||
typedef long (*hashfunc)(PyObject *);
|
typedef Py_hash_t (*hashfunc)(PyObject *);
|
||||||
typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
|
typedef PyObject *(*richcmpfunc) (PyObject *, PyObject *, int);
|
||||||
typedef PyObject *(*getiterfunc) (PyObject *);
|
typedef PyObject *(*getiterfunc) (PyObject *);
|
||||||
typedef PyObject *(*iternextfunc) (PyObject *);
|
typedef PyObject *(*iternextfunc) (PyObject *);
|
||||||
|
@ -440,8 +440,8 @@ PyAPI_FUNC(PyObject *) _PyObject_NextNotImplemented(PyObject *);
|
||||||
PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
|
PyAPI_FUNC(PyObject *) PyObject_GenericGetAttr(PyObject *, PyObject *);
|
||||||
PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *,
|
PyAPI_FUNC(int) PyObject_GenericSetAttr(PyObject *,
|
||||||
PyObject *, PyObject *);
|
PyObject *, PyObject *);
|
||||||
PyAPI_FUNC(long) PyObject_Hash(PyObject *);
|
PyAPI_FUNC(Py_hash_t) PyObject_Hash(PyObject *);
|
||||||
PyAPI_FUNC(long) PyObject_HashNotImplemented(PyObject *);
|
PyAPI_FUNC(Py_hash_t) PyObject_HashNotImplemented(PyObject *);
|
||||||
PyAPI_FUNC(int) PyObject_IsTrue(PyObject *);
|
PyAPI_FUNC(int) PyObject_IsTrue(PyObject *);
|
||||||
PyAPI_FUNC(int) PyObject_Not(PyObject *);
|
PyAPI_FUNC(int) PyObject_Not(PyObject *);
|
||||||
PyAPI_FUNC(int) PyCallable_Check(PyObject *);
|
PyAPI_FUNC(int) PyCallable_Check(PyObject *);
|
||||||
|
@ -470,8 +470,8 @@ PyAPI_FUNC(int) Py_ReprEnter(PyObject *);
|
||||||
PyAPI_FUNC(void) Py_ReprLeave(PyObject *);
|
PyAPI_FUNC(void) Py_ReprLeave(PyObject *);
|
||||||
|
|
||||||
/* Helpers for hash functions */
|
/* Helpers for hash functions */
|
||||||
PyAPI_FUNC(long) _Py_HashDouble(double);
|
PyAPI_FUNC(Py_hash_t) _Py_HashDouble(double);
|
||||||
PyAPI_FUNC(long) _Py_HashPointer(void*);
|
PyAPI_FUNC(Py_hash_t) _Py_HashPointer(void*);
|
||||||
|
|
||||||
/* Helper for passing objects to printf and the like */
|
/* Helper for passing objects to printf and the like */
|
||||||
#define PyObject_REPR(obj) _PyUnicode_AsString(PyObject_Repr(obj))
|
#define PyObject_REPR(obj) _PyUnicode_AsString(PyObject_Repr(obj))
|
||||||
|
|
|
@ -130,7 +130,7 @@ Used in: PY_LONG_LONG
|
||||||
_PyHash_Double in Objects/object.c. Numeric hashes are based on
|
_PyHash_Double in Objects/object.c. Numeric hashes are based on
|
||||||
reduction modulo the prime 2**_PyHASH_BITS - 1. */
|
reduction modulo the prime 2**_PyHASH_BITS - 1. */
|
||||||
|
|
||||||
#if SIZEOF_LONG >= 8
|
#if SIZEOF_VOID_P >= 8
|
||||||
#define _PyHASH_BITS 61
|
#define _PyHASH_BITS 61
|
||||||
#else
|
#else
|
||||||
#define _PyHASH_BITS 31
|
#define _PyHASH_BITS 31
|
||||||
|
@ -177,6 +177,9 @@ typedef Py_intptr_t Py_ssize_t;
|
||||||
# error "Python needs a typedef for Py_ssize_t in pyport.h."
|
# error "Python needs a typedef for Py_ssize_t in pyport.h."
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Py_hash_t is the same size as a pointer. */
|
||||||
|
typedef Py_ssize_t Py_hash_t;
|
||||||
|
|
||||||
/* Largest possible value of size_t.
|
/* Largest possible value of size_t.
|
||||||
SIZE_MAX is part of C99, so it might be defined on some
|
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
|
platforms. If it is not defined, (size_t)-1 is a portable
|
||||||
|
|
|
@ -22,11 +22,8 @@ no meaning otherwise.
|
||||||
#define PySet_MINSIZE 8
|
#define PySet_MINSIZE 8
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
/* Cached hash code of the key. Note that hash codes are C longs.
|
/* Cached hash code of the key. */
|
||||||
* We have to use Py_ssize_t instead because set_pop() abuses
|
Py_hash_t hash;
|
||||||
* the hash field to hold a search finger.
|
|
||||||
*/
|
|
||||||
Py_ssize_t hash;
|
|
||||||
PyObject *key;
|
PyObject *key;
|
||||||
} setentry;
|
} setentry;
|
||||||
|
|
||||||
|
@ -53,10 +50,10 @@ struct _setobject {
|
||||||
* saves repeated runtime null-tests.
|
* saves repeated runtime null-tests.
|
||||||
*/
|
*/
|
||||||
setentry *table;
|
setentry *table;
|
||||||
setentry *(*lookup)(PySetObject *so, PyObject *key, long hash);
|
setentry *(*lookup)(PySetObject *so, PyObject *key, Py_hash_t hash);
|
||||||
setentry smalltable[PySet_MINSIZE];
|
setentry smalltable[PySet_MINSIZE];
|
||||||
|
|
||||||
long hash; /* only used by frozenset objects */
|
Py_hash_t hash; /* only used by frozenset objects */
|
||||||
PyObject *weakreflist; /* List of weak references */
|
PyObject *weakreflist; /* List of weak references */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -93,7 +90,7 @@ PyAPI_FUNC(int) PySet_Clear(PyObject *set);
|
||||||
PyAPI_FUNC(int) PySet_Contains(PyObject *anyset, PyObject *key);
|
PyAPI_FUNC(int) PySet_Contains(PyObject *anyset, PyObject *key);
|
||||||
PyAPI_FUNC(int) PySet_Discard(PyObject *set, PyObject *key);
|
PyAPI_FUNC(int) PySet_Discard(PyObject *set, PyObject *key);
|
||||||
PyAPI_FUNC(int) PySet_Add(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, long *hash);
|
PyAPI_FUNC(int) _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash);
|
||||||
PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set);
|
PyAPI_FUNC(PyObject *) PySet_Pop(PyObject *set);
|
||||||
PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);
|
PyAPI_FUNC(int) _PySet_Update(PyObject *set, PyObject *iterable);
|
||||||
|
|
||||||
|
|
|
@ -372,7 +372,7 @@ typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
Py_ssize_t length; /* Length of raw Unicode data in buffer */
|
Py_ssize_t length; /* Length of raw Unicode data in buffer */
|
||||||
Py_UNICODE *str; /* Raw Unicode buffer */
|
Py_UNICODE *str; /* Raw Unicode buffer */
|
||||||
long hash; /* Hash value; -1 if not set */
|
Py_hash_t hash; /* Hash value; -1 if not set */
|
||||||
int state; /* != 0 if interned. In this case the two
|
int state; /* != 0 if interned. In this case the two
|
||||||
* references from the dictionary to this object
|
* references from the dictionary to this object
|
||||||
* are *not* counted in ob_refcnt. */
|
* are *not* counted in ob_refcnt. */
|
||||||
|
|
|
@ -27,7 +27,7 @@ struct _PyWeakReference {
|
||||||
/* A cache for wr_object's hash code. As usual for hashes, this is -1
|
/* A cache for wr_object's hash code. As usual for hashes, this is -1
|
||||||
* if the hash code isn't known yet.
|
* if the hash code isn't known yet.
|
||||||
*/
|
*/
|
||||||
long hash;
|
Py_hash_t hash;
|
||||||
|
|
||||||
/* If wr_object is weakly referenced, wr_object has a doubly-linked NULL-
|
/* 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.
|
* terminated list of weak references to it. These are the list pointers.
|
||||||
|
|
|
@ -93,6 +93,12 @@ Extensions
|
||||||
|
|
||||||
- The Unicode database was updated to 6.0.0.
|
- The Unicode database was updated to 6.0.0.
|
||||||
|
|
||||||
|
C-API
|
||||||
|
-----
|
||||||
|
|
||||||
|
- Issue #9778: Hash values are now always the size of pointers. A new Py_hash_t
|
||||||
|
type has been introduced.
|
||||||
|
|
||||||
Tools/Demos
|
Tools/Demos
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
|
|
|
@ -1843,7 +1843,7 @@ delta_richcompare(PyObject *self, PyObject *other, int op)
|
||||||
|
|
||||||
static PyObject *delta_getstate(PyDateTime_Delta *self);
|
static PyObject *delta_getstate(PyDateTime_Delta *self);
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
delta_hash(PyDateTime_Delta *self)
|
delta_hash(PyDateTime_Delta *self)
|
||||||
{
|
{
|
||||||
if (self->hashcode == -1) {
|
if (self->hashcode == -1) {
|
||||||
|
@ -2777,11 +2777,11 @@ date_replace(PyDateTime_Date *self, PyObject *args, PyObject *kw)
|
||||||
/*
|
/*
|
||||||
Borrowed from stringobject.c, originally it was string_hash()
|
Borrowed from stringobject.c, originally it was string_hash()
|
||||||
*/
|
*/
|
||||||
static long
|
static Py_hash_t
|
||||||
generic_hash(unsigned char *data, int len)
|
generic_hash(unsigned char *data, int len)
|
||||||
{
|
{
|
||||||
register unsigned char *p;
|
register unsigned char *p;
|
||||||
register long x;
|
register Py_hash_t x;
|
||||||
|
|
||||||
p = (unsigned char *) data;
|
p = (unsigned char *) data;
|
||||||
x = *p << 7;
|
x = *p << 7;
|
||||||
|
@ -2797,7 +2797,7 @@ generic_hash(unsigned char *data, int len)
|
||||||
|
|
||||||
static PyObject *date_getstate(PyDateTime_Date *self);
|
static PyObject *date_getstate(PyDateTime_Date *self);
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
date_hash(PyDateTime_Date *self)
|
date_hash(PyDateTime_Date *self)
|
||||||
{
|
{
|
||||||
if (self->hashcode == -1)
|
if (self->hashcode == -1)
|
||||||
|
@ -3246,7 +3246,7 @@ timezone_richcompare(PyDateTime_TimeZone *self,
|
||||||
return delta_richcompare(self->offset, other->offset, op);
|
return delta_richcompare(self->offset, other->offset, op);
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
timezone_hash(PyDateTime_TimeZone *self)
|
timezone_hash(PyDateTime_TimeZone *self)
|
||||||
{
|
{
|
||||||
return delta_hash((PyDateTime_Delta *)self->offset);
|
return delta_hash((PyDateTime_Delta *)self->offset);
|
||||||
|
@ -3751,7 +3751,7 @@ time_richcompare(PyObject *self, PyObject *other, int op)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
time_hash(PyDateTime_Time *self)
|
time_hash(PyDateTime_Time *self)
|
||||||
{
|
{
|
||||||
if (self->hashcode == -1) {
|
if (self->hashcode == -1) {
|
||||||
|
@ -4640,7 +4640,7 @@ datetime_richcompare(PyObject *self, PyObject *other, int op)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
datetime_hash(PyDateTime_DateTime *self)
|
datetime_hash(PyDateTime_DateTime *self)
|
||||||
{
|
{
|
||||||
if (self->hashcode == -1) {
|
if (self->hashcode == -1) {
|
||||||
|
|
|
@ -486,7 +486,7 @@ _PyMemoTable_Lookup(PyMemoTable *self, PyObject *key)
|
||||||
size_t mask = (size_t)self->mt_mask;
|
size_t mask = (size_t)self->mt_mask;
|
||||||
PyMemoEntry *table = self->mt_table;
|
PyMemoEntry *table = self->mt_table;
|
||||||
PyMemoEntry *entry;
|
PyMemoEntry *entry;
|
||||||
long hash = (long)key >> 3;
|
Py_hash_t hash = (Py_hash_t)key >> 3;
|
||||||
|
|
||||||
i = hash & mask;
|
i = hash & mask;
|
||||||
entry = &table[i];
|
entry = &table[i];
|
||||||
|
|
|
@ -868,12 +868,12 @@ bytes_richcompare(PyBytesObject *a, PyBytesObject *b, int op)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
bytes_hash(PyBytesObject *a)
|
bytes_hash(PyBytesObject *a)
|
||||||
{
|
{
|
||||||
register Py_ssize_t len;
|
register Py_ssize_t len;
|
||||||
register unsigned char *p;
|
register unsigned char *p;
|
||||||
register long x;
|
register Py_hash_t x;
|
||||||
|
|
||||||
if (a->ob_shash != -1)
|
if (a->ob_shash != -1)
|
||||||
return a->ob_shash;
|
return a->ob_shash;
|
||||||
|
|
|
@ -263,10 +263,10 @@ method_repr(PyMethodObject *a)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
method_hash(PyMethodObject *a)
|
method_hash(PyMethodObject *a)
|
||||||
{
|
{
|
||||||
long x, y;
|
Py_hash_t x, y;
|
||||||
if (a->im_self == NULL)
|
if (a->im_self == NULL)
|
||||||
x = PyObject_Hash(Py_None);
|
x = PyObject_Hash(Py_None);
|
||||||
else
|
else
|
||||||
|
|
|
@ -417,10 +417,10 @@ code_richcompare(PyObject *self, PyObject *other, int op)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
code_hash(PyCodeObject *co)
|
code_hash(PyCodeObject *co)
|
||||||
{
|
{
|
||||||
long h, h0, h1, h2, h3, h4, h5, h6;
|
Py_hash_t h, h0, h1, h2, h3, h4, h5, h6;
|
||||||
h0 = PyObject_Hash(co->co_name);
|
h0 = PyObject_Hash(co->co_name);
|
||||||
if (h0 == -1) return -1;
|
if (h0 == -1) return -1;
|
||||||
h1 = PyObject_Hash(co->co_code);
|
h1 = PyObject_Hash(co->co_code);
|
||||||
|
|
|
@ -394,7 +394,7 @@ complex_repr(PyComplexObject *v)
|
||||||
return complex_format(v, 0, 'r');
|
return complex_format(v, 0, 'r');
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
complex_hash(PyComplexObject *v)
|
complex_hash(PyComplexObject *v)
|
||||||
{
|
{
|
||||||
unsigned long hashreal, hashimag, combined;
|
unsigned long hashreal, hashimag, combined;
|
||||||
|
@ -413,7 +413,7 @@ complex_hash(PyComplexObject *v)
|
||||||
combined = hashreal + _PyHASH_IMAG * hashimag;
|
combined = hashreal + _PyHASH_IMAG * hashimag;
|
||||||
if (combined == (unsigned long)-1)
|
if (combined == (unsigned long)-1)
|
||||||
combined = (unsigned long)-2;
|
combined = (unsigned long)-2;
|
||||||
return (long)combined;
|
return (Py_hash_t)combined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This macro may return! */
|
/* This macro may return! */
|
||||||
|
|
|
@ -916,10 +916,10 @@ wrapper_richcompare(PyObject *a, PyObject *b, int op)
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
wrapper_hash(wrapperobject *wp)
|
wrapper_hash(wrapperobject *wp)
|
||||||
{
|
{
|
||||||
int x, y;
|
Py_hash_t x, y;
|
||||||
x = _Py_HashPointer(wp->descr);
|
x = _Py_HashPointer(wp->descr);
|
||||||
if (x == -1)
|
if (x == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -318,7 +318,7 @@ the caller can (if it wishes) add the <key, value> pair to the returned
|
||||||
PyDictEntry*.
|
PyDictEntry*.
|
||||||
*/
|
*/
|
||||||
static PyDictEntry *
|
static PyDictEntry *
|
||||||
lookdict(PyDictObject *mp, PyObject *key, register long hash)
|
lookdict(PyDictObject *mp, PyObject *key, register Py_hash_t hash)
|
||||||
{
|
{
|
||||||
register size_t i;
|
register size_t i;
|
||||||
register size_t perturb;
|
register size_t perturb;
|
||||||
|
@ -407,7 +407,7 @@ lookdict(PyDictObject *mp, PyObject *key, register long hash)
|
||||||
* This is valuable because dicts with only unicode keys are very common.
|
* This is valuable because dicts with only unicode keys are very common.
|
||||||
*/
|
*/
|
||||||
static PyDictEntry *
|
static PyDictEntry *
|
||||||
lookdict_unicode(PyDictObject *mp, PyObject *key, register long hash)
|
lookdict_unicode(PyDictObject *mp, PyObject *key, register Py_hash_t hash)
|
||||||
{
|
{
|
||||||
register size_t i;
|
register size_t i;
|
||||||
register size_t perturb;
|
register size_t perturb;
|
||||||
|
@ -527,7 +527,7 @@ Eats a reference to key and one to value.
|
||||||
Returns -1 if an error occurred, or 0 on success.
|
Returns -1 if an error occurred, or 0 on success.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
insertdict(register PyDictObject *mp, PyObject *key, long hash, PyObject *value)
|
insertdict(register PyDictObject *mp, PyObject *key, Py_hash_t hash, PyObject *value)
|
||||||
{
|
{
|
||||||
PyObject *old_value;
|
PyObject *old_value;
|
||||||
register PyDictEntry *ep;
|
register PyDictEntry *ep;
|
||||||
|
@ -555,7 +555,7 @@ insertdict(register PyDictObject *mp, PyObject *key, long hash, PyObject *value)
|
||||||
Py_DECREF(dummy);
|
Py_DECREF(dummy);
|
||||||
}
|
}
|
||||||
ep->me_key = key;
|
ep->me_key = key;
|
||||||
ep->me_hash = (Py_ssize_t)hash;
|
ep->me_hash = hash;
|
||||||
ep->me_value = value;
|
ep->me_value = value;
|
||||||
mp->ma_used++;
|
mp->ma_used++;
|
||||||
}
|
}
|
||||||
|
@ -571,7 +571,7 @@ Note that no refcounts are changed by this routine; if needed, the caller
|
||||||
is responsible for incref'ing `key` and `value`.
|
is responsible for incref'ing `key` and `value`.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
insertdict_clean(register PyDictObject *mp, PyObject *key, long hash,
|
insertdict_clean(register PyDictObject *mp, PyObject *key, Py_hash_t hash,
|
||||||
PyObject *value)
|
PyObject *value)
|
||||||
{
|
{
|
||||||
register size_t i;
|
register size_t i;
|
||||||
|
@ -590,7 +590,7 @@ insertdict_clean(register PyDictObject *mp, PyObject *key, long hash,
|
||||||
assert(ep->me_value == NULL);
|
assert(ep->me_value == NULL);
|
||||||
mp->ma_fill++;
|
mp->ma_fill++;
|
||||||
ep->me_key = key;
|
ep->me_key = key;
|
||||||
ep->me_hash = (Py_ssize_t)hash;
|
ep->me_hash = hash;
|
||||||
ep->me_value = value;
|
ep->me_value = value;
|
||||||
mp->ma_used++;
|
mp->ma_used++;
|
||||||
}
|
}
|
||||||
|
@ -667,8 +667,7 @@ dictresize(PyDictObject *mp, Py_ssize_t minused)
|
||||||
for (ep = oldtable; i > 0; ep++) {
|
for (ep = oldtable; i > 0; ep++) {
|
||||||
if (ep->me_value != NULL) { /* active entry */
|
if (ep->me_value != NULL) { /* active entry */
|
||||||
--i;
|
--i;
|
||||||
insertdict_clean(mp, ep->me_key, (long)ep->me_hash,
|
insertdict_clean(mp, ep->me_key, ep->me_hash, ep->me_value);
|
||||||
ep->me_value);
|
|
||||||
}
|
}
|
||||||
else if (ep->me_key != NULL) { /* dummy entry */
|
else if (ep->me_key != NULL) { /* dummy entry */
|
||||||
--i;
|
--i;
|
||||||
|
@ -713,7 +712,7 @@ _PyDict_NewPresized(Py_ssize_t minused)
|
||||||
PyObject *
|
PyObject *
|
||||||
PyDict_GetItem(PyObject *op, PyObject *key)
|
PyDict_GetItem(PyObject *op, PyObject *key)
|
||||||
{
|
{
|
||||||
long hash;
|
Py_hash_t hash;
|
||||||
PyDictObject *mp = (PyDictObject *)op;
|
PyDictObject *mp = (PyDictObject *)op;
|
||||||
PyDictEntry *ep;
|
PyDictEntry *ep;
|
||||||
PyThreadState *tstate;
|
PyThreadState *tstate;
|
||||||
|
@ -763,7 +762,7 @@ PyDict_GetItem(PyObject *op, PyObject *key)
|
||||||
PyObject *
|
PyObject *
|
||||||
PyDict_GetItemWithError(PyObject *op, PyObject *key)
|
PyDict_GetItemWithError(PyObject *op, PyObject *key)
|
||||||
{
|
{
|
||||||
long hash;
|
Py_hash_t hash;
|
||||||
PyDictObject*mp = (PyDictObject *)op;
|
PyDictObject*mp = (PyDictObject *)op;
|
||||||
PyDictEntry *ep;
|
PyDictEntry *ep;
|
||||||
|
|
||||||
|
@ -796,7 +795,7 @@ int
|
||||||
PyDict_SetItem(register PyObject *op, PyObject *key, PyObject *value)
|
PyDict_SetItem(register PyObject *op, PyObject *key, PyObject *value)
|
||||||
{
|
{
|
||||||
register PyDictObject *mp;
|
register PyDictObject *mp;
|
||||||
register long hash;
|
register Py_hash_t hash;
|
||||||
register Py_ssize_t n_used;
|
register Py_ssize_t n_used;
|
||||||
|
|
||||||
if (!PyDict_Check(op)) {
|
if (!PyDict_Check(op)) {
|
||||||
|
@ -842,7 +841,7 @@ int
|
||||||
PyDict_DelItem(PyObject *op, PyObject *key)
|
PyDict_DelItem(PyObject *op, PyObject *key)
|
||||||
{
|
{
|
||||||
register PyDictObject *mp;
|
register PyDictObject *mp;
|
||||||
register long hash;
|
register Py_hash_t hash;
|
||||||
register PyDictEntry *ep;
|
register PyDictEntry *ep;
|
||||||
PyObject *old_value, *old_key;
|
PyObject *old_value, *old_key;
|
||||||
|
|
||||||
|
@ -988,7 +987,7 @@ PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue)
|
||||||
|
|
||||||
/* Internal version of PyDict_Next that returns a hash value in addition to the key and value.*/
|
/* Internal version of PyDict_Next that returns a hash value in addition to the key and value.*/
|
||||||
int
|
int
|
||||||
_PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue, long *phash)
|
_PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue, Py_hash_t *phash)
|
||||||
{
|
{
|
||||||
register Py_ssize_t i;
|
register Py_ssize_t i;
|
||||||
register Py_ssize_t mask;
|
register Py_ssize_t mask;
|
||||||
|
@ -1006,7 +1005,7 @@ _PyDict_Next(PyObject *op, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue,
|
||||||
*ppos = i+1;
|
*ppos = i+1;
|
||||||
if (i > mask)
|
if (i > mask)
|
||||||
return 0;
|
return 0;
|
||||||
*phash = (long)(ep[i].me_hash);
|
*phash = ep[i].me_hash;
|
||||||
if (pkey)
|
if (pkey)
|
||||||
*pkey = ep[i].me_key;
|
*pkey = ep[i].me_key;
|
||||||
if (pvalue)
|
if (pvalue)
|
||||||
|
@ -1128,7 +1127,7 @@ static PyObject *
|
||||||
dict_subscript(PyDictObject *mp, register PyObject *key)
|
dict_subscript(PyDictObject *mp, register PyObject *key)
|
||||||
{
|
{
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
long hash;
|
Py_hash_t hash;
|
||||||
PyDictEntry *ep;
|
PyDictEntry *ep;
|
||||||
assert(mp->ma_table != NULL);
|
assert(mp->ma_table != NULL);
|
||||||
if (!PyUnicode_CheckExact(key) ||
|
if (!PyUnicode_CheckExact(key) ||
|
||||||
|
@ -1322,7 +1321,7 @@ dict_fromkeys(PyObject *cls, PyObject *args)
|
||||||
PyObject *oldvalue;
|
PyObject *oldvalue;
|
||||||
Py_ssize_t pos = 0;
|
Py_ssize_t pos = 0;
|
||||||
PyObject *key;
|
PyObject *key;
|
||||||
long hash;
|
Py_hash_t hash;
|
||||||
|
|
||||||
if (dictresize(mp, Py_SIZE(seq)))
|
if (dictresize(mp, Py_SIZE(seq)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1340,7 +1339,7 @@ dict_fromkeys(PyObject *cls, PyObject *args)
|
||||||
PyDictObject *mp = (PyDictObject *)d;
|
PyDictObject *mp = (PyDictObject *)d;
|
||||||
Py_ssize_t pos = 0;
|
Py_ssize_t pos = 0;
|
||||||
PyObject *key;
|
PyObject *key;
|
||||||
long hash;
|
Py_hash_t hash;
|
||||||
|
|
||||||
if (dictresize(mp, PySet_GET_SIZE(seq)))
|
if (dictresize(mp, PySet_GET_SIZE(seq)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1549,7 +1548,7 @@ PyDict_Merge(PyObject *a, PyObject *b, int override)
|
||||||
Py_INCREF(entry->me_key);
|
Py_INCREF(entry->me_key);
|
||||||
Py_INCREF(entry->me_value);
|
Py_INCREF(entry->me_value);
|
||||||
if (insertdict(mp, entry->me_key,
|
if (insertdict(mp, entry->me_key,
|
||||||
(long)entry->me_hash,
|
entry->me_hash,
|
||||||
entry->me_value) != 0)
|
entry->me_value) != 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1732,7 +1731,7 @@ dict_richcompare(PyObject *v, PyObject *w, int op)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
dict_contains(register PyDictObject *mp, PyObject *key)
|
dict_contains(register PyDictObject *mp, PyObject *key)
|
||||||
{
|
{
|
||||||
long hash;
|
Py_hash_t hash;
|
||||||
PyDictEntry *ep;
|
PyDictEntry *ep;
|
||||||
|
|
||||||
if (!PyUnicode_CheckExact(key) ||
|
if (!PyUnicode_CheckExact(key) ||
|
||||||
|
@ -1753,7 +1752,7 @@ dict_get(register PyDictObject *mp, PyObject *args)
|
||||||
PyObject *key;
|
PyObject *key;
|
||||||
PyObject *failobj = Py_None;
|
PyObject *failobj = Py_None;
|
||||||
PyObject *val = NULL;
|
PyObject *val = NULL;
|
||||||
long hash;
|
Py_hash_t hash;
|
||||||
PyDictEntry *ep;
|
PyDictEntry *ep;
|
||||||
|
|
||||||
if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &failobj))
|
if (!PyArg_UnpackTuple(args, "get", 1, 2, &key, &failobj))
|
||||||
|
@ -1782,7 +1781,7 @@ dict_setdefault(register PyDictObject *mp, PyObject *args)
|
||||||
PyObject *key;
|
PyObject *key;
|
||||||
PyObject *failobj = Py_None;
|
PyObject *failobj = Py_None;
|
||||||
PyObject *val = NULL;
|
PyObject *val = NULL;
|
||||||
long hash;
|
Py_hash_t hash;
|
||||||
PyDictEntry *ep;
|
PyDictEntry *ep;
|
||||||
|
|
||||||
if (!PyArg_UnpackTuple(args, "setdefault", 1, 2, &key, &failobj))
|
if (!PyArg_UnpackTuple(args, "setdefault", 1, 2, &key, &failobj))
|
||||||
|
@ -1818,7 +1817,7 @@ dict_clear(register PyDictObject *mp)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
dict_pop(PyDictObject *mp, PyObject *args)
|
dict_pop(PyDictObject *mp, PyObject *args)
|
||||||
{
|
{
|
||||||
long hash;
|
Py_hash_t hash;
|
||||||
PyDictEntry *ep;
|
PyDictEntry *ep;
|
||||||
PyObject *old_value, *old_key;
|
PyObject *old_value, *old_key;
|
||||||
PyObject *key, *deflt = NULL;
|
PyObject *key, *deflt = NULL;
|
||||||
|
@ -1864,7 +1863,7 @@ dict_pop(PyDictObject *mp, PyObject *args)
|
||||||
static PyObject *
|
static PyObject *
|
||||||
dict_popitem(PyDictObject *mp)
|
dict_popitem(PyDictObject *mp)
|
||||||
{
|
{
|
||||||
Py_ssize_t i = 0;
|
Py_hash_t i = 0;
|
||||||
PyDictEntry *ep;
|
PyDictEntry *ep;
|
||||||
PyObject *res;
|
PyObject *res;
|
||||||
|
|
||||||
|
@ -2039,7 +2038,7 @@ static PyMethodDef mapp_methods[] = {
|
||||||
int
|
int
|
||||||
PyDict_Contains(PyObject *op, PyObject *key)
|
PyDict_Contains(PyObject *op, PyObject *key)
|
||||||
{
|
{
|
||||||
long hash;
|
Py_hash_t hash;
|
||||||
PyDictObject *mp = (PyDictObject *)op;
|
PyDictObject *mp = (PyDictObject *)op;
|
||||||
PyDictEntry *ep;
|
PyDictEntry *ep;
|
||||||
|
|
||||||
|
@ -2055,7 +2054,7 @@ PyDict_Contains(PyObject *op, PyObject *key)
|
||||||
|
|
||||||
/* Internal version of PyDict_Contains used when the hash value is already known */
|
/* Internal version of PyDict_Contains used when the hash value is already known */
|
||||||
int
|
int
|
||||||
_PyDict_Contains(PyObject *op, PyObject *key, long hash)
|
_PyDict_Contains(PyObject *op, PyObject *key, Py_hash_t hash)
|
||||||
{
|
{
|
||||||
PyDictObject *mp = (PyDictObject *)op;
|
PyDictObject *mp = (PyDictObject *)op;
|
||||||
PyDictEntry *ep;
|
PyDictEntry *ep;
|
||||||
|
|
|
@ -522,7 +522,7 @@ float_richcompare(PyObject *v, PyObject *w, int op)
|
||||||
return Py_NotImplemented;
|
return Py_NotImplemented;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
float_hash(PyFloatObject *v)
|
float_hash(PyFloatObject *v)
|
||||||
{
|
{
|
||||||
return _Py_HashDouble(v->ob_fval);
|
return _Py_HashDouble(v->ob_fval);
|
||||||
|
|
|
@ -2552,7 +2552,7 @@ long_richcompare(PyObject *self, PyObject *other, int op)
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
long_hash(PyLongObject *v)
|
long_hash(PyLongObject *v)
|
||||||
{
|
{
|
||||||
unsigned long x;
|
unsigned long x;
|
||||||
|
@ -2606,7 +2606,7 @@ long_hash(PyLongObject *v)
|
||||||
x = x * sign;
|
x = x * sign;
|
||||||
if (x == (unsigned long)-1)
|
if (x == (unsigned long)-1)
|
||||||
x = (unsigned long)-2;
|
x = (unsigned long)-2;
|
||||||
return (long)x;
|
return (Py_hash_t)x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -224,10 +224,10 @@ meth_richcompare(PyObject *self, PyObject *other, int op)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
meth_hash(PyCFunctionObject *a)
|
meth_hash(PyCFunctionObject *a)
|
||||||
{
|
{
|
||||||
long x,y;
|
Py_hash_t x, y;
|
||||||
if (a->m_self == NULL)
|
if (a->m_self == NULL)
|
||||||
x = 0;
|
x = 0;
|
||||||
else {
|
else {
|
||||||
|
|
|
@ -687,7 +687,7 @@ PyObject_RichCompareBool(PyObject *v, PyObject *w, int op)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
long
|
Py_hash_t
|
||||||
_Py_HashDouble(double v)
|
_Py_HashDouble(double v)
|
||||||
{
|
{
|
||||||
int e, sign;
|
int e, sign;
|
||||||
|
@ -730,24 +730,24 @@ _Py_HashDouble(double v)
|
||||||
x = x * sign;
|
x = x * sign;
|
||||||
if (x == (unsigned long)-1)
|
if (x == (unsigned long)-1)
|
||||||
x = (unsigned long)-2;
|
x = (unsigned long)-2;
|
||||||
return (long)x;
|
return (Py_hash_t)x;
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
Py_hash_t
|
||||||
_Py_HashPointer(void *p)
|
_Py_HashPointer(void *p)
|
||||||
{
|
{
|
||||||
long x;
|
Py_hash_t x;
|
||||||
size_t y = (size_t)p;
|
size_t y = (size_t)p;
|
||||||
/* bottom 3 or 4 bits are likely to be 0; rotate y by 4 to avoid
|
/* bottom 3 or 4 bits are likely to be 0; rotate y by 4 to avoid
|
||||||
excessive hash collisions for dicts and sets */
|
excessive hash collisions for dicts and sets */
|
||||||
y = (y >> 4) | (y << (8 * SIZEOF_VOID_P - 4));
|
y = (y >> 4) | (y << (8 * SIZEOF_VOID_P - 4));
|
||||||
x = (long)y;
|
x = (Py_hash_t)y;
|
||||||
if (x == -1)
|
if (x == -1)
|
||||||
x = -2;
|
x = -2;
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
Py_hash_t
|
||||||
PyObject_HashNotImplemented(PyObject *v)
|
PyObject_HashNotImplemented(PyObject *v)
|
||||||
{
|
{
|
||||||
PyErr_Format(PyExc_TypeError, "unhashable type: '%.200s'",
|
PyErr_Format(PyExc_TypeError, "unhashable type: '%.200s'",
|
||||||
|
@ -755,7 +755,7 @@ PyObject_HashNotImplemented(PyObject *v)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
long
|
Py_hash_t
|
||||||
PyObject_Hash(PyObject *v)
|
PyObject_Hash(PyObject *v)
|
||||||
{
|
{
|
||||||
PyTypeObject *tp = Py_TYPE(v);
|
PyTypeObject *tp = Py_TYPE(v);
|
||||||
|
|
|
@ -75,7 +75,7 @@ NULL if the rich comparison returns an error.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static setentry *
|
static setentry *
|
||||||
set_lookkey(PySetObject *so, PyObject *key, register long hash)
|
set_lookkey(PySetObject *so, PyObject *key, register Py_hash_t hash)
|
||||||
{
|
{
|
||||||
register Py_ssize_t i;
|
register Py_ssize_t i;
|
||||||
register size_t perturb;
|
register size_t perturb;
|
||||||
|
@ -157,7 +157,7 @@ set_lookkey(PySetObject *so, PyObject *key, register long hash)
|
||||||
* see if the comparison altered the table.
|
* see if the comparison altered the table.
|
||||||
*/
|
*/
|
||||||
static setentry *
|
static setentry *
|
||||||
set_lookkey_unicode(PySetObject *so, PyObject *key, register long hash)
|
set_lookkey_unicode(PySetObject *so, PyObject *key, register Py_hash_t hash)
|
||||||
{
|
{
|
||||||
register Py_ssize_t i;
|
register Py_ssize_t i;
|
||||||
register size_t perturb;
|
register size_t perturb;
|
||||||
|
@ -211,7 +211,7 @@ Used by the public insert routine.
|
||||||
Eats a reference to key.
|
Eats a reference to key.
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
set_insert_key(register PySetObject *so, PyObject *key, long hash)
|
set_insert_key(register PySetObject *so, PyObject *key, Py_hash_t hash)
|
||||||
{
|
{
|
||||||
register setentry *entry;
|
register setentry *entry;
|
||||||
typedef setentry *(*lookupfunc)(PySetObject *, PyObject *, long);
|
typedef setentry *(*lookupfunc)(PySetObject *, PyObject *, long);
|
||||||
|
@ -248,7 +248,7 @@ Note that no refcounts are changed by this routine; if needed, the caller
|
||||||
is responsible for incref'ing `key`.
|
is responsible for incref'ing `key`.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
set_insert_clean(register PySetObject *so, PyObject *key, long hash)
|
set_insert_clean(register PySetObject *so, PyObject *key, Py_hash_t hash)
|
||||||
{
|
{
|
||||||
register size_t i;
|
register size_t i;
|
||||||
register size_t perturb;
|
register size_t perturb;
|
||||||
|
@ -349,7 +349,7 @@ set_table_resize(PySetObject *so, Py_ssize_t minused)
|
||||||
} else {
|
} else {
|
||||||
/* ACTIVE */
|
/* ACTIVE */
|
||||||
--i;
|
--i;
|
||||||
set_insert_clean(so, entry->key, (long) entry->hash);
|
set_insert_clean(so, entry->key, entry->hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -369,7 +369,7 @@ set_add_entry(register PySetObject *so, setentry *entry)
|
||||||
assert(so->fill <= so->mask); /* at least one empty slot */
|
assert(so->fill <= so->mask); /* at least one empty slot */
|
||||||
n_used = so->used;
|
n_used = so->used;
|
||||||
Py_INCREF(key);
|
Py_INCREF(key);
|
||||||
if (set_insert_key(so, key, (long) entry->hash) == -1) {
|
if (set_insert_key(so, key, entry->hash) == -1) {
|
||||||
Py_DECREF(key);
|
Py_DECREF(key);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -381,7 +381,7 @@ set_add_entry(register PySetObject *so, setentry *entry)
|
||||||
static int
|
static int
|
||||||
set_add_key(register PySetObject *so, PyObject *key)
|
set_add_key(register PySetObject *so, PyObject *key)
|
||||||
{
|
{
|
||||||
register long hash;
|
register Py_hash_t hash;
|
||||||
register Py_ssize_t n_used;
|
register Py_ssize_t n_used;
|
||||||
|
|
||||||
if (!PyUnicode_CheckExact(key) ||
|
if (!PyUnicode_CheckExact(key) ||
|
||||||
|
@ -410,7 +410,7 @@ set_discard_entry(PySetObject *so, setentry *oldentry)
|
||||||
{ register setentry *entry;
|
{ register setentry *entry;
|
||||||
PyObject *old_key;
|
PyObject *old_key;
|
||||||
|
|
||||||
entry = (so->lookup)(so, oldentry->key, (long) oldentry->hash);
|
entry = (so->lookup)(so, oldentry->key, oldentry->hash);
|
||||||
if (entry == NULL)
|
if (entry == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
if (entry->key == NULL || entry->key == dummy)
|
if (entry->key == NULL || entry->key == dummy)
|
||||||
|
@ -426,7 +426,7 @@ set_discard_entry(PySetObject *so, setentry *oldentry)
|
||||||
static int
|
static int
|
||||||
set_discard_key(PySetObject *so, PyObject *key)
|
set_discard_key(PySetObject *so, PyObject *key)
|
||||||
{
|
{
|
||||||
register long hash;
|
register Py_hash_t hash;
|
||||||
register setentry *entry;
|
register setentry *entry;
|
||||||
PyObject *old_key;
|
PyObject *old_key;
|
||||||
|
|
||||||
|
@ -675,7 +675,7 @@ set_merge(PySetObject *so, PyObject *otherset)
|
||||||
static int
|
static int
|
||||||
set_contains_key(PySetObject *so, PyObject *key)
|
set_contains_key(PySetObject *so, PyObject *key)
|
||||||
{
|
{
|
||||||
long hash;
|
Py_hash_t hash;
|
||||||
setentry *entry;
|
setentry *entry;
|
||||||
|
|
||||||
if (!PyUnicode_CheckExact(key) ||
|
if (!PyUnicode_CheckExact(key) ||
|
||||||
|
@ -697,7 +697,7 @@ set_contains_entry(PySetObject *so, setentry *entry)
|
||||||
PyObject *key;
|
PyObject *key;
|
||||||
setentry *lu_entry;
|
setentry *lu_entry;
|
||||||
|
|
||||||
lu_entry = (so->lookup)(so, entry->key, (long) entry->hash);
|
lu_entry = (so->lookup)(so, entry->key, entry->hash);
|
||||||
if (lu_entry == NULL)
|
if (lu_entry == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
key = lu_entry->key;
|
key = lu_entry->key;
|
||||||
|
@ -761,11 +761,11 @@ set_traverse(PySetObject *so, visitproc visit, void *arg)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
frozenset_hash(PyObject *self)
|
frozenset_hash(PyObject *self)
|
||||||
{
|
{
|
||||||
PySetObject *so = (PySetObject *)self;
|
PySetObject *so = (PySetObject *)self;
|
||||||
long h, hash = 1927868237L;
|
Py_hash_t h, hash = 1927868237L;
|
||||||
setentry *entry;
|
setentry *entry;
|
||||||
Py_ssize_t pos = 0;
|
Py_ssize_t pos = 0;
|
||||||
|
|
||||||
|
@ -926,7 +926,7 @@ set_update_internal(PySetObject *so, PyObject *other)
|
||||||
if (PyDict_CheckExact(other)) {
|
if (PyDict_CheckExact(other)) {
|
||||||
PyObject *value;
|
PyObject *value;
|
||||||
Py_ssize_t pos = 0;
|
Py_ssize_t pos = 0;
|
||||||
long hash;
|
Py_hash_t hash;
|
||||||
Py_ssize_t dictsize = PyDict_Size(other);
|
Py_ssize_t dictsize = PyDict_Size(other);
|
||||||
|
|
||||||
/* Do one big resize at the start, rather than
|
/* Do one big resize at the start, rather than
|
||||||
|
@ -1114,7 +1114,7 @@ set_swap_bodies(PySetObject *a, PySetObject *b)
|
||||||
{
|
{
|
||||||
Py_ssize_t t;
|
Py_ssize_t t;
|
||||||
setentry *u;
|
setentry *u;
|
||||||
setentry *(*f)(PySetObject *so, PyObject *key, long hash);
|
setentry *(*f)(PySetObject *so, PyObject *key, Py_ssize_t hash);
|
||||||
setentry tab[PySet_MINSIZE];
|
setentry tab[PySet_MINSIZE];
|
||||||
long h;
|
long h;
|
||||||
|
|
||||||
|
@ -1285,7 +1285,7 @@ set_intersection(PySetObject *so, PyObject *other)
|
||||||
while ((key = PyIter_Next(it)) != NULL) {
|
while ((key = PyIter_Next(it)) != NULL) {
|
||||||
int rv;
|
int rv;
|
||||||
setentry entry;
|
setentry entry;
|
||||||
long hash = PyObject_Hash(key);
|
Py_hash_t hash = PyObject_Hash(key);
|
||||||
|
|
||||||
if (hash == -1) {
|
if (hash == -1) {
|
||||||
Py_DECREF(it);
|
Py_DECREF(it);
|
||||||
|
@ -1442,7 +1442,7 @@ set_isdisjoint(PySetObject *so, PyObject *other)
|
||||||
while ((key = PyIter_Next(it)) != NULL) {
|
while ((key = PyIter_Next(it)) != NULL) {
|
||||||
int rv;
|
int rv;
|
||||||
setentry entry;
|
setentry entry;
|
||||||
long hash = PyObject_Hash(key);
|
Py_hash_t hash = PyObject_Hash(key);
|
||||||
|
|
||||||
if (hash == -1) {
|
if (hash == -1) {
|
||||||
Py_DECREF(key);
|
Py_DECREF(key);
|
||||||
|
@ -1641,7 +1641,7 @@ set_symmetric_difference_update(PySetObject *so, PyObject *other)
|
||||||
if (PyDict_CheckExact(other)) {
|
if (PyDict_CheckExact(other)) {
|
||||||
PyObject *value;
|
PyObject *value;
|
||||||
int rv;
|
int rv;
|
||||||
long hash;
|
Py_hash_t hash;
|
||||||
while (_PyDict_Next(other, &pos, &key, &value, &hash)) {
|
while (_PyDict_Next(other, &pos, &key, &value, &hash)) {
|
||||||
setentry an_entry;
|
setentry an_entry;
|
||||||
|
|
||||||
|
@ -2308,7 +2308,7 @@ PySet_Add(PyObject *anyset, PyObject *key)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
_PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash)
|
_PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, Py_hash_t *hash)
|
||||||
{
|
{
|
||||||
setentry *entry;
|
setentry *entry;
|
||||||
|
|
||||||
|
@ -2319,7 +2319,7 @@ _PySet_NextEntry(PyObject *set, Py_ssize_t *pos, PyObject **key, long *hash)
|
||||||
if (set_next((PySetObject *)set, pos, &entry) == 0)
|
if (set_next((PySetObject *)set, pos, &entry) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
*key = entry->key;
|
*key = entry->key;
|
||||||
*hash = (long) entry->hash;
|
*hash = entry->hash;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2363,7 +2363,7 @@ test_c_api(PySetObject *so)
|
||||||
Py_ssize_t i;
|
Py_ssize_t i;
|
||||||
PyObject *elem=NULL, *dup=NULL, *t, *f, *dup2, *x;
|
PyObject *elem=NULL, *dup=NULL, *t, *f, *dup2, *x;
|
||||||
PyObject *ob = (PyObject *)so;
|
PyObject *ob = (PyObject *)so;
|
||||||
long hash;
|
Py_hash_t hash;
|
||||||
PyObject *str;
|
PyObject *str;
|
||||||
|
|
||||||
/* Verify preconditions */
|
/* Verify preconditions */
|
||||||
|
|
|
@ -312,10 +312,10 @@ Done:
|
||||||
1330111, 1412633, 1165069, 1247599, 1495177, 1577699
|
1330111, 1412633, 1165069, 1247599, 1495177, 1577699
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
tuplehash(PyTupleObject *v)
|
tuplehash(PyTupleObject *v)
|
||||||
{
|
{
|
||||||
register long x, y;
|
register Py_hash_t x, y;
|
||||||
register Py_ssize_t len = Py_SIZE(v);
|
register Py_ssize_t len = Py_SIZE(v);
|
||||||
register PyObject **p;
|
register PyObject **p;
|
||||||
long mult = 1000003L;
|
long mult = 1000003L;
|
||||||
|
|
|
@ -4918,13 +4918,12 @@ slot_tp_str(PyObject *self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
slot_tp_hash(PyObject *self)
|
slot_tp_hash(PyObject *self)
|
||||||
{
|
{
|
||||||
PyObject *func, *res;
|
PyObject *func, *res;
|
||||||
static PyObject *hash_str;
|
static PyObject *hash_str;
|
||||||
long h;
|
Py_ssize_t h;
|
||||||
int overflow;
|
|
||||||
|
|
||||||
func = lookup_method(self, "__hash__", &hash_str);
|
func = lookup_method(self, "__hash__", &hash_str);
|
||||||
|
|
||||||
|
@ -4947,20 +4946,20 @@ slot_tp_hash(PyObject *self)
|
||||||
"__hash__ method should return an integer");
|
"__hash__ method should return an integer");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* Transform the PyLong `res` to a C long `h`. For an existing
|
/* Transform the PyLong `res` to a Py_hash_t `h`. For an existing
|
||||||
hashable Python object x, hash(x) will always lie within the range
|
hashable Python object x, hash(x) will always lie within the range of
|
||||||
of a C long. Therefore our transformation must preserve values
|
Py_hash_t. Therefore our transformation must preserve values that
|
||||||
that already lie within this range, to ensure that if x.__hash__()
|
already lie within this range, to ensure that if x.__hash__() returns
|
||||||
returns hash(y) then hash(x) == hash(y). */
|
hash(y) then hash(x) == hash(y). */
|
||||||
h = PyLong_AsLongAndOverflow(res, &overflow);
|
h = PyLong_AsSsize_t(res);
|
||||||
if (overflow)
|
if (h == -1 && PyErr_Occurred()) {
|
||||||
/* res was not within the range of a C long, so we're free to
|
/* res was not within the range of a Py_hash_t, so we're free to
|
||||||
use any sufficiently bit-mixing transformation;
|
use any sufficiently bit-mixing transformation;
|
||||||
long.__hash__ will do nicely. */
|
long.__hash__ will do nicely. */
|
||||||
|
PyErr_Clear();
|
||||||
h = PyLong_Type.tp_hash(res);
|
h = PyLong_Type.tp_hash(res);
|
||||||
|
}
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
if (h == -1 && !PyErr_Occurred())
|
|
||||||
h = -2;
|
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7444,12 +7444,12 @@ unicode_getitem(PyUnicodeObject *self, Py_ssize_t index)
|
||||||
|
|
||||||
/* Believe it or not, this produces the same value for ASCII strings
|
/* Believe it or not, this produces the same value for ASCII strings
|
||||||
as string_hash(). */
|
as string_hash(). */
|
||||||
static long
|
static Py_hash_t
|
||||||
unicode_hash(PyUnicodeObject *self)
|
unicode_hash(PyUnicodeObject *self)
|
||||||
{
|
{
|
||||||
Py_ssize_t len;
|
Py_ssize_t len;
|
||||||
Py_UNICODE *p;
|
Py_UNICODE *p;
|
||||||
long x;
|
Py_hash_t x;
|
||||||
|
|
||||||
if (self->hash != -1)
|
if (self->hash != -1)
|
||||||
return self->hash;
|
return self->hash;
|
||||||
|
|
|
@ -139,7 +139,7 @@ weakref_call(PyWeakReference *self, PyObject *args, PyObject *kw)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static long
|
static Py_hash_t
|
||||||
weakref_hash(PyWeakReference *self)
|
weakref_hash(PyWeakReference *self)
|
||||||
{
|
{
|
||||||
if (self->hash != -1)
|
if (self->hash != -1)
|
||||||
|
|
|
@ -1148,12 +1148,12 @@ Delete a named attribute on an object; delattr(x, 'y') is equivalent to\n\
|
||||||
static PyObject *
|
static PyObject *
|
||||||
builtin_hash(PyObject *self, PyObject *v)
|
builtin_hash(PyObject *self, PyObject *v)
|
||||||
{
|
{
|
||||||
long x;
|
Py_hash_t x;
|
||||||
|
|
||||||
x = PyObject_Hash(v);
|
x = PyObject_Hash(v);
|
||||||
if (x == -1)
|
if (x == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
return PyLong_FromLong(x);
|
return PyLong_FromSsize_t(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
PyDoc_STRVAR(hash_doc,
|
PyDoc_STRVAR(hash_doc,
|
||||||
|
|
|
@ -2102,7 +2102,7 @@ PyEval_EvalFrameEx(PyFrameObject *f, int throwflag)
|
||||||
/* Inline the PyDict_GetItem() calls.
|
/* Inline the PyDict_GetItem() calls.
|
||||||
WARNING: this is an extreme speed hack.
|
WARNING: this is an extreme speed hack.
|
||||||
Do not try this at home. */
|
Do not try this at home. */
|
||||||
long hash = ((PyUnicodeObject *)w)->hash;
|
Py_hash_t hash = ((PyUnicodeObject *)w)->hash;
|
||||||
if (hash != -1) {
|
if (hash != -1) {
|
||||||
PyDictObject *d;
|
PyDictObject *d;
|
||||||
PyDictEntry *e;
|
PyDictEntry *e;
|
||||||
|
|
|
@ -567,7 +567,7 @@ get_hash_info(void)
|
||||||
if (hash_info == NULL)
|
if (hash_info == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
PyStructSequence_SET_ITEM(hash_info, field++,
|
PyStructSequence_SET_ITEM(hash_info, field++,
|
||||||
PyLong_FromLong(8*sizeof(long)));
|
PyLong_FromLong(8*sizeof(Py_hash_t)));
|
||||||
PyStructSequence_SET_ITEM(hash_info, field++,
|
PyStructSequence_SET_ITEM(hash_info, field++,
|
||||||
PyLong_FromLong(_PyHASH_MODULUS));
|
PyLong_FromLong(_PyHASH_MODULUS));
|
||||||
PyStructSequence_SET_ITEM(hash_info, field++,
|
PyStructSequence_SET_ITEM(hash_info, field++,
|
||||||
|
|
Loading…
Reference in New Issue