Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 41c3244

Browse files
committed
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.)
1 parent a3af41d commit 41c3244

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

Objects/object.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ PyObject_Hash(PyObject *v)
914914
PyTypeObject *tp = v->ob_type;
915915
if (tp->tp_hash != NULL)
916916
return (*tp->tp_hash)(v);
917-
if (tp->tp_compare == NULL) {
917+
if (tp->tp_compare == NULL && tp->tp_richcompare == NULL) {
918918
return _Py_HashPointer(v); /* Use address as hash value */
919919
}
920920
/* If there's a cmp but no hash defined, the object can't be hashed */

0 commit comments

Comments
 (0)