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

Fix store subscr list finalizer deadlock (#8956) · RustPython/RustPython@7536730 · GitHub

Repository navigation

Commit 7536730

Browse files
authored
Fix store subscr list finalizer deadlock (#8956)
* Release replaced list item outside the lock in STORE_SUBSCR_LIST_INT Assisted-by: Claude Code:claude-opus-5-5 * Add a snippet for finalizers reading a list during a specialized store Assisted-by: Claude Code:claude-opus-5-5
1 parent f39b054 commit 7536730

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

‎crates/vm/src/frame.rs‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6430,7 +6430,11 @@ impl ExecutingFrame<'_> {
64306430
{
64316431
let mut vec = list.borrow_vec_mut();
64326432
if i < vec.len() {
6433-
vec[i] = value;
6433+
// Unlock before dropping the replaced element; its
6434+
// finalizer may access this list.
6435+
let old = core::mem::replace(&mut vec[i], value);
6436+
drop(vec);
6437+
drop(old);
64346438
return Ok(None);
64356439
}
64366440
}

‎extra_tests/snippets/vm_specialization.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,3 +342,33 @@ def read():
342342

343343

344344
module_attribute_custom_dict_key()
345+
346+
347+
## STORE_SUBSCR_LIST_INT: the replaced element's finalizer can read the list
348+
349+
350+
def store_subscr_list_int_finalizer_reads_list():
351+
target = [None]
352+
seen = []
353+
354+
class Item:
355+
def __init__(self, value):
356+
self.value = value
357+
358+
def __del__(self):
359+
seen.append((self.value, len(target), target[0] is self))
360+
361+
def store(value):
362+
target[0] = value
363+
364+
for i in range(300):
365+
store(Item(i))
366+
assert any(
367+
op.opname == "STORE_SUBSCR_LIST_INT"
368+
for op in dis.get_instructions(store, adaptive=True)
369+
)
370+
store(None)
371+
assert seen == [(i, 1, False) for i in range(300)]
372+
373+
374+
store_subscr_list_int_finalizer_reads_list()

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL