mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
Rich comparisons fallout: PyObject_Hash() should check for both
tp_compare and tp_richcompare NULL before deciding to do a quickie based on the object address. (Tim Peters discovered this.)
This commit is contained in:
parent
a3af41d564
commit
41c3244875
1 changed files with 1 additions and 1 deletions
|
@ -914,7 +914,7 @@ PyObject_Hash(PyObject *v)
|
||||||
PyTypeObject *tp = v->ob_type;
|
PyTypeObject *tp = v->ob_type;
|
||||||
if (tp->tp_hash != NULL)
|
if (tp->tp_hash != NULL)
|
||||||
return (*tp->tp_hash)(v);
|
return (*tp->tp_hash)(v);
|
||||||
if (tp->tp_compare == NULL) {
|
if (tp->tp_compare == NULL && tp->tp_richcompare == NULL) {
|
||||||
return _Py_HashPointer(v); /* Use address as hash value */
|
return _Py_HashPointer(v); /* Use address as hash value */
|
||||||
}
|
}
|
||||||
/* If there's a cmp but no hash defined, the object can't be hashed */
|
/* If there's a cmp but no hash defined, the object can't be hashed */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue