Commit f233879f authored by Guido van Rossum's avatar Guido van Rossum

Rich comparisons fall-out:

- Use PyObject_RichCompare*() where possible: when comparing
  keyword arguments, in _PyEval_SliceIndex(), and of course in
  cmp_outcome().

Unrelated stuff:

- Removed all trailing whitespace.

- Folded some long lines.
parent 0da32440
......@@ -48,7 +48,7 @@ static PyObject *fast_function(PyObject *, PyObject ***, int, int, int);
static PyObject *fast_cfunction(PyObject *, PyObject ***, int);
static PyObject *do_call(PyObject *, PyObject ***, int, int);
static PyObject *ext_do_call(PyObject *, PyObject ***, int, int, int);
static PyObject *update_keyword_args(PyObject *, int, PyObject ***, PyObject *);
static PyObject *update_keyword_args(PyObject *, int, PyObject ***,PyObject *);
static PyObject *update_star_args(int, int, PyObject *, PyObject ***);
static PyObject *load_args(PyObject ***, int);
#define CALL_FLAG_VAR 1
......@@ -493,8 +493,12 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
for (j = 0; j < co->co_argcount; j++) {
PyObject *nm = PyTuple_GET_ITEM(
co->co_varnames, j);
if (PyObject_Compare(keyword, nm) == 0)
int cmp = PyObject_RichCompareBool(
keyword, nm, Py_EQ);
if (cmp > 0)
break;
else if (cmp < 0)
goto fail;
}
/* Check errors from Compare */
if (PyErr_Occurred())
......@@ -2128,7 +2132,8 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals,
}
static void
set_exc_info(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb)
set_exc_info(PyThreadState *tstate,
PyObject *type, PyObject *value, PyObject *tb)
{
PyFrameObject *frame;
PyObject *tmp_type, *tmp_value, *tmp_tb;
......@@ -3002,32 +3007,37 @@ _PyEval_SliceIndex(PyObject *v, int *pi)
x = PyLong_AsLong(v);
if (x==-1 && PyErr_Occurred()) {
PyObject *long_zero;
int cmp;
if (!PyErr_ExceptionMatches( PyExc_OverflowError ) ) {
if (!PyErr_ExceptionMatches(
PyExc_OverflowError)) {
/* It's not an overflow error, so just
signal an error */
return 0;
}
/* Clear the OverflowError */
PyErr_Clear();
/* It's an overflow error, so we need to
check the sign of the long integer,
set the value to INT_MAX or 0, and clear
the error. */
/* Create a long integer with a value of 0 */
long_zero = PyLong_FromLong( 0L );
long_zero = PyLong_FromLong(0L);
if (long_zero == NULL) return 0;
/* Check sign */
if (PyObject_Compare(long_zero, v) < 0)
cmp = PyObject_RichCompareBool(v, long_zero,
Py_GT);
Py_DECREF(long_zero);
if (cmp < 0)
return 0;
else if (cmp > 0)
x = INT_MAX;
else
x = 0;
/* Free the long integer we created, and clear the
OverflowError */
Py_DECREF(long_zero);
PyErr_Clear();
}
} else {
PyErr_SetString(PyExc_TypeError,
......@@ -3056,7 +3066,8 @@ apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */
}
static int
assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x) /* u[v:w] = x */
assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x)
/* u[v:w] = x */
{
int ilow = 0, ihigh = INT_MAX;
if (!_PyEval_SliceIndex(v, &ilow))
......@@ -3072,8 +3083,7 @@ assign_slice(PyObject *u, PyObject *v, PyObject *w, PyObject *x) /* u[v:w] = x *
static PyObject *
cmp_outcome(int op, register PyObject *v, register PyObject *w)
{
register int cmp;
register int res = 0;
int res = 0;
switch (op) {
case IS:
case IS_NOT:
......@@ -3093,18 +3103,7 @@ cmp_outcome(int op, register PyObject *v, register PyObject *w)
res = PyErr_GivenExceptionMatches(v, w);
break;
default:
cmp = PyObject_Compare(v, w);
if (cmp && PyErr_Occurred())
return NULL;
switch (op) {
case LT: res = cmp < 0; break;
case LE: res = cmp <= 0; break;
case EQ: res = cmp == 0; break;
case NE: res = cmp != 0; break;
case GT: res = cmp > 0; break;
case GE: res = cmp >= 0; break;
/* XXX no default? (res is initialized to 0 though) */
}
return PyObject_RichCompare(v, w, op);
}
v = res ? Py_True : Py_False;
Py_INCREF(v);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment