]> granicus.if.org Git - python/commitdiff
My change to string_item() left an extra reference to each 1-character
authorTim Peters <tim.peters@gmail.com>
Wed, 9 May 2001 00:24:55 +0000 (00:24 +0000)
committerTim Peters <tim.peters@gmail.com>
Wed, 9 May 2001 00:24:55 +0000 (00:24 +0000)
interned string created by "string"[i].  Since they're immortal anyway,
this was hard to notice, but it was still wrong <wink>.

Objects/stringobject.c

index afaa0541aa2a01bddd1fa8360c8a2f8f60d3c4ba..5bdbce9d594c9f19d97242d861739bf050edf133 100644 (file)
@@ -553,7 +553,6 @@ string_contains(PyObject *a, PyObject *el)
 static PyObject *
 string_item(PyStringObject *a, register int i)
 {
-       int c;
        PyObject *v;
        char *pchar;
        if (i < 0 || i >= a->ob_size) {
@@ -561,11 +560,11 @@ string_item(PyStringObject *a, register int i)
                return NULL;
        }
        pchar = a->ob_sval + i;
-       c = *pchar & UCHAR_MAX;
-       v = (PyObject *) characters[c];
+       v = (PyObject *)characters[*pchar & UCHAR_MAX];
        if (v == NULL)
                v = PyString_FromStringAndSize(pchar, 1);
-       Py_XINCREF(v);
+       else
+               Py_INCREF(v);
        return v;
 }