diff options
| author | Guido van Rossum <guido@python.org> | 2006-03-07 18:50:55 +0000 |
|---|---|---|
| committer | Guido van Rossum <guido@python.org> | 2006-03-07 18:50:55 +0000 |
| commit | 38fff8c4e4276e4e57660a78f305e68bfa87874b (patch) | |
| tree | 5f79c06159053f9c7113410fc69dccba01e331ab /Objects/unicodeobject.c | |
| parent | 9d7855076a8e030e30459de685e762f63bdecac6 (diff) | |
| download | cpython-git-38fff8c4e4276e4e57660a78f305e68bfa87874b.tar.gz | |
Checking in the code for PEP 357.
This was mostly written by Travis Oliphant.
I've inspected it all; Neal Norwitz and MvL have also looked at it
(in an earlier incarnation).
Diffstat (limited to 'Objects/unicodeobject.c')
| -rw-r--r-- | Objects/unicodeobject.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 4146f1d880..a0d3de97f1 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -6460,11 +6460,14 @@ static PySequenceMethods unicode_as_sequence = { (objobjproc)PyUnicode_Contains, /*sq_contains*/ }; +#define HASINDEX(o) PyType_HasFeature((o)->ob_type, Py_TPFLAGS_HAVE_INDEX) + static PyObject* unicode_subscript(PyUnicodeObject* self, PyObject* item) { - if (PyInt_Check(item) || PyLong_Check(item)) { - Py_ssize_t i = PyInt_AsSsize_t(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 (i == -1 && PyErr_Occurred()) return NULL; if (i < 0) |
