MCPcopy Index your code
hub / github.com/RustPython/RustPython / exit_code

Function exit_code

crates/common/src/os.rs:11–23  ·  view source on GitHub ↗

Convert exit code to std::process::ExitCode On Windows, this supports the full u32 range including STATUS_CONTROL_C_EXIT (0xC000013A). On other platforms, only the lower 8 bits are used.

(code: u32)

Source from the content-addressed store, hash-verified

9/// On Windows, this supports the full u32 range including STATUS_CONTROL_C_EXIT (0xC000013A).
10/// On other platforms, only the lower 8 bits are used.
11pub fn exit_code(code: u32) -> ExitCode {
12 #[cfg(windows)]
13 {
14 // For large exit codes like STATUS_CONTROL_C_EXIT (0xC000013A),
15 // we need to call std::process::exit() directly since ExitCode::from(u8)
16 // would truncate the value, and ExitCode::from_raw() is still unstable.
17 // FIXME: side effect in exit_code is not ideal.
18 if code > u8::MAX as u32 {
19 std::process::exit(code as i32)
20 }
21 }
22 ExitCode::from(code as u8)
23}
24
25pub trait ErrorExt {
26 fn posix_errno(&self) -> i32;

Callers 3

runFunction · 0.85
mainFunction · 0.85
mainFunction · 0.85

Calls 1

exitFunction · 0.50

Tested by

no test coverage detected