1
Fork 0

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.
This commit is contained in:
Alex Crichton 2015-03-09 20:04:35 -07:00
parent 206ee0e853
commit c933d44f7b
35 changed files with 86 additions and 176 deletions

View file

@ -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;
////////////////////////////////////////////////////////////////////////

View file

@ -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};

View file

@ -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();

View file

@ -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;

View file

@ -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 {

View file

@ -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,
};

View file

@ -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> {

View file

@ -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

View file

@ -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,

View file

@ -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(())

View file

@ -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());

View file

@ -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;

View file

@ -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);
}

View file

@ -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

View file

@ -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)
}
}
}

View file

@ -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

View file

@ -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 }
}