summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorPauli Virtanen <pav@iki.fi>2010-07-31 13:48:52 +0000
committerPauli Virtanen <pav@iki.fi>2010-07-31 13:48:52 +0000
commitc7978bd8e8e557dcc760a30c9f7a13987f56db6f (patch)
tree3bb05aedd0242d49e74db2a226bf80f7bf0a1d0e /numpy
parent869ccb83cbff2cb10842f7b3080f460ca8ba8b55 (diff)
downloadnumpy-c7978bd8e8e557dcc760a30c9f7a13987f56db6f.tar.gz
BUG: core: fix refcount error in PyArray_Take (#939)
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/src/multiarray/item_selection.c1
-rw-r--r--numpy/core/tests/test_regression.py14
2 files changed, 15 insertions, 0 deletions
diff --git a/numpy/core/src/multiarray/item_selection.c b/numpy/core/src/multiarray/item_selection.c
index 398acfe71..224e11e3b 100644
--- a/numpy/core/src/multiarray/item_selection.c
+++ b/numpy/core/src/multiarray/item_selection.c
@@ -43,6 +43,7 @@ PyArray_TakeFrom(PyArrayObject *self0, PyObject *indices0, int axis,
PyArray_INTP,
1, 0);
if (indices == NULL) {
+ Py_XINCREF(ret);
goto fail;
}
n = m = chunk = 1;
diff --git a/numpy/core/tests/test_regression.py b/numpy/core/tests/test_regression.py
index 1257a54c2..5959d6dd9 100644
--- a/numpy/core/tests/test_regression.py
+++ b/numpy/core/tests/test_regression.py
@@ -1359,5 +1359,19 @@ class TestRegression(TestCase):
y = np.add(x, x, x)
assert_equal(id(x), id(y))
+ def test_take_refcount(self):
+ # ticket #939
+ a = np.arange(16, dtype=np.float)
+ a.shape = (4,4)
+ lut = np.ones((5 + 3, 4), np.float)
+ rgba = np.empty(shape=a.shape + (4,), dtype=lut.dtype)
+ c1 = sys.getrefcount(rgba)
+ try:
+ lut.take(a, axis=0, mode='clip', out=rgba)
+ except TypeError:
+ pass
+ c2 = sys.getrefcount(rgba)
+ assert_equal(c1, c2)
+
if __name__ == "__main__":
run_module_suite()