FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix store subscr list finalizer deadlock by teddygood · Pull Request #8956 · RustPython/RustPython · GitHub

Repository navigation

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

Filter by extension

Filter by extension .py  (1) .rs  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
6 changes: 5 additions & 1 deletion crates/vm/src/frame.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6430,7 +6430,11 @@ impl ExecutingFrame<'_> {
{
let mut vec = list.borrow_vec_mut();
if i < vec.len() {
vec[i] = value;
// Unlock before dropping the replaced element; its
// finalizer may access this list.
let old = core::mem::replace(&mut vec[i], value);
drop(vec);
drop(old);
return Ok(None);
}
}
Expand Down
30 changes: 30 additions & 0 deletions extra_tests/snippets/vm_specialization.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -342,3 +342,33 @@ def read():


module_attribute_custom_dict_key()


## STORE_SUBSCR_LIST_INT: the replaced element's finalizer can read the list


def store_subscr_list_int_finalizer_reads_list():
target = [None]
seen = []

class Item:
def __init__(self, value):
self.value = value

def __del__(self):
seen.append((self.value, len(target), target[0] is self))

def store(value):
target[0] = value

for i in range(300):
store(Item(i))
assert any(
op.opname == "STORE_SUBSCR_LIST_INT"
for op in dis.get_instructions(store, adaptive=True)
)
store(None)
assert seen == [(i, 1, False) for i in range(300)]


store_subscr_list_int_finalizer_reads_list()
Loading

Back | FazBrowse Home | New Git URL