I'm trying to deal with an API that returns an array of PyObject
s and I want to extend
an existing python list
with it's contents.
So far I'm just appending every item of the array:
static PyObject *
myfunc(PyObject *module, PyObject *alist, PyObject **items, Py_ssize_t arrsize)
{
Py_ssize_t i;
for (i = 0 ; i < arrsize; i++) {
if (PyList_Append(alist, items[i]) == -1) {
return NULL;
}
}
return alist;
}
But a list is more or less just a wrapper around an array of PyObject
s itself.
So is there a better (or faster) way to extend that list? I haven't found a function in the Python-C-API and given the overallocation of PyList_Object
it seems hacky to create a new array, then memcpy
the original arrays and then just assign it to ((PyList_Object *)alist)->ob_item
.