diff options
author | Jay Bourque <jay.bourque@continuum.io> | 2013-07-27 12:16:17 -0500 |
---|---|---|
committer | Jay Bourque <jay.bourque@continuum.io> | 2013-08-16 16:39:33 -0500 |
commit | 336151e810904277f227584eadc2de119a1a5ac6 (patch) | |
tree | b67beea2b652b9576da660fed7b8af4c61b65506 | |
parent | 1e4d589d7252ffcc55da930496cbe01c078cc3a6 (diff) | |
download | numpy-336151e810904277f227584eadc2de119a1a5ac6.tar.gz |
Fix memory leaks and inc dtype refs
-rw-r--r-- | numpy/core/src/umath/ufunc_object.c | 6 | ||||
-rw-r--r-- | numpy/core/tests/test_ufunc.py | 8 |
2 files changed, 10 insertions, 4 deletions
diff --git a/numpy/core/src/umath/ufunc_object.c b/numpy/core/src/umath/ufunc_object.c index eaca76af6..982d10fbf 100644 --- a/numpy/core/src/umath/ufunc_object.c +++ b/numpy/core/src/umath/ufunc_object.c @@ -4986,16 +4986,19 @@ ufunc_at(PyUFuncObject *ufunc, PyObject *args) count[0] = 1; stride[0] = 1; + Py_INCREF(PyArray_DESCR(op1_array)); array_operands[0] = PyArray_NewFromDescr(&PyArray_Type, PyArray_DESCR(op1_array), 1, dims, NULL, iter->dataptr, NPY_ARRAY_WRITEABLE, NULL); if (iter2 != NULL) { + Py_INCREF(PyArray_DESCR(op2_array)); array_operands[1] = PyArray_NewFromDescr(&PyArray_Type, PyArray_DESCR(op2_array), 1, dims, NULL, PyArray_ITER_DATA(iter2), NPY_ARRAY_WRITEABLE, NULL); + Py_INCREF(PyArray_DESCR(op1_array)); array_operands[2] = PyArray_NewFromDescr(&PyArray_Type, PyArray_DESCR(op1_array), 1, dims, NULL, @@ -5003,6 +5006,7 @@ ufunc_at(PyUFuncObject *ufunc, PyObject *args) NPY_ARRAY_WRITEABLE, NULL); } else { + Py_INCREF(PyArray_DESCR(op1_array)); array_operands[1] = PyArray_NewFromDescr(&PyArray_Type, PyArray_DESCR(op1_array), 1, dims, NULL, @@ -5128,6 +5132,7 @@ ufunc_at(PyUFuncObject *ufunc, PyObject *args) Py_XDECREF(array_operands[0]); Py_XDECREF(array_operands[1]); Py_XDECREF(array_operands[2]); + Py_XDECREF(errobj); Py_RETURN_NONE; @@ -5139,6 +5144,7 @@ fail: Py_XDECREF(array_operands[0]); Py_XDECREF(array_operands[1]); Py_XDECREF(array_operands[2]); + Py_XDECREF(errobj); return NULL; } diff --git a/numpy/core/tests/test_ufunc.py b/numpy/core/tests/test_ufunc.py index 1c728ff16..e099a68d7 100644 --- a/numpy/core/tests/test_ufunc.py +++ b/numpy/core/tests/test_ufunc.py @@ -989,11 +989,11 @@ class TestUfunc(TestCase): np.add.at(a, [0,1], 3) assert_array_equal(orig, np.arange(4)) - dt = np.dtype(np.intp).newbyteorder() - index = np.array([1,2,3], dt) - dt = np.dtype(np.float_).newbyteorder() - values = np.array([1,2,3,4], dt) + # Test with swapped byte order + index = np.array([1,2,1], np.dtype('i').newbyteorder()) + values = np.array([1,2,3,4], np.dtype('f').newbyteorder()) np.add.at(values, index, 3) + assert_array_equal(values, [1,8,6,4]) if __name__ == "__main__": run_module_suite() |