summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-07-01 18:48:04 (GMT)
committerGuido van Rossum <guido@python.org>1991-07-01 18:48:04 (GMT)
commit9fb036811a326eedd152fe105e2940f240f114b4 (patch)
treecf4025c68cce428cdde45d789e8057ae584a1f58 /Objects
parentef0068ff9d0f9c9a8f90f66a253f2dee0de5d0e0 (diff)
downloadcpython-9fb036811a326eedd152fe105e2940f240f114b4.zip
cpython-9fb036811a326eedd152fe105e2940f240f114b4.tar.gz
cpython-9fb036811a326eedd152fe105e2940f240f114b4.tar.bz2
Change cmpobject() to coerce numerical values before comparing them
Diffstat (limited to 'Objects')
-rw-r--r--Objects/object.c19
1 files changed, 17 insertions, 2 deletions
diff --git a/Objects/object.c b/Objects/object.c
index b63f067..79c12f2 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -117,11 +117,26 @@ cmpobject(v, w)
return -1;
if (w == NULL)
return 1;
- if ((tp = v->ob_type) != w->ob_type)
+ if ((tp = v->ob_type) != w->ob_type) {
+ if (tp->tp_as_number != NULL &&
+ w->ob_type->tp_as_number != NULL) {
+ if (coerce(&v, &w) != 0) {
+ err_clear();
+ /* XXX Should report the error,
+ XXX but the interface isn't there... */
+ }
+ else {
+ int cmp = (*v->ob_type->tp_compare)(v, w);
+ DECREF(v);
+ DECREF(w);
+ return cmp;
+ }
+ }
return strcmp(tp->tp_name, w->ob_type->tp_name);
+ }
if (tp->tp_compare == NULL)
return (v < w) ? -1 : 1;
- return ((*tp->tp_compare)(v, w));
+ return (*tp->tp_compare)(v, w);
}
object *