From f48944c1fbd3a02f3018462e306b88a4ccb3f435 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 3 Jan 2018 09:46:41 -0800 Subject: [PATCH] process: Update winapi to 0.3 --- Cargo.toml | 15 +++++++++++++-- src/lib.rs | 10 +++++----- src/windows.rs | 48 +++++++++++++++++++++++++++--------------------- tests/stdio.rs | 10 +++++----- 4 files changed, 50 insertions(+), 33 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c2666098c..f95e0a8b6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,10 +26,21 @@ env_logger = { version = "0.3", default-features = false } log = "0.3" [target.'cfg(windows)'.dependencies] -winapi = "0.2" -kernel32-sys = "0.2" mio-named-pipes = "0.1" +[target.'cfg(windows)'.dependencies.winapi] +version = "0.3" +features = [ + "handleapi", + "winerror", + "minwindef", + "processthreadsapi", + "synchapi", + "threadpoollegacyapiset", + "winbase", + "winnt", +] + [target.'cfg(unix)'.dependencies] libc = "0.2" tokio-signal = "0.1" diff --git a/src/lib.rs b/src/lib.rs index 3962b54e6..d6205d09f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -294,9 +294,9 @@ impl CommandExt for process::Command { self.stdout(Stdio::piped()); self.stderr(Stdio::piped()); OutputAsync { - inner: self.spawn_async(handle).into_future().and_then(|c| { + inner: Box::new(self.spawn_async(handle).into_future().and_then(|c| { c.wait_with_output() - }).boxed(), + })), } } } @@ -383,13 +383,13 @@ impl Child { }; WaitWithOutput { - inner: self.join3(stdout, stderr).map(|(status, stdout, stderr)| { + inner: Box::new(self.join3(stdout, stderr).map(|(status, stdout, stderr)| { Output { status: status, stdout: stdout, stderr: stderr, } - }).boxed() + })) } } @@ -668,7 +668,7 @@ impl Command { pub fn spawn(mut self) -> Spawn { Spawn { - inner: self.inner.spawn_async(&self.handle).into_future().boxed() + inner: Box::new(self.inner.spawn_async(&self.handle).into_future()), } } } diff --git a/src/windows.rs b/src/windows.rs index 8ed1781fc..d60d7b8de 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -16,7 +16,6 @@ //! from then on out. extern crate winapi; -extern crate kernel32; extern crate mio_named_pipes; use std::fmt; @@ -25,10 +24,18 @@ use std::os::windows::prelude::*; use std::os::windows::process::ExitStatusExt; use std::process::{self, ExitStatus}; -use futures::{Future, Poll, Async} ; -use futures::sync::oneshot; use futures::future::Fuse; +use futures::sync::oneshot; +use futures::{Future, Poll, Async} ; use self::mio_named_pipes::NamedPipe; +use self::winapi::shared::minwindef::*; +use self::winapi::shared::winerror::*; +use self::winapi::um::handleapi::*; +use self::winapi::um::processthreadsapi::*; +use self::winapi::um::synchapi::*; +use self::winapi::um::threadpoollegacyapiset::*; +use self::winapi::um::winbase::*; +use self::winapi::um::winnt::*; use tokio_core::reactor::{PollEvented, Handle}; #[must_use = "futures do nothing unless polled"] @@ -49,7 +56,7 @@ impl fmt::Debug for Child { struct Waiting { rx: Fuse>, - wait_object: winapi::HANDLE, + wait_object: HANDLE, tx: *mut Option>, } @@ -105,13 +112,13 @@ impl Child { let ptr = Box::into_raw(Box::new(Some(tx))); let mut wait_object = 0 as *mut _; let rc = unsafe { - kernel32::RegisterWaitForSingleObject(&mut wait_object, - self.child.as_raw_handle(), - Some(callback), - ptr as *mut _, - winapi::INFINITE, - winapi::WT_EXECUTEINWAITTHREAD | - winapi::WT_EXECUTEONLYONCE) + RegisterWaitForSingleObject(&mut wait_object, + self.child.as_raw_handle(), + Some(callback), + ptr as *mut _, + INFINITE, + WT_EXECUTEINWAITTHREAD | + WT_EXECUTEONLYONCE) }; if rc == 0 { let err = io::Error::last_os_error(); @@ -130,8 +137,7 @@ impl Child { impl Drop for Waiting { fn drop(&mut self) { unsafe { - let rc = kernel32::UnregisterWaitEx(self.wait_object, - winapi::INVALID_HANDLE_VALUE); + let rc = UnregisterWaitEx(self.wait_object, INVALID_HANDLE_VALUE); if rc == 0 { panic!("failed to unregister: {}", io::Error::last_os_error()); } @@ -140,22 +146,22 @@ impl Drop for Waiting { } } -unsafe extern "system" fn callback(ptr: winapi::PVOID, - _timer_fired: winapi::BOOLEAN) { - let mut complete = &mut *(ptr as *mut Option>); +unsafe extern "system" fn callback(ptr: PVOID, + _timer_fired: BOOLEAN) { + let complete = &mut *(ptr as *mut Option>); drop(complete.take().unwrap().send(())); } pub fn try_wait(child: &process::Child) -> io::Result> { unsafe { - match kernel32::WaitForSingleObject(child.as_raw_handle(), 0) { - winapi::WAIT_OBJECT_0 => {} - winapi::WAIT_TIMEOUT => return Ok(None), + match WaitForSingleObject(child.as_raw_handle(), 0) { + WAIT_OBJECT_0 => {} + WAIT_TIMEOUT => return Ok(None), _ => return Err(io::Error::last_os_error()), } let mut status = 0; - let rc = kernel32::GetExitCodeProcess(child.as_raw_handle(), &mut status); - if rc == winapi::FALSE { + let rc = GetExitCodeProcess(child.as_raw_handle(), &mut status); + if rc == FALSE { Err(io::Error::last_os_error()) } else { Ok(Some(ExitStatus::from_raw(status))) diff --git a/tests/stdio.rs b/tests/stdio.rs index 79177131c..401e8082a 100644 --- a/tests/stdio.rs +++ b/tests/stdio.rs @@ -10,7 +10,7 @@ use std::io; use std::process::{Stdio, ExitStatus, Command}; use std::time::Duration; -use futures::future::{BoxFuture, Future}; +use futures::future::Future; use futures::stream::{self, Stream}; use tokio_io::io::{read_until, write_all, read_to_end}; use tokio_core::reactor::{Core, Timeout}; @@ -25,13 +25,13 @@ fn cat() -> Command { cmd } -fn feed_cat(mut cat: Child, n: usize) -> BoxFuture { +fn feed_cat(mut cat: Child, n: usize) -> Box> { let stdin = cat.stdin().take().unwrap(); let stdout = cat.stdout().take().unwrap(); debug!("starting to feed"); // Produce n lines on the child's stdout. - let numbers = stream::iter((0..n).into_iter().map(Ok)); + let numbers = stream::iter_ok(0..n); let write = numbers.fold(stdin, |stdin, i| { debug!("sending line {} to child", i); write_all(stdin, format!("line {}\n", i).into_bytes()).map(|p| p.0) @@ -40,7 +40,7 @@ fn feed_cat(mut cat: Child, n: usize) -> BoxFuture { // Try to read `n + 1` lines, ensuring the last one is empty // (i.e. EOF is reached after `n` lines. let reader = io::BufReader::new(stdout); - let expected_numbers = stream::iter((0..n + 1).map(Ok)); + let expected_numbers = stream::iter_ok(0..n + 1); let read = expected_numbers.fold((reader, 0), move |(reader, i), _| { let done = i >= n; debug!("starting read from child"); @@ -68,7 +68,7 @@ fn feed_cat(mut cat: Child, n: usize) -> BoxFuture { }); // Compose reading and writing concurrently. - write.join(read).and_then(|_| cat).boxed() + Box::new(write.join(read).and_then(|_| cat)) } #[test]