Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 462f54f

Browse files
committed
Fix with __exit__ error handling
1 parent 1c4e99c commit 462f54f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

vm/src/frame.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -925,15 +925,15 @@ impl ExecutingFrame<'_> {
925925
_ => None,
926926
};
927927

928-
let exit = self.pop_value();
928+
let exit = self.top_value();
929929

930930
let args = if let Some(exc) = exc {
931931
vm.split_exception(exc)
932932
} else {
933933
(vm.ctx.none(), vm.ctx.none(), vm.ctx.none())
934934
};
935935
let exit_res = exit.call(args, vm)?;
936-
self.push_value(exit_res);
936+
self.replace_top(exit_res);
937937

938938
Ok(None)
939939
}
@@ -994,7 +994,7 @@ impl ExecutingFrame<'_> {
994994
}
995995
bytecode::Instruction::GetANext => {
996996
let aiter = self.top_value();
997-
let awaitable = vm.call_special_method(&aiter, identifier!(vm, __anext__), ())?;
997+
let awaitable = vm.call_special_method(aiter, identifier!(vm, __anext__), ())?;
998998
let awaitable = if awaitable.payload_is::<PyCoroutine>() {
999999
awaitable
10001000
} else {
@@ -1954,6 +1954,13 @@ impl ExecutingFrame<'_> {
19541954
self.state.stack.drain(stack_len - count..)
19551955
}
19561956

1957+
#[inline]
1958+
fn replace_top(&mut self, mut top: PyObjectRef) -> PyObjectRef {
1959+
let last = self.state.stack.last_mut().unwrap();
1960+
std::mem::swap(&mut top, last);
1961+
top
1962+
}
1963+
19571964
#[inline]
19581965
#[track_caller] // not a real track_caller but top_value is not very useful
19591966
fn top_value(&self) -> &PyObject {

0 commit comments

Comments
 (0)