Skip to content

Commit 17a679c

Browse files
committed
Match simple interpreter execution errors and current Clippy
Restore main's ExitCode functions without duplicate must_use attributes: Rust 1.100 marks ExitCode itself must_use and CI rejects the duplicate. Follow CPython 3.15.2 PyRun_SimpleStringFlags by acquiring __main__ before compilation and reporting setup, compile and execution failures through the existing PyErr_Print-compatible helper. This preserves last-exception state, audit callbacks and SystemExit handling without adding another implementation. Regression probes remain outside the repository as requested. Assisted-by: OpenAI Codex:model-version-not-exposed
1 parent 101c69c commit 17a679c

3 files changed

Lines changed: 20 additions & 25 deletions

File tree

‎crates/vm/src/stdlib/_testinternalcapi.rs‎

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -723,15 +723,16 @@ mod _testinternalcapi {
723723
{
724724
if args.main.into_bool() {
725725
crate::vm::crossinterp::with_interpreter(id, vm, |target| {
726-
run_interpreter_source(source, target)
726+
Ok(run_interpreter_source(source, target))
727727
})
728728
} else if id == vm.state.interpreter_id {
729-
vm.new_thread()
730-
.run(|target| run_interpreter_source(source, target))
729+
Ok(vm
730+
.new_thread()
731+
.run(|target| run_interpreter_source(source, target)))
731732
} else {
732733
let thread = crate::vm::runtime::owned_new_thread(id)
733734
.ok_or_else(|| crate::stdlib::_interpreters::interpreter_not_found(vm, id))?;
734-
thread.run(|target| run_interpreter_source(source, target))
735+
Ok(thread.run(|target| run_interpreter_source(source, target)))
735736
}
736737
}
737738
#[cfg(not(feature = "threading"))]
@@ -2079,27 +2080,24 @@ fn run_string_in_new_subinterp(
20792080
thread.run(|target| run_interpreter_source(source, target))
20802081
};
20812082
let _ = crate::vm::runtime::destroy_owned_interpreter(id);
2082-
outcome
2083+
Ok(outcome)
20832084
}
20842085

20852086
#[cfg(feature = "threading")]
2086-
fn run_interpreter_source(source: &str, target: &VirtualMachine) -> PyResult<i32> {
2087-
match target.compile(source, crate::compiler::Mode::Exec, "<string>") {
2088-
Ok(code) => {
2089-
let ns = target.main_namespace()?;
2090-
let scope = crate::scope::Scope::with_builtins(None, ns, target);
2091-
match target.run_code_obj(code, scope) {
2092-
Ok(_) => Ok(0),
2093-
Err(exc) => {
2094-
target.print_exception(&exc);
2095-
Ok(-1)
2096-
}
2097-
}
2098-
}
2099-
Err(err) => {
2100-
let exc = err.into_pyexception(target, Some(source));
2101-
target.print_exception(&exc);
2102-
Ok(-1)
2087+
fn run_interpreter_source(source: &str, target: &VirtualMachine) -> i32 {
2088+
let result = (|| {
2089+
let ns = target.add_main_module()?.dict();
2090+
let code = target
2091+
.compile(source, crate::compiler::Mode::Exec, "<string>")
2092+
.map_err(|err| err.into_pyexception(target, Some(source)))?;
2093+
let scope = crate::scope::Scope::with_builtins(None, ns, target);
2094+
target.run_code_obj(code, scope)
2095+
})();
2096+
match result {
2097+
Ok(_) => 0,
2098+
Err(exc) => {
2099+
target.print_uncaught_exception(&exc);
2100+
-1
21032101
}
21042102
}
21052103
}

‎src/lib.rs‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ compile_error!(
9090
/// **Note**: This function provides no way to further initialize the VM after the builder is applied.
9191
/// All VM initialization (adding native modules, init hooks, etc.) must be done through the
9292
/// [`InterpreterBuilder`] parameter before calling this function.
93-
#[must_use]
9493
pub fn run(builder: InterpreterBuilder) -> ExitCode {
9594
run_impl(builder, false)
9695
}
@@ -102,7 +101,6 @@ pub fn run(builder: InterpreterBuilder) -> ExitCode {
102101
/// Call only during single-threaded startup, before other threads or libraries
103102
/// can read the environment or use the process-global locale. Embedded callers
104103
/// that cannot guarantee this should use `run` or build an interpreter directly.
105-
#[must_use]
106104
pub unsafe fn run_with_locale(builder: InterpreterBuilder) -> ExitCode {
107105
run_impl(builder, true)
108106
}

‎src/main.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use rustpython::{InterpreterBuilder, InterpreterBuilderExt};
44
#[global_allocator]
55
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
66

7-
#[must_use]
87
pub fn main() -> std::process::ExitCode {
98
let mut config = InterpreterBuilder::new();
109
#[cfg(feature = "stdlib")]

0 commit comments

Comments
 (0)