@@ -1971,7 +1971,6 @@ mod posix {
1971
1971
unsafe { libc:: WEXITSTATUS ( status) }
1972
1972
}
1973
1973
1974
- // TODO: os.wait[pid] for windows
1975
1974
#[ pyfunction]
1976
1975
fn waitpid ( pid : libc:: pid_t , opt : i32 , vm : & VirtualMachine ) -> PyResult < ( libc:: pid_t , i32 ) > {
1977
1976
let mut status = 0 ;
@@ -2134,6 +2133,8 @@ mod nt {
2134
2133
use super :: * ;
2135
2134
pub ( super ) use std:: os:: windows:: fs:: OpenOptionsExt ;
2136
2135
use std:: os:: windows:: io:: RawHandle ;
2136
+ #[ cfg( target_env = "msvc" ) ]
2137
+ use winapi:: vc:: vcruntime:: intptr_t;
2137
2138
2138
2139
pub ( super ) type OpenFlags = u32 ;
2139
2140
@@ -2290,6 +2291,46 @@ mod nt {
2290
2291
get_stats ( ) . map_err ( |e| convert_io_error ( vm, e) )
2291
2292
}
2292
2293
2294
+ // cwait is available on MSVC only (according to CPython)
2295
+ #[ cfg( target_env = "msvc" ) ]
2296
+ extern "C" {
2297
+ fn _cwait ( termstat : * mut i32 , procHandle : intptr_t , action : i32 ) -> intptr_t ;
2298
+ fn _get_errno ( pValue : * mut i32 ) -> i32 ;
2299
+ }
2300
+
2301
+ #[ cfg( target_env = "msvc" ) ]
2302
+ #[ pyfunction]
2303
+ fn waitpid ( pid : intptr_t , opt : i32 , vm : & VirtualMachine ) -> PyResult < ( intptr_t , i32 ) > {
2304
+ const ECHILD : i32 = 10 ;
2305
+ const EINVAL : i32 = 22 ;
2306
+
2307
+ let mut status = 0 ;
2308
+ let pid = unsafe { suppress_iph ! ( _cwait( & mut status, pid, opt) ) } ;
2309
+ if pid == -1 {
2310
+ let mut errno = 0 ;
2311
+ unsafe { _get_errno ( & mut errno) } ;
2312
+ match errno {
2313
+ ECHILD => Err ( vm. new_exception_msg (
2314
+ vm. ctx . exceptions . os_error . clone ( ) ,
2315
+ "ECHILD: No spawned processes" . to_owned ( ) ,
2316
+ ) ) ,
2317
+ EINVAL => Err ( vm. new_exception_msg (
2318
+ vm. ctx . exceptions . os_error . clone ( ) ,
2319
+ "EINVAL: Invalid argument" . to_owned ( ) ,
2320
+ ) ) ,
2321
+ _ => unreachable ! ( ) ,
2322
+ }
2323
+ } else {
2324
+ Ok ( ( pid, status << 8 ) )
2325
+ }
2326
+ }
2327
+
2328
+ #[ cfg( target_env = "msvc" ) ]
2329
+ #[ pyfunction]
2330
+ fn wait ( vm : & VirtualMachine ) -> PyResult < ( intptr_t , i32 ) > {
2331
+ waitpid ( -1 , 0 , vm)
2332
+ }
2333
+
2293
2334
#[ pyfunction]
2294
2335
fn kill ( pid : i32 , sig : isize , vm : & VirtualMachine ) -> PyResult < ( ) > {
2295
2336
{
0 commit comments