From: Sjoerd Mullender Date: Wed, 19 Oct 1994 15:11:52 +0000 (+0000) Subject: Comparison of two class instances without __cmp__ or __rcmp__ methods X-Git-Tag: v1.1.1~34 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b9a6d1249894c60eb38d3cc8ce4c1b808482b377;p=thirdparty%2FPython%2Fcpython.git Comparison of two class instances without __cmp__ or __rcmp__ methods was broken. --- diff --git a/Objects/classobject.c b/Objects/classobject.c index 923ad45ab312..a3958010b159 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -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())