summaryrefslogtreecommitdiff
path: root/numpy/numarray
diff options
context:
space:
mode:
authorNathaniel J. Smith <njs@pobox.com>2012-05-15 18:32:14 +0100
committerNathaniel J. Smith <njs@pobox.com>2012-05-15 18:48:08 +0100
commit6a90adaea6ba4330e8da4db546425d9cdcc5a940 (patch)
tree46ba8a1b87620db81c1a1f3d7217380f0c675eac /numpy/numarray
parentcbce4e6565e7a7fbe065502b264622ce7d64740a (diff)
downloadnumpy-6a90adaea6ba4330e8da4db546425d9cdcc5a940.tar.gz
Funnel all assignments to PyArrayObject->base through a single point
This patch removes all direct assignments of non-NULL values to the 'base' field on PyArrayObjects. A new utility function was created to set up UPDATEIFCOPY arrays, and all assignments to 'base' were adjusted to use either PyArray_SetBaseObject or the new PyArray_SetUpdateIfCopyBase. One advantage of this is that it produces more consistent error handling. This error handling revealed a bug in the nditer code, which this patch does *not* yet fix. The bug is that npyiter_new_temp_array sometimes (when dealing with reversed axes) creates an array and then returns a view onto it. But, npyiter_allocate_arrays assumes that the array returned by npyiter_new_temp_array can have UPDATEIFCOPY set, which requires reassigning its 'base' field. Previously, this meant that the temporary array leaked. Now, it produces a ValueError. This code path doesn't seem to actually be hit very often; only one of the nditer tests fails because of the change. See numpy/core/tests/test_nditer.py:test_iter_array_cast_buggy
Diffstat (limited to 'numpy/numarray')
-rw-r--r--numpy/numarray/_capi.c4
1 files changed, 1 insertions, 3 deletions
diff --git a/numpy/numarray/_capi.c b/numpy/numarray/_capi.c
index b6e5c1a3c..6acf7324a 100644
--- a/numpy/numarray/_capi.c
+++ b/numpy/numarray/_capi.c
@@ -1101,12 +1101,10 @@ NA_OutputArray(PyObject *a, NumarrayType t, int requires)
PyArray_DIMS((PyArrayObject *)a),
dtype, 0);
Py_INCREF(a);
- if (PyArray_SetBaseObject(ret, a) < 0) {
+ if (PyArray_SetUpdateIfCopyBase(ret, a) < 0) {
Py_DECREF(ret);
return NULL;
}
- PyArray_ENABLEFLAGS(ret, NPY_ARRAY_UPDATEIFCOPY);
- PyArray_CLEARFLAGS((PyArrayObject *)a, NPY_ARRAY_WRITEABLE);
return ret;
}