diff options
| author | bors <bors@rust-lang.org> | 2015-01-07 05:31:23 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-01-07 05:31:23 +0000 |
| commit | 9e4e524e0eb17c8f463e731f23b544003e8709c6 (patch) | |
| tree | 916024d35e08f0826c20654f629ec596b5cb1f14 /src/libstd/sys/windows | |
| parent | ea6f65c5f1a3f84e010d2cef02a0160804e9567a (diff) | |
| parent | a64000820f0fc32be4d7535a9a92418a434fa4ba (diff) | |
| download | rust-9e4e524e0eb17c8f463e731f23b544003e8709c6.tar.gz rust-9e4e524e0eb17c8f463e731f23b544003e8709c6.zip | |
auto merge of #20677 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/libstd/sys/windows')
| -rw-r--r-- | src/libstd/sys/windows/backtrace.rs | 3 | ||||
| -rw-r--r-- | src/libstd/sys/windows/c.rs | 69 | ||||
| -rw-r--r-- | src/libstd/sys/windows/os.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/windows/pipe.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/windows/process.rs | 7 | ||||
| -rw-r--r-- | src/libstd/sys/windows/thread.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/windows/tty.rs | 16 |
7 files changed, 70 insertions, 31 deletions
diff --git a/src/libstd/sys/windows/backtrace.rs b/src/libstd/sys/windows/backtrace.rs index 4ccecfd1f5f..eb76f13afe7 100644 --- a/src/libstd/sys/windows/backtrace.rs +++ b/src/libstd/sys/windows/backtrace.rs @@ -23,6 +23,7 @@ use dynamic_lib::DynamicLibrary; use ffi; +use core::ops::Index; use intrinsics; use io::{IoResult, Writer}; use libc; @@ -361,7 +362,7 @@ pub fn write(w: &mut Writer) -> IoResult<()> { let bytes = unsafe { ffi::c_str_to_bytes(&ptr) }; match str::from_utf8(bytes) { Ok(s) => try!(demangle(w, s)), - Err(..) => try!(w.write(bytes[..bytes.len()-1])), + Err(..) => try!(w.write(bytes.index(&(..(bytes.len()-1))))), } } try!(w.write(&['\n' as u8])); diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index 945c2e8e7d1..37ed32fa367 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -84,6 +84,32 @@ pub fn fd_set(set: &mut fd_set, s: libc::SOCKET) { set.fd_count += 1; } +pub type SHORT = libc::c_short; + +#[repr(C)] +pub struct COORD { + pub X: SHORT, + pub Y: SHORT, +} + +#[repr(C)] +pub struct SMALL_RECT { + pub Left: SHORT, + pub Top: SHORT, + pub Right: SHORT, + pub Bottom: SHORT, +} + +#[repr(C)] +pub struct CONSOLE_SCREEN_BUFFER_INFO { + pub dwSize: COORD, + pub dwCursorPosition: COORD, + pub wAttributes: libc::WORD, + pub srWindow: SMALL_RECT, + pub dwMaximumWindowSize: COORD, +} +pub type PCONSOLE_SCREEN_BUFFER_INFO = *mut CONSOLE_SCREEN_BUFFER_INFO; + #[link(name = "ws2_32")] extern "system" { pub fn WSAStartup(wVersionRequested: libc::WORD, @@ -170,7 +196,7 @@ pub mod compat { /// they are used to be passed to the real function if available. macro_rules! compat_fn { ($module:ident::$symbol:ident($($argname:ident: $argtype:ty),*) - -> $rettype:ty $fallback:block) => ( + -> $rettype:ty { $fallback:expr }) => ( #[inline(always)] pub unsafe fn $symbol($($argname: $argtype),*) -> $rettype { static mut ptr: extern "system" fn($($argname: $argtype),*) -> $rettype = thunk; @@ -185,14 +211,11 @@ pub mod compat { } } - extern "system" fn fallback($($argname: $argtype),*) -> $rettype $fallback + extern "system" fn fallback($($argname: $argtype),*) + -> $rettype { $fallback } ::intrinsics::atomic_load_relaxed(&ptr)($($argname),*) } - ); - - ($module:ident::$symbol:ident($($argname:ident: $argtype:ty),*) $fallback:block) => ( - compat_fn!($module::$symbol($($argname: $argtype),*) -> () $fallback) ) } @@ -210,20 +233,22 @@ pub mod compat { fn SetLastError(dwErrCode: DWORD); } - compat_fn! { kernel32::CreateSymbolicLinkW(_lpSymlinkFileName: LPCWSTR, - _lpTargetFileName: LPCWSTR, - _dwFlags: DWORD) -> BOOLEAN { - unsafe { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); } - 0 - } } - - compat_fn! { kernel32::GetFinalPathNameByHandleW(_hFile: HANDLE, - _lpszFilePath: LPCWSTR, - _cchFilePath: DWORD, - _dwFlags: DWORD) -> DWORD { - unsafe { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); } - 0 - } } + compat_fn! { + kernel32::CreateSymbolicLinkW(_lpSymlinkFileName: LPCWSTR, + _lpTargetFileName: LPCWSTR, + _dwFlags: DWORD) -> BOOLEAN { + unsafe { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 } + } + } + + compat_fn! { + kernel32::GetFinalPathNameByHandleW(_hFile: HANDLE, + _lpszFilePath: LPCWSTR, + _cchFilePath: DWORD, + _dwFlags: DWORD) -> DWORD { + unsafe { SetLastError(ERROR_CALL_NOT_IMPLEMENTED as DWORD); 0 } + } + } } } @@ -246,4 +271,8 @@ extern "system" { pub fn SetConsoleMode(hConsoleHandle: libc::HANDLE, lpMode: libc::DWORD) -> libc::BOOL; + pub fn GetConsoleScreenBufferInfo( + hConsoleOutput: libc::HANDLE, + lpConsoleScreenBufferInfo: PCONSOLE_SCREEN_BUFFER_INFO, + ) -> libc::BOOL; } diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index dfdee0e0385..fcde5c01080 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -36,7 +36,7 @@ const BUF_BYTES : uint = 2048u; pub fn truncate_utf16_at_nul<'a>(v: &'a [u16]) -> &'a [u16] { match v.iter().position(|c| *c == 0) { // don't include the 0 - Some(i) => v[..i], + Some(i) => v.index(&(0..i)), None => v } } diff --git a/src/libstd/sys/windows/pipe.rs b/src/libstd/sys/windows/pipe.rs index 9996909f2f5..016757ef63e 100644 --- a/src/libstd/sys/windows/pipe.rs +++ b/src/libstd/sys/windows/pipe.rs @@ -453,7 +453,7 @@ impl UnixStream { } let ret = unsafe { libc::WriteFile(self.handle(), - buf[offset..].as_ptr() as libc::LPVOID, + buf.index(&(offset..)).as_ptr() as libc::LPVOID, (buf.len() - offset) as libc::DWORD, &mut bytes_written, &mut overlapped) diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index 7b667416b17..8e1f169b5cd 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -25,6 +25,8 @@ use path::BytesContainer; use ptr; use str; use sys::fs::FileDesc; +use sync::{StaticMutex, MUTEX_INIT}; + use sys::fs; use sys::{self, retry, c, wouldblock, set_nonblocking, ms_to_timeval, timer}; use sys_common::helper_thread::Helper; @@ -32,6 +34,10 @@ use sys_common::{AsInner, mkerr_libc, timeout}; pub use sys_common::ProcessConfig; +// `CreateProcess` is racy! +// http://support.microsoft.com/kb/315939 +static CREATE_PROCESS_LOCK: StaticMutex = MUTEX_INIT; + /// A value representing a child process. /// /// The lifetime of this value is linked to the lifetime of the actual @@ -224,6 +230,7 @@ impl Process { with_dirp(cfg.cwd(), |dirp| { let mut cmd_str: Vec<u16> = cmd_str.utf16_units().collect(); cmd_str.push(0); + let _lock = CREATE_PROCESS_LOCK.lock().unwrap(); let created = CreateProcessW(ptr::null(), cmd_str.as_mut_ptr(), ptr::null_mut(), diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index 4498f56c00a..30707488b30 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -62,7 +62,7 @@ pub unsafe fn create(stack: uint, p: Thunk) -> rust_thread { if ret as uint == 0 { // be sure to not leak the closure let _p: Box<Thunk> = mem::transmute(arg); - panic!("failed to spawn native thread: {}", ret); + panic!("failed to spawn native thread: {:?}", ret); } return ret; } diff --git a/src/libstd/sys/windows/tty.rs b/src/libstd/sys/windows/tty.rs index 4305f7743b5..f9e1f0d3ed0 100644 --- a/src/libstd/sys/windows/tty.rs +++ b/src/libstd/sys/windows/tty.rs @@ -32,13 +32,15 @@ use iter::repeat; use libc::types::os::arch::extra::LPCVOID; use libc::{c_int, HANDLE, LPDWORD, DWORD, LPVOID}; use libc::{get_osfhandle, CloseHandle}; +use mem; use ptr; use str::from_utf8; use super::c::{ENABLE_ECHO_INPUT, ENABLE_EXTENDED_FLAGS}; use super::c::{ENABLE_INSERT_MODE, ENABLE_LINE_INPUT}; use super::c::{ENABLE_PROCESSED_INPUT, ENABLE_QUICK_EDIT_MODE}; -use super::c::{ERROR_ILLEGAL_CHARACTER}; +use super::c::{ERROR_ILLEGAL_CHARACTER, CONSOLE_SCREEN_BUFFER_INFO}; use super::c::{ReadConsoleW, WriteConsoleW, GetConsoleMode, SetConsoleMode}; +use super::c::{GetConsoleScreenBufferInfo}; fn invalid_encoding() -> IoError { IoError { @@ -146,12 +148,12 @@ impl TTY { } pub fn get_winsize(&mut self) -> IoResult<(int, int)> { - // FIXME - // Get console buffer via CreateFile with CONOUT$ - // Make a CONSOLE_SCREEN_BUFFER_INFO - // Call GetConsoleScreenBufferInfo - // Maybe call GetLargestConsoleWindowSize instead? - Err(super::unimpl()) + let mut info: CONSOLE_SCREEN_BUFFER_INFO = unsafe { mem::zeroed() }; + match unsafe { GetConsoleScreenBufferInfo(self.handle, &mut info as *mut _) } { + 0 => Err(super::last_error()), + _ => Ok(((info.srWindow.Right + 1 - info.srWindow.Left) as int, + (info.srWindow.Bottom + 1 - info.srWindow.Top) as int)), + } } // Let us magically declare this as a TTY |
