about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-01-07 05:31:23 +0000
committerbors <bors@rust-lang.org>2015-01-07 05:31:23 +0000
commit9e4e524e0eb17c8f463e731f23b544003e8709c6 (patch)
tree916024d35e08f0826c20654f629ec596b5cb1f14 /src/libstd/sys
parentea6f65c5f1a3f84e010d2cef02a0160804e9567a (diff)
parenta64000820f0fc32be4d7535a9a92418a434fa4ba (diff)
downloadrust-9e4e524e0eb17c8f463e731f23b544003e8709c6.tar.gz
rust-9e4e524e0eb17c8f463e731f23b544003e8709c6.zip
auto merge of #20677 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/common/backtrace.rs28
-rw-r--r--src/libstd/sys/common/helper_thread.rs2
-rw-r--r--src/libstd/sys/common/mutex.rs2
-rw-r--r--src/libstd/sys/common/net.rs2
-rw-r--r--src/libstd/sys/unix/backtrace.rs2
-rw-r--r--src/libstd/sys/unix/c.rs8
-rw-r--r--src/libstd/sys/unix/fs.rs2
-rw-r--r--src/libstd/sys/unix/mutex.rs2
-rw-r--r--src/libstd/sys/unix/process.rs14
-rw-r--r--src/libstd/sys/unix/thread_local.rs12
-rw-r--r--src/libstd/sys/windows/backtrace.rs3
-rw-r--r--src/libstd/sys/windows/c.rs69
-rw-r--r--src/libstd/sys/windows/os.rs2
-rw-r--r--src/libstd/sys/windows/pipe.rs2
-rw-r--r--src/libstd/sys/windows/process.rs7
-rw-r--r--src/libstd/sys/windows/thread.rs2
-rw-r--r--src/libstd/sys/windows/tty.rs16
17 files changed, 111 insertions, 64 deletions
diff --git a/src/libstd/sys/common/backtrace.rs b/src/libstd/sys/common/backtrace.rs
index d4039fd96ff..be44aa99f49 100644
--- a/src/libstd/sys/common/backtrace.rs
+++ b/src/libstd/sys/common/backtrace.rs
@@ -88,7 +88,7 @@ pub fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> {
             while rest.len() > 0 {
                 if rest.starts_with("$") {
                     macro_rules! demangle {
-                        ($($pat:expr => $demangled:expr),*) => ({
+                        ($($pat:expr, => $demangled:expr),*) => ({
                             $(if rest.starts_with($pat) {
                                 try!(writer.write_str($demangled));
                                 rest = rest.slice_from($pat.len());
@@ -103,22 +103,22 @@ pub fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> {
 
                     // see src/librustc/back/link.rs for these mappings
                     demangle! (
-                        "$SP$" => "@",
-                        "$UP$" => "Box",
-                        "$RP$" => "*",
-                        "$BP$" => "&",
-                        "$LT$" => "<",
-                        "$GT$" => ">",
-                        "$LP$" => "(",
-                        "$RP$" => ")",
-                        "$C$"  => ",",
+                        "$SP$", => "@",
+                        "$UP$", => "Box",
+                        "$RP$", => "*",
+                        "$BP$", => "&",
+                        "$LT$", => "<",
+                        "$GT$", => ">",
+                        "$LP$", => "(",
+                        "$RP$", => ")",
+                        "$C$", => ",",
 
                         // in theory we can demangle any Unicode code point, but
                         // for simplicity we just catch the common ones.
-                        "$u{20}" => " ",
-                        "$u{27}" => "'",
-                        "$u{5b}" => "[",
-                        "$u{5d}" => "]"
+                        "$u{20}", => " ",
+                        "$u{27}", => "'",
+                        "$u{5b}", => "[",
+                        "$u{5d}", => "]"
                     )
                 } else {
                     let idx = match rest.find('$') {
diff --git a/src/libstd/sys/common/helper_thread.rs b/src/libstd/sys/common/helper_thread.rs
index bdf1bf3dfd0..f940b6ed368 100644
--- a/src/libstd/sys/common/helper_thread.rs
+++ b/src/libstd/sys/common/helper_thread.rs
@@ -99,7 +99,7 @@ impl<M: Send> Helper<M> {
                     let _g = self.lock.lock().unwrap();
                     *self.shutdown.get() = true;
                     self.cond.notify_one()
-                }).detach();
+                });
 
                 rt::at_exit(move|:| { self.shutdown() });
                 *self.initialized.get() = true;
diff --git a/src/libstd/sys/common/mutex.rs b/src/libstd/sys/common/mutex.rs
index 567c26956ef..9aea0fb3b31 100644
--- a/src/libstd/sys/common/mutex.rs
+++ b/src/libstd/sys/common/mutex.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use kinds::Sync;
+use marker::Sync;
 use sys::mutex as imp;
 
 /// An OS-based mutual exclusion lock.
diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs
index 4cf891ac498..902942d7244 100644
--- a/src/libstd/sys/common/net.rs
+++ b/src/libstd/sys/common/net.rs
@@ -469,7 +469,7 @@ pub fn write<T, L, W>(fd: sock_t,
             // Also as with read(), we use MSG_DONTWAIT to guard ourselves
             // against unforeseen circumstances.
             let _guard = lock();
-            let ptr = buf[written..].as_ptr();
+            let ptr = buf.index(&(written..)).as_ptr();
             let len = buf.len() - written;
             match retry(|| write(deadline.is_some(), ptr, len)) {
                 -1 if wouldblock() => {}
diff --git a/src/libstd/sys/unix/backtrace.rs b/src/libstd/sys/unix/backtrace.rs
index ca268a8f27f..7164931c55a 100644
--- a/src/libstd/sys/unix/backtrace.rs
+++ b/src/libstd/sys/unix/backtrace.rs
@@ -370,7 +370,7 @@ fn print(w: &mut Writer, idx: int, addr: *mut libc::c_void) -> IoResult<()> {
 // Finally, after all that work above, we can emit a symbol.
 fn output(w: &mut Writer, idx: int, addr: *mut libc::c_void,
           s: Option<&[u8]>) -> IoResult<()> {
-    try!(write!(w, "  {:2}: {:2$} - ", idx, addr, HEX_WIDTH));
+    try!(write!(w, "  {:2}: {:2$?} - ", idx, addr, HEX_WIDTH));
     match s.and_then(|s| str::from_utf8(s).ok()) {
         Some(string) => try!(demangle(w, string)),
         None => try!(write!(w, "<unknown>")),
diff --git a/src/libstd/sys/unix/c.rs b/src/libstd/sys/unix/c.rs
index ca419d1c7f4..cc661877bc0 100644
--- a/src/libstd/sys/unix/c.rs
+++ b/src/libstd/sys/unix/c.rs
@@ -165,8 +165,8 @@ mod signal {
         sa_restorer: *mut libc::c_void,
     }
 
-    unsafe impl ::kinds::Send for sigaction { }
-    unsafe impl ::kinds::Sync for sigaction { }
+    unsafe impl ::marker::Send for sigaction { }
+    unsafe impl ::marker::Sync for sigaction { }
 
     #[repr(C)]
     #[cfg(target_word_size = "32")]
@@ -217,8 +217,8 @@ mod signal {
         sa_resv: [libc::c_int; 1],
     }
 
-    unsafe impl ::kinds::Send for sigaction { }
-    unsafe impl ::kinds::Sync for sigaction { }
+    unsafe impl ::marker::Send for sigaction { }
+    unsafe impl ::marker::Sync for sigaction { }
 
     #[repr(C)]
     pub struct sigset_t {
diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs
index 1ad775517bb..c53f9d22790 100644
--- a/src/libstd/sys/unix/fs.rs
+++ b/src/libstd/sys/unix/fs.rs
@@ -381,7 +381,7 @@ mod tests {
                 assert_eq!(buf[2], 's' as u8);
                 assert_eq!(buf[3], 't' as u8);
             }
-            r => panic!("invalid read: {}", r),
+            r => panic!("invalid read: {:?}", r),
         }
 
         assert!(writer.read(&mut buf).is_err());
diff --git a/src/libstd/sys/unix/mutex.rs b/src/libstd/sys/unix/mutex.rs
index 81f8659d6ae..ada8a7f2349 100644
--- a/src/libstd/sys/unix/mutex.rs
+++ b/src/libstd/sys/unix/mutex.rs
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 use cell::UnsafeCell;
-use kinds::Sync;
+use marker::Sync;
 use sys::sync as ffi;
 use sys_common::mutex;
 
diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs
index 5bc6b0c703b..1357bbdd5a3 100644
--- a/src/libstd/sys/unix/process.rs
+++ b/src/libstd/sys/unix/process.rs
@@ -125,7 +125,7 @@ impl Process {
                     return match input.read(&mut bytes) {
                         Ok(8) => {
                             assert!(combine(CLOEXEC_MSG_FOOTER) == combine(bytes.slice(4, 8)),
-                                "Validation on the CLOEXEC pipe failed: {}", bytes);
+                                "Validation on the CLOEXEC pipe failed: {:?}", bytes);
                             let errno = combine(bytes.slice(0, 4));
                             assert!(p.wait(0).is_ok(), "wait(0) should either return Ok or panic");
                             Err(super::decode_error(errno))
@@ -133,7 +133,7 @@ impl Process {
                         Err(ref e) if e.kind == EndOfFile => Ok(p),
                         Err(e) => {
                             assert!(p.wait(0).is_ok(), "wait(0) should either return Ok or panic");
-                            panic!("the CLOEXEC pipe failed: {}", e)
+                            panic!("the CLOEXEC pipe failed: {:?}", e)
                         },
                         Ok(..) => { // pipe I/O up to PIPE_BUF bytes should be atomic
                             assert!(p.wait(0).is_ok(), "wait(0) should either return Ok or panic");
@@ -285,7 +285,7 @@ impl Process {
         let mut status = 0 as c_int;
         if deadline == 0 {
             return match retry(|| unsafe { c::waitpid(self.pid, &mut status, 0) }) {
-                -1 => panic!("unknown waitpid error: {}", super::last_error()),
+                -1 => panic!("unknown waitpid error: {:?}", super::last_error()),
                 _ => Ok(translate_status(status)),
             }
         }
@@ -410,7 +410,7 @@ impl Process {
                         continue
                     }
 
-                    n => panic!("error in select {} ({})", os::errno(), n),
+                    n => panic!("error in select {:?} ({:?})", os::errno(), n),
                 }
 
                 // Process any pending messages
@@ -491,7 +491,7 @@ impl Process {
                     n if n > 0 => { ret = true; }
                     0 => return true,
                     -1 if wouldblock() => return ret,
-                    n => panic!("bad read {} ({})", os::last_os_error(), n),
+                    n => panic!("bad read {:?} ({:?})", os::last_os_error(), n),
                 }
             }
         }
@@ -514,7 +514,7 @@ impl Process {
             } {
                 1 => {}
                 -1 if wouldblock() => {} // see above comments
-                n => panic!("bad error on write fd: {} {}", n, os::errno()),
+                n => panic!("bad error on write fd: {:?} {:?}", n, os::errno()),
             }
         }
     }
@@ -526,7 +526,7 @@ impl Process {
         }) {
             n if n == self.pid => Some(translate_status(status)),
             0 => None,
-            n => panic!("unknown waitpid error `{}`: {}", n,
+            n => panic!("unknown waitpid error `{:?}`: {:?}", n,
                        super::last_error()),
         }
     }
diff --git a/src/libstd/sys/unix/thread_local.rs b/src/libstd/sys/unix/thread_local.rs
index e507377a8fc..ea1e9c261fe 100644
--- a/src/libstd/sys/unix/thread_local.rs
+++ b/src/libstd/sys/unix/thread_local.rs
@@ -37,10 +37,18 @@ pub unsafe fn destroy(key: Key) {
     debug_assert_eq!(r, 0);
 }
 
-#[cfg(target_os = "macos")]
+#[cfg(any(target_os = "macos",
+          target_os = "ios"))]
 type pthread_key_t = ::libc::c_ulong;
 
-#[cfg(not(target_os = "macos"))]
+#[cfg(any(target_os = "freebsd",
+          target_os = "dragonfly"))]
+type pthread_key_t = ::libc::c_int;
+
+#[cfg(not(any(target_os = "macos",
+              target_os = "ios",
+              target_os = "freebsd",
+              target_os = "dragonfly")))]
 type pthread_key_t = ::libc::c_uint;
 
 extern {
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