From bfa853f8ed45d1908c98ec350f52c7a6790661da Mon Sep 17 00:00:00 2001 From: Aaron Turon Date: Wed, 2 Jul 2014 13:50:45 -0700 Subject: io::process::Command: add fine-grained env builder This commit changes the `io::process::Command` API to provide fine-grained control over the environment: * The `env` method now inserts/updates a key/value pair. * The `env_remove` method removes a key from the environment. * The old `env` method, which sets the entire environment in one shot, is renamed to `env_set_all`. It can be used in conjunction with the finer-grained methods. This renaming is a breaking change. To support these new methods, the internal `env` representation for `Command` has been changed to an optional `HashMap` holding owned `CString`s (to support non-utf8 data). The `HashMap` is only materialized if the environment is updated. The implementation does not try hard to avoid allocation, since the cost of launching a process will dwarf any allocation cost. This patch also adds `PartialOrd`, `Eq`, and `Hash` implementations for `CString`. [breaking-change] --- src/libnative/io/process.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/libnative') diff --git a/src/libnative/io/process.rs b/src/libnative/io/process.rs index 71702d180b9..21da0104c2f 100644 --- a/src/libnative/io/process.rs +++ b/src/libnative/io/process.rs @@ -729,7 +729,7 @@ fn with_argv(prog: &CString, args: &[CString], } #[cfg(unix)] -fn with_envp(env: Option<&[(CString, CString)]>, +fn with_envp(env: Option<&[(&CString, &CString)]>, cb: proc(*const c_void) -> T) -> T { // On posixy systems we can pass a char** for envp, which is a // null-terminated array of "k=v\0" strings. Since we must create @@ -762,7 +762,7 @@ fn with_envp(env: Option<&[(CString, CString)]>, } #[cfg(windows)] -fn with_envp(env: Option<&[(CString, CString)]>, cb: |*mut c_void| -> T) -> T { +fn with_envp(env: Option<&[(&CString, &CString)]>, cb: |*mut c_void| -> T) -> T { // On win32 we pass an "environment block" which is not a char**, but // rather a concatenation of null-terminated k=v\0 sequences, with a final // \0 to terminate. -- cgit 1.4.1-3-g733a5