Don't pop exeption for context

This commit is contained in:
Aviv Palivoda
2019-04-27 21:53:08 +03:00
parent 4b9bafc824
commit 60afbb4bf5
2 changed files with 13 additions and 2 deletions

View File

@@ -739,8 +739,8 @@ impl Frame {
};
let context = match argc {
0 => vm.get_none(), // We have already got the exception,
_ => match vm.pop_exception() {
Some(exc) => exc,
_ => match vm.last_exception() {
Some(exc) => exc.clone(),
None => vm.get_none(),
},
};

View File

@@ -931,6 +931,17 @@ impl VirtualMachine {
pub fn pop_exception(&self) -> Option<PyObjectRef> {
self.exceptions.borrow_mut().pop()
}
pub fn last_exception(&self) -> Option<Ref<PyObjectRef>> {
let exceptions = self.exceptions.borrow();
if exceptions.is_empty() {
None
} else {
Some(Ref::map(self.exceptions.borrow(), |exceptions| {
exceptions.last().unwrap()
}))
}
}
}
impl Default for VirtualMachine {