@@ -36,8 +36,8 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) }
36
36
#[ cfg( test) ] pub unsafe fn cleanup ( ) { realargs:: cleanup ( ) }
37
37
38
38
/// Take the global arguments from global storage.
39
- #[ cfg( not( test) ) ] pub fn take ( ) -> Option < ~[ ~str ] > { imp:: take ( ) }
40
- #[ cfg( test) ] pub fn take ( ) -> Option < ~[ ~str ] > {
39
+ #[ cfg( not( test) ) ] pub fn take ( ) -> Option < ~[ ~[ u8 ] ] > { imp:: take ( ) }
40
+ #[ cfg( test) ] pub fn take ( ) -> Option < ~[ ~[ u8 ] ] > {
41
41
match realargs:: take ( ) {
42
42
realstd:: option:: Some ( a) => Some ( a) ,
43
43
realstd:: option:: None => None ,
@@ -47,12 +47,12 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) }
47
47
/// Give the global arguments to global storage.
48
48
///
49
49
/// It is an error if the arguments already exist.
50
- #[ cfg( not( test) ) ] pub fn put ( args : ~[ ~str ] ) { imp:: put ( args) }
51
- #[ cfg( test) ] pub fn put ( args : ~[ ~str ] ) { realargs:: put ( args) }
50
+ #[ cfg( not( test) ) ] pub fn put ( args : ~[ ~[ u8 ] ] ) { imp:: put ( args) }
51
+ #[ cfg( test) ] pub fn put ( args : ~[ ~[ u8 ] ] ) { realargs:: put ( args) }
52
52
53
53
/// Make a clone of the global arguments.
54
- #[ cfg( not( test) ) ] pub fn clone ( ) -> Option < ~[ ~str ] > { imp:: clone ( ) }
55
- #[ cfg( test) ] pub fn clone ( ) -> Option < ~[ ~str ] > {
54
+ #[ cfg( not( test) ) ] pub fn clone ( ) -> Option < ~[ ~[ u8 ] ] > { imp:: clone ( ) }
55
+ #[ cfg( test) ] pub fn clone ( ) -> Option < ~[ ~[ u8 ] ] > {
56
56
match realargs:: clone ( ) {
57
57
realstd:: option:: Some ( a) => Some ( a) ,
58
58
realstd:: option:: None => None ,
@@ -65,15 +65,12 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) }
65
65
mod imp {
66
66
use cast;
67
67
use clone:: Clone ;
68
- #[ cfg( not( test) ) ] use libc;
69
68
use option:: { Option , Some , None } ;
70
69
use ptr:: RawPtr ;
71
70
use iter:: Iterator ;
72
- #[ cfg( not( test) ) ] use str;
73
71
use unstable:: finally:: Finally ;
74
72
use unstable:: mutex:: { Mutex , MUTEX_INIT } ;
75
73
use mem;
76
- #[ cfg( not( test) ) ] use vec;
77
74
78
75
static mut global_args_ptr: uint = 0 ;
79
76
static mut lock: Mutex = MUTEX_INIT ;
@@ -90,26 +87,26 @@ mod imp {
90
87
lock. destroy ( ) ;
91
88
}
92
89
93
- pub fn take ( ) -> Option < ~[ ~str ] > {
90
+ pub fn take ( ) -> Option < ~[ ~[ u8 ] ] > {
94
91
with_lock ( || unsafe {
95
92
let ptr = get_global_ptr ( ) ;
96
93
let val = mem:: replace ( & mut * ptr, None ) ;
97
- val. as_ref ( ) . map ( |s : & ~~[ ~str ] | ( * * s) . clone ( ) )
94
+ val. as_ref ( ) . map ( |s : & ~~[ ~[ u8 ] ] | ( * * s) . clone ( ) )
98
95
} )
99
96
}
100
97
101
- pub fn put ( args : ~[ ~str ] ) {
98
+ pub fn put ( args : ~[ ~[ u8 ] ] ) {
102
99
with_lock ( || unsafe {
103
100
let ptr = get_global_ptr ( ) ;
104
101
rtassert ! ( ( * ptr) . is_none( ) ) ;
105
102
( * ptr) = Some ( ~args. clone ( ) ) ;
106
103
} )
107
104
}
108
105
109
- pub fn clone ( ) -> Option < ~[ ~str ] > {
106
+ pub fn clone ( ) -> Option < ~[ ~[ u8 ] ] > {
110
107
with_lock ( || unsafe {
111
108
let ptr = get_global_ptr ( ) ;
112
- ( * ptr) . as_ref ( ) . map ( |s : & ~~[ ~str ] | ( * * s) . clone ( ) )
109
+ ( * ptr) . as_ref ( ) . map ( |s : & ~~[ ~[ u8 ] ] | ( * * s) . clone ( ) )
113
110
} )
114
111
}
115
112
@@ -126,15 +123,20 @@ mod imp {
126
123
} )
127
124
}
128
125
129
- fn get_global_ptr ( ) -> * mut Option < ~~[ ~str ] > {
126
+ fn get_global_ptr ( ) -> * mut Option < ~~[ ~[ u8 ] ] > {
130
127
unsafe { cast:: transmute ( & global_args_ptr) }
131
128
}
132
129
133
130
// Copied from `os`.
134
131
#[ cfg( not( test) ) ]
135
- unsafe fn load_argc_and_argv ( argc : int , argv : * * u8 ) -> ~[ ~str ] {
132
+ unsafe fn load_argc_and_argv ( argc : int , argv : * * u8 ) -> ~[ ~[ u8 ] ] {
133
+ use c_str:: CString ;
134
+ use { vec, libc} ;
135
+ use vec:: CloneableVector ;
136
+
136
137
vec:: from_fn ( argc as uint , |i| {
137
- str:: raw:: from_c_str ( * ( argv as * * libc:: c_char ) . offset ( i as int ) )
138
+ let cs = CString :: new ( * ( argv as * * libc:: c_char ) . offset ( i as int ) , false ) ;
139
+ cs. as_bytes_no_nul ( ) . to_owned ( )
138
140
} )
139
141
}
140
142
@@ -149,7 +151,7 @@ mod imp {
149
151
// Preserve the actual global state.
150
152
let saved_value = take ( ) ;
151
153
152
- let expected = ~[ ~ "happy", ~ "today?"] ;
154
+ let expected = ~[ bytes ! ( "happy" ) . to_owned ( ) , bytes ! ( "today?" ) . to_owned ( ) ] ;
153
155
154
156
put ( expected. clone ( ) ) ;
155
157
assert ! ( clone( ) == Some ( expected. clone( ) ) ) ;
@@ -179,15 +181,15 @@ mod imp {
179
181
pub fn cleanup ( ) {
180
182
}
181
183
182
- pub fn take ( ) -> Option < ~[ ~str ] > {
184
+ pub fn take ( ) -> Option < ~[ ~[ u8 ] ] > {
183
185
fail ! ( )
184
186
}
185
187
186
- pub fn put ( _args : ~[ ~str ] ) {
188
+ pub fn put ( _args : ~[ ~[ u8 ] ] ) {
187
189
fail ! ( )
188
190
}
189
191
190
- pub fn clone ( ) -> Option < ~[ ~str ] > {
192
+ pub fn clone ( ) -> Option < ~[ ~[ u8 ] ] > {
191
193
fail ! ( )
192
194
}
193
195
}
0 commit comments