diff options
author | Guido van Rossum <guido@python.org> | 2001-01-22 15:59:32 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2001-01-22 15:59:32 (GMT) |
commit | 8f9143da335ec2118017f62a22a9968bfe47b04b (patch) | |
tree | 97c9305de5f1d438a52a9312e4558d8bfdafefab | |
parent | af4c942b8a96f9d4bc5ae90c24f66c491ba915f8 (diff) | |
download | cpython-8f9143da335ec2118017f62a22a9968bfe47b04b.zip cpython-8f9143da335ec2118017f62a22a9968bfe47b04b.tar.gz cpython-8f9143da335ec2118017f62a22a9968bfe47b04b.tar.bz2 |
Once again, numeric-smelling objects compare smaller than non-numeric
ones.
-rw-r--r-- | Objects/object.c | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/Objects/object.c b/Objects/object.c index a263bda..b15e76e 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -522,6 +522,7 @@ static int default_3way_compare(PyObject *v, PyObject *w) { int c; + char *vname, *wname; if (v->ob_type == w->ob_type) { /* When comparing these pointers, they must be cast to @@ -550,8 +551,22 @@ default_3way_compare(PyObject *v, PyObject *w) } /* different type: compare type names */ - c = strcmp(v->ob_type->tp_name, w->ob_type->tp_name); - return (c < 0) ? -1 : (c > 0) ? 1 : 0; + if (v->ob_type->tp_as_number) + vname = ""; + else + vname = v->ob_type->tp_name; + if (w->ob_type->tp_as_number) + wname = ""; + else + wname = w->ob_type->tp_name; + c = strcmp(vname, wname); + if (c < 0) + return -1; + if (c > 0) + return 1; + /* Same type name, or (more likely) incomparable numeric types */ + return ((Py_uintptr_t)(v->ob_type) < ( + Py_uintptr_t)(w->ob_type)) ? -1 : 1; } #define CHECK_TYPES(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_CHECKTYPES) |