Skip to content

Commit a80d79c

Browse files
committed
run: Process::new() should take &[Str] instead of &[~str] for args
Fixes #7928.
1 parent 7c6c751 commit a80d79c

File tree

3 files changed

+38
-28
lines changed

3 files changed

+38
-28
lines changed

src/librust/rust.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ fn cmd_test(args: &[~str]) -> ValidUsage {
165165
let test_exec = Path(*filename).filestem().unwrap() + "test~";
166166
invoke("rustc", &[~"--test", filename.to_owned(),
167167
~"-o", test_exec.to_owned()], rustc::main_args);
168-
let exit_code = run::process_status(~"./" + test_exec, []);
168+
let args: &[&str] = [];
169+
let exit_code = run::process_status(~"./" + test_exec, args);
169170
Valid(exit_code)
170171
}
171172
_ => Invalid

src/libstd/run.rs

+30-24
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use prelude::*;
2525
use ptr;
2626
use task;
2727
use 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
})

src/test/run-pass/core-run-destroy.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ use std::str;
2222

2323
#[test]
2424
fn test_destroy_once() {
25-
let mut p = run::Process::new("echo", [], run::ProcessOptions::new());
25+
let args: &[&str] = [];
26+
let mut p = run::Process::new("echo", args, run::ProcessOptions::new());
2627
p.destroy(); // this shouldn't crash (and nor should the destructor)
2728
}
2829

2930
#[test]
3031
fn test_destroy_twice() {
31-
let mut p = run::Process::new("echo", [], run::ProcessOptions::new());
32+
let args: &[&str] = [];
33+
let mut p = run::Process::new("echo", args, run::ProcessOptions::new());
3234
p.destroy(); // this shouldnt crash...
3335
p.destroy(); // ...and nor should this (and nor should the destructor)
3436
}
@@ -74,7 +76,8 @@ fn test_destroy_actually_kills(force: bool) {
7476
}
7577

7678
// this process will stay alive indefinitely trying to read from stdin
77-
let mut p = run::Process::new(BLOCK_COMMAND, [], run::ProcessOptions::new());
79+
let args: &[&str] = [];
80+
let mut p = run::Process::new(BLOCK_COMMAND, args, run::ProcessOptions::new());
7881

7982
assert!(process_exists(p.get_id()));
8083

0 commit comments

Comments
 (0)