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/intobject.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/intobject.c')
-rw-r--r-- | Objects/intobject.c | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/Objects/intobject.c b/Objects/intobject.c index 2062bee..c7137df 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -193,16 +193,21 @@ PyInt_AsSsize_t(register PyObject *op) PyIntObject *io; Py_ssize_t val; #endif - if (op && !PyInt_CheckExact(op) && PyLong_Check(op)) + + if (op == NULL) { + PyErr_SetString(PyExc_TypeError, "an integer is required"); + return -1; + } + + if (PyInt_Check(op)) + return PyInt_AS_LONG((PyIntObject*) op); + if (PyLong_Check(op)) return _PyLong_AsSsize_t(op); #if SIZEOF_SIZE_T == SIZEOF_LONG return PyInt_AsLong(op); #else - if (op && PyInt_Check(op)) - return PyInt_AS_LONG((PyIntObject*) op); - - if (op == NULL || (nb = op->ob_type->tp_as_number) == NULL || + if ((nb = op->ob_type->tp_as_number) == NULL || (nb->nb_int == NULL && nb->nb_long == 0)) { PyErr_SetString(PyExc_TypeError, "an integer is required"); return -1; @@ -1079,7 +1084,7 @@ static PyNumberMethods int_as_number = { int_true_divide, /* nb_true_divide */ 0, /* nb_inplace_floor_divide */ 0, /* nb_inplace_true_divide */ - PyInt_AsSsize_t, /* nb_index */ + (unaryfunc)int_int, /* nb_index */ }; PyTypeObject PyInt_Type = { |