summaryrefslogtreecommitdiff
path: root/Objects/listobject.c
diff options
context:
space:
mode:
authorNeal Norwitz <nnorwitz@gmail.com>2006-08-12 17:03:09 +0000
committerNeal Norwitz <nnorwitz@gmail.com>2006-08-12 17:03:09 +0000
commit8a87f5d37e6aab91ddc4c6491877b6cbd48a12cf (patch)
tree330bb4b553958f129b31e31ccea2a2c835b19de0 /Objects/listobject.c
parentf3e304297e94b9b1956a4ed95debd1b163958d71 (diff)
downloadcpython-git-8a87f5d37e6aab91ddc4c6491877b6cbd48a12cf.tar.gz
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/listobject.c')
-rw-r--r--Objects/listobject.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index f917385fa0..ad276447d3 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2450,14 +2450,13 @@ PyDoc_STRVAR(list_doc,
"list() -> new list\n"
"list(sequence) -> new list initialized from sequence's items");
-#define HASINDEX(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_HAVE_INDEX)
static PyObject *
list_subscript(PyListObject* self, PyObject* item)
{
- PyNumberMethods *nb = item->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(item) && nb->nb_index != NULL) {
- Py_ssize_t i = nb->nb_index(item);
+ if (PyIndex_Check(item)) {
+ Py_ssize_t i;
+ i = PyNumber_AsSsize_t(item, PyExc_IndexError);
if (i == -1 && PyErr_Occurred())
return NULL;
if (i < 0)
@@ -2504,9 +2503,8 @@ list_subscript(PyListObject* self, PyObject* item)
static int
list_ass_subscript(PyListObject* self, PyObject* item, PyObject* value)
{
- PyNumberMethods *nb = item->ob_type->tp_as_number;
- if (nb != NULL && HASINDEX(item) && nb->nb_index != NULL) {
- Py_ssize_t i = nb->nb_index(item);
+ if (PyIndex_Check(item)) {
+ Py_ssize_t i = PyNumber_AsSsize_t(item, PyExc_IndexError);
if (i == -1 && PyErr_Occurred())
return -1;
if (i < 0)