@@ -25,6 +25,7 @@ use prelude::*;
2525use ptr;
2626use task;
2727use vec:: ImmutableVector ;
28+ use str:: Str ;
2829
2930/**
3031 * A value representing a child process.
@@ -147,9 +148,8 @@ impl Process {
147148 * * options - Options to configure the environment of the process,
148149 * the working directory and the standard IO streams.
149150 */
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 {
153153 #[ fixed_stack_segment] ; #[ inline( never) ] ;
154154
155155 let ( in_pipe, in_fd) = match options. in_fd {
@@ -452,10 +452,10 @@ struct SpawnProcessResult {
452452}
453453
454454#[ 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 {
459459 #[ fixed_stack_segment] ; #[ inline( never) ] ;
460460
461461 use libc:: types:: os:: arch:: extra:: { DWORD , HANDLE , STARTUPINFO } ;
@@ -584,12 +584,12 @@ fn zeroed_process_information() -> libc::types::os::arch::extra::PROCESS_INFORMA
584584
585585// FIXME: this is only pub so it can be tested (see issue #4536)
586586#[ 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 {
588588 let mut cmd = ~"";
589589 append_arg ( & mut cmd, prog) ;
590590 for arg in args. iter ( ) {
591591 cmd. push_char ( ' ' ) ;
592- append_arg ( & mut cmd, * arg) ;
592+ append_arg ( & mut cmd, arg. as_slice ( ) ) ;
593593 }
594594 return cmd;
595595
@@ -636,10 +636,10 @@ pub fn make_command_line(prog: &str, args: &[~str]) -> ~str {
636636}
637637
638638#[ 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 {
643643 #[ fixed_stack_segment] ; #[ inline( never) ] ;
644644
645645 use libc:: funcs:: posix88:: unistd:: { fork, dup2, close, chdir, execvp} ;
@@ -700,7 +700,7 @@ fn spawn_process_os(prog: &str, args: &[~str],
700700}
701701
702702#[ 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 {
704704 use vec;
705705
706706 // 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 {
711711 tmps. push ( prog. to_c_str ( ) ) ;
712712
713713 for arg in args. iter ( ) {
714- tmps. push ( arg. to_c_str ( ) ) ;
714+ tmps. push ( arg. as_slice ( ) . to_c_str ( ) ) ;
715715 }
716716
717717 // Next, convert each of the byte strings into a pointer. This is
@@ -817,7 +817,7 @@ fn free_handle(_handle: *()) {
817817 *
818818 * The process's exit code
819819 */
820- pub fn process_status ( prog : & str , args : & [ ~ str ] ) -> int {
820+ pub fn process_status < S : Str > ( prog : & str , args : & [ S ] ) -> int {
821821 let mut prog = Process :: new ( prog, args, ProcessOptions {
822822 env : None ,
823823 dir : None ,
@@ -840,7 +840,7 @@ pub fn process_status(prog: &str, args: &[~str]) -> int {
840840 *
841841 * The process's stdout/stderr output and exit code.
842842 */
843- pub fn process_output ( prog : & str , args : & [ ~ str ] ) -> ProcessOutput {
843+ pub fn process_output < S : Str > ( prog : & str , args : & [ S ] ) -> ProcessOutput {
844844 let mut prog = Process :: new ( prog, args, ProcessOptions :: new ( ) ) ;
845845 prog. finish_with_output ( )
846846}
@@ -981,8 +981,9 @@ mod tests {
981981 #[ test]
982982 #[ cfg( not( target_os="android" ) ) ]
983983 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 ) ;
986987 }
987988 #[ test]
988989 #[ cfg( target_os="android" ) ]
@@ -1052,7 +1053,8 @@ mod tests {
10521053 let pipe_out = os::pipe();
10531054 let pipe_err = os::pipe();
10541055
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 {
10561058 dir: None,
10571059 env: None,
10581060 in_fd: Some(pipe_in.input),
@@ -1098,7 +1100,8 @@ mod tests {
10981100 #[test]
10991101 #[cfg(not(target_os=" android"))]
11001102 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());
11021105 assert_eq!(prog.finish(), 1);
11031106 }
11041107 #[test]
@@ -1112,7 +1115,8 @@ mod tests {
11121115 #[test]
11131116 #[cfg(not(target_os=" android"))]
11141117 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());
11161120 assert_eq!(prog.finish(), 1);
11171121 assert_eq!(prog.finish(), 1);
11181122 }
@@ -1247,7 +1251,8 @@ mod tests {
12471251
12481252 #[cfg(unix,not(target_os=" android"))]
12491253 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 {
12511256 dir: dir,
12521257 .. run::ProcessOptions::new()
12531258 })
@@ -1302,7 +1307,8 @@ mod tests {
13021307
13031308 #[cfg(unix,not(target_os=" android"))]
13041309 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 {
13061312 env: env,
13071313 .. run::ProcessOptions::new()
13081314 })
0 commit comments