Use #[cfg(unix)] and #[cfg(windows)] everywhere

This commit is contained in:
Brian Anderson
2012-06-07 21:38:25 -07:00
parent 7ef825bb60
commit 95b9d538b8
18 changed files with 103 additions and 187 deletions

View File

@@ -48,12 +48,10 @@ native mod c_double {
pure fn frexp(n: c_double, &value: c_int) -> c_double;
pure fn hypot(x: c_double, y: c_double) -> c_double;
pure fn ldexp(x: c_double, n: c_int) -> c_double;
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
#[link_name="lgamma_r"] pure fn lgamma(n: c_double,
&sign: c_int) -> c_double;
#[cfg(target_os = "win32")]
#[cfg(windows)]
#[link_name="__lgamma_r"] pure fn lgamma(n: c_double,
&sign: c_int) -> c_double;
// renamed: log is a reserved keyword; ln seems more natural, too
@@ -131,13 +129,11 @@ native mod c_float {
#[link_name="hypotf"] pure fn hypot(x: c_float, y: c_float) -> c_float;
#[link_name="ldexpf"] pure fn ldexp(x: c_float, n: c_int) -> c_float;
#[cfg(target_os="linux")]
#[cfg(target_os="macos")]
#[cfg(target_os="freebsd")]
#[cfg(unix)]
#[link_name="lgammaf_r"] pure fn lgamma(n: c_float,
&sign: c_int) -> c_float;
#[cfg(target_os="win32")]
#[cfg(windows)]
#[link_name="__lgammaf_r"] pure fn lgamma(n: c_float,
&sign: c_int) -> c_float;

View File

@@ -420,7 +420,7 @@ fn test_recv_chan() {
#[test]
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn test_recv_chan_dead() {
let ch = chan(port());
send(ch, "flower");
@@ -428,7 +428,7 @@ fn test_recv_chan_dead() {
}
#[test]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn test_recv_chan_wrong_task() {
let po = port();
let ch = chan(po);
@@ -464,7 +464,7 @@ fn test_listen() {
}
#[test]
#[ignore(cfg(target_os="win32"))]
#[ignore(cfg(windows))]
fn test_port_detach_fail() {
iter::repeat(100u) {||
let builder = task::builder();

View File

@@ -398,12 +398,10 @@ fn fd_writer(fd: fd_t, cleanup: bool) -> writer {
fn mk_file_writer(path: str, flags: [fileflag])
-> result<writer, str> {
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn wb() -> c_int { (O_WRONLY | O_BINARY) as c_int }
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn wb() -> c_int { O_WRONLY as c_int }
let mut fflags: c_int = wb();

View File

@@ -229,7 +229,7 @@ fn test_min() {
#[test]
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn test_min_empty() {
min::<int, [int]>([]);
}
@@ -241,7 +241,7 @@ fn test_max() {
#[test]
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn test_max_empty() {
max::<int, [int]>([]);
}

View File

@@ -79,7 +79,7 @@ fn fill_charp_buf(f: fn(*mut c_char, size_t) -> bool)
}
}
#[cfg(target_os = "win32")]
#[cfg(windows)]
mod win32 {
import dword = libc::types::os::arch::extra::DWORD;
@@ -200,9 +200,7 @@ mod global_env {
mod impl {
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn getenv(n: str) -> option<str> unsafe {
let s = str::as_c_str(n, libc::getenv);
ret if unsafe::reinterpret_cast(s) == 0 {
@@ -213,7 +211,7 @@ mod global_env {
};
}
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn getenv(n: str) -> option<str> unsafe {
import libc::types::os::arch::extra::*;
import libc::funcs::extra::kernel32::*;
@@ -226,9 +224,7 @@ mod global_env {
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn setenv(n: str, v: str) {
// FIXME: remove this when export globs work properly.
@@ -241,7 +237,7 @@ mod global_env {
}
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn setenv(n: str, v: str) {
// FIXME: remove imports when export globs work properly.
import libc::funcs::extra::kernel32::*;
@@ -265,7 +261,7 @@ fn fdopen(fd: c_int) -> *FILE {
// fsync related
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn fsync_fd(fd: c_int, _level: io::fsync::level) -> c_int {
import libc::funcs::extra::msvcrt::*;
ret commit(fd);
@@ -305,14 +301,12 @@ fn fsync_fd(fd: c_int, _l: io::fsync::level) -> c_int {
}
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn waitpid(pid: pid_t) -> c_int {
ret rustrt::rust_process_wait(pid);
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]
#[cfg(target_os = "macos")]
#[cfg(unix)]
fn waitpid(pid: pid_t) -> c_int {
import libc::funcs::posix01::wait::*;
let status = 0 as c_int;
@@ -323,9 +317,7 @@ fn waitpid(pid: pid_t) -> c_int {
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]
#[cfg(target_os = "macos")]
#[cfg(unix)]
fn pipe() -> {in: c_int, out: c_int} {
let fds = {mut in: 0 as c_int,
mut out: 0 as c_int };
@@ -335,7 +327,7 @@ fn pipe() -> {in: c_int, out: c_int} {
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn pipe() -> {in: c_int, out: c_int} {
// FIXME: remove this when export globs work properly.
import libc::consts::os::extra::*;
@@ -359,12 +351,10 @@ fn pipe() -> {in: c_int, out: c_int} {
fn dll_filename(base: str) -> str {
ret pre() + base + dll_suffix();
#[cfg(target_os = "macos")]
#[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn pre() -> str { "lib" }
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn pre() -> str { "" }
}
@@ -405,7 +395,7 @@ fn self_exe_path() -> option<path> {
}
}
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn load_self() -> option<path> unsafe {
// FIXME: remove imports when export globs work properly.
import libc::types::os::arch::extra::*;
@@ -449,14 +439,12 @@ fn homedir() -> option<path> {
}
};
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn secondary() -> option<path> {
none
}
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn secondary() -> option<path> {
option::chain(getenv("USERPROFILE")) {|p|
if !str::is_empty(p) {
@@ -536,7 +524,7 @@ fn make_absolute(p: path) -> path {
fn make_dir(p: path, mode: c_int) -> bool {
ret mkdir(p, mode);
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn mkdir(p: path, _mode: c_int) -> bool unsafe {
// FIXME: remove imports when export globs work properly.
import libc::types::os::arch::extra::*;
@@ -549,9 +537,7 @@ fn make_dir(p: path, mode: c_int) -> bool {
}
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn mkdir(p: path, mode: c_int) -> bool {
as_c_charp(p) {|c|
libc::mkdir(c, mode as mode_t) == (0 as c_int)
@@ -562,12 +548,10 @@ fn make_dir(p: path, mode: c_int) -> bool {
#[doc = "Lists the contents of a directory"]
fn list_dir(p: path) -> [str] {
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn star(p: str) -> str { p }
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn star(p: str) -> str {
let pl = str::len(p);
if pl == 0u || (p[pl - 1u] as char != path::consts::path_sep
@@ -602,7 +586,7 @@ fn list_dir_path(p: path) -> [str] {
fn remove_dir(p: path) -> bool {
ret rmdir(p);
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn rmdir(p: path) -> bool {
// FIXME: remove imports when export globs work properly.
import libc::funcs::extra::kernel32::*;
@@ -613,9 +597,7 @@ fn remove_dir(p: path) -> bool {
};
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn rmdir(p: path) -> bool {
ret as_c_charp(p) {|buf|
libc::rmdir(buf) == (0 as c_int)
@@ -626,7 +608,7 @@ fn remove_dir(p: path) -> bool {
fn change_dir(p: path) -> bool {
ret chdir(p);
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn chdir(p: path) -> bool {
// FIXME: remove imports when export globs work properly.
import libc::funcs::extra::kernel32::*;
@@ -637,9 +619,7 @@ fn change_dir(p: path) -> bool {
};
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn chdir(p: path) -> bool {
ret as_c_charp(p) {|buf|
libc::chdir(buf) == (0 as c_int)
@@ -651,7 +631,7 @@ fn change_dir(p: path) -> bool {
fn copy_file(from: path, to: path) -> bool {
ret do_copy_file(from, to);
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn do_copy_file(from: path, to: path) -> bool {
// FIXME: remove imports when export globs work properly.
import libc::funcs::extra::kernel32::*;
@@ -664,9 +644,7 @@ fn copy_file(from: path, to: path) -> bool {
}
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn do_copy_file(from: path, to: path) -> bool unsafe {
let istream = as_c_charp(from) {|fromp|
as_c_charp("rb") {|modebuf|
@@ -716,7 +694,7 @@ fn copy_file(from: path, to: path) -> bool {
fn remove_file(p: path) -> bool {
ret unlink(p);
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn unlink(p: path) -> bool {
// FIXME: remove imports when export globs work properly.
// (similar to Issue #2006)
@@ -728,9 +706,7 @@ fn remove_file(p: path) -> bool {
};
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn unlink(p: path) -> bool {
ret as_c_charp(p) {|buf|
libc::unlink(buf) == (0 as c_int)
@@ -755,12 +731,10 @@ fn set_exit_status(code: int) {
rustrt::rust_set_exit_status(code as libc::intptr_t);
}
#[cfg(target_os = "macos")]
#[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn family() -> str { "unix" }
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn family() -> str { "windows" }
#[cfg(target_os = "macos")]
@@ -824,7 +798,8 @@ mod tests {
}
#[test]
#[ignore(cgf(target_os = "win32"))]
#[ignore(cfg(windows))]
#[ignore]
fn test_setenv_overwrite() {
let n = make_rand_name();
setenv(n, "1");
@@ -837,7 +812,8 @@ mod tests {
// Windows GetEnvironmentVariable requires some extra work to make sure
// the buffer the variable is copied into is the right size
#[test]
#[ignore(cgf(target_os = "win32"))]
#[ignore(cfg(windows))]
#[ignore]
fn test_getenv_big() {
let mut s = "";
let mut i = 0;
@@ -902,9 +878,7 @@ mod tests {
}
#[test]
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn homedir() {
let oldhome = getenv("HOME");
@@ -918,7 +892,7 @@ mod tests {
}
#[test]
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn homedir() {
let oldhome = getenv("HOME");

View File

@@ -16,9 +16,7 @@ export normalize;
#[doc = "A path or fragment of a filesystem path"]
type path = str;
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(target_os = "linux")]
#[cfg(unix)]
mod consts {
#[doc = "
The primary path seperator character for the platform
@@ -34,7 +32,7 @@ mod consts {
const alt_path_sep: char = '/';
}
#[cfg(target_os = "win32")]
#[cfg(windows)]
mod consts {
const path_sep: char = '/';
const alt_path_sep: char = '\\';
@@ -46,14 +44,12 @@ Indicates whether a path is absolute.
A path is considered absolute if it begins at the filesystem root (\"/\") or,
on Windows, begins with a drive letter.
"]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(target_os = "linux")]
#[cfg(unix)]
fn path_is_absolute(p: path) -> bool {
str::char_at(p, 0u) == '/'
}
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn path_is_absolute(p: str) -> bool {
ret str::char_at(p, 0u) == '/' ||
str::char_at(p, 1u) == ':'
@@ -271,9 +267,7 @@ fn normalize(p: path) -> path {
ret t;
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn reabsolute(orig: path, n: path) -> path {
if path_is_absolute(orig) {
path_sep() + n
@@ -282,7 +276,7 @@ fn normalize(p: path) -> path {
}
}
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn reabsolute(orig: path, newp: path) -> path {
if path_is_absolute(orig) && orig[0] == consts::path_sep as u8 {
str::from_char(consts::path_sep) + newp
@@ -427,7 +421,7 @@ mod tests {
}
#[test]
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn normalize12() {
let actual = normalize("C:/whatever");
let expected = "C:/whatever";
@@ -436,7 +430,7 @@ mod tests {
}
#[test]
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn path_is_absolute_win32() {
assert path_is_absolute("C:/whatever");
}

View File

@@ -225,7 +225,7 @@ fn test_weaken_task_stress() unsafe {
}
#[test]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn test_weaken_task_fail() unsafe {
let res = task::try {||
weaken_task {|_po|

View File

@@ -325,7 +325,7 @@ mod tests {
#[test]
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn gen_int_from_fail() {
rand::rng().gen_int_range(5, -2);
}
@@ -341,7 +341,7 @@ mod tests {
#[test]
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn gen_uint_range_fail() {
rand::rng().gen_uint_range(5u, 2u);
}

View File

@@ -90,9 +90,7 @@ fn with_argv<T>(prog: str, args: [str],
vec::as_buf(argptrs, cb)
}
#[cfg(target_os = "macos")]
#[cfg(target_os = "linux")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn with_envp<T>(env: option<[(str,str)]>,
cb: fn(*c_void) -> T) -> T unsafe {
// On posixy systems we can pass a char** for envp, which is
@@ -117,7 +115,7 @@ fn with_envp<T>(env: option<[(str,str)]>,
}
}
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn with_envp<T>(env: option<[(str,str)]>,
cb: fn(*c_void) -> T) -> T unsafe {
// On win32 we pass an "environment block" which is not a char**, but
@@ -278,14 +276,12 @@ fn program_output(prog: str, args: [str]) ->
fn waitpid(pid: pid_t) -> int {
ret waitpid_os(pid);
#[cfg(target_os = "win32")]
#[cfg(windows)]
fn waitpid_os(pid: pid_t) -> int {
os::waitpid(pid) as int
}
#[cfg(target_os = "linux")]
#[cfg(target_os = "macos")]
#[cfg(target_os = "freebsd")]
#[cfg(unix)]
fn waitpid_os(pid: pid_t) -> int {
#[cfg(target_os = "linux")]
fn WIFEXITED(status: i32) -> bool {
@@ -324,7 +320,7 @@ mod tests {
import io::writer_util;
// Regression test for memory leaks
#[ignore(cfg(target_os = "win32"))] // FIXME
#[ignore(cfg(windows))] // FIXME
fn test_leaks() {
run::run_program("echo", []);
run::start_program("echo", []);

View File

@@ -1998,7 +1998,7 @@ mod tests {
#[test]
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn test_pop_char_fail() {
let mut data = "";
let _cc3 = pop_char(data);
@@ -2419,7 +2419,7 @@ mod tests {
#[test]
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn test_slice_fail() {
slice("中华Việt Nam", 0u, 2u);
}
@@ -2512,7 +2512,7 @@ mod tests {
#[test]
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn test_from_bytes_fail() {
let bb = [0xff_u8, 0xb8_u8, 0xa8_u8,
0xe0_u8, 0xb9_u8, 0x84_u8,
@@ -2537,7 +2537,7 @@ mod tests {
}
#[test]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
#[should_fail]
fn test_as_bytes_fail() {
// Don't double free

View File

@@ -605,7 +605,7 @@ fn test_spawn_raw_simple() {
}
#[test]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn test_spawn_raw_unsupervise() {
let opts = {
supervise: false
@@ -617,7 +617,7 @@ fn test_spawn_raw_unsupervise() {
}
#[test]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn test_spawn_raw_notify() {
let task_po = comm::port();
let task_ch = comm::chan(task_po);
@@ -674,7 +674,7 @@ fn test_add_wrapper() {
}
#[test]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn test_future_result() {
let buildr = builder();
let result = future_result(buildr);
@@ -726,7 +726,7 @@ fn test_try_success() {
}
#[test]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn test_try_fail() {
alt try {||
fail
@@ -738,7 +738,7 @@ fn test_try_fail() {
#[test]
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn test_spawn_sched_no_threads() {
spawn_sched(manual_threads(0u)) {|| };
}
@@ -957,7 +957,7 @@ fn test_osmain() {
}
#[test]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
#[should_fail]
fn test_unkillable() unsafe {
import comm::methods;

View File

@@ -247,14 +247,14 @@ fn test_parse_buf() {
#[test]
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn to_str_radix1() {
uint::to_str(100u, 1u);
}
#[test]
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn to_str_radix17() {
uint::to_str(100u, 17u);
}

View File

@@ -2040,7 +2040,7 @@ mod tests {
#[test]
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn test_init_empty() {
init::<int>([]);
}
@@ -2070,7 +2070,7 @@ mod tests {
#[test]
#[should_fail]
#[ignore(cfg(target_os = "win32"))]
#[ignore(cfg(windows))]
fn test_windowed_() {
let _x = windowed (0u, [1u,2u,3u,4u,5u,6u]);
}