Skip to content

Commit 38cb24d

Browse files
committed
Make PySet and PyFrozenSet ThreadSafe
1 parent b3cadbd commit 38cb24d

File tree

2 files changed

+60
-74
lines changed

2 files changed

+60
-74
lines changed

vm/src/dictdatatype.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ impl<T: Clone> Dict<T> {
113113
}
114114

115115
fn unchecked_push(
116-
&mut self,
116+
&self,
117117
hash_index: HashIndex,
118118
hash_value: HashValue,
119119
key: PyObjectRef,
@@ -133,7 +133,7 @@ impl<T: Clone> Dict<T> {
133133

134134
/// Store a key
135135
pub fn insert<K: DictKey + IntoPyObject + Copy>(
136-
&mut self,
136+
&self,
137137
vm: &VirtualMachine,
138138
key: K,
139139
value: T,
@@ -193,23 +193,23 @@ impl<T: Clone> Dict<T> {
193193
}
194194
}
195195

196-
pub fn clear(&mut self) {
196+
pub fn clear(&self) {
197197
let mut inner = self.borrow_value_mut();
198198
inner.entries.clear();
199199
inner.indices.clear();
200200
inner.size = 0
201201
}
202202

203203
/// Delete a key
204-
pub fn delete(&mut self, vm: &VirtualMachine, key: &PyObjectRef) -> PyResult<()> {
204+
pub fn delete(&self, vm: &VirtualMachine, key: &PyObjectRef) -> PyResult<()> {
205205
if self.delete_if_exists(vm, key)? {
206206
Ok(())
207207
} else {
208208
Err(vm.new_key_error(key.clone()))
209209
}
210210
}
211211

212-
pub fn delete_if_exists(&mut self, vm: &VirtualMachine, key: &PyObjectRef) -> PyResult<bool> {
212+
pub fn delete_if_exists(&self, vm: &VirtualMachine, key: &PyObjectRef) -> PyResult<bool> {
213213
loop {
214214
if let LookupResult::Existing(entry_index) = self.lookup(vm, key)? {
215215
let mut inner = self.borrow_value_mut();
@@ -228,7 +228,7 @@ impl<T: Clone> Dict<T> {
228228
}
229229

230230
pub fn delete_or_insert(
231-
&mut self,
231+
&self,
232232
vm: &VirtualMachine,
233233
key: &PyObjectRef,
234234
value: T,
@@ -361,7 +361,7 @@ impl<T: Clone> Dict<T> {
361361
}
362362

363363
/// Retrieve and delete a key
364-
pub fn pop<K: DictKey + Copy>(&mut self, vm: &VirtualMachine, key: K) -> PyResult<Option<T>> {
364+
pub fn pop<K: DictKey + Copy>(&self, vm: &VirtualMachine, key: K) -> PyResult<Option<T>> {
365365
loop {
366366
if let LookupResult::Existing(index) = self.lookup(vm, key)? {
367367
let mut inner = self.borrow_value_mut();
@@ -380,7 +380,7 @@ impl<T: Clone> Dict<T> {
380380
}
381381
}
382382

383-
pub fn pop_front(&mut self) -> Option<(PyObjectRef, T)> {
383+
pub fn pop_front(&self) -> Option<(PyObjectRef, T)> {
384384
let mut position = 0;
385385
let mut inner = self.borrow_value_mut();
386386
let first_item = inner.entries.iter().find_map(|entry| {

0 commit comments

Comments
 (0)