Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Lib/test/test_bytes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2380,12 +2380,22 @@ def ass_subscript(b, a): # MODIFIES!
b.wait()
a[:] = c

def ass_subscript2(b, a, c): # MODIFIES!
b.wait()
a[:] = c
assert b'\xdd' not in a

def mod(b, a):
c = tuple(range(4096))
b.wait()
try: a % c
except TypeError: pass

def mod2(b, a, c):
b.wait()
d = a % c
assert b'\xdd' not in d

def repr_(b, a):
b.wait()
repr(a)
Expand Down Expand Up @@ -2503,7 +2513,9 @@ def check(funcs, a=None, *args):

check([clear] + [contains] * 10)
check([clear] + [subscript] * 10)
check([clear2] + [ass_subscript2] * 10, None, bytearray(b'0' * 0x400000))
check([clear] + [mod] * 10, bytearray(b'%d' * 4096))
check([clear2] + [mod2] * 10, bytearray(b'%s'), bytearray(b'0' * 0x400000))

check([clear] + [capitalize] * 10, bytearray(b'a' * 0x40000))
check([clear] + [center] * 10, bytearray(b'a' * 0x40000))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix two more :class:`bytearray` functions for :term:`free threading`.
26 changes: 20 additions & 6 deletions Objects/bytearrayobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,9 +864,16 @@ static int
bytearray_ass_subscript(PyObject *op, PyObject *index, PyObject *values)
{
int ret;
Py_BEGIN_CRITICAL_SECTION(op);
ret = bytearray_ass_subscript_lock_held(op, index, values);
Py_END_CRITICAL_SECTION();
if (values != NULL && PyByteArray_Check(values)) {
Py_BEGIN_CRITICAL_SECTION2(op, values);
ret = bytearray_ass_subscript_lock_held(op, index, values);
Py_END_CRITICAL_SECTION2();
}
else {
Py_BEGIN_CRITICAL_SECTION(op);
ret = bytearray_ass_subscript_lock_held(op, index, values);
Py_END_CRITICAL_SECTION();
}
return ret;
}

Expand Down Expand Up @@ -2751,9 +2758,16 @@ static PyObject *
bytearray_mod(PyObject *v, PyObject *w)
{
PyObject *ret;
Py_BEGIN_CRITICAL_SECTION(v);
ret = bytearray_mod_lock_held(v, w);
Py_END_CRITICAL_SECTION();
if (PyByteArray_Check(w)) {
Py_BEGIN_CRITICAL_SECTION2(v, w);
ret = bytearray_mod_lock_held(v, w);
Py_END_CRITICAL_SECTION2();
}
else {
Py_BEGIN_CRITICAL_SECTION(v);
ret = bytearray_mod_lock_held(v, w);
Py_END_CRITICAL_SECTION();
}
return ret;
}

Expand Down
Loading