Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9fb0368

Browse files
committed
Change cmpobject() to coerce numerical values before comparing them
1 parent ef0068f commit 9fb0368

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

Objects/object.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,26 @@ cmpobject(v, w)
117117
return -1;
118118
if (w == NULL)
119119
return 1;
120-
if ((tp = v->ob_type) != w->ob_type)
120+
if ((tp = v->ob_type) != w->ob_type) {
121+
if (tp->tp_as_number != NULL &&
122+
w->ob_type->tp_as_number != NULL) {
123+
if (coerce(&v, &w) != 0) {
124+
err_clear();
125+
/* XXX Should report the error,
126+
XXX but the interface isn't there... */
127+
}
128+
else {
129+
int cmp = (*v->ob_type->tp_compare)(v, w);
130+
DECREF(v);
131+
DECREF(w);
132+
return cmp;
133+
}
134+
}
121135
return strcmp(tp->tp_name, w->ob_type->tp_name);
136+
}
122137
if (tp->tp_compare == NULL)
123138
return (v < w) ? -1 : 1;
124-
return ((*tp->tp_compare)(v, w));
139+
return (*tp->tp_compare)(v, w);
125140
}
126141

127142
object *

0 commit comments

Comments
 (0)