Skip to content

De-realstd os::args #14430

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

Merged
merged 2 commits into from
May 26, 2014
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
4 changes: 2 additions & 2 deletions src/libstd/io/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,7 @@ mod test {
})

iotest!(fn file_test_io_seek_shakedown() {
use std::str; // 01234567890123
use str; // 01234567890123
let initial_msg = "qwer-asdf-zxcv";
let chunk_one: &str = "qwer";
let chunk_two: &str = "asdf";
Expand Down Expand Up @@ -947,7 +947,7 @@ mod test {
})

iotest!(fn file_test_directoryinfo_readdir() {
use std::str;
use str;
let tmpdir = tmpdir();
let dir = &tmpdir.join("di_readdir");
check!(mkdir(dir, io::UserRWX));
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/io/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use prelude::*;

use std::str;
use str;
use fmt;
use io::IoResult;
use io;
Expand Down
25 changes: 11 additions & 14 deletions src/libstd/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,24 +266,21 @@ pub mod rt;
// can be resolved within libstd.
#[doc(hidden)]
mod std {
// mods used for deriving
pub use clone;
pub use cmp;
pub use comm;
pub use fmt;
pub use hash;
pub use io;
pub use kinds;
pub use local_data;
pub use option;
pub use os;
pub use rt;
pub use str;
pub use to_str;
pub use ty;
pub use unstable;
pub use vec;

pub use comm; // used for select!()
pub use fmt; // used for any formatting strings
pub use io; // used for println!()
pub use local_data; // used for local_data_key!()
pub use option; // used for bitflags!()
pub use rt; // used for fail!()
pub use vec; // used for vec![]

// The test runner calls ::std::os::args() but really wants realstd
#[cfg(test)] pub use os = realstd::os;
// The test runner requires std::slice::Vector, so re-export std::slice just for it.
#[cfg(test)] pub use slice;
#[cfg(test)] pub use string;
}
25 changes: 6 additions & 19 deletions src/libstd/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -918,17 +918,10 @@ extern "system" {
///
/// The arguments are interpreted as utf-8, with invalid bytes replaced with \uFFFD.
/// See `str::from_utf8_lossy` for details.
#[cfg(not(test))]
pub fn args() -> Vec<String> {
real_args()
}

#[cfg(test)]
#[allow(missing_doc)]
pub fn args() -> ::realstd::vec::Vec<::realstd::string::String> {
::realstd::os::args()
}

/// Returns the arguments which this program was started with (normally passed
/// via the command line) as byte vectors.
pub fn args_as_bytes() -> Vec<Vec<u8>> {
Expand Down Expand Up @@ -1328,7 +1321,7 @@ impl Drop for MemoryMap {

#[cfg(target_os = "linux")]
pub mod consts {
pub use std::os::arch_consts::ARCH;
pub use os::arch_consts::ARCH;

pub static FAMILY: &'static str = "unix";

Expand Down Expand Up @@ -1359,7 +1352,7 @@ pub mod consts {

#[cfg(target_os = "macos")]
pub mod consts {
pub use std::os::arch_consts::ARCH;
pub use os::arch_consts::ARCH;

pub static FAMILY: &'static str = "unix";

Expand Down Expand Up @@ -1390,7 +1383,7 @@ pub mod consts {

#[cfg(target_os = "freebsd")]
pub mod consts {
pub use std::os::arch_consts::ARCH;
pub use os::arch_consts::ARCH;

pub static FAMILY: &'static str = "unix";

Expand Down Expand Up @@ -1421,7 +1414,7 @@ pub mod consts {

#[cfg(target_os = "android")]
pub mod consts {
pub use std::os::arch_consts::ARCH;
pub use os::arch_consts::ARCH;

pub static FAMILY: &'static str = "unix";

Expand Down Expand Up @@ -1452,7 +1445,7 @@ pub mod consts {

#[cfg(target_os = "win32")]
pub mod consts {
pub use std::os::arch_consts::ARCH;
pub use os::arch_consts::ARCH;

pub static FAMILY: &'static str = "windows";

Expand Down Expand Up @@ -1507,7 +1500,7 @@ mod tests {
use prelude::*;
use c_str::ToCStr;
use option;
use os::{env, getcwd, getenv, make_absolute, args};
use os::{env, getcwd, getenv, make_absolute};
use os::{setenv, unsetenv};
use os;
use rand::Rng;
Expand All @@ -1518,12 +1511,6 @@ mod tests {
debug!("{}", os::last_os_error());
}

#[test]
pub fn test_args() {
let a = args();
assert!(a.len() >= 1);
}

fn make_rand_name() -> String {
let mut rng = rand::task_rng();
let n = format_strbuf!("TEST{}", rng.gen_ascii_str(10u).as_slice());
Expand Down
41 changes: 7 additions & 34 deletions src/libstd/rt/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,23 @@

use option::Option;
use vec::Vec;
#[cfg(test)] use option::{Some, None};
#[cfg(test)] use realstd;
#[cfg(test)] use realargs = realstd::rt::args;

/// One-time global initialization.
#[cfg(not(test))]
pub unsafe fn init(argc: int, argv: **u8) { imp::init(argc, argv) }
#[cfg(test)]
pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) }

/// One-time global cleanup.
#[cfg(not(test))] pub unsafe fn cleanup() { imp::cleanup() }
#[cfg(test)] pub unsafe fn cleanup() { realargs::cleanup() }
pub unsafe fn cleanup() { imp::cleanup() }

/// Take the global arguments from global storage.
#[cfg(not(test))] pub fn take() -> Option<Vec<Vec<u8>>> { imp::take() }
#[cfg(test)] pub fn take() -> Option<Vec<Vec<u8>>> {
match realargs::take() {
realstd::option::Some(v) => Some(unsafe{ ::mem::transmute(v) }),
realstd::option::None => None,
}
}
pub fn take() -> Option<Vec<Vec<u8>>> { imp::take() }

/// Give the global arguments to global storage.
///
/// It is an error if the arguments already exist.
#[cfg(not(test))] pub fn put(args: Vec<Vec<u8>>) { imp::put(args) }
#[cfg(test)] pub fn put(args: Vec<Vec<u8>>) {
realargs::put(unsafe {
::mem::transmute(args)
})
}
pub fn put(args: Vec<Vec<u8>>) { imp::put(args) }

/// Make a clone of the global arguments.
#[cfg(not(test))] pub fn clone() -> Option<Vec<Vec<u8>>> { imp::clone() }
#[cfg(test)] pub fn clone() -> Option<Vec<Vec<u8>>> {
match realargs::clone() {
realstd::option::Some(v) => Some(unsafe { ::mem::transmute(v) }),
realstd::option::None => None,
}
}
pub fn clone() -> Option<Vec<Vec<u8>>> { imp::clone() }

#[cfg(target_os = "linux")]
#[cfg(target_os = "android")]
Expand All @@ -75,18 +51,16 @@ mod imp {
use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use mem;
use vec::Vec;
#[cfg(not(test))] use ptr::RawPtr;
use ptr::RawPtr;

static mut global_args_ptr: uint = 0;
static mut lock: StaticNativeMutex = NATIVE_MUTEX_INIT;

#[cfg(not(test))]
pub unsafe fn init(argc: int, argv: **u8) {
let args = load_argc_and_argv(argc, argv);
put(args);
}

#[cfg(not(test))]
pub unsafe fn cleanup() {
rtassert!(take().is_some());
lock.destroy();
Expand Down Expand Up @@ -127,7 +101,6 @@ mod imp {
}

// Copied from `os`.
#[cfg(not(test))]
unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> Vec<Vec<u8>> {
use c_str::CString;
use ptr::RawPtr;
Expand Down Expand Up @@ -173,8 +146,8 @@ mod imp {
}
}

#[cfg(target_os = "macos", not(test))]
#[cfg(target_os = "win32", not(test))]
#[cfg(target_os = "macos")]
#[cfg(target_os = "win32")]
mod imp {
use option::Option;
use vec::Vec;
Expand Down