@@ -25,6 +25,7 @@ use prelude::*;
25
25
use ptr;
26
26
use task;
27
27
use vec:: ImmutableVector ;
28
+ use str:: Str ;
28
29
29
30
/**
30
31
* A value representing a child process.
@@ -147,9 +148,8 @@ impl Process {
147
148
* * options - Options to configure the environment of the process,
148
149
* the working directory and the standard IO streams.
149
150
*/
150
- pub fn new ( prog : & str , args : & [ ~str ] ,
151
- options : ProcessOptions )
152
- -> Process {
151
+ pub fn new < S : Str > ( prog : & str , args : & [ S ] , options : ProcessOptions )
152
+ -> Process {
153
153
#[ fixed_stack_segment] ; #[ inline( never) ] ;
154
154
155
155
let ( in_pipe, in_fd) = match options. in_fd {
@@ -452,10 +452,10 @@ struct SpawnProcessResult {
452
452
}
453
453
454
454
#[ cfg( windows) ]
455
- fn spawn_process_os ( prog : & str , args : & [ ~ str ] ,
456
- env : Option < ~[ ( ~str , ~str ) ] > ,
457
- dir : Option < & Path > ,
458
- in_fd : c_int , out_fd : c_int , err_fd : c_int ) -> SpawnProcessResult {
455
+ fn spawn_process_os < S : Str > ( prog : & str , args : & [ S ] ,
456
+ env : Option < ~[ ( ~str , ~str ) ] > ,
457
+ dir : Option < & Path > ,
458
+ in_fd : c_int , out_fd : c_int , err_fd : c_int ) -> SpawnProcessResult {
459
459
#[ fixed_stack_segment] ; #[ inline( never) ] ;
460
460
461
461
use libc:: types:: os:: arch:: extra:: { DWORD , HANDLE , STARTUPINFO } ;
@@ -584,12 +584,12 @@ fn zeroed_process_information() -> libc::types::os::arch::extra::PROCESS_INFORMA
584
584
585
585
// FIXME: this is only pub so it can be tested (see issue #4536)
586
586
#[ cfg( windows) ]
587
- pub fn make_command_line ( prog : & str , args : & [ ~ str ] ) -> ~str {
587
+ pub fn make_command_line < S : Str > ( prog : & str , args : & [ S ] ) -> ~str {
588
588
let mut cmd = ~"";
589
589
append_arg ( & mut cmd, prog) ;
590
590
for arg in args. iter ( ) {
591
591
cmd. push_char ( ' ' ) ;
592
- append_arg ( & mut cmd, * arg) ;
592
+ append_arg ( & mut cmd, arg. as_slice ( ) ) ;
593
593
}
594
594
return cmd;
595
595
@@ -636,10 +636,10 @@ pub fn make_command_line(prog: &str, args: &[~str]) -> ~str {
636
636
}
637
637
638
638
#[ cfg( unix) ]
639
- fn spawn_process_os ( prog : & str , args : & [ ~ str ] ,
640
- env : Option < ~[ ( ~str , ~str ) ] > ,
641
- dir : Option < & Path > ,
642
- in_fd : c_int , out_fd : c_int , err_fd : c_int ) -> SpawnProcessResult {
639
+ fn spawn_process_os < S : Str > ( prog : & str , args : & [ S ] ,
640
+ env : Option < ~[ ( ~str , ~str ) ] > ,
641
+ dir : Option < & Path > ,
642
+ in_fd : c_int , out_fd : c_int , err_fd : c_int ) -> SpawnProcessResult {
643
643
#[ fixed_stack_segment] ; #[ inline( never) ] ;
644
644
645
645
use libc:: funcs:: posix88:: unistd:: { fork, dup2, close, chdir, execvp} ;
@@ -700,7 +700,7 @@ fn spawn_process_os(prog: &str, args: &[~str],
700
700
}
701
701
702
702
#[ cfg( unix) ]
703
- fn with_argv < T > ( prog : & str , args : & [ ~ str ] , cb : & fn ( * * libc:: c_char ) -> T ) -> T {
703
+ fn with_argv < T , S : Str > ( prog : & str , args : & [ S ] , cb : & fn ( * * libc:: c_char ) -> T ) -> T {
704
704
use vec;
705
705
706
706
// We can't directly convert `str`s into `*char`s, as someone needs to hold
@@ -711,7 +711,7 @@ fn with_argv<T>(prog: &str, args: &[~str], cb: &fn(**libc::c_char) -> T) -> T {
711
711
tmps. push ( prog. to_c_str ( ) ) ;
712
712
713
713
for arg in args. iter ( ) {
714
- tmps. push ( arg. to_c_str ( ) ) ;
714
+ tmps. push ( arg. as_slice ( ) . to_c_str ( ) ) ;
715
715
}
716
716
717
717
// Next, convert each of the byte strings into a pointer. This is
@@ -817,7 +817,7 @@ fn free_handle(_handle: *()) {
817
817
*
818
818
* The process's exit code
819
819
*/
820
- pub fn process_status ( prog : & str , args : & [ ~ str ] ) -> int {
820
+ pub fn process_status < S : Str > ( prog : & str , args : & [ S ] ) -> int {
821
821
let mut prog = Process :: new ( prog, args, ProcessOptions {
822
822
env : None ,
823
823
dir : None ,
@@ -840,7 +840,7 @@ pub fn process_status(prog: &str, args: &[~str]) -> int {
840
840
*
841
841
* The process's stdout/stderr output and exit code.
842
842
*/
843
- pub fn process_output ( prog : & str , args : & [ ~ str ] ) -> ProcessOutput {
843
+ pub fn process_output < S : Str > ( prog : & str , args : & [ S ] ) -> ProcessOutput {
844
844
let mut prog = Process :: new ( prog, args, ProcessOptions :: new ( ) ) ;
845
845
prog. finish_with_output ( )
846
846
}
@@ -981,8 +981,9 @@ mod tests {
981
981
#[ test]
982
982
#[ cfg( not( target_os="android" ) ) ]
983
983
fn test_process_status( ) {
984
- assert_eq!( run:: process_status( "false" , [ ] ) , 1 ) ;
985
- assert_eq!( run:: process_status( "true" , [ ] ) , 0 ) ;
984
+ let args: & [ & str ] = [ ] ;
985
+ assert_eq!( run:: process_status( "false" , args) , 1 ) ;
986
+ assert_eq!( run:: process_status( "true" , args) , 0 ) ;
986
987
}
987
988
#[ test]
988
989
#[ cfg( target_os="android" ) ]
@@ -1052,7 +1053,8 @@ mod tests {
1052
1053
let pipe_out = os::pipe();
1053
1054
let pipe_err = os::pipe();
1054
1055
1055
- let mut proc = run::Process::new(" cat", [], run::ProcessOptions {
1056
+ let args: &[&str] = [];
1057
+ let mut proc = run::Process::new(" cat", args, run::ProcessOptions {
1056
1058
dir: None,
1057
1059
env: None,
1058
1060
in_fd: Some(pipe_in.input),
@@ -1098,7 +1100,8 @@ mod tests {
1098
1100
#[test]
1099
1101
#[cfg(not(target_os=" android"))]
1100
1102
fn test_finish_once() {
1101
- let mut prog = run::Process::new(" false ", [], run::ProcessOptions::new());
1103
+ let args: &[&str] = [];
1104
+ let mut prog = run::Process::new(" false ", args, run::ProcessOptions::new());
1102
1105
assert_eq!(prog.finish(), 1);
1103
1106
}
1104
1107
#[test]
@@ -1112,7 +1115,8 @@ mod tests {
1112
1115
#[test]
1113
1116
#[cfg(not(target_os=" android"))]
1114
1117
fn test_finish_twice() {
1115
- let mut prog = run::Process::new(" false ", [], run::ProcessOptions::new());
1118
+ let args: &[&str] = [];
1119
+ let mut prog = run::Process::new(" false ", args, run::ProcessOptions::new());
1116
1120
assert_eq!(prog.finish(), 1);
1117
1121
assert_eq!(prog.finish(), 1);
1118
1122
}
@@ -1247,7 +1251,8 @@ mod tests {
1247
1251
1248
1252
#[cfg(unix,not(target_os=" android"))]
1249
1253
fn run_pwd(dir: Option<&Path>) -> run::Process {
1250
- run::Process::new(" pwd", [], run::ProcessOptions {
1254
+ let args: &[&str] = [];
1255
+ run::Process::new(" pwd", args, run::ProcessOptions {
1251
1256
dir: dir,
1252
1257
.. run::ProcessOptions::new()
1253
1258
})
@@ -1302,7 +1307,8 @@ mod tests {
1302
1307
1303
1308
#[cfg(unix,not(target_os=" android"))]
1304
1309
fn run_env(env: Option<~[(~str, ~str)]>) -> run::Process {
1305
- run::Process::new(" env", [], run::ProcessOptions {
1310
+ let args: &[&str] = [];
1311
+ run::Process::new(" env", args, run::ProcessOptions {
1306
1312
env: env,
1307
1313
.. run::ProcessOptions::new()
1308
1314
})
0 commit comments