about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-02-18 18:02:58 -0800
committerAlex Crichton <alex@alexcrichton.com>2015-02-19 07:03:18 -0800
commit0cd54b85ef1fdad3bc4c1c4e1a989b9f6540a0fa (patch)
treeb2973ab6fdb99ec1d3ff8fd930f29cf78da183f4 /src/libstd
parentcb29c468f38ba93f624277c2c3a8e46a4d85e619 (diff)
downloadrust-0cd54b85ef1fdad3bc4c1c4e1a989b9f6540a0fa.tar.gz
rust-0cd54b85ef1fdad3bc4c1c4e1a989b9f6540a0fa.zip
Round 5 test fixes and rebase conflicts
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/old_io/process.rs14
-rw-r--r--src/libstd/os.rs5
-rw-r--r--src/libstd/sys/unix/os.rs2
-rw-r--r--src/libstd/sys/windows/backtrace.rs4
-rw-r--r--src/libstd/sys/windows/process.rs29
5 files changed, 48 insertions, 6 deletions
diff --git a/src/libstd/old_io/process.rs b/src/libstd/old_io/process.rs
index c761bf705a8..c803cfbcb7d 100644
--- a/src/libstd/old_io/process.rs
+++ b/src/libstd/old_io/process.rs
@@ -104,7 +104,7 @@ struct EnvKey(CString);
 #[derive(Eq, Clone, Debug)]
 struct EnvKey(CString);
 
-#[cfg(windows)]
+#[cfg(all(windows, stage0))]
 impl<H: hash::Writer + hash::Hasher> hash::Hash<H> for EnvKey {
     fn hash(&self, state: &mut H) {
         let &EnvKey(ref x) = self;
@@ -116,6 +116,18 @@ impl<H: hash::Writer + hash::Hasher> hash::Hash<H> for EnvKey {
         }
     }
 }
+#[cfg(all(windows, not(stage0)))]
+impl hash::Hash for EnvKey {
+    fn hash<H: hash::Hasher>(&self, state: &mut H) {
+        let &EnvKey(ref x) = self;
+        match str::from_utf8(x.as_bytes()) {
+            Ok(s) => for ch in s.chars() {
+                (ch as u8 as char).to_lowercase().hash(state);
+            },
+            Err(..) => x.hash(state)
+        }
+    }
+}
 
 #[cfg(windows)]
 impl PartialEq for EnvKey {
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index a4213e7373b..f181fc5df57 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -561,10 +561,11 @@ pub fn get_exit_status() -> int {
 #[cfg(target_os = "macos")]
 unsafe fn load_argc_and_argv(argc: int,
                              argv: *const *const c_char) -> Vec<Vec<u8>> {
+    use ffi::CStr;
     use iter::range;
 
-    (0..argc as uint).map(|i| {
-        ffi::c_str_to_bytes(&*argv.offset(i as int)).to_vec()
+    (0..argc).map(|i| {
+        CStr::from_ptr(*argv.offset(i)).to_bytes().to_vec()
     }).collect()
 }
 
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs
index 66856a2f2c2..3d1ef3a2c37 100644
--- a/src/libstd/sys/unix/os.rs
+++ b/src/libstd/sys/unix/os.rs
@@ -266,7 +266,7 @@ pub fn args() -> Args {
         let (argc, argv) = (*_NSGetArgc() as isize,
                             *_NSGetArgv() as *const *const c_char);
         range(0, argc as isize).map(|i| {
-            let bytes = CStr::from_ptr(&*argv.offset(i)).to_bytes().to_vec();
+            let bytes = CStr::from_ptr(*argv.offset(i)).to_bytes().to_vec();
             OsStringExt::from_vec(bytes)
         }).collect::<Vec<_>>()
     };
diff --git a/src/libstd/sys/windows/backtrace.rs b/src/libstd/sys/windows/backtrace.rs
index 92e309da34b..51cf3032423 100644
--- a/src/libstd/sys/windows/backtrace.rs
+++ b/src/libstd/sys/windows/backtrace.rs
@@ -25,7 +25,7 @@
 #![allow(dead_code)]
 
 use dynamic_lib::DynamicLibrary;
-use ffi;
+use ffi::CStr;
 use intrinsics;
 use old_io::{IoResult, Writer};
 use libc;
@@ -362,7 +362,7 @@ pub fn write(w: &mut Writer) -> IoResult<()> {
         if ret == libc::TRUE {
             try!(write!(w, " - "));
             let ptr = info.Name.as_ptr() as *const libc::c_char;
-            let bytes = unsafe { ffi::c_str_to_bytes(&ptr) };
+            let bytes = unsafe { CStr::from_ptr(ptr).to_bytes() };
             match str::from_utf8(bytes) {
                 Ok(s) => try!(demangle(w, s)),
                 Err(..) => try!(w.write_all(&bytes[..bytes.len()-1])),
diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs
index e001cd9a1ec..60d24e6174f 100644
--- a/src/libstd/sys/windows/process.rs
+++ b/src/libstd/sys/windows/process.rs
@@ -589,6 +589,7 @@ fn make_command_line(prog: &CString, args: &[CString]) -> String {
     }
 }
 
+#[cfg(stage0)]
 fn with_envp<K, V, T, F>(env: Option<&collections::HashMap<K, V>>, cb: F) -> T
     where K: BytesContainer + Eq + Hash<Hasher>,
           V: BytesContainer,
@@ -616,6 +617,34 @@ fn with_envp<K, V, T, F>(env: Option<&collections::HashMap<K, V>>, cb: F) -> T
         _ => cb(ptr::null_mut())
     }
 }
+#[cfg(not(stage0))]
+fn with_envp<K, V, T, F>(env: Option<&collections::HashMap<K, V>>, cb: F) -> T
+    where K: BytesContainer + Eq + Hash,
+          V: BytesContainer,
+          F: FnOnce(*mut c_void) -> T,
+{
+    // On Windows 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.
+    match env {
+        Some(env) => {
+            let mut blk = Vec::new();
+
+            for pair in env {
+                let kv = format!("{}={}",
+                                 pair.0.container_as_str().unwrap(),
+                                 pair.1.container_as_str().unwrap());
+                blk.extend(kv.utf16_units());
+                blk.push(0);
+            }
+
+            blk.push(0);
+
+            cb(blk.as_mut_ptr() as *mut c_void)
+        }
+        _ => cb(ptr::null_mut())
+    }
+}
 
 fn with_dirp<T, F>(d: Option<&CString>, cb: F) -> T where
     F: FnOnce(*const u16) -> T,