diff Python/ceval.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 ed65765eb679
children c7ff02c1559f
line wrap: on
line diff
--- a/Python/ceval.c	Sat Aug 12 08:32:02 2006 +0000
+++ b/Python/ceval.c	Sat Aug 12 17:03:09 2006 +0000
@@ -3866,12 +3866,14 @@
 	if (v != NULL) {
 		Py_ssize_t x;
 		if (PyInt_Check(v)) {
-			x = PyInt_AsSsize_t(v);
+			/* XXX(nnorwitz): I think PyInt_AS_LONG is correct,
+			   however, it looks like it should be AsSsize_t.
+			   There should be a comment here explaining why.
+			*/
+			x = PyInt_AS_LONG(v);
 		}
-		else if (v->ob_type->tp_as_number &&
-			 PyType_HasFeature(v->ob_type, Py_TPFLAGS_HAVE_INDEX)
-			 && v->ob_type->tp_as_number->nb_index) {
-			x = v->ob_type->tp_as_number->nb_index(v);
+		else if (PyIndex_Check(v)) {
+			x = PyNumber_AsSsize_t(v, NULL);
 			if (x == -1 && PyErr_Occurred())
 				return 0;
 		}
@@ -3887,10 +3889,8 @@
 }
 
 #undef ISINDEX
-#define ISINDEX(x) ((x) == NULL || PyInt_Check(x) || PyLong_Check(x) || \
-		    ((x)->ob_type->tp_as_number && \
-                     PyType_HasFeature((x)->ob_type, Py_TPFLAGS_HAVE_INDEX) \
-		     && (x)->ob_type->tp_as_number->nb_index))
+#define ISINDEX(x) ((x) == NULL || \
+		    PyInt_Check(x) || PyLong_Check(x) || PyIndex_Check(x))
 
 static PyObject *
 apply_slice(PyObject *u, PyObject *v, PyObject *w) /* return u[v:w] */