diff options
author | Sebastian Berg <sebastian@sipsolutions.net> | 2016-05-24 11:31:55 +0200 |
---|---|---|
committer | Sebastian Berg <sebastian@sipsolutions.net> | 2016-05-24 18:30:10 +0200 |
commit | 7803c5c510d465eb17b973d0eb4e79922db1d044 (patch) | |
tree | 55fccc4eb9e0b788ed8cfbd49655c23f30ff6b5b | |
parent | 25e3ebf4def51b290f544fb0bc7f6d8eb5c04b85 (diff) | |
download | numpy-7803c5c510d465eb17b973d0eb4e79922db1d044.tar.gz |
BUG: boolean assignment no GIL release when transfer needs API
This caused bugs when the iteration does not need the API, but
the data copy does.
closes gh-7666
-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 |