]> granicus.if.org Git - python/commitdiff
Rich comparisons fallout: PyObject_Hash() should check for both
authorGuido van Rossum <guido@python.org>
Thu, 18 Jan 2001 23:33:37 +0000 (23:33 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 18 Jan 2001 23:33:37 +0000 (23:33 +0000)
tp_compare and tp_richcompare NULL before deciding to do a quickie
based on the object address.  (Tim Peters discovered this.)

Objects/object.c

index 323ed54b51b2342a9ae6ae3e1496e18be4ff4da6..44344f9b2c25f508323c2bf590f9fcd4e433a2d5 100644 (file)
@@ -914,7 +914,7 @@ PyObject_Hash(PyObject *v)
        PyTypeObject *tp = v->ob_type;
        if (tp->tp_hash != NULL)
                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 */
        }
        /* If there's a cmp but no hash defined, the object can't be hashed */