diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index ce14967090e0fb40c8208fc65b9212722873c189..a05d6752073af4f7139445d4ab5550eab938edc6 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -273,13 +273,14 @@ pub mod thread; pub mod sync; +#[macro_use] +#[path = "sys/common/mod.rs"] mod sys_common; + #[cfg(unix)] #[path = "sys/unix/mod.rs"] mod sys; #[cfg(windows)] #[path = "sys/windows/mod.rs"] mod sys; -#[path = "sys/common/mod.rs"] mod sys_common; - pub mod rt; mod panicking; diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index fe32a51e81c9ac323cab3852cefd967634658e79..90cc189b9a0f0a3f8c4e93eb4945f9e740263dbb 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -108,9 +108,7 @@ fn lang_start(main: *const u8, argc: int, argv: *const *const u8) -> int { // but we just do this to name the main thread and to give it correct // info about the stack bounds. let thread: Thread = NewThread::new(Some("
".to_string())); - thread_info::set((my_stack_bottom, my_stack_top), - sys::thread::guard::main(), - thread); + thread_info::set(sys::thread::guard::main(), thread); // By default, some platforms will send a *signal* when a EPIPE error // would otherwise be delivered. This runtime doesn't install a SIGPIPE diff --git a/src/libstd/sys/common/helper_thread.rs b/src/libstd/sys/common/helper_thread.rs index 5faaa928ee973893d345e29aab91b8446f1947a1..3b5fd5a57146010e08ed7e8a13f2d5a7bf327803 100644 --- a/src/libstd/sys/common/helper_thread.rs +++ b/src/libstd/sys/common/helper_thread.rs @@ -70,6 +70,17 @@ unsafe impl Sync for Helper { } unsafe impl Send for RaceBox {} unsafe impl Sync for RaceBox {} +macro_rules! helper_init { (static $name:ident: Helper<$m:ty>) => ( + static $name: Helper<$m> = Helper { + lock: ::sync::MUTEX_INIT, + cond: ::sync::CONDVAR_INIT, + chan: ::cell::UnsafeCell { value: 0 as *mut Sender<$m> }, + signal: ::cell::UnsafeCell { value: 0 }, + initialized: ::cell::UnsafeCell { value: false }, + shutdown: ::cell::UnsafeCell { value: false }, + }; +) } + impl Helper { /// Lazily boots a helper thread, becoming a no-op if the helper has already /// been spawned. diff --git a/src/libstd/sys/common/mod.rs b/src/libstd/sys/common/mod.rs index 5054f72ea98791d5931d66f917ccd2e87fd71604..328c536e18879d91e054ef209cb51c5972a34633 100644 --- a/src/libstd/sys/common/mod.rs +++ b/src/libstd/sys/common/mod.rs @@ -9,7 +9,6 @@ // except according to those terms. #![allow(missing_docs)] -#![allow(dead_code)] use old_io::{self, IoError, IoResult}; use prelude::v1::*; @@ -19,9 +18,10 @@ use old_path::BytesContainer; use collections; +#[macro_use] pub mod helper_thread; + pub mod backtrace; pub mod condvar; -pub mod helper_thread; pub mod mutex; pub mod net; pub mod net2; diff --git a/src/libstd/sys/common/net.rs b/src/libstd/sys/common/net.rs index 344645dfc1a159904c59a03698103a3b2a5b9a31..96b72b42e5400bb20af2c494a0f3cec93c0e04ed 100644 --- a/src/libstd/sys/common/net.rs +++ b/src/libstd/sys/common/net.rs @@ -26,7 +26,9 @@ use sys::{self, retry, c, sock_t, last_error, last_net_error, last_gai_error, close_sock, wrlen, msglen_t, os, wouldblock, set_nonblocking, timer, ms_to_timeval, decode_error_detailed}; -use sync::{Arc, Mutex, MutexGuard}; +use sync::{Arc, Mutex}; +#[cfg(not(target_os = "linux"))] +use sync::MutexGuard; use sys_common::{self, keep_going, short_write, timeout}; use cmp; use old_io; @@ -620,11 +622,13 @@ impl Drop for Inner { fn drop(&mut self) { unsafe { close_sock(self.fd); } } } +#[cfg(not(target_os = "linux"))] pub struct Guard<'a> { pub fd: sock_t, pub guard: MutexGuard<'a, ()>, } +#[cfg(not(target_os = "linux"))] #[unsafe_destructor] impl<'a> Drop for Guard<'a> { fn drop(&mut self) { diff --git a/src/libstd/sys/common/net2.rs b/src/libstd/sys/common/net2.rs index 713f79c5d0814d29b64d0936779ce547cd3ce29c..af5b49a42392b4a6177fa38567d4d29c4cedbee5 100644 --- a/src/libstd/sys/common/net2.rs +++ b/src/libstd/sys/common/net2.rs @@ -15,7 +15,6 @@ use libc::{self, c_int, c_char, c_void, socklen_t}; use mem; use net::{IpAddr, SocketAddr, Shutdown}; -use num::Int; use sys::c; use sys::net::{cvt, cvt_r, cvt_gai, Socket, init, wrlen_t}; use sys_common::{AsInner, FromInner, IntoInner}; @@ -24,9 +23,6 @@ // sockaddr and misc bindings //////////////////////////////////////////////////////////////////////////////// -fn hton(i: I) -> I { i.to_be() } -fn ntoh(i: I) -> I { Int::from_be(i) } - fn setsockopt(sock: &Socket, opt: c_int, val: c_int, payload: T) -> io::Result<()> { unsafe { @@ -39,7 +35,7 @@ fn setsockopt(sock: &Socket, opt: c_int, val: c_int, #[allow(dead_code)] fn getsockopt(sock: &Socket, opt: c_int, - val: c_int) -> io::Result { + val: c_int) -> io::Result { unsafe { let mut slot: T = mem::zeroed(); let mut len = mem::size_of::() as socklen_t; diff --git a/src/libstd/sys/common/stack.rs b/src/libstd/sys/common/stack.rs index 5ebc851e194efa28da8fc669fa4ebb4ebc1d5211..8c428275ccf6d782c9a4314eaf75814beb45481a 100644 --- a/src/libstd/sys/common/stack.rs +++ b/src/libstd/sys/common/stack.rs @@ -121,37 +121,6 @@ pub unsafe fn record_os_managed_stack_bounds(stack_lo: uint, _stack_hi: uint) { record_sp_limit(stack_lo + RED_ZONE); } -#[inline(always)] -pub unsafe fn record_rust_managed_stack_bounds(stack_lo: uint, stack_hi: uint) { - // When the old runtime had segmented stacks, it used a calculation that was - // "limit + RED_ZONE + FUDGE". The red zone was for things like dynamic - // symbol resolution, llvm function calls, etc. In theory this red zone - // value is 0, but it matters far less when we have gigantic stacks because - // we don't need to be so exact about our stack budget. The "fudge factor" - // was because LLVM doesn't emit a stack check for functions < 256 bytes in - // size. Again though, we have giant stacks, so we round all these - // calculations up to the nice round number of 20k. - record_sp_limit(stack_lo + RED_ZONE); - - return target_record_stack_bounds(stack_lo, stack_hi); - - #[cfg(not(windows))] #[inline(always)] - unsafe fn target_record_stack_bounds(_stack_lo: uint, _stack_hi: uint) {} - - #[cfg(all(windows, target_arch = "x86"))] #[inline(always)] - unsafe fn target_record_stack_bounds(stack_lo: uint, stack_hi: uint) { - // stack range is at TIB: %fs:0x04 (top) and %fs:0x08 (bottom) - asm!("mov $0, %fs:0x04" :: "r"(stack_hi) :: "volatile"); - asm!("mov $0, %fs:0x08" :: "r"(stack_lo) :: "volatile"); - } - #[cfg(all(windows, target_arch = "x86_64"))] #[inline(always)] - unsafe fn target_record_stack_bounds(stack_lo: uint, stack_hi: uint) { - // stack range is at TIB: %gs:0x08 (top) and %gs:0x10 (bottom) - asm!("mov $0, %gs:0x08" :: "r"(stack_hi) :: "volatile"); - asm!("mov $0, %gs:0x10" :: "r"(stack_lo) :: "volatile"); - } -} - /// Records the current limit of the stack as specified by `end`. /// /// This is stored in an OS-dependent location, likely inside of the thread diff --git a/src/libstd/sys/common/thread_info.rs b/src/libstd/sys/common/thread_info.rs index 65c706033f213034c2923f4a78b1c8ce859fe16e..e4985e703ba7645243ec3efd7e41a407eefa47c3 100644 --- a/src/libstd/sys/common/thread_info.rs +++ b/src/libstd/sys/common/thread_info.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![allow(dead_code)] // stack_guard isn't used right now on all platforms + use core::prelude::*; use cell::RefCell; @@ -16,10 +18,6 @@ use thread_local::State; struct ThreadInfo { - // This field holds the known bounds of the stack in (lo, hi) - // form. Not all threads necessarily know their precise bounds, - // hence this is optional. - stack_bounds: (uint, uint), stack_guard: uint, thread: Thread, } @@ -36,7 +34,6 @@ fn with(f: F) -> R where F: FnOnce(&mut ThreadInfo) -> R { THREAD_INFO.with(move |c| { if c.borrow().is_none() { *c.borrow_mut() = Some(ThreadInfo { - stack_bounds: (0, 0), stack_guard: 0, thread: NewThread::new(None), }) @@ -54,10 +51,9 @@ pub fn stack_guard() -> uint { ThreadInfo::with(|info| info.stack_guard) } -pub fn set(stack_bounds: (uint, uint), stack_guard: uint, thread: Thread) { +pub fn set(stack_guard: uint, thread: Thread) { THREAD_INFO.with(|c| assert!(c.borrow().is_none())); THREAD_INFO.with(move |c| *c.borrow_mut() = Some(ThreadInfo{ - stack_bounds: stack_bounds, stack_guard: stack_guard, thread: thread, })); diff --git a/src/libstd/sys/common/thread_local.rs b/src/libstd/sys/common/thread_local.rs index 279362416392b767c10b5f8334cddcf6470347a4..ecd047710bb96c7d3bcdf2bbb3ca698c04acbf75 100644 --- a/src/libstd/sys/common/thread_local.rs +++ b/src/libstd/sys/common/thread_local.rs @@ -56,6 +56,7 @@ #![allow(non_camel_case_types)] #![unstable(feature = "thread_local_internals")] +#![allow(dead_code)] // sys isn't exported yet use prelude::v1::*; diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index 7a02df23b19c5659a287d06dceab3c16a7b23a6d..6c17f9910ac88367a005cda453836905e14a2376 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -21,6 +21,10 @@ //! nor can it decode WTF-8 from arbitrary bytes. //! WTF-8 strings can be obtained from UTF-8, UTF-16, or code points. +// this module is imported from @SimonSapin's repo and has tons of dead code on +// unix (it's mostly used on windows), so don't worry about dead code here. +#![allow(dead_code)] + use core::prelude::*; use core::char::{encode_utf8_raw, encode_utf16_raw}; diff --git a/src/libstd/sys/unix/backtrace.rs b/src/libstd/sys/unix/backtrace.rs index e7ac6e2cd011c865a44b31653108766e79da8a93..24d709e9928b66336a694ee4be4f9fbe879e5a16 100644 --- a/src/libstd/sys/unix/backtrace.rs +++ b/src/libstd/sys/unix/backtrace.rs @@ -84,9 +84,8 @@ /// all unix platforms we support right now, so it at least gets the job done. use prelude::v1::*; -use os::unix::prelude::*; -use ffi::{CStr, AsOsStr}; +use ffi::CStr; use old_io::IoResult; use libc; use mem; @@ -151,7 +150,7 @@ struct Context<'a> { // I/O done here is blocking I/O, not green I/O, so we don't have to // worry about this being a native vs green mutex. static LOCK: StaticMutex = MUTEX_INIT; - let _g = unsafe { LOCK.lock() }; + let _g = LOCK.lock(); try!(writeln!(w, "stack backtrace:")); @@ -253,6 +252,8 @@ fn dladdr(addr: *const libc::c_void, fn print(w: &mut Writer, idx: int, addr: *mut libc::c_void, symaddr: *mut libc::c_void) -> IoResult<()> { use env; + use ffi::AsOsStr; + use os::unix::prelude::*; use ptr; //////////////////////////////////////////////////////////////////////// diff --git a/src/libstd/sys/unix/fd.rs b/src/libstd/sys/unix/fd.rs index 327d117823ee37e1360164a678ad4a71fabb5b6b..f7c57c3f5e53747992ef77809b574dc02ae0a1a2 100644 --- a/src/libstd/sys/unix/fd.rs +++ b/src/libstd/sys/unix/fd.rs @@ -9,7 +9,6 @@ // except according to those terms. use core::prelude::*; -use io::prelude::*; use io; use libc::{self, c_int, size_t, c_void}; diff --git a/src/libstd/sys/unix/fs2.rs b/src/libstd/sys/unix/fs2.rs index 72e0b8dd36c66151eab686d374a2f44f928c42d3..ea74aab3331ae5e49c12b76e6f89b999de9ace63 100644 --- a/src/libstd/sys/unix/fs2.rs +++ b/src/libstd/sys/unix/fs2.rs @@ -13,8 +13,8 @@ use os::unix::prelude::*; use ffi::{CString, CStr, OsString, AsOsStr, OsStr}; -use io::{self, Error, Seek, SeekFrom}; -use libc::{self, c_int, c_void, size_t, off_t, c_char, mode_t}; +use io::{self, Error, SeekFrom}; +use libc::{self, c_int, size_t, off_t, c_char, mode_t}; use mem; use path::{Path, PathBuf}; use ptr; @@ -324,14 +324,6 @@ pub fn rmdir(p: &Path) -> io::Result<()> { Ok(()) } -pub fn chown(p: &Path, uid: isize, gid: isize) -> io::Result<()> { - let p = try!(cstr(p)); - try!(cvt_r(|| unsafe { - libc::chown(p.as_ptr(), uid as libc::uid_t, gid as libc::gid_t) - })); - Ok(()) -} - pub fn readlink(p: &Path) -> io::Result { let c_path = try!(cstr(p)); let p = c_path.as_ptr(); diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index 80bfd57e933c42af7cb23da3a33006a8f553c59f..865ea9872792b7e1ff66b7dca645527b00889552 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -10,10 +10,6 @@ #![allow(missing_docs)] #![allow(non_camel_case_types)] -#![allow(unused_imports)] -#![allow(dead_code)] -#![allow(unused_unsafe)] -#![allow(unused_mut)] use prelude::v1::*; @@ -21,22 +17,10 @@ use io::{self, ErrorKind}; use libc; use num::{Int, SignedInt}; -use num; -use old_io::{self, IoResult, IoError}; +use old_io::{self, IoError}; use str; use sys_common::mkerr_libc; -macro_rules! helper_init { (static $name:ident: Helper<$m:ty>) => ( - static $name: Helper<$m> = Helper { - lock: ::sync::MUTEX_INIT, - cond: ::sync::CONDVAR_INIT, - chan: ::cell::UnsafeCell { value: 0 as *mut Sender<$m> }, - signal: ::cell::UnsafeCell { value: 0 }, - initialized: ::cell::UnsafeCell { value: false }, - shutdown: ::cell::UnsafeCell { value: false }, - }; -) } - pub mod backtrace; pub mod c; pub mod condvar; diff --git a/src/libstd/sys/unix/mutex.rs b/src/libstd/sys/unix/mutex.rs index f87c0339533dfb672273d881cbf9b7623e9b16c2..1c0ce2938040dceee727939abeff47242bda5f19 100644 --- a/src/libstd/sys/unix/mutex.rs +++ b/src/libstd/sys/unix/mutex.rs @@ -12,7 +12,6 @@ use cell::UnsafeCell; use sys::sync as ffi; -use sys_common::mutex; pub struct Mutex { inner: UnsafeCell } @@ -28,6 +27,7 @@ pub unsafe fn raw(m: &Mutex) -> *mut ffi::pthread_mutex_t { unsafe impl Send for Mutex {} unsafe impl Sync for Mutex {} +#[allow(dead_code)] // sys isn't exported yet impl Mutex { #[inline] pub unsafe fn new() -> Mutex { diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index a38c7a30b757840983f0e523db3aae11f827af0a..3266da5eb31cb8a283a7a75e875f3bf28cedb72f 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -10,6 +10,8 @@ //! Implementation of `std::os` functionality for unix systems +#![allow(unused_imports)] // lots of cfg code here + use prelude::v1::*; use os::unix::*; @@ -482,7 +484,7 @@ unsafe fn fallback() -> Option { None } #[cfg(not(any(target_os = "android", target_os = "ios")))] unsafe fn fallback() -> Option { - let mut amt = match libc::sysconf(c::_SC_GETPW_R_SIZE_MAX) { + let amt = match libc::sysconf(c::_SC_GETPW_R_SIZE_MAX) { n if n < 0 => 512 as usize, n => n as usize, }; diff --git a/src/libstd/sys/unix/os_str.rs b/src/libstd/sys/unix/os_str.rs index c8ac524876b5bdfd651ee2d976604f6ea2a90ca8..89ab3e1981be4bf35da3402bcceb9fb8fcf49503 100644 --- a/src/libstd/sys/unix/os_str.rs +++ b/src/libstd/sys/unix/os_str.rs @@ -70,7 +70,7 @@ fn from_u8_slice(s: &[u8]) -> &Slice { } pub fn from_str(s: &str) -> &Slice { - unsafe { mem::transmute(s.as_bytes()) } + Slice::from_u8_slice(s.as_bytes()) } pub fn to_str(&self) -> Option<&str> { diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs index 33863d31437f3f7f68d4a6e2aaf4d1907cbc3d75..9cddfca69cbdd048752c620cc81e64f242e87b9c 100644 --- a/src/libstd/sys/unix/pipe.rs +++ b/src/libstd/sys/unix/pipe.rs @@ -143,7 +143,7 @@ fn lock_nonblocking(&self) {} fn lock_nonblocking<'a>(&'a self) -> Guard<'a> { let ret = Guard { fd: self.fd(), - guard: unsafe { self.inner.lock.lock().unwrap() }, + guard: self.inner.lock.lock().unwrap(), }; set_nonblocking(self.fd(), true); ret diff --git a/src/libstd/sys/unix/process.rs b/src/libstd/sys/unix/process.rs index 62a1799de94c938fe0c3ef9f94ef6632323bff86..d5469eb82efd1933f93fdfcba24ff51e75525719 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -17,7 +17,7 @@ use ffi::CString; use hash::Hash; use old_io::process::{ProcessExit, ExitStatus, ExitSignal}; -use old_io::{self, IoResult, IoError, EndOfFile}; +use old_io::{IoResult, EndOfFile}; use libc::{self, pid_t, c_void, c_int}; use mem; use os; @@ -33,12 +33,6 @@ helper_init! { static HELPER: Helper } -/// Unix-specific extensions to the Command builder -pub struct CommandExt { - uid: Option, - gid: Option, -} - /// The unique id of the process (this should never be negative). pub struct Process { pub pid: pid_t @@ -332,7 +326,7 @@ pub fn wait(&self, deadline: u64) -> IoResult { // The actual communication between the helper thread and this thread is // quite simple, just a channel moving data around. - unsafe { HELPER.boot(register_sigchld, waitpid_helper) } + HELPER.boot(register_sigchld, waitpid_helper); match self.try_wait() { Some(ret) => return Ok(ret), @@ -340,7 +334,7 @@ pub fn wait(&self, deadline: u64) -> IoResult { } let (tx, rx) = channel(); - unsafe { HELPER.send(NewChild(self.pid, tx, deadline)); } + HELPER.send(NewChild(self.pid, tx, deadline)); return match rx.recv() { Ok(e) => Ok(e), Err(..) => Err(timeout("wait timed out")), @@ -424,8 +418,15 @@ fn waitpid_helper(input: libc::c_int, Ok(NewChild(pid, tx, deadline)) => { active.push((pid, tx, deadline)); } + // Once we've been disconnected it means the main + // thread is exiting (at_exit has run). We could + // still have active waiter for other threads, so + // we're just going to drop them all on the floor. + // This means that they won't receive a "you're + // done" message in which case they'll be considered + // as timed out, but more generally errors will + // start propagating. Err(TryRecvError::Disconnected) => { - assert!(active.len() == 0); break 'outer; } Err(TryRecvError::Empty) => break, diff --git a/src/libstd/sys/unix/process2.rs b/src/libstd/sys/unix/process2.rs index 1ae59139bc413e1aa7db20a1c9f1829a51f49917..03b77eb75d785d023d010fb302e0b7e8ac038296 100644 --- a/src/libstd/sys/unix/process2.rs +++ b/src/libstd/sys/unix/process2.rs @@ -14,18 +14,13 @@ use env; use ffi::{OsString, OsStr, CString}; use fmt; -use hash::Hash; use io::{self, Error, ErrorKind}; use libc::{self, pid_t, c_void, c_int, gid_t, uid_t}; use mem; -use old_io; -use os; use os::unix::OsStrExt; use ptr; -use sync::mpsc::{channel, Sender, Receiver}; use sys::pipe2::AnonPipe; -use sys::{self, retry, c, wouldblock, set_nonblocking, ms_to_timeval, cvt}; -use sys_common::AsInner; +use sys::{self, retry, c, cvt}; //////////////////////////////////////////////////////////////////////////////// // Command @@ -127,10 +122,6 @@ pub struct Process { const CLOEXEC_MSG_FOOTER: &'static [u8] = b"NOEX"; impl Process { - pub fn id(&self) -> pid_t { - self.pid - } - pub unsafe fn kill(&self) -> io::Result<()> { try!(cvt(libc::funcs::posix88::signal::kill(self.pid, libc::SIGKILL))); Ok(()) diff --git a/src/libstd/sys/unix/rwlock.rs b/src/libstd/sys/unix/rwlock.rs index b857f4ab75fed31160e45e63acdf887f545acdca..adf9da2d067cd202686cecaded415165c3ce3ff7 100644 --- a/src/libstd/sys/unix/rwlock.rs +++ b/src/libstd/sys/unix/rwlock.rs @@ -23,12 +23,6 @@ unsafe impl Send for RWLock {} unsafe impl Sync for RWLock {} impl RWLock { - #[inline] - pub unsafe fn new() -> RWLock { - // Might be moved and address is changing it is better to avoid - // initialization of potentially opaque OS data before it landed - RWLOCK_INIT - } #[inline] pub unsafe fn read(&self) { let r = ffi::pthread_rwlock_rdlock(self.inner.get()); diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs index c2044c502b72fb4bf1ed42ada4132e0e28fb97ee..1f212ea5a61678233b5f2daab54c15537dbc9543 100644 --- a/src/libstd/sys/unix/stack_overflow.rs +++ b/src/libstd/sys/unix/stack_overflow.rs @@ -37,7 +37,6 @@ fn drop(&mut self) { target_os = "bitrig", target_os = "openbsd"))] mod imp { - use core::prelude::*; use sys_common::stack; use super::Handler; diff --git a/src/libstd/sys/unix/tcp.rs b/src/libstd/sys/unix/tcp.rs index 4fcaf504c3da5d7f447c1a933064ad5fe932c89a..2a6994824c7eb7c0f44d2fef0b211ddfc7783575 100644 --- a/src/libstd/sys/unix/tcp.rs +++ b/src/libstd/sys/unix/tcp.rs @@ -139,10 +139,6 @@ pub fn accept(&mut self) -> IoResult { Err(sys_common::eof()) } - pub fn socket_name(&mut self) -> IoResult { - net::sockname(self.fd(), libc::getsockname) - } - pub fn set_timeout(&mut self, timeout: Option) { self.deadline = timeout.map(|a| sys::timer::now() + a).unwrap_or(0); } diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 827e2afdca85c81eaaecd97a50ae4e82fa549359..b4002f266a18751bda61bedb871a91db4bc0b13e 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![allow(dead_code)] + use core::prelude::*; use io; @@ -262,15 +264,15 @@ pub unsafe fn set_name(name: &str) { // pthread_setname_np() since glibc 2.12 // availability autodetected via weak linkage let cname = CString::new(name).unwrap(); - type F = unsafe extern "C" fn(libc::pthread_t, *const libc::c_char) -> libc::c_int; + type F = unsafe extern "C" fn(libc::pthread_t, *const libc::c_char) + -> libc::c_int; extern { #[linkage = "extern_weak"] static pthread_setname_np: *const (); } if !pthread_setname_np.is_null() { - unsafe { - mem::transmute::<*const (), F>(pthread_setname_np)(pthread_self(), cname.as_ptr()); - } + mem::transmute::<*const (), F>(pthread_setname_np)(pthread_self(), + cname.as_ptr()); } } @@ -300,6 +302,7 @@ pub unsafe fn detach(native: rust_thread) { } pub unsafe fn yield_now() { assert_eq!(sched_yield(), 0); } + // glibc >= 2.15 has a __pthread_get_minstack() function that returns // PTHREAD_STACK_MIN plus however many bytes are needed for thread-local // storage. We need that information to avoid blowing up when a small stack diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs index 1104bc995c6ea7961e8b2d2a979590b75f3614d5..d2f51678d497fa737c463c0089b4729fe63b1a73 100644 --- a/src/libstd/sys/unix/time.rs +++ b/src/libstd/sys/unix/time.rs @@ -58,11 +58,9 @@ impl<'a> Sub for &'a SteadyTime { type Output = Duration; fn sub(self, other: &SteadyTime) -> Duration { - unsafe { - let info = info(); - let diff = self.t as i64 - other.t as i64; - Duration::nanoseconds(diff * info.numer as i64 / info.denom as i64) - } + let info = info(); + let diff = self.t as i64 - other.t as i64; + Duration::nanoseconds(diff * info.numer as i64 / info.denom as i64) } } } diff --git a/src/libstd/sys/unix/timer.rs b/src/libstd/sys/unix/timer.rs index 4cd98f4442b0fcb8bab3506f4c7ff0388adced53..ce9748ede85647c9ce882f809bf34f7d0ca80642 100644 --- a/src/libstd/sys/unix/timer.rs +++ b/src/libstd/sys/unix/timer.rs @@ -100,7 +100,7 @@ pub fn now() -> u64 { fn helper(input: libc::c_int, messages: Receiver, _: ()) { let mut set: c::fd_set = unsafe { mem::zeroed() }; - let mut fd = FileDesc::new(input, true); + let fd = FileDesc::new(input, true); let mut timeout: libc::timeval = unsafe { mem::zeroed() }; // active timers are those which are able to be selected upon (and it's a diff --git a/src/libstd/sys/unix/tty.rs b/src/libstd/sys/unix/tty.rs index 8e60bbf4cbd00a5e655fb1e6d477bb0fc239a788..1d74b36a62517d24518a13a42c1527200febd3fe 100644 --- a/src/libstd/sys/unix/tty.rs +++ b/src/libstd/sys/unix/tty.rs @@ -11,7 +11,7 @@ use prelude::v1::*; use sys::fs::FileDesc; -use libc::{self, c_int, c_ulong, funcs}; +use libc::{self, c_int, c_ulong}; use old_io::{self, IoResult, IoError}; use sys::c; use sys_common; @@ -86,6 +86,4 @@ struct winsize { pub fn get_winsize(&mut self) -> IoResult<(int, int)> { Err(sys_common::unimpl()) } - - pub fn isatty(&self) -> bool { false } } diff --git a/src/libstd/sys/windows/backtrace.rs b/src/libstd/sys/windows/backtrace.rs index 51cf30324233c772cfaa66185365640db174b275..8de2fe1336f3a9f24ba8a2cd7f14beeb51f6d2b0 100644 --- a/src/libstd/sys/windows/backtrace.rs +++ b/src/libstd/sys/windows/backtrace.rs @@ -24,19 +24,16 @@ #![allow(dead_code)] +use prelude::v1::*; + use dynamic_lib::DynamicLibrary; use ffi::CStr; use intrinsics; -use old_io::{IoResult, Writer}; +use old_io::IoResult; use libc; use mem; -use ops::Drop; -use option::Option::{Some}; -use old_path::Path; use ptr; -use result::Result::{Ok, Err}; -use slice::SliceExt; -use str::{self, StrExt}; +use str; use sync::{StaticMutex, MUTEX_INIT}; use sys_common::backtrace::*; diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index 309d6c9dc48c26b48c27f4cae8af38e2a11a194c..5e6fcc664076bfee2d7843a7fe5bef48c74c28a0 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -18,7 +18,7 @@ use prelude::v1::*; use sys; -use sys_common::{mkerr_libc}; +use sys_common::{self, mkerr_libc}; use old_io::{FilePermission, Write, UnstableFileStat, Open, FileAccess, FileMode}; use old_io::{IoResult, IoError, FileStat, SeekStyle}; @@ -434,7 +434,7 @@ pub fn stat(p: &Path) -> IoResult { // FIXME: move this to platform-specific modules (for now)? pub fn lstat(_p: &Path) -> IoResult { // FIXME: implementation is missing - Err(super::unimpl()) + Err(sys_common::unimpl()) } pub fn utime(p: &Path, atime: u64, mtime: u64) -> IoResult<()> { diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index 3bdadbb9012e04da91a39f5635bfb779614b5e42..46085826e60db09a66c35fe7c3fe2364eb20fa43 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -24,17 +24,6 @@ use path::PathBuf; use sync::{Once, ONCE_INIT}; -macro_rules! helper_init { (static $name:ident: Helper<$m:ty>) => ( - static $name: Helper<$m> = Helper { - lock: ::sync::MUTEX_INIT, - cond: ::sync::CONDVAR_INIT, - chan: ::cell::UnsafeCell { value: 0 as *mut ::sync::mpsc::Sender<$m> }, - signal: ::cell::UnsafeCell { value: 0 }, - initialized: ::cell::UnsafeCell { value: false }, - shutdown: ::cell::UnsafeCell { value: false }, - }; -) } - pub mod backtrace; pub mod c; pub mod condvar; @@ -216,15 +205,7 @@ pub fn init_net() { } } -pub fn unimpl() -> IoError { - IoError { - kind: old_io::IoUnavailable, - desc: "operation is not implemented", - detail: None, - } -} - -fn to_utf16(s: Option<&str>) -> IoResult> { +pub fn to_utf16(s: Option<&str>) -> IoResult> { match s { Some(s) => Ok(to_utf16_os(OsStr::from_str(s))), None => Err(IoError { diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index ca3ed54eb036a4b2e55e11235fe21d63086dfbfb..119ff3dbcc8e0175971f4e19db0365b5b5b64966 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -29,7 +29,6 @@ use str; use sync::{StaticMutex, MUTEX_INIT}; use sys::fs::FileDesc; - use sys::timer; use sys_common::{AsInner, timeout}; @@ -129,8 +128,6 @@ pub fn spawn(cfg: &C, in_fd: Option

, use libc::funcs::extra::msvcrt::get_osfhandle; use mem; - use iter::IteratorExt; - use str::StrExt; if cfg.gid().is_some() || cfg.uid().is_some() { return Err(IoError { diff --git a/src/libstd/sys/windows/tcp.rs b/src/libstd/sys/windows/tcp.rs index 8547de145f8c40cddbc83a7180562288affd924e..6e46bf97d1bac9cbca646e100655b2bcd5aa74dc 100644 --- a/src/libstd/sys/windows/tcp.rs +++ b/src/libstd/sys/windows/tcp.rs @@ -10,12 +10,13 @@ #![allow(deprecated)] +use prelude::v1::*; + use old_io::net::ip; use old_io::IoResult; use libc; use mem; use ptr; -use prelude::v1::*; use super::{last_error, last_net_error, sock_t}; use sync::Arc; use sync::atomic::{AtomicBool, Ordering}; diff --git a/src/libstd/sys/windows/timer.rs b/src/libstd/sys/windows/timer.rs index d156dd801f974905fa2d2adc64d461bbdd1f7525..a23a90a9cf8f897b03c281687fe5e46ce44dfbd2 100644 --- a/src/libstd/sys/windows/timer.rs +++ b/src/libstd/sys/windows/timer.rs @@ -20,15 +20,15 @@ //! Other than that, the implementation is pretty straightforward in terms of //! the other two implementations of timers with nothing *that* new showing up. -use self::Req::*; use prelude::v1::*; +use self::Req::*; use libc; use ptr; use old_io::IoResult; -use sync::mpsc::{channel, Sender, Receiver, TryRecvError}; use sys_common::helper_thread::Helper; +use sync::mpsc::{channel, TryRecvError, Sender, Receiver}; helper_init! { static HELPER: Helper } diff --git a/src/libstd/sys/windows/tty.rs b/src/libstd/sys/windows/tty.rs index c9bac69c434c32ff965213742d1c4d0c08346d51..37dce423a687f6f38118d1ef9c53db40bbf4aacd 100644 --- a/src/libstd/sys/windows/tty.rs +++ b/src/libstd/sys/windows/tty.rs @@ -38,7 +38,7 @@ 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::{CONSOLE_SCREEN_BUFFER_INFO}; +use super::c::CONSOLE_SCREEN_BUFFER_INFO; use super::c::{ReadConsoleW, WriteConsoleW, GetConsoleMode, SetConsoleMode}; use super::c::{GetConsoleScreenBufferInfo}; diff --git a/src/libstd/thread.rs b/src/libstd/thread.rs index 4c7dcc8b9eb6130d3236cf083721aeaf0f993f6b..5c5f9f75fd9dbda818ec949e845869be9e19ee0e 100644 --- a/src/libstd/thread.rs +++ b/src/libstd/thread.rs @@ -281,17 +281,13 @@ fn spawn_inner(self, f: Thunk<(), T>) -> io::Result> { let my_stack_top = addr as usize; let my_stack_bottom = my_stack_top - stack_size + 1024; unsafe { - stack::record_os_managed_stack_bounds(my_stack_bottom, my_stack_top); - } - match their_thread.name() { - Some(name) => unsafe { imp::set_name(name); }, - None => {} + if let Some(name) = their_thread.name() { + imp::set_name(name); + } + stack::record_os_managed_stack_bounds(my_stack_bottom, + my_stack_top); + thread_info::set(imp::guard::current(), their_thread); } - thread_info::set( - (my_stack_bottom, my_stack_top), - unsafe { imp::guard::current() }, - their_thread - ); let mut output = None; let f: Thunk<(), T> = if stdout.is_some() || stderr.is_some() {