[Python-Dev] PyList API missing PyList_Pop() and PyList_Delete
Raymond Hettinger
raymond.hettinger at verizon.net
Thu Oct 23 18:38:10 EDT 2003
Was there a reason for leaving this out of the API or should it be
added? Is the right way to simulate a pop something like this:
n = PyList_GET_SIZE(outbasket);
if (n == 0) {
PyErr_SetString(PyExc_IndexError, "Pop from an empty list.");
return NULL;
}
result = PyList_Get_Item(outbasket, n-1);
if (result == NULL)
return NULL;
Py_INCREF(result);
empty_list = Py_ListNew(0);
if (empty_list == NULL) {
Py_DECREF(result);
return NULL;
}
err = PyList_SetSlice(to->outbasket, n-1, n, empty_list);
Py_DECREF(empty_list);
if (err == -1) {
Py_DECREF(result);
return NULL;
}
return result;
/* Whew, that was a lot of code for a pop have a popped result */
Raymond Hettinger
More information about the Python-Dev
mailing list