SWIGPython: return None if attempting a NumPy view of a NULL pointer
Description
When trying to access a C struct array field which is a NULL
pointer, the Python binding currently return (via a NumPy feature) a newly-allocated zero-length array, instead of an array view. The memory from this array is allocated by NumPy from a cache, which can have the confusing side effect of returning results from previous function calls. See #281 (closed) for an example of how this can occur in practise.
This MR modifies the wrappings to instead return None
if the underlying C array is NULL
, to indicate there is no valid array data to view.
Closes #281 (closed)
API Changes and Justification
Backwards Compatible Changes
-
This change introduces no API changes -
This change adds new API calls
Backwards Incompatible Changes
-
This change modifies an existing API -
This change removes an existing API
It is unlikely anyone was relying on the previous behaviour, as this only occurs when the C struct field is NULL
- and if they were, they may well have noticed weird results as in #281 (closed)
Review Status
N/A