diff options
Diffstat (limited to 'numpy/core/src/arrayobject.c')
-rw-r--r-- | numpy/core/src/arrayobject.c | 63 |
1 files changed, 27 insertions, 36 deletions
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c index 66a30c11a..d1d49d797 100644 --- a/numpy/core/src/arrayobject.c +++ b/numpy/core/src/arrayobject.c @@ -743,7 +743,7 @@ _copy_from0d(PyArrayObject *dest, PyArrayObject *src, int usecopy, int swap) NPY_BEGIN_THREADS_DEF - numcopies = PyArray_SIZE(dest); + numcopies = PyArray_SIZE(dest); if (numcopies < 1) return 0; nbytes = PyArray_ITEMSIZE(src); @@ -784,7 +784,6 @@ _copy_from0d(PyArrayObject *dest, PyArrayObject *src, int usecopy, int swap) dstride = nbytes; /* Refcount note: src and dest may have different sizes */ - PyArray_INCREF(src); PyArray_XDECREF(dest); NPY_BEGIN_THREADS @@ -795,8 +794,7 @@ _copy_from0d(PyArrayObject *dest, PyArrayObject *src, int usecopy, int swap) NPY_END_THREADS - PyArray_INCREF(dest); - PyArray_XDECREF(src); + PyArray_INCREF(dest); } else { PyArrayIterObject *dit; @@ -805,8 +803,8 @@ _copy_from0d(PyArrayObject *dest, PyArrayObject *src, int usecopy, int swap) PyArray_IterAllButAxis((PyObject *)dest, &axis); if (dit == NULL) goto finish; /* Refcount note: src and dest may have different sizes */ - PyArray_INCREF(src); PyArray_XDECREF(dest); + NPY_BEGIN_THREADS while(dit->index < dit->size) { myfunc(dit->dataptr, PyArray_STRIDE(dest, axis), @@ -819,9 +817,9 @@ _copy_from0d(PyArrayObject *dest, PyArrayObject *src, int usecopy, int swap) PyArray_ITER_NEXT(dit); } NPY_END_THREADS - PyArray_INCREF(dest); - PyArray_XDECREF(src); - Py_DECREF(dit); + + PyArray_INCREF(dest); + Py_DECREF(dit); } retval = 0; finish: @@ -844,16 +842,15 @@ int _flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order) { NPY_BEGIN_THREADS_DEF - if (PyArray_NDIM(src) == 0) { - /* Refcount note: src and dst have the same size */ - PyArray_INCREF((PyArrayObject *)src); - PyArray_XDECREF((PyArrayObject *)dst); - NPY_BEGIN_THREADS - memcpy(PyArray_BYTES(dst), PyArray_BYTES(src), - PyArray_ITEMSIZE(src)); - NPY_END_THREADS - return 0; - } + if (PyArray_NDIM(src) == 0) { + PyArray_XDECREF((PyArrayObject *)dst); + NPY_BEGIN_THREADS + memcpy(PyArray_BYTES(dst), PyArray_BYTES(src), + PyArray_ITEMSIZE(src)); + NPY_END_THREADS + PyArray_INCREF((PyArrayObject *)dst); + return 0; + } if (order == PyArray_FORTRANORDER) { axis = 0; @@ -876,8 +873,6 @@ int _flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order) { elsize = PyArray_ITEMSIZE(dst); nbytes = elsize * PyArray_DIM(src, axis); - /* Refcount note: src and dst have the same size */ - PyArray_INCREF((PyArrayObject *)src); PyArray_XDECREF((PyArrayObject *)dst); NPY_BEGIN_THREADS while(it->index < it->size) { @@ -889,6 +884,8 @@ int _flat_copyinto(PyObject *dst, PyObject *src, NPY_ORDER order) { } NPY_END_THREADS + PyArray_INCREF((PyArrayObject *)dst); + Py_DECREF(it); return 0; } @@ -918,8 +915,6 @@ _copy_from_same_shape(PyArrayObject *dest, PyArrayObject *src, } elsize = PyArray_ITEMSIZE(dest); - /* Refcount note: src and dst have the same size */ - PyArray_INCREF(src); PyArray_XDECREF(dest); NPY_BEGIN_THREADS @@ -939,6 +934,8 @@ _copy_from_same_shape(PyArrayObject *dest, PyArrayObject *src, } NPY_END_THREADS + PyArray_INCREF(dest); + Py_DECREF(sit); Py_DECREF(dit); return 0; @@ -968,11 +965,10 @@ _broadcast_copy(PyArrayObject *dest, PyArrayObject *src, maxaxis = PyArray_RemoveSmallest(multi); if (maxaxis < 0) { /* copy 1 0-d array to another */ - /* Refcount note: src and dst have the same size */ - PyArray_INCREF(src); PyArray_XDECREF(dest); memcpy(dest->data, src->data, elsize); if (swap) byte_swap_vector(dest->data, 1, elsize); + PyArray_INCREF(dest); return 0; } maxdim = multi->dimensions[maxaxis]; @@ -980,8 +976,6 @@ _broadcast_copy(PyArrayObject *dest, PyArrayObject *src, /* Increment the source and decrement the destination reference counts */ - /* Refcount note: src and dest may have different sizes */ - PyArray_INCREF(src); PyArray_XDECREF(dest); NPY_BEGIN_THREADS @@ -1001,7 +995,6 @@ _broadcast_copy(PyArrayObject *dest, PyArrayObject *src, NPY_END_THREADS PyArray_INCREF(dest); - PyArray_XDECREF(src); Py_DECREF(multi); return 0; @@ -1043,16 +1036,15 @@ _array_copy_into(PyArrayObject *dest, PyArrayObject *src, int usecopy) (PyArray_ISFARRAY_RO(src) && PyArray_ISFARRAY(dest))); if (simple) { - /* Refcount note: src and dest have the same size */ - PyArray_INCREF(src); PyArray_XDECREF(dest); NPY_BEGIN_THREADS if (usecopy) memcpy(dest->data, src->data, PyArray_NBYTES(dest)); else memmove(dest->data, src->data, PyArray_NBYTES(dest)); - NPY_END_THREADS - return 0; + NPY_END_THREADS + PyArray_INCREF(dest); + return 0; } swap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src); @@ -1117,12 +1109,12 @@ PyArray_CopyAnyInto(PyArrayObject *dest, PyArrayObject *src) if (simple) { /* Refcount note: src and dest have the same size */ - PyArray_INCREF(src); PyArray_XDECREF(dest); NPY_BEGIN_THREADS memcpy(dest->data, src->data, PyArray_NBYTES(dest)); NPY_END_THREADS - return 0; + PyArray_INCREF(dest); + return 0; } if (PyArray_SAMESHAPE(dest, src)) { @@ -1143,8 +1135,6 @@ PyArray_CopyAnyInto(PyArrayObject *dest, PyArrayObject *src) isrc = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src); if (isrc == NULL) {Py_DECREF(idest); return -1;} elsize = dest->descr->elsize; - /* Refcount note: src and dest have the same size */ - PyArray_INCREF(src); PyArray_XDECREF(dest); NPY_BEGIN_THREADS while(idest->index < idest->size) { @@ -1153,7 +1143,8 @@ PyArray_CopyAnyInto(PyArrayObject *dest, PyArrayObject *src) PyArray_ITER_NEXT(isrc); } NPY_END_THREADS - Py_DECREF(idest); + PyArray_INCREF(dest); + Py_DECREF(idest); Py_DECREF(isrc); return 0; } |