🌐 AI搜索 & 代理 主页
Skip to content
Open
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
2 changes: 0 additions & 2 deletions Lib/test/test_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -1809,7 +1809,6 @@ def check_set_op_does_not_crash(self, function):
self.assertIn("changed size during iteration", str(e))


@unittest.skip("TODO: RUSTPYTHON; segfault")
class TestBinaryOpsMutating(TestOperationsMutating):

def test_eq_with_mutation(self):
Expand Down Expand Up @@ -1898,7 +1897,6 @@ class TestBinaryOpsMutating_Subclass_Set(TestBinaryOpsMutating, unittest.TestCas
constructor2 = set


@unittest.skip("TODO: RUSTPYTHON; segfault")
class TestMethodsMutating(TestOperationsMutating):

def test_issubset_with_mutation(self):
Expand Down
18 changes: 15 additions & 3 deletions vm/src/dict_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ impl<T: Clone> Dict<T> {
) -> PyResult<LookupResult> {
let mut idxs = None;
let mut free_slot = None;
let original_size = self.size();
let ret = 'outer: loop {
let (entry_key, ret) = {
let inner = lock.take().unwrap_or_else(|| self.read());
Expand All @@ -582,9 +583,12 @@ impl<T: Clone> Dict<T> {
});
loop {
let index_index = idxs.next();
let index_entry = *unsafe {
// Safety: index_index is generated
inner.indices.get_unchecked(index_index)
let index_entry = match inner.indices.get(index_index) {
None => {
// Dictionary was modified under our hands, see TestMethodsMutating.
return Err(vm.new_runtime_error("set changed size during iteration"));
}
Some(v) => *v,
};
match index_entry {
IndexEntry::DUMMY => {
Expand All @@ -597,6 +601,11 @@ impl<T: Clone> Dict<T> {
Some(free) => (IndexEntry::DUMMY, free),
None => (IndexEntry::FREE, index_index),
};
if self.has_changed_size(&original_size) {
return Err(
vm.new_runtime_error("set changed size during iteration")
);
}
return Ok(idxs);
}
idx => {
Expand Down Expand Up @@ -628,6 +637,9 @@ impl<T: Clone> Dict<T> {

// warn!("Perturb value: {}", i);
};
if self.has_changed_size(&original_size) {
return Err(vm.new_runtime_error("set changed size during iteration"));
}
Ok(ret)
}

Expand Down
Loading