mirror of
https://github.com/RustPython/RustPython.git
synced 2026-10-28 18:59:04 +08:00
Prevent array.tofile re-entrant deadlock and add regression snippet (#6559)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com>
This commit is contained in:
1 parent
f8199d7099
commit
04a4d1e02f
2 files changed
+21
-2
No files matched your search
@@ -938,8 +938,10 @@ mod array {
|
||||
/* XXX Make the block size settable */
|
||||
const BLOCKSIZE: usize = 64 * 1024;
|
||||
|
||||
let bytes = self.read();
|
||||
let bytes = bytes.get_bytes();
|
||||
let bytes = {
|
||||
let bytes = self.read();
|
||||
bytes.get_bytes().to_vec()
|
||||
};
|
||||
|
||||
for b in bytes.chunks(BLOCKSIZE) {
|
||||
let b = PyBytes::from(b.to_vec()).into_ref(&vm.ctx);
|
||||
|
||||
@@ -126,3 +126,20 @@ assert str(i.__class__.__name__) == "arrayiterator"
|
||||
a = array("B", [0])
|
||||
assert a.__contains__(0)
|
||||
assert not a.__contains__(1)
|
||||
|
||||
|
||||
class _ReenteringWriter:
|
||||
def __init__(self, arr):
|
||||
self.arr = arr
|
||||
self.reentered = False
|
||||
|
||||
def write(self, chunk):
|
||||
if not self.reentered:
|
||||
self.reentered = True
|
||||
self.arr.append(0)
|
||||
return len(chunk)
|
||||
|
||||
|
||||
arr = array("b", range(128))
|
||||
arr.tofile(_ReenteringWriter(arr))
|
||||
assert len(arr) == 129
|
||||
Reference in new issue
Block a user