diff options
author | Guido van Rossum <guido@python.org> | 1998-06-09 18:58:44 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1998-06-09 18:58:44 (GMT) |
commit | cd5a5f627a4b30aacc1991feca5bc7f48ef7584d (patch) | |
tree | 7ad1275d831e057c2a7a803ca7de46725c58fe0b /Objects | |
parent | 5d23758be7bca6c64f6b74f49227a8039d93fb5d (diff) | |
download | cpython-cd5a5f627a4b30aacc1991feca5bc7f48ef7584d.zip cpython-cd5a5f627a4b30aacc1991feca5bc7f48ef7584d.tar.gz cpython-cd5a5f627a4b30aacc1991feca5bc7f48ef7584d.tar.bz2 |
When comparing objects of different types (which is done by comparing
the type names), make sure that numeric objects are considered smaller
than all other objects, by forcing their name to "".
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/object.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/Objects/object.c b/Objects/object.c index 964c5c5..2428cc9 100644 --- a/Objects/object.c +++ b/Objects/object.c @@ -284,7 +284,7 @@ int PyObject_Compare(v, w) PyObject *v, *w; { - PyTypeObject *tp; + PyTypeObject *vtp, *wtp; if (v == NULL || w == NULL) { PyErr_BadInternalCall(); return -1; @@ -309,9 +309,11 @@ PyObject_Compare(v, w) Py_DECREF(res); return (c < 0) ? -1 : (c > 0) ? 1 : 0; } - if ((tp = v->ob_type) != w->ob_type) { - if (tp->tp_as_number != NULL && - w->ob_type->tp_as_number != NULL) { + if ((vtp = v->ob_type) != (wtp = w->ob_type)) { + char *vname = vtp->tp_name; + char *wname = wtp->tp_name; + if (vtp->tp_as_number != NULL && + wtp->tp_as_number != NULL) { int err; err = PyNumber_CoerceEx(&v, &w); if (err < 0) @@ -323,11 +325,16 @@ PyObject_Compare(v, w) return cmp; } } - return strcmp(tp->tp_name, w->ob_type->tp_name); - } - if (tp->tp_compare == NULL) + else if (vtp->tp_as_number != NULL) + vname = ""; + else if (wtp->tp_as_number != NULL) + wname = ""; + /* Numerical types compare smaller than all other types */ + return strcmp(vname, wname); + } + if (vtp->tp_compare == NULL) return (v < w) ? -1 : 1; - return (*tp->tp_compare)(v, w); + return (*vtp->tp_compare)(v, w); } long |