🌐 AI搜索 & 代理 主页
Skip to content

Commit 3440811

Browse files
committed
Enable TestMethodsMutating
Make Dict::lookup check if the dictionary has been modified. This is a workaround for a possible segfault. See bpo-46615 for the original discussion in CPython.
1 parent 1d23f6e commit 3440811

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Lib/test/test_set.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,6 @@ class TestBinaryOpsMutating_Subclass_Set(TestBinaryOpsMutating, unittest.TestCas
18981898
constructor2 = set
18991899

19001900

1901-
@unittest.skip("TODO: RUSTPYTHON; segfault")
19021901
class TestMethodsMutating(TestOperationsMutating):
19031902

19041903
def test_issubset_with_mutation(self):

vm/src/dict_inner.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,12 @@ impl<T: Clone> Dict<T> {
582582
});
583583
loop {
584584
let index_index = idxs.next();
585-
let index_entry = *unsafe {
586-
// Safety: index_index is generated
587-
inner.indices.get_unchecked(index_index)
588-
};
585+
let index_entry_ptr = inner.indices.get(index_index);
586+
if index_entry_ptr.is_none() {
587+
// Dictionary was modified under our hands, see TestMethodsMutating.
588+
continue 'outer;
589+
}
590+
let index_entry = *index_entry_ptr.unwrap();
589591
match index_entry {
590592
IndexEntry::DUMMY => {
591593
if free_slot.is_none() {

0 commit comments

Comments
 (0)