Skip to content

Commit c39d143

Browse files
authored
Merge pull request RustPython#3133 from youknowone/exception-utils-as-vm-methods
Exception utils as vm methods
2 parents 2423f34 + 256de1e commit c39d143

File tree

12 files changed

+208
-210
lines changed

12 files changed

+208
-210
lines changed

examples/freeze/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ fn run(vm: &vm::VirtualMachine) -> vm::PyResult<()> {
1313

1414
let res = vm.run_code_obj(vm.new_code_object(module), scope);
1515

16-
if let Err(err) = res {
17-
vm::exceptions::print_exception(&vm, err);
16+
if let Err(exc) = res {
17+
vm.print_exception(exc);
1818
}
1919

2020
Ok(())

examples/mini_repl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ def fib(n):
7676
scope.globals.set_item("last", output, vm)?;
7777
}
7878
}
79-
Err(e) => {
80-
vm::exceptions::print_exception(vm, e);
79+
Err(exc) => {
80+
vm.print_exception(exc);
8181
}
8282
}
8383
}

src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@ extern crate log;
4545

4646
use clap::{App, AppSettings, Arg, ArgMatches};
4747
use rustpython_vm::{
48-
builtins::PyDictRef, builtins::PyInt, compile, exceptions::print_exception, match_class,
49-
scope::Scope, stdlib::sys, InitParameter, Interpreter, ItemProtocol, PyObjectRef, PyResult,
50-
PySettings, TryFromObject, TypeProtocol, VirtualMachine,
48+
builtins::PyDictRef, builtins::PyInt, compile, match_class, scope::Scope, stdlib::sys,
49+
InitParameter, Interpreter, ItemProtocol, PyObjectRef, PyResult, PySettings, TryFromObject,
50+
TypeProtocol, VirtualMachine,
5151
};
5252

5353
use std::convert::TryInto;
@@ -136,8 +136,8 @@ where
136136
}
137137
}
138138
}
139-
Err(err) => {
140-
print_exception(vm, err);
139+
Err(exc) => {
140+
vm.print_exception(exc);
141141
1
142142
}
143143
};

src/shell.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use rustpython_vm::readline::{Readline, ReadlineResult};
55
use rustpython_vm::{
66
builtins::PyBaseExceptionRef,
77
compile::{self, CompileError, CompileErrorType},
8-
exceptions::print_exception,
98
scope::Scope,
109
PyResult, TypeProtocol, VirtualMachine,
1110
};
@@ -130,7 +129,7 @@ pub fn run_shell(vm: &VirtualMachine, scope: Scope) -> PyResult<()> {
130129
repl.save_history(&repl_history_path).unwrap();
131130
return Err(exc);
132131
}
133-
print_exception(vm, exc);
132+
vm.print_exception(exc);
134133
}
135134
}
136135
repl.save_history(&repl_history_path).unwrap();

vm/src/coroutine.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::{
22
builtins::{PyBaseExceptionRef, PyStrRef},
33
common::lock::PyMutex,
4-
exceptions,
54
frame::{ExecutionResult, FrameRef},
65
protocol::PyIterReturn,
76
IdProtocol, PyObjectRef, PyResult, TypeProtocol, VirtualMachine,
@@ -140,7 +139,7 @@ impl Coro {
140139
vm: &VirtualMachine,
141140
) -> PyResult<PyIterReturn> {
142141
if self.closed.load() {
143-
return Err(exceptions::normalize(exc_type, exc_val, exc_tb, vm)?);
142+
return Err(vm.normalize_exception(exc_type, exc_val, exc_tb)?);
144143
}
145144
let result = self.run_with_context(gen, vm, |f| f.gen_throw(vm, exc_type, exc_val, exc_tb));
146145
self.maybe_close(&result);

0 commit comments

Comments
 (0)