mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Change cmpobject() to coerce numerical values before comparing them
This commit is contained in:
parent
ef0068ff9d
commit
9fb036811a
1 changed files with 17 additions and 2 deletions
|
@ -117,11 +117,26 @@ cmpobject(v, w)
|
||||||
return -1;
|
return -1;
|
||||||
if (w == NULL)
|
if (w == NULL)
|
||||||
return 1;
|
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);
|
return strcmp(tp->tp_name, w->ob_type->tp_name);
|
||||||
|
}
|
||||||
if (tp->tp_compare == NULL)
|
if (tp->tp_compare == NULL)
|
||||||
return (v < w) ? -1 : 1;
|
return (v < w) ? -1 : 1;
|
||||||
return ((*tp->tp_compare)(v, w));
|
return (*tp->tp_compare)(v, w);
|
||||||
}
|
}
|
||||||
|
|
||||||
object *
|
object *
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue