diff options
| author | bors <bors@rust-lang.org> | 2014-07-10 21:41:36 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-07-10 21:41:36 +0000 |
| commit | a672456c40d28f051ecbdb2caf5bf6733371d494 (patch) | |
| tree | 1ce9d7ff9d26425e9c581d7ce377531c1155da0b /src/librustrt | |
| parent | 8bbf598d50960087342667fc47f5d38f4a9c2165 (diff) | |
| parent | bfa853f8ed45d1908c98ec350f52c7a6790661da (diff) | |
| download | rust-a672456c40d28f051ecbdb2caf5bf6733371d494.tar.gz rust-a672456c40d28f051ecbdb2caf5bf6733371d494.zip | |
auto merge of #15353 : aturon/rust/env-hashmap, r=alexcrichton
This commit adds `env_insert` and `env_remove` methods to the `Command` builder, easing updates to the environment variables for the child process. The existing method, `env`, is still available for overriding the entire environment in one shot (after which the `env_insert` and `env_remove` methods can be used to make further adjustments). 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`.
Diffstat (limited to 'src/librustrt')
| -rw-r--r-- | src/librustrt/c_str.rs | 17 | ||||
| -rw-r--r-- | src/librustrt/lib.rs | 2 | ||||
| -rw-r--r-- | src/librustrt/rtio.rs | 2 |
3 files changed, 19 insertions, 2 deletions
diff --git a/src/librustrt/c_str.rs b/src/librustrt/c_str.rs index 06f4e71871d..396d51f4fcb 100644 --- a/src/librustrt/c_str.rs +++ b/src/librustrt/c_str.rs @@ -69,6 +69,7 @@ use core::prelude::*; use alloc::libc_heap::malloc_raw; use collections::string::String; +use collections::hash; use core::kinds::marker; use core::mem; use core::ptr; @@ -116,6 +117,22 @@ impl PartialEq for CString { } } +impl PartialOrd for CString { + #[inline] + fn partial_cmp(&self, other: &CString) -> Option<Ordering> { + self.as_bytes().partial_cmp(&other.as_bytes()) + } +} + +impl Eq for CString {} + +impl<S: hash::Writer> hash::Hash<S> for CString { + #[inline] + fn hash(&self, state: &mut S) { + self.as_bytes().hash(state) + } +} + impl CString { /// Create a C String from a pointer. pub unsafe fn new(buf: *const libc::c_char, owns_buffer: bool) -> CString { diff --git a/src/librustrt/lib.rs b/src/librustrt/lib.rs index b707c62bb70..c830b2e122e 100644 --- a/src/librustrt/lib.rs +++ b/src/librustrt/lib.rs @@ -17,7 +17,7 @@ html_root_url = "http://doc.rust-lang.org/0.11.0/")] #![feature(macro_rules, phase, globs, thread_local, managed_boxes, asm)] -#![feature(linkage, lang_items, unsafe_destructor)] +#![feature(linkage, lang_items, unsafe_destructor, default_type_params)] #![no_std] #![experimental] diff --git a/src/librustrt/rtio.rs b/src/librustrt/rtio.rs index 0205f2405f9..7a91cca6265 100644 --- a/src/librustrt/rtio.rs +++ b/src/librustrt/rtio.rs @@ -75,7 +75,7 @@ pub struct ProcessConfig<'a> { /// Optional environment to specify for the program. If this is None, then /// it will inherit the current process's environment. - pub env: Option<&'a [(CString, CString)]>, + pub env: Option<&'a [(&'a CString, &'a CString)]>, /// Optional working directory for the new process. If this is None, then /// the current directory of the running process is inherited. |
