diff options
Diffstat (limited to 'numpy/numarray/_capi.c')
-rw-r--r-- | numpy/numarray/_capi.c | 18 |
1 files changed, 8 insertions, 10 deletions
diff --git a/numpy/numarray/_capi.c b/numpy/numarray/_capi.c index fee07d79d..b6e5c1a3c 100644 --- a/numpy/numarray/_capi.c +++ b/numpy/numarray/_capi.c @@ -1077,9 +1077,12 @@ NA_OutputArray(PyObject *a, NumarrayType t, int requires) PyArray_Descr *dtype; PyArrayObject *ret; - if (!PyArray_Check(a) || !PyArray_ISWRITEABLE((PyArrayObject *)a)) { + if (!PyArray_Check(a)) { PyErr_Format(PyExc_TypeError, - "NA_OutputArray: only writeable arrays work for output."); + "NA_OutputArray: only arrays work for output."); + return NULL; + } + if (PyArray_RequireWriteable((PyArrayObject *)a, NULL) < 0) { return NULL; } @@ -1127,9 +1130,7 @@ NA_IoArray(PyObject *a, NumarrayType t, int requires) /* Guard against non-writable, but otherwise satisfying requires. In this case, shadow == a. */ - if (!PyArray_ISWRITABLE(shadow)) { - PyErr_Format(PyExc_TypeError, - "NA_IoArray: I/O array must be writable array"); + if (!PyArray_RequireWriteable(shadow, NULL)) { PyArray_XDECREF_ERR(shadow); return NULL; } @@ -2488,13 +2489,10 @@ _setFromPythonScalarCore(PyArrayObject *a, long offset, PyObject*value, int entr static int NA_setFromPythonScalar(PyArrayObject *a, long offset, PyObject *value) { - if (PyArray_FLAGS(a) & NPY_ARRAY_WRITEABLE) - return _setFromPythonScalarCore(a, offset, value, 0); - else { - PyErr_Format( - PyExc_ValueError, "NA_setFromPythonScalar: assigment to readonly array buffer"); + if (PyArray_RequireWriteable(a, NULL) < 0) { return -1; } + return _setFromPythonScalarCore(a, offset, value, 0); } |