Skip to content

Commit 04b69bd

Browse files
committed
---
yaml --- r: 151462 b: refs/heads/try2 c: f340fb9 h: refs/heads/master v: v3
1 parent 9b8dd02 commit 04b69bd

File tree

3 files changed

+48
-45
lines changed

3 files changed

+48
-45
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 001a8741b42be9fed5521d9a5a96cf1ea7269fbb
8+
refs/heads/try2: f340fb9b1292f519d0bf09019cd34e7068cc9618
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/os.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn with_env_lock<T>(f: || -> T) -> T {
169169
///
170170
/// Invalid UTF-8 bytes are replaced with \uFFFD. See `str::from_utf8_lossy()`
171171
/// for details.
172-
pub fn env() -> ~[(~str,~str)] {
172+
pub fn env() -> Vec<(~str,~str)> {
173173
env_as_bytes().move_iter().map(|(k,v)| {
174174
let k = str::from_utf8_lossy(k).into_owned();
175175
let v = str::from_utf8_lossy(v).into_owned();
@@ -179,7 +179,7 @@ pub fn env() -> ~[(~str,~str)] {
179179

180180
/// Returns a vector of (variable, value) byte-vector pairs for all the
181181
/// environment variables of the current process.
182-
pub fn env_as_bytes() -> ~[(~[u8],~[u8])] {
182+
pub fn env_as_bytes() -> Vec<(~[u8],~[u8])> {
183183
unsafe {
184184
#[cfg(windows)]
185185
unsafe fn get_env_pairs() -> Vec<~[u8]> {
@@ -224,16 +224,16 @@ pub fn env_as_bytes() -> ~[(~[u8],~[u8])] {
224224
fn env_convert(input: Vec<~[u8]>) -> Vec<(~[u8], ~[u8])> {
225225
let mut pairs = Vec::new();
226226
for p in input.iter() {
227-
let vs: ~[&[u8]] = p.splitn(1, |b| *b == '=' as u8).collect();
228-
let key = vs[0].to_owned();
229-
let val = if vs.len() < 2 { box [] } else { vs[1].to_owned() };
227+
let mut it = p.splitn(1, |b| *b == '=' as u8);
228+
let key = it.next().unwrap().to_owned();
229+
let val = it.next().unwrap_or(&[]).to_owned();
230230
pairs.push((key, val));
231231
}
232232
pairs
233233
}
234234
with_env_lock(|| {
235235
let unparsed_environ = get_env_pairs();
236-
env_convert(unparsed_environ).move_iter().collect()
236+
env_convert(unparsed_environ)
237237
})
238238
}
239239
}
@@ -416,7 +416,7 @@ pub fn dll_filename(base: &str) -> ~str {
416416
pub fn self_exe_name() -> Option<Path> {
417417

418418
#[cfg(target_os = "freebsd")]
419-
fn load_self() -> Option<~[u8]> {
419+
fn load_self() -> Option<Vec<u8>> {
420420
unsafe {
421421
use libc::funcs::bsd44::*;
422422
use libc::consts::os::extra::*;
@@ -436,23 +436,23 @@ pub fn self_exe_name() -> Option<Path> {
436436
if err != 0 { return None; }
437437
if sz == 0 { return None; }
438438
v.set_len(sz as uint - 1); // chop off trailing NUL
439-
Some(v.move_iter().collect())
439+
Some(v)
440440
}
441441
}
442442

443443
#[cfg(target_os = "linux")]
444444
#[cfg(target_os = "android")]
445-
fn load_self() -> Option<~[u8]> {
445+
fn load_self() -> Option<Vec<u8>> {
446446
use std::io;
447447

448448
match io::fs::readlink(&Path::new("/proc/self/exe")) {
449-
Ok(path) => Some(path.as_vec().to_owned()),
449+
Ok(path) => Some(path.into_vec()),
450450
Err(..) => None
451451
}
452452
}
453453

454454
#[cfg(target_os = "macos")]
455-
fn load_self() -> Option<~[u8]> {
455+
fn load_self() -> Option<Vec<u8>> {
456456
unsafe {
457457
use libc::funcs::extra::_NSGetExecutablePath;
458458
let mut sz: u32 = 0;
@@ -462,19 +462,19 @@ pub fn self_exe_name() -> Option<Path> {
462462
let err = _NSGetExecutablePath(v.as_mut_ptr() as *mut i8, &mut sz);
463463
if err != 0 { return None; }
464464
v.set_len(sz as uint - 1); // chop off trailing NUL
465-
Some(v.move_iter().collect())
465+
Some(v)
466466
}
467467
}
468468

469469
#[cfg(windows)]
470-
fn load_self() -> Option<~[u8]> {
470+
fn load_self() -> Option<Vec<u8>> {
471471
use str::OwnedStr;
472472

473473
unsafe {
474474
use os::win32::fill_utf16_buf_and_decode;
475475
fill_utf16_buf_and_decode(|buf, sz| {
476476
libc::GetModuleFileNameW(0u as libc::DWORD, buf, sz)
477-
}).map(|s| s.into_bytes())
477+
}).map(|s| s.into_strbuf().into_bytes())
478478
}
479479
}
480480

@@ -789,12 +789,12 @@ pub fn get_exit_status() -> int {
789789
}
790790

791791
#[cfg(target_os = "macos")]
792-
unsafe fn load_argc_and_argv(argc: int, argv: **c_char) -> ~[~[u8]] {
792+
unsafe fn load_argc_and_argv(argc: int, argv: **c_char) -> Vec<~[u8]> {
793793
use c_str::CString;
794794

795795
Vec::from_fn(argc as uint, |i| {
796796
CString::new(*argv.offset(i as int), false).as_bytes_no_nul().to_owned()
797-
}).move_iter().collect()
797+
})
798798
}
799799

800800
/**
@@ -803,7 +803,7 @@ unsafe fn load_argc_and_argv(argc: int, argv: **c_char) -> ~[~[u8]] {
803803
* Returns a list of the command line arguments.
804804
*/
805805
#[cfg(target_os = "macos")]
806-
fn real_args_as_bytes() -> ~[~[u8]] {
806+
fn real_args_as_bytes() -> Vec<~[u8]> {
807807
unsafe {
808808
let (argc, argv) = (*_NSGetArgc() as int,
809809
*_NSGetArgv() as **c_char);
@@ -814,7 +814,7 @@ fn real_args_as_bytes() -> ~[~[u8]] {
814814
#[cfg(target_os = "linux")]
815815
#[cfg(target_os = "android")]
816816
#[cfg(target_os = "freebsd")]
817-
fn real_args_as_bytes() -> ~[~[u8]] {
817+
fn real_args_as_bytes() -> Vec<~[u8]> {
818818
use rt;
819819

820820
match rt::args::clone() {
@@ -824,12 +824,12 @@ fn real_args_as_bytes() -> ~[~[u8]] {
824824
}
825825

826826
#[cfg(not(windows))]
827-
fn real_args() -> ~[~str] {
827+
fn real_args() -> Vec<~str> {
828828
real_args_as_bytes().move_iter().map(|v| str::from_utf8_lossy(v).into_owned()).collect()
829829
}
830830

831831
#[cfg(windows)]
832-
fn real_args() -> ~[~str] {
832+
fn real_args() -> Vec<~str> {
833833
use slice;
834834
use option::Expect;
835835

@@ -855,11 +855,11 @@ fn real_args() -> ~[~str] {
855855
LocalFree(szArgList as *c_void);
856856
}
857857

858-
return args.move_iter().collect();
858+
return args
859859
}
860860

861861
#[cfg(windows)]
862-
fn real_args_as_bytes() -> ~[~[u8]] {
862+
fn real_args_as_bytes() -> Vec<~[u8]> {
863863
real_args().move_iter().map(|s| s.into_bytes()).collect()
864864
}
865865

@@ -883,13 +883,13 @@ extern "system" {
883883
///
884884
/// The arguments are interpreted as utf-8, with invalid bytes replaced with \uFFFD.
885885
/// See `str::from_utf8_lossy` for details.
886-
pub fn args() -> ~[~str] {
886+
pub fn args() -> Vec<~str> {
887887
real_args()
888888
}
889889

890890
/// Returns the arguments which this program was started with (normally passed
891891
/// via the command line) as byte vectors.
892-
pub fn args_as_bytes() -> ~[~[u8]] {
892+
pub fn args_as_bytes() -> Vec<~[u8]> {
893893
real_args_as_bytes()
894894
}
895895

branches/try2/src/libstd/rt/args.rs

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
//! FIXME #7756: This has a lot of C glue for lack of globals.
2222
2323
use option::Option;
24+
use vec::Vec;
2425
#[cfg(test)] use option::{Some, None};
2526
#[cfg(test)] use realstd;
2627
#[cfg(test)] use realargs = realstd::rt::args;
@@ -36,25 +37,25 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) }
3637
#[cfg(test)] pub unsafe fn cleanup() { realargs::cleanup() }
3738

3839
/// Take the global arguments from global storage.
39-
#[cfg(not(test))] pub fn take() -> Option<~[~[u8]]> { imp::take() }
40-
#[cfg(test)] pub fn take() -> Option<~[~[u8]]> {
40+
#[cfg(not(test))] pub fn take() -> Option<Vec<~[u8]>> { imp::take() }
41+
#[cfg(test)] pub fn take() -> Option<Vec<~[u8]>> {
4142
match realargs::take() {
42-
realstd::option::Some(a) => Some(a),
43+
realstd::option::Some(v) => Some(unsafe{ ::cast::transmute(v) }),
4344
realstd::option::None => None,
4445
}
4546
}
4647

4748
/// Give the global arguments to global storage.
4849
///
4950
/// It is an error if the arguments already exist.
50-
#[cfg(not(test))] pub fn put(args: ~[~[u8]]) { imp::put(args) }
51-
#[cfg(test)] pub fn put(args: ~[~[u8]]) { realargs::put(args) }
51+
#[cfg(not(test))] pub fn put(args: Vec<~[u8]>) { imp::put(args) }
52+
#[cfg(test)] pub fn put(args: Vec<~[u8]>) { realargs::put(unsafe { ::cast::transmute(args) }) }
5253

5354
/// Make a clone of the global arguments.
54-
#[cfg(not(test))] pub fn clone() -> Option<~[~[u8]]> { imp::clone() }
55-
#[cfg(test)] pub fn clone() -> Option<~[~[u8]]> {
55+
#[cfg(not(test))] pub fn clone() -> Option<Vec<~[u8]>> { imp::clone() }
56+
#[cfg(test)] pub fn clone() -> Option<Vec<~[u8]>> {
5657
match realargs::clone() {
57-
realstd::option::Some(a) => Some(a),
58+
realstd::option::Some(v) => Some(unsafe { ::cast::transmute(v) }),
5859
realstd::option::None => None,
5960
}
6061
}
@@ -70,6 +71,7 @@ mod imp {
7071
use owned::Box;
7172
use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
7273
use mem;
74+
use vec::Vec;
7375
#[cfg(not(test))] use ptr::RawPtr;
7476

7577
static mut global_args_ptr: uint = 0;
@@ -87,26 +89,26 @@ mod imp {
8789
lock.destroy();
8890
}
8991

90-
pub fn take() -> Option<~[~[u8]]> {
92+
pub fn take() -> Option<Vec<~[u8]>> {
9193
with_lock(|| unsafe {
9294
let ptr = get_global_ptr();
9395
let val = mem::replace(&mut *ptr, None);
94-
val.as_ref().map(|s: &Box<~[~[u8]]>| (**s).clone())
96+
val.as_ref().map(|s: &Box<Vec<~[u8]>>| (**s).clone())
9597
})
9698
}
9799

98-
pub fn put(args: ~[~[u8]]) {
100+
pub fn put(args: Vec<~[u8]>) {
99101
with_lock(|| unsafe {
100102
let ptr = get_global_ptr();
101103
rtassert!((*ptr).is_none());
102104
(*ptr) = Some(box args.clone());
103105
})
104106
}
105107

106-
pub fn clone() -> Option<~[~[u8]]> {
108+
pub fn clone() -> Option<Vec<~[u8]>> {
107109
with_lock(|| unsafe {
108110
let ptr = get_global_ptr();
109-
(*ptr).as_ref().map(|s: &Box<~[~[u8]]>| (**s).clone())
111+
(*ptr).as_ref().map(|s: &Box<Vec<~[u8]>>| (**s).clone())
110112
})
111113
}
112114

@@ -117,13 +119,13 @@ mod imp {
117119
}
118120
}
119121

120-
fn get_global_ptr() -> *mut Option<Box<~[~[u8]]>> {
122+
fn get_global_ptr() -> *mut Option<Box<Vec<~[u8]>>> {
121123
unsafe { cast::transmute(&global_args_ptr) }
122124
}
123125

124126
// Copied from `os`.
125127
#[cfg(not(test))]
126-
unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> ~[~[u8]] {
128+
unsafe fn load_argc_and_argv(argc: int, argv: **u8) -> Vec<~[u8]> {
127129
use c_str::CString;
128130
use ptr::RawPtr;
129131
use libc;
@@ -133,7 +135,7 @@ mod imp {
133135
Vec::from_fn(argc as uint, |i| {
134136
let cs = CString::new(*(argv as **libc::c_char).offset(i as int), false);
135137
cs.as_bytes_no_nul().to_owned()
136-
}).move_iter().collect()
138+
})
137139
}
138140

139141
#[cfg(test)]
@@ -147,7 +149,7 @@ mod imp {
147149
// Preserve the actual global state.
148150
let saved_value = take();
149151

150-
let expected = box [bytes!("happy").to_owned(), bytes!("today?").to_owned()];
152+
let expected = vec![bytes!("happy").to_owned(), bytes!("today?").to_owned()];
151153

152154
put(expected.clone());
153155
assert!(clone() == Some(expected.clone()));
@@ -170,22 +172,23 @@ mod imp {
170172
#[cfg(target_os = "win32", not(test))]
171173
mod imp {
172174
use option::Option;
175+
use vec::Vec;
173176

174177
pub unsafe fn init(_argc: int, _argv: **u8) {
175178
}
176179

177180
pub fn cleanup() {
178181
}
179182

180-
pub fn take() -> Option<~[~[u8]]> {
183+
pub fn take() -> Option<Vec<~[u8]>> {
181184
fail!()
182185
}
183186

184-
pub fn put(_args: ~[~[u8]]) {
187+
pub fn put(_args: Vec<~[u8]>) {
185188
fail!()
186189
}
187190

188-
pub fn clone() -> Option<~[~[u8]]> {
191+
pub fn clone() -> Option<Vec<~[u8]>> {
189192
fail!()
190193
}
191194
}

0 commit comments

Comments
 (0)