[Python-checkins] TRUNK IS UNFROZEN, available for 2.6 work if you are so inclined

Jack Diederich jackdied at jackdied.com
Thu Aug 17 20:50:49 CEST 2006


On Thu, Aug 17, 2006 at 04:40:45PM +0200, Georg Brandl wrote:
> Is the following fix for #1541682 okay?
>
> Index: Doc/api/intro.tex
> ===================================================================
> --- Doc/api/intro.tex   (Revision 51336)
> +++ Doc/api/intro.tex   (Arbeitskopie)
> @@ -276,8 +276,12 @@
>       if (n < 0)
>           return -1;
>       for (i = 0; i < n; i++) {
> -        if (PyObject_SetItem(target, i, item) < 0)
> +        PyObject *index = PyInt_FromLong(i);
> +        if (!index)
>               return -1;
> +        if (PyObject_SetItem(target, index, item) < 0)
> +            return -1;
> +        Py_DECREF(index);
>       }
>       return 0;
>   }
> 

Looks good to me.  While you are on that page do you want to change

l = PyList_New(3);
x = PyInt_FromLong(1L);
PySequence_SetItem(l, 0, x); Py_DECREF(x);
x = PyInt_FromLong(2L);
PySequence_SetItem(l, 1, x); Py_DECREF(x);
x = PyString_FromString("three");
PySequence_SetItem(l, 2, x); Py_DECREF(x);

to

l = PyList_New(3);
x = PyInt_FromLong(1L);
PyList_SetItem(l, 0, x);
x = PyInt_FromLong(2L);
PyList_SetItem(l, 1, x);
x = PyString_FromString("three");
PyList_SetItem(l, 2, x);

The example code causes segfaults and probably always has (at last to 2.2)

-Jack


More information about the Python-checkins mailing list