C-API: deallocating a partially filled object array
Hi gurus, is it (in C) safe to deallocate an array of type NPY_OBJECT, which carries NULL pointers? TIA, Martin
Martin Wiechert wrote:
Hi gurus,
is it (in C) safe to deallocate an array of type NPY_OBJECT, which carries NULL pointers?
Possibly, I'm not sure without doing some more code-diving. However, I strongly doubt that many other operations are safe. Depending on how you got such an array and how long it's expected to live, you might want to fix the NULL pointers. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
On Friday 26 January 2007 21:03, Robert Kern wrote:
Martin Wiechert wrote:
Hi gurus,
is it (in C) safe to deallocate an array of type NPY_OBJECT, which carries NULL pointers?
Possibly, I'm not sure without doing some more code-diving. However, I strongly doubt that many other operations are safe. Depending on how you got such an array and how long it's expected to live, you might want to fix the NULL pointers.
I'm asking because I'm using s.th. like the following idiom. Is the cleanup part clean? --- snip --- a = PyArray_SimpleNew (1, &n, NPY_OBJECT); for (i=0; i < n; i++) { new_obj = some_object_factory (...); if (new_obj == NULL) goto cleanup; ((PyObject **) PyArray_DATA (a)) [i] = new_obj; } return a; cleanup: Py_DECREF (a); return NULL;
Martin Wiechert wrote:
On Friday 26 January 2007 21:03, Robert Kern wrote:
Martin Wiechert wrote:
Hi gurus,
is it (in C) safe to deallocate an array of type NPY_OBJECT, which carries NULL pointers?
Possibly, I'm not sure without doing some more code-diving. However, I strongly doubt that many other operations are safe. Depending on how you got such an array and how long it's expected to live, you might want to fix the NULL pointers.
Object arrays with NULL pointers should be fine. Any DECREF (should be using) the XDECREF variant internally. So, yes, it should work fine. -Travis
On Friday 26 January 2007 21:45, Travis Oliphant wrote:
Martin Wiechert wrote:
On Friday 26 January 2007 21:03, Robert Kern wrote:
Martin Wiechert wrote:
Hi gurus,
is it (in C) safe to deallocate an array of type NPY_OBJECT, which carries NULL pointers?
Possibly, I'm not sure without doing some more code-diving. However, I strongly doubt that many other operations are safe. Depending on how you got such an array and how long it's expected to live, you might want to fix the NULL pointers.
Object arrays with NULL pointers should be fine. Any DECREF (should be using) the XDECREF variant internally.
So, yes, it should work fine.
-Travis
_______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion
Thanks!
participants (3)
-
Martin Wiechert
-
Robert Kern
-
Travis Oliphant