Skip to content

Commit

Permalink
Merge pull request #11 from dylni/dependabot/cargo/windows-sys-0.31
Browse files Browse the repository at this point in the history
  • Loading branch information
dependabot[bot] committed Feb 4, 2022
2 parents 6a2e1ca + 0bb01f0 commit 46dd219
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ crossbeam-channel = { version = "0.5", optional = true }
libc = "0.2.98"

[target.'cfg(windows)'.dependencies]
windows-sys = { version = "0.30", features = ["Win32_Foundation", "Win32_Security", "Win32_System_JobObjects", "Win32_System_Threading", "Win32_System_WindowsProgramming"] }
windows-sys = { version = "0.32", features = ["Win32_Foundation", "Win32_Security", "Win32_System_JobObjects", "Win32_System_Threading", "Win32_System_WindowsProgramming"] }
12 changes: 8 additions & 4 deletions src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ fn check_syscall(result: BOOL) -> io::Result<()> {
struct RawHandle(HANDLE);

impl RawHandle {
fn new(process: &Child) -> Self {
Self(process.as_raw_handle() as _)
}

unsafe fn get_exit_code(&self) -> io::Result<DWORD> {
let mut exit_code = 0;
check_syscall(GetExitCodeProcess(self.0, &mut exit_code))?;
Expand Down Expand Up @@ -183,7 +187,7 @@ pub(super) struct SharedHandle {
impl SharedHandle {
pub(super) unsafe fn new(process: &Child) -> Self {
Self {
handle: RawHandle(process.as_raw_handle()),
handle: RawHandle::new(process),
memory_limit: None,
time_limit: None,
job_handle: JobHandle(Cell::new(None)),
Expand All @@ -196,7 +200,7 @@ impl SharedHandle {
if let Some(memory_limit) = self.memory_limit {
let job_handle =
unsafe { CreateJobObjectW(ptr::null(), ptr::null_mut()) };
if job_handle.is_null() {
if job_handle == 0 {
return Err(io::Error::last_os_error());
}
self.job_handle.0.replace_none(RawHandle(job_handle));
Expand Down Expand Up @@ -300,11 +304,11 @@ pub(super) struct DuplicatedHandle(RawHandle);
impl DuplicatedHandle {
pub(super) fn new(process: &Child) -> io::Result<Self> {
let parent_handle = unsafe { GetCurrentProcess() };
let mut handle = ptr::null_mut();
let mut handle = 0;
check_syscall(unsafe {
DuplicateHandle(
parent_handle,
process.as_raw_handle(),
RawHandle::new(process).0,
parent_handle,
&mut handle,
0,
Expand Down

0 comments on commit 46dd219

Please sign in to comment.