1
+ // NB: transitionary, de-mode-ing.
2
+ #[ forbid( deprecated_mode) ] ;
3
+ #[ forbid( deprecated_pattern) ] ;
4
+
1
5
//! Process spawning
2
6
import option:: { some, none} ;
3
7
import libc:: { pid_t, c_void, c_int} ;
@@ -62,9 +66,9 @@ trait program {
62
66
*
63
67
* The process id of the spawned process
64
68
*/
65
- fn spawn_process ( prog : ~ str , args : ~ [ ~str ] ,
66
- env : option < ~[ ( ~str , ~str ) ] > ,
67
- dir : option < ~str > ,
69
+ fn spawn_process ( prog : & str , args : & [ ~str ] ,
70
+ env : & option < ~[ ( ~str , ~str ) ] > ,
71
+ dir : & option < ~str > ,
68
72
in_fd : c_int , out_fd : c_int , err_fd : c_int )
69
73
-> pid_t {
70
74
do with_argv ( prog, args) |argv| {
@@ -77,7 +81,7 @@ fn spawn_process(prog: ~str, args: ~[~str],
77
81
}
78
82
}
79
83
80
- fn with_argv < T > ( prog : ~ str , args : ~ [ ~str ] ,
84
+ fn with_argv < T > ( prog : & str , args : & [ ~str ] ,
81
85
cb : fn ( * * libc:: c_char ) -> T ) -> T {
82
86
let mut argptrs = str:: as_c_str ( prog, |b| ~[ b] ) ;
83
87
let mut tmps = ~[ ] ;
@@ -91,11 +95,11 @@ fn with_argv<T>(prog: ~str, args: ~[~str],
91
95
}
92
96
93
97
#[ cfg( unix) ]
94
- fn with_envp < T > ( env : option < ~[ ( ~str , ~str ) ] > ,
98
+ fn with_envp < T > ( env : & option < ~[ ( ~str , ~str ) ] > ,
95
99
cb : fn ( * c_void ) -> T ) -> T {
96
100
// On posixy systems we can pass a char** for envp, which is
97
101
// a null-terminated array of "k=v\n" strings.
98
- match env {
102
+ match * env {
99
103
some( es) if !vec:: is_empty ( es) => {
100
104
let mut tmps = ~[ ] ;
101
105
let mut ptrs = ~[ ] ;
@@ -140,9 +144,9 @@ fn with_envp<T>(env: option<~[(~str,~str)]>,
140
144
}
141
145
}
142
146
143
- fn with_dirp < T > ( d : option < ~str > ,
147
+ fn with_dirp < T > ( d : & option < ~str > ,
144
148
cb : fn ( * libc:: c_char ) -> T ) -> T {
145
- match d {
149
+ match * d {
146
150
some( dir) => str:: as_c_str ( dir, cb) ,
147
151
none => cb ( ptr:: null ( ) )
148
152
}
@@ -160,8 +164,8 @@ fn with_dirp<T>(d: option<~str>,
160
164
*
161
165
* The process id
162
166
*/
163
- fn run_program ( prog : ~ str , args : ~ [ ~str ] ) -> int {
164
- let pid = spawn_process ( prog, args, none, none,
167
+ fn run_program ( prog : & str , args : & [ ~str ] ) -> int {
168
+ let pid = spawn_process ( prog, args, & none, & none,
165
169
0i32 , 0i32 , 0i32 ) ;
166
170
if pid == -1 as pid_t { fail; }
167
171
return waitpid ( pid) ;
@@ -183,12 +187,12 @@ fn run_program(prog: ~str, args: ~[~str]) -> int {
183
187
*
184
188
* A class with a <program> field
185
189
*/
186
- fn start_program ( prog : ~ str , args : ~ [ ~str ] ) -> program {
190
+ fn start_program ( prog : & str , args : & [ ~str ] ) -> program {
187
191
let pipe_input = os:: pipe ( ) ;
188
192
let pipe_output = os:: pipe ( ) ;
189
193
let pipe_err = os:: pipe ( ) ;
190
194
let pid =
191
- spawn_process ( prog, args, none, none,
195
+ spawn_process ( prog, args, & none, & none,
192
196
pipe_input. in , pipe_output. out ,
193
197
pipe_err. out ) ;
194
198
@@ -203,45 +207,45 @@ fn start_program(prog: ~str, args: ~[~str]) -> program {
203
207
err_file : * libc:: FILE ,
204
208
mut finished : bool } ;
205
209
206
- fn close_repr_input ( r : prog_repr ) {
210
+ fn close_repr_input ( r : & prog_repr ) {
207
211
let invalid_fd = -1i32 ;
208
212
if r. in_fd != invalid_fd {
209
213
libc:: close ( r. in_fd ) ;
210
214
r. in_fd = invalid_fd;
211
215
}
212
216
}
213
- fn finish_repr ( r : prog_repr ) -> int {
217
+ fn finish_repr ( r : & prog_repr ) -> int {
214
218
if r. finished { return 0 ; }
215
219
r. finished = true ;
216
220
close_repr_input ( r) ;
217
221
return waitpid ( r. pid ) ;
218
222
}
219
- fn destroy_repr ( r : prog_repr ) {
223
+ fn destroy_repr ( r : & prog_repr ) {
220
224
finish_repr ( r) ;
221
225
libc:: fclose ( r. out_file ) ;
222
226
libc:: fclose ( r. err_file ) ;
223
227
}
224
228
class prog_res {
225
229
let r: prog_repr;
226
- new ( - r: prog_repr) { self . r = r; }
227
- drop { destroy_repr( self . r ) ; }
230
+ new( + r: prog_repr) { self . r = r; }
231
+ drop { destroy_repr( & self . r ) ; }
228
232
}
229
233
230
234
impl prog_res : program {
231
235
fn get_id ( ) -> pid_t { return self . r . pid ; }
232
236
fn input ( ) -> io:: writer { io:: fd_writer ( self . r . in_fd , false ) }
233
237
fn output ( ) -> io:: reader { io:: FILE_reader ( self . r . out_file , false ) }
234
238
fn err ( ) -> io:: reader { io:: FILE_reader ( self . r . err_file , false ) }
235
- fn close_input ( ) { close_repr_input ( self . r ) ; }
236
- fn finish ( ) -> int { finish_repr ( self . r ) }
237
- fn destroy ( ) { destroy_repr ( self . r ) ; }
239
+ fn close_input ( ) { close_repr_input ( & self . r ) ; }
240
+ fn finish ( ) -> int { finish_repr ( & self . r ) }
241
+ fn destroy ( ) { destroy_repr ( & self . r ) ; }
238
242
}
239
243
let repr = { pid: pid,
240
244
mut in_fd: pipe_input. out ,
241
245
out_file: os:: fdopen ( pipe_output. in ) ,
242
246
err_file: os:: fdopen ( pipe_err. in ) ,
243
247
mut finished: false } ;
244
- return prog_res ( repr) as program ;
248
+ return prog_res ( move repr) as program ;
245
249
}
246
250
247
251
fn read_all ( rd : io:: reader ) -> ~str {
@@ -267,13 +271,13 @@ fn read_all(rd: io::reader) -> ~str {
267
271
* A record, {status: int, out: str, err: str} containing the exit code,
268
272
* the contents of stdout and the contents of stderr.
269
273
*/
270
- fn program_output ( prog : ~ str , args : ~ [ ~str ] ) ->
274
+ fn program_output ( prog : & str , args : & [ ~str ] ) ->
271
275
{ status : int , out : ~str , err : ~str } {
272
276
273
277
let pipe_in = os:: pipe ( ) ;
274
278
let pipe_out = os:: pipe ( ) ;
275
279
let pipe_err = os:: pipe ( ) ;
276
- let pid = spawn_process ( prog, args, none, none,
280
+ let pid = spawn_process ( prog, args, & none, & none,
277
281
pipe_in. in , pipe_out. out , pipe_err. out ) ;
278
282
279
283
os:: close ( pipe_in. in ) ;
@@ -321,7 +325,7 @@ fn program_output(prog: ~str, args: ~[~str]) ->
321
325
return { status: status, out: outs, err: errs} ;
322
326
}
323
327
324
- fn writeclose ( fd : c_int , s : ~ str ) {
328
+ fn writeclose ( fd : c_int , s : & str ) {
325
329
import io:: writer_util;
326
330
327
331
error ! { "writeclose %d, %s" , fd as int, s} ;
@@ -393,9 +397,9 @@ mod tests {
393
397
// Regression test for memory leaks
394
398
#[ ignore( cfg( windows) ) ] // FIXME (#2626)
395
399
fn test_leaks ( ) {
396
- run:: run_program ( ~ "echo", ~ [ ] ) ;
397
- run:: start_program ( ~ "echo", ~ [ ] ) ;
398
- run:: program_output ( ~ "echo", ~ [ ] ) ;
400
+ run:: run_program ( "echo" , [ ] ) ;
401
+ run:: start_program ( "echo" , [ ] ) ;
402
+ run:: program_output ( "echo" , [ ] ) ;
399
403
}
400
404
401
405
#[ test]
@@ -406,7 +410,7 @@ mod tests {
406
410
407
411
let pid =
408
412
run:: spawn_process (
409
- ~ "cat", ~ [ ] , none, none,
413
+ "cat" , [ ] , & none, & none,
410
414
pipe_in. in , pipe_out. out , pipe_err. out ) ;
411
415
os:: close ( pipe_in. in ) ;
412
416
os:: close ( pipe_out. out ) ;
@@ -426,8 +430,8 @@ mod tests {
426
430
427
431
#[ test]
428
432
fn waitpid ( ) {
429
- let pid = run:: spawn_process ( ~ "false ", ~ [ ] ,
430
- none, none,
433
+ let pid = run:: spawn_process ( "false" , [ ] ,
434
+ & none, & none,
431
435
0i32 , 0i32 , 0i32 ) ;
432
436
let status = run:: waitpid ( pid) ;
433
437
assert status == 1 ;
0 commit comments