Skip to content

Commit 6e15abd

Browse files
committed
restore bytearrayiter_next critical section
1 parent cfa80bb commit 6e15abd

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

Lib/test/test_bytes.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2455,9 +2455,6 @@ def check(funcs, a=None, *args):
24552455
with threading_helper.start_threads(threads):
24562456
pass
24572457

2458-
for thread in threads:
2459-
threading_helper.join_thread(thread)
2460-
24612458
# hard errors
24622459

24632460
check([clear] + [reduce] * 10)
@@ -2542,9 +2539,6 @@ def check(funcs, it):
25422539
with threading_helper.start_threads(threads):
25432540
pass
25442541

2545-
for thread in threads:
2546-
threading_helper.join_thread(thread)
2547-
25482542
for _ in range(10):
25492543
ba = bytearray(b'0' * 0x4000) # this is a load-bearing variable, do not remove
25502544

Objects/bytearrayobject.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,14 +2866,19 @@ bytearrayiter_next(PyObject *self)
28662866
PyByteArrayObject *seq = it->it_seq;
28672867
assert(PyByteArray_Check(seq));
28682868

2869-
if (index < PyByteArray_GET_SIZE(seq)) {
2869+
Py_BEGIN_CRITICAL_SECTION(seq);
2870+
if (index < Py_SIZE(seq)) {
28702871
val = (unsigned char)PyByteArray_AS_STRING(seq)[index];
28712872
}
28722873
else {
2874+
val = -1;
2875+
}
2876+
Py_END_CRITICAL_SECTION();
2877+
2878+
if (val == -1) {
28732879
FT_ATOMIC_STORE_SSIZE_RELAXED(it->it_index, -1);
28742880
#ifndef Py_GIL_DISABLED
2875-
it->it_seq = NULL;
2876-
Py_DECREF(seq);
2881+
Py_CLEAR(it->it_seq);
28772882
#endif
28782883
return NULL;
28792884
}

0 commit comments

Comments
 (0)