diff options
-rw-r--r-- | numpy/core/code_generators/cversions.txt | 4 | ||||
-rw-r--r-- | numpy/core/code_generators/numpy_api.py | 2 | ||||
-rw-r--r-- | numpy/core/src/multiarray/array_assign_array.c | 2 | ||||
-rw-r--r-- | numpy/core/src/multiarray/array_assign_scalar.c | 2 | ||||
-rw-r--r-- | numpy/core/src/multiarray/arrayobject.c | 14 | ||||
-rw-r--r-- | numpy/core/src/multiarray/buffer.c | 6 | ||||
-rw-r--r-- | numpy/core/src/multiarray/ctors.c | 25 | ||||
-rw-r--r-- | numpy/core/src/multiarray/item_selection.c | 2 | ||||
-rw-r--r-- | numpy/core/src/multiarray/mapping.c | 4 | ||||
-rw-r--r-- | numpy/core/src/multiarray/methods.c | 6 | ||||
-rw-r--r-- | numpy/core/src/multiarray/nditer_constr.c | 6 | ||||
-rw-r--r-- | numpy/core/src/multiarray/sequence.c | 2 | ||||
-rw-r--r-- | numpy/core/src/umath/ufunc_object.c | 8 | ||||
-rw-r--r-- | numpy/numarray/_capi.c | 6 |
14 files changed, 36 insertions, 53 deletions
diff --git a/numpy/core/code_generators/cversions.txt b/numpy/core/code_generators/cversions.txt index 275e58e7b..3599f47c7 100644 --- a/numpy/core/code_generators/cversions.txt +++ b/numpy/core/code_generators/cversions.txt @@ -9,5 +9,5 @@ # Version 6 (NumPy 1.6) added new iterator, half float and casting functions, # PyArray_CountNonzero, PyArray_NewLikeArray and PyArray_MatrixProduct2. 0x00000006 = e61d5dc51fa1c6459328266e215d6987 -# Version 7 (NumPy 1.7) added API for NA, improved datetime64. -0x00000007 = cae43cbd22b39c8c7fe4905b6b93f004 +# Version 7 (NumPy 1.7) added API for NA, improved datetime64, misc utilities. +0x00000007 = 280023b3ecfc2ad0326874917f6f16f9 diff --git a/numpy/core/code_generators/numpy_api.py b/numpy/core/code_generators/numpy_api.py index ce781ae76..15b868e23 100644 --- a/numpy/core/code_generators/numpy_api.py +++ b/numpy/core/code_generators/numpy_api.py @@ -344,7 +344,7 @@ multiarray_funcs_api = { 'NpyNA_FromDTypeAndPayload': 304, 'PyArray_AllowNAConverter': 305, 'PyArray_OutputAllowNAConverter': 306, - 'PyArray_RequireWriteable': 307, + 'PyArray_FailUnlessWriteable': 307, 'PyArray_SetUpdateIfCopyBase': 308, } diff --git a/numpy/core/src/multiarray/array_assign_array.c b/numpy/core/src/multiarray/array_assign_array.c index 0551b1089..a9f3a35fe 100644 --- a/numpy/core/src/multiarray/array_assign_array.c +++ b/numpy/core/src/multiarray/array_assign_array.c @@ -449,7 +449,7 @@ PyArray_AssignArray(PyArrayObject *dst, PyArrayObject *src, return 0; } - if (PyArray_RequireWriteable(dst, NULL) < 0) { + if (PyArray_FailUnlessWriteable(dst, "assignment destination") < 0) { goto fail; } diff --git a/numpy/core/src/multiarray/array_assign_scalar.c b/numpy/core/src/multiarray/array_assign_scalar.c index 43c4b7350..60658ed4d 100644 --- a/numpy/core/src/multiarray/array_assign_scalar.c +++ b/numpy/core/src/multiarray/array_assign_scalar.c @@ -336,7 +336,7 @@ PyArray_AssignRawScalar(PyArrayObject *dst, int allocated_src_data = 0, dst_has_maskna = PyArray_HASMASKNA(dst); npy_longlong scalarbuffer[4]; - if (PyArray_RequireWriteable(dst, "cannot assign to read-only array") < 0) { + if (PyArray_FailUnlessWriteable(dst, "assignment destination") < 0) { return -1; } diff --git a/numpy/core/src/multiarray/arrayobject.c b/numpy/core/src/multiarray/arrayobject.c index 91a3af47d..4f0181b4a 100644 --- a/numpy/core/src/multiarray/arrayobject.c +++ b/numpy/core/src/multiarray/arrayobject.c @@ -90,8 +90,7 @@ PyArray_SetUpdateIfCopyBase(PyArrayObject *arr, PyArrayObject *base) "Cannot set array with existing base to UPDATEIFCOPY"); goto fail; } - if (PyArray_RequireWriteable(base, - "cannot UPDATEIFCOPY to a non-writeable array") < 0) { + if (PyArray_FailUnlessWriteable(base, "UPDATEIFCOPY base") < 0) { goto fail; } @@ -795,15 +794,16 @@ array_might_be_written(PyArrayObject *obj) * house-keeping, such as issuing warnings on arrays which are transitioning * to become views. Always call this function at some point before writing to * an array. + * + * 'name' is a name for the array, used to give better error + * messages. Something like "assignment destination", "output array", or even + * just "array". */ NPY_NO_EXPORT int -PyArray_RequireWriteable(PyArrayObject *obj, const char * err) +PyArray_FailUnlessWriteable(PyArrayObject *obj, const char *name) { - if (!err) { - err = "array must be writeable (but isn't)"; - } if (!PyArray_ISWRITEABLE(obj)) { - PyErr_SetString(PyExc_ValueError, err); + PyErr_Format(PyExc_ValueError, "%s is read-only", name); return -1; } if (array_might_be_written(obj) < 0) { diff --git a/numpy/core/src/multiarray/buffer.c b/numpy/core/src/multiarray/buffer.c index 7c4b4ad6e..a1ad23911 100644 --- a/numpy/core/src/multiarray/buffer.c +++ b/numpy/core/src/multiarray/buffer.c @@ -58,9 +58,7 @@ array_getreadbuf(PyArrayObject *self, Py_ssize_t segment, void **ptrptr) static Py_ssize_t array_getwritebuf(PyArrayObject *self, Py_ssize_t segment, void **ptrptr) { - if (PyArray_RequireWriteable(self, - "cannot get writeable buffer from " - "non-writeable array") < 0) { + if (PyArray_FailUnlessWriteable(self, "buffer source array") < 0) { return -1; } return array_getreadbuf(self, segment, (void **) ptrptr); @@ -632,7 +630,7 @@ array_getbuffer(PyObject *obj, Py_buffer *view, int flags) goto fail; } if ((flags & PyBUF_WRITEABLE) == PyBUF_WRITEABLE) { - if (PyArray_RequireWriteable(self, NULL) < 0) { + if (PyArray_FailUnlessWriteable(self, "buffer source array") < 0) { goto fail; } } diff --git a/numpy/core/src/multiarray/ctors.c b/numpy/core/src/multiarray/ctors.c index 6f4fdf8a3..eac9ba437 100644 --- a/numpy/core/src/multiarray/ctors.c +++ b/numpy/core/src/multiarray/ctors.c @@ -1351,7 +1351,7 @@ PyArray_GetArrayParamsFromObjectEx(PyObject *op, /* If op is an array */ if (PyArray_Check(op)) { if (writeable - && PyArray_RequireWriteable((PyArrayObject *)op, NULL) < 0) { + && PyArray_FailUnlessWriteable((PyArrayObject *)op, "array") < 0) { return -1; } Py_INCREF(op); @@ -1421,9 +1421,7 @@ PyArray_GetArrayParamsFromObjectEx(PyObject *op, if (!PyBytes_Check(op) && !PyUnicode_Check(op) && _array_from_buffer_3118(op, (PyObject **)out_arr) == 0) { if (writeable - && PyArray_RequireWriteable(*out_arr, - "PEP 3118 buffer is not writeable") - < 0) { + && PyArray_FailUnlessWriteable(*out_arr, "PEP 3118 buffer") < 0) { Py_DECREF(*out_arr); return -1; } @@ -1443,9 +1441,8 @@ PyArray_GetArrayParamsFromObjectEx(PyObject *op, } if (tmp != Py_NotImplemented) { if (writeable - && PyArray_RequireWriteable((PyArrayObject *)tmp, - "array interface object is not " - "writeable") < 0) { + && PyArray_FailUnlessWriteable((PyArrayObject *)tmp, + "array interface object") < 0) { Py_DECREF(tmp); return -1; } @@ -1466,9 +1463,8 @@ PyArray_GetArrayParamsFromObjectEx(PyObject *op, tmp = PyArray_FromArrayAttr(op, requested_dtype, context); if (tmp != Py_NotImplemented) { if (writeable - && PyArray_RequireWriteable((PyArrayObject *)tmp, - "array interface object is not " - "writeable") < 0) { + && PyArray_FailUnlessWriteable((PyArrayObject *)tmp, + "array interface object") < 0) { Py_DECREF(tmp); return -1; } @@ -2036,13 +2032,6 @@ PyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) order = NPY_CORDER; } - if (flags & NPY_ARRAY_UPDATEIFCOPY) { - const char * msg = "cannot copy back to a read-only array"; - if (PyArray_RequireWriteable(arr, msg) < 0) { - Py_DECREF(newtype); - return NULL; - } - } if ((flags & NPY_ARRAY_ENSUREARRAY)) { subok = 0; } @@ -2600,7 +2589,7 @@ PyArray_CopyAsFlat(PyArrayObject *dst, PyArrayObject *src, NPY_ORDER order) NPY_BEGIN_THREADS_DEF; - if (PyArray_RequireWriteable(dst, NULL) < 0) { + if (PyArray_FailUnlessWriteable(dst, "destination array") < 0) { return -1; } diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c index 92cd8ac29..010aa8aa5 100644 --- a/numpy/core/src/multiarray/item_selection.c +++ b/numpy/core/src/multiarray/item_selection.c @@ -1114,7 +1114,7 @@ PyArray_Sort(PyArrayObject *op, int axis, NPY_SORTKIND which) PyErr_Format(PyExc_ValueError, "axis(=%d) out of bounds", axis); return -1; } - if (PyArray_RequireWriteable(op, "attempted sort on read-only array") < 0) { + if (PyArray_FailUnlessWriteable(op, "sort array") < 0) { return -1; } diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c index 851a710a8..f260cf8d9 100644 --- a/numpy/core/src/multiarray/mapping.c +++ b/numpy/core/src/multiarray/mapping.c @@ -176,7 +176,7 @@ array_ass_big_item(PyArrayObject *self, npy_intp i, PyObject *v) return -1; } - if (PyArray_RequireWriteable(self, NULL) < 0) { + if (PyArray_FailUnlessWriteable(self, "assignment destination") < 0) { return -1; } @@ -1500,7 +1500,7 @@ array_ass_sub(PyArrayObject *self, PyObject *ind, PyObject *op) "cannot delete array elements"); return -1; } - if (PyArray_RequireWriteable(self, NULL) < 0) { + if (PyArray_FailUnlessWriteable(self, "assignment destination") < 0) { return -1; } diff --git a/numpy/core/src/multiarray/methods.c b/numpy/core/src/multiarray/methods.c index b1bbe7a13..6d1a52edc 100644 --- a/numpy/core/src/multiarray/methods.c +++ b/numpy/core/src/multiarray/methods.c @@ -532,9 +532,7 @@ PyArray_Byteswap(PyArrayObject *self, npy_bool inplace) copyswapn = PyArray_DESCR(self)->f->copyswapn; if (inplace) { - const char *msg = "Cannot perform in-place byte-swap on a " - "read-only array"; - if (PyArray_RequireWriteable(self, msg) < 0) { + if (PyArray_FailUnlessWriteable(self, "array to be byte-swapped") < 0) { return NULL; } size = PyArray_SIZE(self); @@ -747,7 +745,7 @@ array_setscalar(PyArrayObject *self, PyObject *args) "itemset must have at least one argument"); return NULL; } - if (PyArray_RequireWriteable(self, NULL) < 0) { + if (PyArray_FailUnlessWriteable(self, "assignment destination") < 0) { return NULL; } diff --git a/numpy/core/src/multiarray/nditer_constr.c b/numpy/core/src/multiarray/nditer_constr.c index 7800027b9..af9780b83 100644 --- a/numpy/core/src/multiarray/nditer_constr.c +++ b/numpy/core/src/multiarray/nditer_constr.c @@ -1099,10 +1099,8 @@ npyiter_prepare_one_operand(PyArrayObject **op, npy_uint32 tmp; if ((*op_itflags) & NPY_OP_ITFLAG_WRITE - && PyArray_RequireWriteable(*op, - "Operand array is not writeable, " - "but the iterator write flag is set" - ) < 0) { + && PyArray_FailUnlessWriteable(*op, "operand array with iterator " + "write flag set") < 0) { return 0; } if (!(flags & NPY_ITER_ZEROSIZE_OK) && PyArray_SIZE(*op) == 0) { diff --git a/numpy/core/src/multiarray/sequence.c b/numpy/core/src/multiarray/sequence.c index 8065404c5..cb3b30b3a 100644 --- a/numpy/core/src/multiarray/sequence.c +++ b/numpy/core/src/multiarray/sequence.c @@ -119,7 +119,7 @@ array_ass_slice(PyArrayObject *self, Py_ssize_t ilow, "cannot delete array elements"); return -1; } - if (PyArray_RequireWriteable(self, NULL) < 0) { + if (PyArray_FailUnlessWriteable(self, "assignment destination") < 0) { return -1; } tmp = (PyArrayObject *)array_slice(self, ilow, ihigh); diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c index c42e2d626..3b62e150f 100644 --- a/numpy/core/src/umath/ufunc_object.c +++ b/numpy/core/src/umath/ufunc_object.c @@ -795,8 +795,8 @@ static int get_ufunc_arguments(PyUFuncObject *ufunc, } /* If it's an array, can use it */ if (PyArray_Check(obj)) { - const char *msg = "output array not writeable"; - if (PyArray_RequireWriteable((PyArrayObject *)obj, msg) < 0) { + if (PyArray_FailUnlessWriteable((PyArrayObject *)obj, + "output array") < 0) { return -1; } Py_INCREF(obj); @@ -893,9 +893,9 @@ static int get_ufunc_arguments(PyUFuncObject *ufunc, } if (PyArray_Check(value)) { - const char *msg = "output array not writeable"; + const char *name = "output array"; PyArrayObject *value_arr = (PyArrayObject *)value; - if (PyArray_RequireWriteable(value_arr, msg) < 0) { + if (PyArray_FailUnlessWriteable(value_arr, name) < 0) { goto fail; } Py_INCREF(value); diff --git a/numpy/numarray/_capi.c b/numpy/numarray/_capi.c index 6acf7324a..78187c50e 100644 --- a/numpy/numarray/_capi.c +++ b/numpy/numarray/_capi.c @@ -1082,7 +1082,7 @@ NA_OutputArray(PyObject *a, NumarrayType t, int requires) "NA_OutputArray: only arrays work for output."); return NULL; } - if (PyArray_RequireWriteable((PyArrayObject *)a, NULL) < 0) { + if (PyArray_FailUnlessWriteable((PyArrayObject *)a, "output array") < 0) { return NULL; } @@ -1128,7 +1128,7 @@ NA_IoArray(PyObject *a, NumarrayType t, int requires) /* Guard against non-writable, but otherwise satisfying requires. In this case, shadow == a. */ - if (!PyArray_RequireWriteable(shadow, NULL)) { + if (!PyArray_FailUnlessWriteable(shadow, "input/output array")) { PyArray_XDECREF_ERR(shadow); return NULL; } @@ -2487,7 +2487,7 @@ _setFromPythonScalarCore(PyArrayObject *a, long offset, PyObject*value, int entr static int NA_setFromPythonScalar(PyArrayObject *a, long offset, PyObject *value) { - if (PyArray_RequireWriteable(a, NULL) < 0) { + if (PyArray_FailUnlessWriteable(a, "array") < 0) { return -1; } return _setFromPythonScalarCore(a, offset, value, 0); |