diff Modules/arraymodule.c @ 39463:6cafdc81cfde legacy-trunk

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.
author Neal Norwitz <nnorwitz@gmail.com>
date Sat, 12 Aug 2006 17:03:09 +0000
parents e11caad7e029
children a88bc3bad651
line wrap: on
line diff
--- a/Modules/arraymodule.c	Sat Aug 12 08:32:02 2006 +0000
+++ b/Modules/arraymodule.c	Sat Aug 12 17:03:09 2006 +0000
@@ -1572,14 +1572,11 @@
 	return s;
 }
 
-#define HASINDEX(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_HAVE_INDEX)
-
 static PyObject*
 array_subscr(arrayobject* 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 = PyNumber_AsSsize_t(item, PyExc_IndexError);
 		if (i==-1 && PyErr_Occurred()) {
 			return NULL;
 		}
@@ -1627,9 +1624,8 @@
 static int
 array_ass_subscr(arrayobject* 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)