Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std: Remove #[allow] directives in sys modules #23245

Merged
merged 1 commit into from
Mar 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,14 @@ pub mod collections;
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;

Expand Down
4 changes: 1 addition & 3 deletions src/libstd/rt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("<main>".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
Expand Down
11 changes: 11 additions & 0 deletions src/libstd/sys/common/helper_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,17 @@ struct RaceBox(helper_signal::signal);
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<M: Send> Helper<M> {
/// Lazily boots a helper thread, becoming a no-op if the helper has already
/// been spawned.
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

#![allow(missing_docs)]
#![allow(dead_code)]

use old_io::{self, IoError, IoResult};
use prelude::v1::*;
Expand All @@ -19,9 +18,10 @@ use num::Int;
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;
Expand Down
6 changes: 5 additions & 1 deletion src/libstd/sys/common/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ use str;
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;
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 1 addition & 5 deletions src/libstd/sys/common/net2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use io::{self, Error, ErrorKind};
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};
Expand All @@ -24,9 +23,6 @@ use sys_common::{AsInner, FromInner, IntoInner};
// sockaddr and misc bindings
////////////////////////////////////////////////////////////////////////////////

fn hton<I: Int>(i: I) -> I { i.to_be() }
fn ntoh<I: Int>(i: I) -> I { Int::from_be(i) }

fn setsockopt<T>(sock: &Socket, opt: c_int, val: c_int,
payload: T) -> io::Result<()> {
unsafe {
Expand All @@ -39,7 +35,7 @@ fn setsockopt<T>(sock: &Socket, opt: c_int, val: c_int,

#[allow(dead_code)]
fn getsockopt<T: Copy>(sock: &Socket, opt: c_int,
val: c_int) -> io::Result<T> {
val: c_int) -> io::Result<T> {
unsafe {
let mut slot: T = mem::zeroed();
let mut len = mem::size_of::<T>() as socklen_t;
Expand Down
31 changes: 0 additions & 31 deletions src/libstd/sys/common/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 3 additions & 7 deletions src/libstd/sys/common/thread_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,10 +18,6 @@ use thread::Thread;
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,
}
Expand All @@ -36,7 +34,6 @@ impl ThreadInfo {
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),
})
Expand All @@ -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,
}));
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/common/thread_local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down
4 changes: 4 additions & 0 deletions src/libstd/sys/common/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
7 changes: 4 additions & 3 deletions src/libstd/sys/unix/backtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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:"));

Expand Down Expand Up @@ -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;

////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 0 additions & 1 deletion src/libstd/sys/unix/fd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
12 changes: 2 additions & 10 deletions src/libstd/sys/unix/fs2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
18 changes: 1 addition & 17 deletions src/libstd/sys/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,17 @@

#![allow(missing_docs)]
#![allow(non_camel_case_types)]
#![allow(unused_imports)]
#![allow(dead_code)]
#![allow(unused_unsafe)]
#![allow(unused_mut)]

use prelude::v1::*;

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;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/unix/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> }

Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion src/libstd/sys/unix/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;

Expand Down Expand Up @@ -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,
};
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/unix/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/unix/pipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading