Add os._exit() method

This commit is contained in:
ChJR
2019-10-06 16:23:13 +09:00
parent 672593f49a
commit 8698b00dc5
2 changed files with 10 additions and 0 deletions

1
Lib/os.py vendored
View File

@@ -45,6 +45,7 @@ def _get_exports_list(module):
import _os
from _os import *
from _os import _exit
__all__.extend(_get_exports_list(_os))
del _os

View File

@@ -972,6 +972,14 @@ fn os_cpu_count(vm: &VirtualMachine) -> PyObjectRef {
vm.new_int(cpu_count)
}
fn os_exit(code: PyIntRef, _vm: &VirtualMachine) -> PyResult<()> {
if let Some(code) = code.as_bigint().to_i32() {
std::process::exit(code)
} else {
panic!("unwrap error from code.as_bigint().to_i32() in os_exit()")
}
}
#[cfg(unix)]
fn os_getppid(vm: &VirtualMachine) -> PyObjectRef {
let ppid = unistd::getppid().as_raw();
@@ -1215,6 +1223,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
"fspath" => ctx.new_rustfunc(os_fspath),
"getpid" => ctx.new_rustfunc(os_getpid),
"cpu_count" => ctx.new_rustfunc(os_cpu_count),
"_exit" => ctx.new_rustfunc(os_exit),
"O_RDONLY" => ctx.new_int(libc::O_RDONLY),
"O_WRONLY" => ctx.new_int(libc::O_WRONLY),