10000 Merge pull request #7669 from seberg/issue7666 · numpy/numpy@b65991a · GitHub
[go: up one dir, main page]

Skip to content

Commit b65991a

Browse files
committed
Merge pull request #7669 from seberg/issue7666
BUG: boolean assignment no GIL release when transfer needs API
2 parents 85f6640 + 7803c5c commit b65991a

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

numpy/core/src/multiarray/mapping.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,7 +1129,9 @@ array_assign_boolean_subscript(PyArrayObject *self,
11291129
return -1;
11301130
}
11311131

1132-
NPY_BEGIN_THREADS_NDITER(iter);
1132+
if (!needs_api) {
1133+
NPY_BEGIN_THREADS_NDITER(iter);
1134+
}
11331135

11341136
do {
11351137
innersize = *NpyIter_GetInnerLoopSizePtr(iter);
@@ -1153,7 +1155,9 @@ array_assign_boolean_subscript(PyArrayObject *self,
11531155
}
11541156
} while (iternext(iter));
11551157

1156-
NPY_END_THREADS;
1158+
if (!needs_api) {
1159+
NPY_END_THREADS;
1160+
}
11571161

11581162
NPY_AUXDATA_FREE(transferdata);
11591163
NpyIter_Deallocate(iter);

numpy/core/tests/test_indexing.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,20 @@ def f(a, v):
220220
assert_raises(ValueError, f, a, [1, 2, 3])
221221
assert_raises(ValueError, f, a[:1], [1, 2, 3])
222222

223+
def test_boolean_assignment_needs_api(self):
224+
# See also gh-7666
225+
# This caused a segfault on Python 2 due to the GIL not being
226+
# held when the iterator does not need it, but the transfer function
227+
# does
228+
arr = np.zeros(1000)
229+
indx = np.zeros(1000, dtype=bool)
230+
indx[:100] = True
231+
arr[indx] = np.ones(100, dtype=object)
232+
233+
expected = np.zeros(1000)
234+
expected[:100] = 1
235+
assert_array_equal(arr, expected)
236+
223237
def test_boolean_indexing_twodim(self):
224238
# Indexing a 2-dimensional array with
225239
# 2-dimensional boolean array

0 commit comments

Comments
 (0)
0