From d3444779e6776025ee19202c5e69964abde90374 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Mon, 29 Sep 2014 00:28:50 -0700 Subject: [PATCH] Fix libnative --- src/libnative/io/c_unix.rs | 85 ++++++++++++++++++----------------- src/libnative/io/file_unix.rs | 13 +++--- src/libnative/io/mod.rs | 12 ++--- src/libnative/io/net.rs | 12 ++--- src/libnative/io/process.rs | 11 +++-- src/libnative/lib.rs | 5 +-- 6 files changed, 68 insertions(+), 70 deletions(-) diff --git a/src/libnative/io/c_unix.rs b/src/libnative/io/c_unix.rs index fa7da1de914..2601d493443 100644 --- a/src/libnative/io/c_unix.rs +++ b/src/libnative/io/c_unix.rs @@ -19,41 +19,42 @@ pub use self::signal::{SA_NODEFER, SA_NOCLDWAIT, SA_SIGINFO, SIGCHLD}; use libc; -#[cfg(target_os = "macos")] -#[cfg(target_os = "ios")] -#[cfg(target_os = "freebsd")] -#[cfg(target_os = "dragonfly")] +#[cfg(any(target_os = "macos", + target_os = "ios", + target_os = "freebsd", + target_os = "dragonfly"))] pub static FIONBIO: libc::c_ulong = 0x8004667e; -#[cfg(target_os = "linux", target_arch = "x86")] -#[cfg(target_os = "linux", target_arch = "x86_64")] -#[cfg(target_os = "linux", target_arch = "arm")] -#[cfg(target_os = "android")] +#[cfg(any(all(target_os = "linux", + any(target_arch = "x86", + target_arch = "x86_64", + target_arch = "arm")), + target_os = "android"))] pub static FIONBIO: libc::c_ulong = 0x5421; -#[cfg(target_os = "linux", target_arch = "mips")] -#[cfg(target_os = "linux", target_arch = "mipsel")] +#[cfg(all(target_os = "linux", + any(target_arch = "mips", target_arch = "mipsel")))] pub static FIONBIO: libc::c_ulong = 0x667e; -#[cfg(target_os = "macos")] -#[cfg(target_os = "ios")] -#[cfg(target_os = "freebsd")] -#[cfg(target_os = "dragonfly")] +#[cfg(any(target_os = "macos", + target_os = "ios", + target_os = "freebsd", + target_os = "dragonfly"))] pub static FIOCLEX: libc::c_ulong = 0x20006601; -#[cfg(target_os = "linux", target_arch = "x86")] -#[cfg(target_os = "linux", target_arch = "x86_64")] -#[cfg(target_os = "linux", target_arch = "arm")] -#[cfg(target_os = "android")] +#[cfg(any(all(target_os = "linux", + any(target_arch = "x86", + target_arch = "x86_64", + target_arch = "arm")), + target_os = "android"))] pub static FIOCLEX: libc::c_ulong = 0x5451; -#[cfg(target_os = "linux", target_arch = "mips")] -#[cfg(target_os = "linux", target_arch = "mipsel")] +#[cfg(all(target_os = "linux", + any(target_arch = "mips", target_arch = "mipsel")))] pub static FIOCLEX: libc::c_ulong = 0x6601; -#[cfg(target_os = "macos")] -#[cfg(target_os = "ios")] -#[cfg(target_os = "freebsd")] -#[cfg(target_os = "dragonfly")] +#[cfg(any(target_os = "macos", + target_os = "ios", + target_os = "freebsd", + target_os = "dragonfly"))] pub static MSG_DONTWAIT: libc::c_int = 0x80; -#[cfg(target_os = "linux")] -#[cfg(target_os = "android")] +#[cfg(any(target_os = "linux", target_os = "android"))] pub static MSG_DONTWAIT: libc::c_int = 0x40; pub static WNOHANG: libc::c_int = 1; @@ -86,8 +87,7 @@ extern { pub fn sigemptyset(set: *mut sigset_t) -> libc::c_int; } -#[cfg(target_os = "macos")] -#[cfg(target_os = "ios")] +#[cfg(any(target_os = "macos", target_os = "ios"))] mod select { pub static FD_SETSIZE: uint = 1024; @@ -101,10 +101,10 @@ mod select { } } -#[cfg(target_os = "android")] -#[cfg(target_os = "freebsd")] -#[cfg(target_os = "dragonfly")] -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "android", + target_os = "freebsd", + target_os = "dragonfly", + target_os = "linux"))] mod select { use std::uint; use libc; @@ -123,10 +123,11 @@ mod select { } } -#[cfg(target_os = "linux", target_arch = "x86")] -#[cfg(target_os = "linux", target_arch = "x86_64")] -#[cfg(target_os = "linux", target_arch = "arm")] -#[cfg(target_os = "android")] +#[cfg(any(all(target_os = "linux", + any(target_arch = "x86", + target_arch = "x86_64", + target_arch = "arm")), + target_os = "android"))] mod signal { use libc; @@ -173,8 +174,8 @@ mod signal { } } -#[cfg(target_os = "linux", target_arch = "mips")] -#[cfg(target_os = "linux", target_arch = "mipsel")] +#[cfg(all(target_os = "linux", + any(target_arch = "mips", target_arch = "mipsel")))] mod signal { use libc; @@ -215,10 +216,10 @@ mod signal { } } -#[cfg(target_os = "macos")] -#[cfg(target_os = "ios")] -#[cfg(target_os = "freebsd")] -#[cfg(target_os = "dragonfly")] +#[cfg(any(target_os = "macos", + target_os = "ios", + target_os = "freebsd", + target_os = "dragonfly"))] mod signal { use libc; diff --git a/src/libnative/io/file_unix.rs b/src/libnative/io/file_unix.rs index 1688b009ad7..67aad1904b9 100644 --- a/src/libnative/io/file_unix.rs +++ b/src/libnative/io/file_unix.rs @@ -130,8 +130,7 @@ impl rtio::RtioFileStream for FileDesc { fn datasync(&mut self) -> IoResult<()> { return super::mkerr_libc(os_datasync(self.fd())); - #[cfg(target_os = "macos")] - #[cfg(target_os = "ios")] + #[cfg(any(target_os = "macos", target_os = "ios"))] fn os_datasync(fd: c_int) -> c_int { unsafe { libc::fcntl(fd, libc::F_FULLFSYNC) } } @@ -139,7 +138,7 @@ impl rtio::RtioFileStream for FileDesc { fn os_datasync(fd: c_int) -> c_int { retry(|| unsafe { libc::fdatasync(fd) }) } - #[cfg(not(target_os = "macos"), not(target_os = "ios"), not(target_os = "linux"))] + #[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "linux")))] fn os_datasync(fd: c_int) -> c_int { retry(|| unsafe { libc::fsync(fd) }) } @@ -445,14 +444,14 @@ fn mkstat(stat: &libc::stat) -> rtio::FileStat { // FileStat times are in milliseconds fn mktime(secs: u64, nsecs: u64) -> u64 { secs * 1000 + nsecs / 1000000 } - #[cfg(not(target_os = "linux"), not(target_os = "android"))] + #[cfg(not(any(target_os = "linux", target_os = "android")))] fn flags(stat: &libc::stat) -> u64 { stat.st_flags as u64 } - #[cfg(target_os = "linux")] #[cfg(target_os = "android")] + #[cfg(any(target_os = "linux", target_os = "android"))] fn flags(_stat: &libc::stat) -> u64 { 0 } - #[cfg(not(target_os = "linux"), not(target_os = "android"))] + #[cfg(not(any(target_os = "linux", target_os = "android")))] fn gen(stat: &libc::stat) -> u64 { stat.st_gen as u64 } - #[cfg(target_os = "linux")] #[cfg(target_os = "android")] + #[cfg(any(target_os = "linux", target_os = "android"))] fn gen(_stat: &libc::stat) -> u64 { 0 } rtio::FileStat { diff --git a/src/libnative/io/mod.rs b/src/libnative/io/mod.rs index 86f72bf65dd..954f7bbc59a 100644 --- a/src/libnative/io/mod.rs +++ b/src/libnative/io/mod.rs @@ -48,12 +48,12 @@ pub mod file; #[path = "file_windows.rs"] pub mod file; -#[cfg(target_os = "macos")] -#[cfg(target_os = "ios")] -#[cfg(target_os = "freebsd")] -#[cfg(target_os = "dragonfly")] -#[cfg(target_os = "android")] -#[cfg(target_os = "linux")] +#[cfg(any(target_os = "macos", + target_os = "ios", + target_os = "freebsd", + target_os = "dragonfly", + target_os = "android", + target_os = "linux"))] #[path = "timer_unix.rs"] pub mod timer; diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs index 335a52b0bbe..419748b75c3 100644 --- a/src/libnative/io/net.rs +++ b/src/libnative/io/net.rs @@ -282,20 +282,20 @@ impl TcpStream { } } - #[cfg(target_os = "macos")] - #[cfg(target_os = "ios")] + #[cfg(any(target_os = "macos", target_os = "ios"))] fn set_tcp_keepalive(&mut self, seconds: uint) -> IoResult<()> { setsockopt(self.fd(), libc::IPPROTO_TCP, libc::TCP_KEEPALIVE, seconds as libc::c_int) } - #[cfg(target_os = "freebsd")] - #[cfg(target_os = "dragonfly")] + #[cfg(any(target_os = "freebsd", target_os = "dragonfly"))] fn set_tcp_keepalive(&mut self, seconds: uint) -> IoResult<()> { setsockopt(self.fd(), libc::IPPROTO_TCP, libc::TCP_KEEPIDLE, seconds as libc::c_int) } - #[cfg(not(target_os = "macos"), not(target_os = "ios"), not(target_os = "freebsd"), - not(target_os = "dragonfly"))] + #[cfg(not(any(target_os = "macos", + target_os = "ios", + target_os = "freebsd", + target_os = "dragonfly")))] fn set_tcp_keepalive(&mut self, _seconds: uint) -> IoResult<()> { Ok(()) } diff --git a/src/libnative/io/process.rs b/src/libnative/io/process.rs index cb392e1675f..3a6ae42f946 100644 --- a/src/libnative/io/process.rs +++ b/src/libnative/io/process.rs @@ -840,18 +840,17 @@ fn free_handle(_handle: *mut ()) { #[cfg(unix)] fn translate_status(status: c_int) -> rtio::ProcessExit { #![allow(non_snake_case)] - #[cfg(target_os = "linux")] - #[cfg(target_os = "android")] + #[cfg(any(target_os = "linux", target_os = "android"))] mod imp { pub fn WIFEXITED(status: i32) -> bool { (status & 0xff) == 0 } pub fn WEXITSTATUS(status: i32) -> i32 { (status >> 8) & 0xff } pub fn WTERMSIG(status: i32) -> i32 { status & 0x7f } } - #[cfg(target_os = "macos")] - #[cfg(target_os = "ios")] - #[cfg(target_os = "freebsd")] - #[cfg(target_os = "dragonfly")] + #[cfg(any(target_os = "macos", + target_os = "ios", + target_os = "freebsd", + target_os = "dragonfly"))] mod imp { pub fn WIFEXITED(status: i32) -> bool { (status & 0x7f) == 0 } pub fn WEXITSTATUS(status: i32) -> i32 { status >> 8 } diff --git a/src/libnative/lib.rs b/src/libnative/lib.rs index 06f89d38ca0..267ff3d2a81 100644 --- a/src/libnative/lib.rs +++ b/src/libnative/lib.rs @@ -77,10 +77,9 @@ pub use task::NativeTaskBuilder; pub mod io; pub mod task; -#[cfg(windows)] -#[cfg(android)] +#[cfg(any(windows, android))] static OS_DEFAULT_STACK_ESTIMATE: uint = 1 << 20; -#[cfg(unix, not(android))] +#[cfg(all(unix, not(android)))] static OS_DEFAULT_STACK_ESTIMATE: uint = 2 * (1 << 20); #[lang = "start"]