From e878721d70349e2055f0ef854085de92e9498fde Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 19 May 2014 23:19:56 -0700 Subject: libcore: Remove all uses of `~str` from `libcore`. [breaking-change] --- src/libstd/rt/args.rs | 44 +++++++++++++++++++++++++------------------- src/libstd/rt/util.rs | 1 + 2 files changed, 26 insertions(+), 19 deletions(-) (limited to 'src/libstd/rt') diff --git a/src/libstd/rt/args.rs b/src/libstd/rt/args.rs index 95d0eabd336..cde20521c2f 100644 --- a/src/libstd/rt/args.rs +++ b/src/libstd/rt/args.rs @@ -37,8 +37,8 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) } #[cfg(test)] pub unsafe fn cleanup() { realargs::cleanup() } /// Take the global arguments from global storage. -#[cfg(not(test))] pub fn take() -> Option> { imp::take() } -#[cfg(test)] pub fn take() -> Option> { +#[cfg(not(test))] pub fn take() -> Option>> { imp::take() } +#[cfg(test)] pub fn take() -> Option>> { match realargs::take() { realstd::option::Some(v) => Some(unsafe{ ::mem::transmute(v) }), realstd::option::None => None, @@ -48,12 +48,16 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) } /// Give the global arguments to global storage. /// /// It is an error if the arguments already exist. -#[cfg(not(test))] pub fn put(args: Vec<~[u8]>) { imp::put(args) } -#[cfg(test)] pub fn put(args: Vec<~[u8]>) { realargs::put(unsafe { ::mem::transmute(args) }) } +#[cfg(not(test))] pub fn put(args: Vec>) { imp::put(args) } +#[cfg(test)] pub fn put(args: Vec>) { + realargs::put(unsafe { + ::mem::transmute(args) + }) +} /// Make a clone of the global arguments. -#[cfg(not(test))] pub fn clone() -> Option> { imp::clone() } -#[cfg(test)] pub fn clone() -> Option> { +#[cfg(not(test))] pub fn clone() -> Option>> { imp::clone() } +#[cfg(test)] pub fn clone() -> Option>> { match realargs::clone() { realstd::option::Some(v) => Some(unsafe { ::mem::transmute(v) }), realstd::option::None => None, @@ -88,15 +92,15 @@ mod imp { lock.destroy(); } - pub fn take() -> Option> { + pub fn take() -> Option>> { with_lock(|| unsafe { let ptr = get_global_ptr(); let val = mem::replace(&mut *ptr, None); - val.as_ref().map(|s: &Box>| (**s).clone()) + val.as_ref().map(|s: &Box>>| (**s).clone()) }) } - pub fn put(args: Vec<~[u8]>) { + pub fn put(args: Vec>) { with_lock(|| unsafe { let ptr = get_global_ptr(); rtassert!((*ptr).is_none()); @@ -104,10 +108,10 @@ mod imp { }) } - pub fn clone() -> Option> { + pub fn clone() -> Option>> { with_lock(|| unsafe { let ptr = get_global_ptr(); - (*ptr).as_ref().map(|s: &Box>| (**s).clone()) + (*ptr).as_ref().map(|s: &Box>>| (**s).clone()) }) } @@ -118,22 +122,21 @@ mod imp { } } - fn get_global_ptr() -> *mut Option>> { + fn get_global_ptr() -> *mut Option>>> { unsafe { mem::transmute(&global_args_ptr) } } // Copied from `os`. #[cfg(not(test))] - unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> Vec<~[u8]> { + unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> Vec> { use c_str::CString; use ptr::RawPtr; use libc; - use slice::CloneableVector; use vec::Vec; Vec::from_fn(argc as uint, |i| { let cs = CString::new(*(argv as **libc::c_char).offset(i as int), false); - cs.as_bytes_no_nul().to_owned() + Vec::from_slice(cs.as_bytes_no_nul()) }) } @@ -148,7 +151,10 @@ mod imp { // Preserve the actual global state. let saved_value = take(); - let expected = vec![bytes!("happy").to_owned(), bytes!("today?").to_owned()]; + let expected = vec![ + Vec::from_slice(bytes!("happy")), + Vec::from_slice(bytes!("today?")), + ]; put(expected.clone()); assert!(clone() == Some(expected.clone())); @@ -179,15 +185,15 @@ mod imp { pub fn cleanup() { } - pub fn take() -> Option> { + pub fn take() -> Option>> { fail!() } - pub fn put(_args: Vec<~[u8]>) { + pub fn put(_args: Vec>) { fail!() } - pub fn clone() -> Option> { + pub fn clone() -> Option>> { fail!() } } diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index 7aebb6e4796..1ab9ac1b11e 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -145,6 +145,7 @@ which at the time convulsed us with joy, yet which are now partly lost to my memory and partly incapable of presentation to others.", _ => "You've met with a terrible fate, haven't you?" }; + ::alloc::util::make_stdlib_link_work(); // see comments in liballoc rterrln!("{}", ""); rterrln!("{}", quote); rterrln!("{}", ""); -- cgit 1.4.1-3-g733a5