diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2016-05-24 12:12:01 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2016-05-24 12:12:01 -0600 |
commit | b65991aa41ac073ed070992acfccd7d6bb24035f (patch) | |
tree | ef1d9c449955ea39811fbd409a4041487405a933 | |
parent | 85f66400d6e02c25eb80d673a8b993af614d42b2 (diff) | |
parent | 7803c5c510d465eb17b973d0eb4e79922db1d044 (diff) | |
download | numpy-b65991aa41ac073ed070992acfccd7d6bb24035f.tar.gz |
Merge pull request #7669 from seberg/issue7666
BUG: boolean assignment no GIL release when transfer needs API
-rw-r--r-- | numpy/core/src/multiarray/mapping.c | 8 | ||||
-rw-r--r-- | numpy/core/tests/test_indexing.py | 14 |
2 files changed, 20 insertions, 2 deletions
diff --git a/numpy/core/src/multiarray/mapping.c b/numpy/core/src/multiarray/mapping.c index 6a30fc492..5da76a39b 100644 --- a/numpy/core/src/multiarray/mapping.c +++ b/numpy/core/src/multiarray/mapping.c @@ -1129,7 +1129,9 @@ array_assign_boolean_subscript(PyArrayObject *self, return -1; } - NPY_BEGIN_THREADS_NDITER(iter); + if (!needs_api) { + NPY_BEGIN_THREADS_NDITER(iter); + } do { innersize = *NpyIter_GetInnerLoopSizePtr(iter); @@ -1153,7 +1155,9 @@ array_assign_boolean_subscript(PyArrayObject *self, } } while (iternext(iter)); - NPY_END_THREADS; + if (!needs_api) { + NPY_END_THREADS; + } NPY_AUXDATA_FREE(transferdata); NpyIter_Deallocate(iter); diff --git a/numpy/core/tests/test_indexing.py b/numpy/core/tests/test_indexing.py index c64aed22f..49231f37e 100644 --- a/numpy/core/tests/test_indexing.py +++ b/numpy/core/tests/test_indexing.py @@ -220,6 +220,20 @@ class TestIndexing(TestCase): assert_raises(ValueError, f, a, [1, 2, 3]) assert_raises(ValueError, f, a[:1], [1, 2, 3]) + def test_boolean_assignment_needs_api(self): + # See also gh-7666 + # This caused a segfault on Python 2 due to the GIL not being + # held when the iterator does not need it, but the transfer function + # does + arr = np.zeros(1000) + indx = np.zeros(1000, dtype=bool) + indx[:100] = True + arr[indx] = np.ones(100, dtype=object) + + expected = np.zeros(1000) + expected[:100] = 1 + assert_array_equal(arr, expected) + def test_boolean_indexing_twodim(self): # Indexing a 2-dimensional array with # 2-dimensional boolean array |