diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2015-11-24 08:30:10 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2015-11-24 08:30:10 -0700 |
commit | 239917609779503d0b4071d59d5b780df6e5b575 (patch) | |
tree | 1f87e619b8ca070369f51e4676a713717467b608 | |
parent | 65aa24aa9e3c5da0a6ec1c2fc3d335d506a511df (diff) | |
parent | 2a47ffc477fc72e2bc59341e1debac2096d10499 (diff) | |
download | numpy-239917609779503d0b4071d59d5b780df6e5b575.tar.gz |
Merge pull request #6702 from ahaldane/fix_getfield_p_arith
BUG: fix pointer arithmetic in _get_field_view
-rw-r--r-- | numpy/core/src/multiarray/mapping.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c index 7d0bfa822..6c56d77bb 100644 --- a/numpy/core/src/multiarray/mapping.c +++ b/numpy/core/src/multiarray/mapping.c @@ -169,7 +169,8 @@ prepare_index(PyArrayObject *self, PyObject *index, int new_ndim, fancy_ndim, used_ndim, index_ndim; int curr_idx, get_idx; - npy_intp i, n; + int i; + npy_intp n; npy_bool make_tuple = 0; PyObject *obj = NULL; @@ -348,14 +349,15 @@ prepare_index(PyArrayObject *self, PyObject *index, #else if (PyLong_CheckExact(obj) || !PyArray_Check(obj)) { #endif - i = PyArray_PyIntAsIntp(obj); - if ((i == -1) && PyErr_Occurred()) { + npy_intp ind = PyArray_PyIntAsIntp(obj); + + if ((ind == -1) && PyErr_Occurred()) { PyErr_Clear(); } else { index_type |= HAS_INTEGER; indices[curr_idx].object = NULL; - indices[curr_idx].value = i; + indices[curr_idx].value = ind; indices[curr_idx].type = HAS_INTEGER; used_ndim += 1; new_ndim += 0; @@ -527,15 +529,16 @@ prepare_index(PyArrayObject *self, PyObject *index, * sure that array-likes or odder arrays are always * handled right. */ - i = PyArray_PyIntAsIntp((PyObject *)arr); + npy_intp ind = PyArray_PyIntAsIntp((PyObject *)arr); + Py_DECREF(arr); - if ((i == -1) && PyErr_Occurred()) { + if ((ind == -1) && PyErr_Occurred()) { goto failed_building_indices; } else { index_type |= (HAS_INTEGER | HAS_SCALAR_ARRAY); indices[curr_idx].object = NULL; - indices[curr_idx].value = i; + indices[curr_idx].value = ind; indices[curr_idx].type = HAS_INTEGER; used_ndim += 1; new_ndim += 0; @@ -1293,7 +1296,7 @@ _get_field_view(PyArrayObject *arr, PyObject *ind, PyArrayObject **view) PyArray_NDIM(arr), PyArray_SHAPE(arr), PyArray_STRIDES(arr), - ((char *)PyArray_DATA(arr)) + offset, + PyArray_BYTES(arr) + offset, PyArray_FLAGS(arr), (PyObject *)arr); if (*view == NULL) { @@ -2445,8 +2448,8 @@ mapiter_fill_info(PyArrayMapIterObject *mit, npy_index_info *indices, /* advance curr_dim for non-fancy indices */ else if (indices[i].type == HAS_ELLIPSIS) { - curr_dim += indices[i].value; - result_dim += indices[i].value; + curr_dim += (int)indices[i].value; + result_dim += (int)indices[i].value; } else if (indices[i].type != HAS_NEWAXIS){ curr_dim += 1; @@ -2891,7 +2894,7 @@ PyArray_MapIterNew(npy_index_info *indices , int index_num, int index_type, stride = extra_op_dtype->elsize; for (i=PyArray_NDIM(subspace) - 1; i >= 0; i--) { strides[mit->nd_fancy + strideperm[i].perm] = stride; - stride *= PyArray_DIM(subspace, strideperm[i].perm); + stride *= PyArray_DIM(subspace, (int)strideperm[i].perm); } /* |