Skip to content

Commit aeb53c7

Browse files
committed
Fix format, revert eager retained_back materialization
Remove double blank line in frame.rs (lint failure). Revert with_frame retained_back to only use already-materialized caller FrameObjects — eagerly materializing the caller added refcounts on local variables, preventing timely deallocation and causing test_io, test_memoryview, and test_futures failures. Assisted-by: Claude
1 parent 8264e2c commit aeb53c7

2 files changed

Lines changed: 9 additions & 5 deletions

File tree

‎crates/vm/src/frame.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,6 @@ impl FrameObject {
15941594
self.iframe().lasti.store(val, Relaxed);
15951595
}
15961596

1597-
15981597
fn has_active_hidden_locals(&self) -> bool {
15991598
use rustpython_compiler_core::bytecode::{CO_FAST_CELL, CO_FAST_FREE, CO_FAST_HIDDEN};
16001599
let code = self.iframe().code();

‎crates/vm/src/vm/mod.rs‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,14 +1756,19 @@ impl VirtualMachine {
17561756
// reference to this FrameObject can walk the chain after return.
17571757
if !old_chain.is_null() {
17581758
let strong = frame.as_object().strong_count();
1759-
// Only set retained_back if someone else holds a reference (escaped).
1759+
// Only set retained_back if someone else holds a reference (escaped)
1760+
// AND the caller already has a FrameObject. Materializing the caller
1761+
// here would add refcounts on its local variables, preventing timely
1762+
// __del__ / ResourceWarning on dealloc. If the caller hasn't been
1763+
// materialized, f_back will resolve via the TLS chain while the
1764+
// caller is still executing, or return None after it returns.
17601765
if strong > 1 {
17611766
let mut guard = frame.iframe().retained_back.lock();
17621767
if guard.is_none() {
17631768
let prev_iframe = unsafe { &*old_chain };
1764-
// Materialize the caller if needed so f_back resolves.
1765-
let fo = prev_iframe.materialize(self);
1766-
*guard = Some(fo.to_owned());
1769+
if let Some(fo) = prev_iframe.frame_obj() {
1770+
*guard = Some(fo.to_owned());
1771+
}
17671772
}
17681773
}
17691774
}

0 commit comments

Comments
 (0)