-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Implement os.waitpid on Windows #2048
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This function has a corresponding CPython test suite, although it's not possible to run it on Windows yet. |
vm/src/stdlib/os.rs
Outdated
#[cfg(all(windows, target_env = "msvc"))] | ||
extend_module!(vm, module, { | ||
"wait" => ctx.new_function(os_wait), | ||
"waitpid" => ctx.new_function(os_waitpid), | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is placed in unix extend_module_platform_specific
for now. Moving this code a few lines below will be perfect.
vm/src/stdlib/os.rs
Outdated
_ => unreachable!(), | ||
} | ||
} else { | ||
Ok((pid, status)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, this should be lshifted by a byte.
c3063ba
to
cf9370a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks a bit different to CPython implementation but good enough to work . I wish we had a test for this. We really need to import os test from CPython.
I rebased this due to #2041
let mut errno = 0; | ||
unsafe { _get_errno(&mut errno) }; | ||
match errno { | ||
ECHILD => Err(vm.new_exception_msg( | ||
vm.ctx.exceptions.os_error.clone(), | ||
"ECHILD: No spawned processes".to_owned(), | ||
)), | ||
EINVAL => Err(vm.new_exception_msg( | ||
vm.ctx.exceptions.os_error.clone(), | ||
"EINVAL: Invalid argument".to_owned(), | ||
)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following unix convert_nix_error
, here could be convert_nt_error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd love to use that kind of error handler, but it seems like in _cwait
Microsoft uses some kind of POSIX-like errno which means it's neither WinAPI error nor POSIX error.
This PR implements os.waitpid using MSVCRT's
_cwait
function.