diff options
| author | Charles Harris <charlesr.harris@gmail.com> | 2016-05-24 15:19:18 -0600 |
|---|---|---|
| committer | Charles Harris <charlesr.harris@gmail.com> | 2016-05-24 15:19:18 -0600 |
| commit | 89b5742d3c5105ca80ff2646ba7c68b5ffbeaf4c (patch) | |
| tree | e41d458b211e352b2b617b0ce2907c8f5635623c | |
| parent | 4916a7586dfab2b7fd75c47611861a8799d9521a (diff) | |
| parent | 750130067cb24ef08b4d9e6b4bab37f98d6b8826 (diff) | |
| download | numpy-89b5742d3c5105ca80ff2646ba7c68b5ffbeaf4c.tar.gz | |
Merge pull request #7671 from charris/backport-7669
Backport 7669, 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 178740f1d..93f3fda15 100644 --- a/numpy/core/src/multiarray/mapping.c +++ b/numpy/core/src/multiarray/mapping.c @@ -1258,7 +1258,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); @@ -1282,7 +1284,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 70029f804..a537a0179 100644 --- a/numpy/core/tests/test_indexing.py +++ b/numpy/core/tests/test_indexing.py @@ -158,6 +158,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 |
