]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Comparison of two class instances without __cmp__ or __rcmp__ methods
authorSjoerd Mullender <sjoerd@acm.org>
Wed, 19 Oct 1994 15:11:52 +0000 (15:11 +0000)
committerSjoerd Mullender <sjoerd@acm.org>
Wed, 19 Oct 1994 15:11:52 +0000 (15:11 +0000)
was broken.

Objects/classobject.c

index 923ad45ab312a70c80e3028986dab97640f1636f..a3958010b1596643c890c088cb6c8423c42d60a1 100644 (file)
@@ -523,8 +523,11 @@ instance_compare(inst, other)
        object *result;
        int outcome;
        result  = instancebinop(inst, other, "__cmp__", "__rcmp__");
-       if (result == NULL)
-               return -2;
+       if (result == NULL) {
+               /* no __cmp__ or __rcmp__ methods, so use addresses */
+               err_clear();
+               return inst < other ? -1 : (inst > other ? 1 : 0);
+       }
        outcome = getintvalue(result);
        DECREF(result);
        if (outcome == -1 && err_occurred())