static PyObject *
-min_max(PyObject *args, int sign)
+min_max(PyObject *args, int op)
{
int i;
PyObject *v, *w, *x;
if (w == NULL)
w = x;
else {
- int c = PyObject_Compare(x, w);
- if (c && PyErr_Occurred()) {
+ int cmp = PyObject_RichCompareBool(x, w, op);
+ if (cmp > 0) {
+ Py_DECREF(w);
+ w = x;
+ }
+ else if (cmp < 0) {
Py_DECREF(x);
Py_XDECREF(w);
return NULL;
}
- if (c * sign > 0) {
- Py_DECREF(w);
- w = x;
- }
else
Py_DECREF(x);
}
static PyObject *
builtin_min(PyObject *self, PyObject *v)
{
- return min_max(v, -1);
+ return min_max(v, Py_LT);
}
static char min_doc[] =
static PyObject *
builtin_max(PyObject *self, PyObject *v)
{
- return min_max(v, 1);
+ return min_max(v, Py_GT);
}
static char max_doc[] =