@@ -11,6 +11,8 @@ use std::os::windows::fs::OpenOptionsExt;
1111use std:: time:: { Duration , SystemTime } ;
1212use std:: { env, fs} ;
1313
14+ #[ cfg( unix) ]
15+ use exitcode;
1416#[ cfg( unix) ]
1517use nix:: errno:: Errno ;
1618#[ cfg( all( unix, not( target_os = "redox" ) ) ) ]
@@ -972,6 +974,14 @@ fn os_cpu_count(vm: &VirtualMachine) -> PyObjectRef {
972974 vm. new_int ( cpu_count)
973975}
974976
977+ fn os_exit ( code : PyIntRef , _vm : & VirtualMachine ) -> PyResult < ( ) > {
978+ if let Some ( code) = code. as_bigint ( ) . to_i32 ( ) {
979+ std:: process:: exit ( code)
980+ } else {
981+ panic ! ( "unwrap error from code.as_bigint().to_i32() in os_exit()" )
982+ }
983+ }
984+
975985#[ cfg( unix) ]
976986fn os_getppid ( vm : & VirtualMachine ) -> PyObjectRef {
977987 let ppid = unistd:: getppid ( ) . as_raw ( ) ;
@@ -1215,6 +1225,7 @@ pub fn make_module(vm: &VirtualMachine) -> PyObjectRef {
12151225 "fspath" => ctx. new_rustfunc( os_fspath) ,
12161226 "getpid" => ctx. new_rustfunc( os_getpid) ,
12171227 "cpu_count" => ctx. new_rustfunc( os_cpu_count) ,
1228+ "_exit" => ctx. new_rustfunc( os_exit) ,
12181229
12191230 "O_RDONLY" => ctx. new_int( libc:: O_RDONLY ) ,
12201231 "O_WRONLY" => ctx. new_int( libc:: O_WRONLY ) ,
@@ -1283,6 +1294,22 @@ fn extend_module_platform_specific(vm: &VirtualMachine, module: PyObjectRef) ->
12831294 "SEEK_SET" => ctx. new_int( Whence :: SeekSet as i8 ) ,
12841295 "SEEK_CUR" => ctx. new_int( Whence :: SeekCur as i8 ) ,
12851296 "SEEK_END" => ctx. new_int( Whence :: SeekEnd as i8 ) ,
1297+ "EX_OK" => ctx. new_int( exitcode:: OK as i8 ) ,
1298+ "EX_USAGE" => ctx. new_int( exitcode:: USAGE as i8 ) ,
1299+ "EX_DATAERR" => ctx. new_int( exitcode:: DATAERR as i8 ) ,
1300+ "EX_NOINPUT" => ctx. new_int( exitcode:: NOINPUT as i8 ) ,
1301+ "EX_NOUSER" => ctx. new_int( exitcode:: NOUSER as i8 ) ,
1302+ "EX_NOHOST" => ctx. new_int( exitcode:: NOHOST as i8 ) ,
1303+ "EX_UNAVAILABLE" => ctx. new_int( exitcode:: UNAVAILABLE as i8 ) ,
1304+ "EX_SOFTWARE" => ctx. new_int( exitcode:: SOFTWARE as i8 ) ,
1305+ "EX_OSERR" => ctx. new_int( exitcode:: OSERR as i8 ) ,
1306+ "EX_OSFILE" => ctx. new_int( exitcode:: OSFILE as i8 ) ,
1307+ "EX_CANTCREAT" => ctx. new_int( exitcode:: CANTCREAT as i8 ) ,
1308+ "EX_IOERR" => ctx. new_int( exitcode:: IOERR as i8 ) ,
1309+ "EX_TEMPFAIL" => ctx. new_int( exitcode:: TEMPFAIL as i8 ) ,
1310+ "EX_PROTOCOL" => ctx. new_int( exitcode:: PROTOCOL as i8 ) ,
1311+ "EX_NOPERM" => ctx. new_int( exitcode:: NOPERM as i8 ) ,
1312+ "EX_CONFIG" => ctx. new_int( exitcode:: CONFIG as i8 ) ,
12861313 } ) ;
12871314
12881315 #[ cfg( not( target_os = "redox" ) ) ]
0 commit comments