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:
parent
f9efc23e2d
commit
56796cad61
2 changed files with 11 additions and 1 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue