Follow up on pull request 21. Since PyCapsule_GetPointer returns NULL on error, we should check if the list element is Py_None.

This commit is contained in:
Siu Kwan Lam 2012-09-14 18:42:49 -07:00
commit 56796cad61
2 changed files with 11 additions and 1 deletions

View file

@ -101,7 +101,14 @@ void **make_array_from_list(PyObject *list, int n)
int i;
for (i=0; i<n; i++) {
PyObject *e = PyList_GetItem(list, i);
arr[i] = PyCapsule_GetPointer(e, NULL);
if ( e == Py_None ) { // is None object?
arr[i] = NULL;
}
else { // otherwise, it must be a PyCapsule
void * ptr = PyCapsule_GetPointer(e, NULL);
if ( !ptr ) return NULL; // exception is raised
else arr[i] = ptr;
}
}
return arr;