Mercurial > cpython-lru_cache-weakref
diff Objects/complexobject.c @ 39603:40bbe669b089
Get rid of most of the rest of coerce (slot is still there for now).
| author | Neal Norwitz <nnorwitz@gmail.com> |
|---|---|
| date | Mon, 21 Aug 2006 17:06:07 +0000 |
| parents | 654c380cf8b9 |
| children | 6f1020743077 |
line wrap: on
line diff
--- a/Objects/complexobject.c Mon Aug 21 16:27:31 2006 +0000 +++ b/Objects/complexobject.c Mon Aug 21 17:06:07 2006 +0000 @@ -573,65 +573,20 @@ return v->cval.real != 0.0 || v->cval.imag != 0.0; } -static int -complex_coerce(PyObject **pv, PyObject **pw) -{ - Py_complex cval; - cval.imag = 0.; - if (PyInt_Check(*pw)) { - cval.real = (double)PyInt_AsLong(*pw); - *pw = PyComplex_FromCComplex(cval); - Py_INCREF(*pv); - return 0; - } - else if (PyLong_Check(*pw)) { - cval.real = PyLong_AsDouble(*pw); - if (cval.real == -1.0 && PyErr_Occurred()) - return -1; - *pw = PyComplex_FromCComplex(cval); - Py_INCREF(*pv); - return 0; - } - else if (PyFloat_Check(*pw)) { - cval.real = PyFloat_AsDouble(*pw); - *pw = PyComplex_FromCComplex(cval); - Py_INCREF(*pv); - return 0; - } - else if (PyComplex_Check(*pw)) { - Py_INCREF(*pv); - Py_INCREF(*pw); - return 0; - } - return 1; /* Can't do it */ -} - static PyObject * complex_richcompare(PyObject *v, PyObject *w, int op) { - int c; Py_complex i, j; PyObject *res; - c = PyNumber_CoerceEx(&v, &w); - if (c < 0) - return NULL; - if (c > 0) { - Py_INCREF(Py_NotImplemented); - return Py_NotImplemented; - } /* Make sure both arguments are complex. */ if (!(PyComplex_Check(v) && PyComplex_Check(w))) { - Py_DECREF(v); - Py_DECREF(w); Py_INCREF(Py_NotImplemented); return Py_NotImplemented; } i = ((PyComplexObject *)v)->cval; j = ((PyComplexObject *)w)->cval; - Py_DECREF(v); - Py_DECREF(w); if (op != Py_EQ && op != Py_NE) { PyErr_SetString(PyExc_TypeError, @@ -996,7 +951,7 @@ 0, /* nb_and */ 0, /* nb_xor */ 0, /* nb_or */ - complex_coerce, /* nb_coerce */ + (coercion)0, /* nb_coerce */ complex_int, /* nb_int */ complex_long, /* nb_long */ complex_float, /* nb_float */
