diff options
| author | Neal Norwitz <nnorwitz@gmail.com> | 2006-08-12 17:03:09 (GMT) |
|---|---|---|
| committer | Neal Norwitz <nnorwitz@gmail.com> | 2006-08-12 17:03:09 (GMT) |
| commit | 8a87f5d37e6aab91ddc4c6491877b6cbd48a12cf (patch) | |
| tree | 330bb4b553958f129b31e31ccea2a2c835b19de0 /Objects/classobject.c | |
| parent | f3e304297e94b9b1956a4ed95debd1b163958d71 (diff) | |
| download | cpython-8a87f5d37e6aab91ddc4c6491877b6cbd48a12cf.zip cpython-8a87f5d37e6aab91ddc4c6491877b6cbd48a12cf.tar.gz cpython-8a87f5d37e6aab91ddc4c6491877b6cbd48a12cf.tar.bz2 | |
Patch #1538606, Patch to fix __index__() clipping.
I modified this patch some by fixing style, some error checking, and adding
XXX comments. This patch requires review and some changes are to be expected.
I'm checking in now to get the greatest possible review and establish a
baseline for moving forward. I don't want this to hold up release if possible.
Diffstat (limited to 'Objects/classobject.c')
| -rw-r--r-- | Objects/classobject.c | 24 |
1 files changed, 6 insertions, 18 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c index 56bf29c..1e93908 100644 --- a/Objects/classobject.c +++ b/Objects/classobject.c @@ -1670,40 +1670,28 @@ instance_nonzero(PyInstanceObject *self) return outcome > 0; } -static Py_ssize_t +static PyObject * instance_index(PyInstanceObject *self) { PyObject *func, *res; - Py_ssize_t outcome; static PyObject *indexstr = NULL; if (indexstr == NULL) { indexstr = PyString_InternFromString("__index__"); if (indexstr == NULL) - return -1; + return NULL; } if ((func = instance_getattr(self, indexstr)) == NULL) { if (!PyErr_ExceptionMatches(PyExc_AttributeError)) - return -1; + return NULL; PyErr_Clear(); PyErr_SetString(PyExc_TypeError, "object cannot be interpreted as an index"); - return -1; + return NULL; } res = PyEval_CallObject(func, (PyObject *)NULL); Py_DECREF(func); - if (res == NULL) - return -1; - if (PyInt_Check(res) || PyLong_Check(res)) { - outcome = res->ob_type->tp_as_number->nb_index(res); - } - else { - PyErr_SetString(PyExc_TypeError, - "__index__ must return an int or a long"); - outcome = -1; - } - Py_DECREF(res); - return outcome; + return res; } @@ -2026,7 +2014,7 @@ static PyNumberMethods instance_as_number = { instance_truediv, /* nb_true_divide */ instance_ifloordiv, /* nb_inplace_floor_divide */ instance_itruediv, /* nb_inplace_true_divide */ - (lenfunc)instance_index, /* nb_index */ + (unaryfunc)instance_index, /* nb_index */ }; PyTypeObject PyInstance_Type = { |
