PySequence_SetItem
Bill Pursell
bill.pursell at gmail.com
Wed Aug 16 15:18:25 EDT 2006
Bill Pursell wrote:
> The following code is pretty much straight out of
> section 1.2.1.1 of the Python/C reference manual:
>
> #include <Python.h>
>
> int
> main(void)
> {
> PyObject *l, *x;
>
> Py_Initialize();
>
> l = PyList_New(3);
> x = PyInt_FromLong(1L);
>
> if (l == NULL || x == NULL) {
> PyErr_Print();
> exit (EXIT_FAILURE);
> }
> PySequence_SetItem(l, 0, x);
> Py_DECREF(x);
>
> Py_Finalize();
> return EXIT_SUCCESS;
> }
Also note that the problem goes away if I replace
the call to PySequence_SetItem with:
PySequence_SetItem(l, 0, PyInt_FromLong(1L));
but the problem persists if I add a Py_INCREF(x)
after the assignment of x. (Which seems like a
completely silly thing to do, but I'm grasping
at strings...)
More information about the Python-list
mailing list