diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-03-09 20:04:35 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-12 10:23:27 -0700 |
| commit | c933d44f7bb908aa520250b608f85bfacfccc337 (patch) | |
| tree | 82cab26f340e4cfdc5d373d621fd77713f6c6d78 /src/libstd/sys/unix | |
| parent | 206ee0e8533dd3e1ee324da445e02ad79c51e849 (diff) | |
| download | rust-c933d44f7bb908aa520250b608f85bfacfccc337.tar.gz rust-c933d44f7bb908aa520250b608f85bfacfccc337.zip | |
std: Remove #[allow] directives in sys modules
These were suppressing lots of interesting warnings! Turns out there was also quite a bit of dead code.
Diffstat (limited to 'src/libstd/sys/unix')
| -rw-r--r-- | src/libstd/sys/unix/backtrace.rs | 7 | ||||
| -rw-r--r-- | src/libstd/sys/unix/fd.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/unix/fs2.rs | 12 | ||||
| -rw-r--r-- | src/libstd/sys/unix/mod.rs | 18 | ||||
| -rw-r--r-- | src/libstd/sys/unix/mutex.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/os.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/unix/os_str.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/pipe.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/process.rs | 21 | ||||
| -rw-r--r-- | src/libstd/sys/unix/process2.rs | 11 | ||||
| -rw-r--r-- | src/libstd/sys/unix/rwlock.rs | 6 | ||||
| -rw-r--r-- | src/libstd/sys/unix/stack_overflow.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/unix/tcp.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/unix/thread.rs | 11 | ||||
| -rw-r--r-- | src/libstd/sys/unix/time.rs | 8 | ||||
| -rw-r--r-- | src/libstd/sys/unix/timer.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/tty.rs | 4 |
17 files changed, 37 insertions, 79 deletions
diff --git a/src/libstd/sys/unix/backtrace.rs b/src/libstd/sys/unix/backtrace.rs index e7ac6e2cd01..24d709e9928 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 @@ pub fn write(w: &mut Writer) -> IoResult<()> { // 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 print(w: &mut Writer, idx: int, addr: *mut 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 327d117823e..f7c57c3f5e5 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 72e0b8dd36c..ea74aab3331 100644 --- a/src/libstd/sys/unix/fs2.rs +++ b/src/libstd/sys/unix/fs2.rs @@ -13,8 +13,8 @@ use io::prelude::*; 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<PathBuf> { 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 80bfd57e933..865ea987279 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 ffi::CStr; 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 f87c0339533..1c0ce293804 100644 --- a/src/libstd/sys/unix/mutex.rs +++ b/src/libstd/sys/unix/mutex.rs @@ -12,7 +12,6 @@ use prelude::v1::*; use cell::UnsafeCell; use sys::sync as ffi; -use sys_common::mutex; pub struct Mutex { inner: UnsafeCell<ffi::pthread_mutex_t> } @@ -28,6 +27,7 @@ pub const MUTEX_INIT: Mutex = Mutex { 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 a38c7a30b75..3266da5eb31 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 @@ pub fn home_dir() -> Option<PathBuf> { #[cfg(not(any(target_os = "android", target_os = "ios")))] unsafe fn fallback() -> Option<OsString> { - 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 c8ac524876b..89ab3e1981b 100644 --- a/src/libstd/sys/unix/os_str.rs +++ b/src/libstd/sys/unix/os_str.rs @@ -70,7 +70,7 @@ impl 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 33863d31437..9cddfca69cb 100644 --- a/src/libstd/sys/unix/pipe.rs +++ b/src/libstd/sys/unix/pipe.rs @@ -143,7 +143,7 @@ impl UnixStream { 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 62a1799de94..d5469eb82ef 100644 --- a/src/libstd/sys/unix/process.rs +++ b/src/libstd/sys/unix/process.rs @@ -17,7 +17,7 @@ use collections::HashMap; 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 @@ pub use sys_common::ProcessConfig; helper_init! { static HELPER: Helper<Req> } -/// Unix-specific extensions to the Command builder -pub struct CommandExt { - uid: Option<u32>, - gid: Option<u32>, -} - /// The unique id of the process (this should never be negative). pub struct Process { pub pid: pid_t @@ -332,7 +326,7 @@ impl Process { // 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 @@ impl Process { } 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 @@ impl Process { 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 1ae59139bc4..03b77eb75d7 100644 --- a/src/libstd/sys/unix/process2.rs +++ b/src/libstd/sys/unix/process2.rs @@ -14,18 +14,13 @@ use collections::HashMap; 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 b857f4ab75f..adf9da2d067 100644 --- a/src/libstd/sys/unix/rwlock.rs +++ b/src/libstd/sys/unix/rwlock.rs @@ -24,12 +24,6 @@ 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()); debug_assert_eq!(r, 0); diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs index c2044c502b7..1f212ea5a61 100644 --- a/src/libstd/sys/unix/stack_overflow.rs +++ b/src/libstd/sys/unix/stack_overflow.rs @@ -37,7 +37,6 @@ impl Drop for Handler { 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 4fcaf504c3d..2a6994824c7 100644 --- a/src/libstd/sys/unix/tcp.rs +++ b/src/libstd/sys/unix/tcp.rs @@ -139,10 +139,6 @@ impl TcpAcceptor { Err(sys_common::eof()) } - pub fn socket_name(&mut self) -> IoResult<ip::SocketAddr> { - net::sockname(self.fd(), libc::getsockname) - } - pub fn set_timeout(&mut self, timeout: Option<u64>) { 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 827e2afdca8..b4002f266a1 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 1104bc995c6..d2f51678d49 100644 --- a/src/libstd/sys/unix/time.rs +++ b/src/libstd/sys/unix/time.rs @@ -58,11 +58,9 @@ mod inner { 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 4cd98f4442b..ce9748ede85 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<Req>, _: ()) { 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 8e60bbf4cbd..1d74b36a625 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 @@ impl TTY { pub fn get_winsize(&mut self) -> IoResult<(int, int)> { Err(sys_common::unimpl()) } - - pub fn isatty(&self) -> bool { false } } |
