diff Objects/stringobject.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 1b4e5eb21049
children 71baa06767dd
line wrap: on
line diff
--- a/Objects/stringobject.c	Sat Aug 12 08:32:02 2006 +0000
+++ b/Objects/stringobject.c	Sat Aug 12 17:03:09 2006 +0000
@@ -1184,14 +1184,11 @@
 	return x;
 }
 
-#define HASINDEX(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_HAVE_INDEX)
-
 static PyObject*
 string_subscript(PyStringObject* 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;
 		if (i < 0)