about summary refs log tree commit diff
path: root/src/libstd/sys
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-12-23 02:41:48 +0000
committerbors <bors@rust-lang.org>2014-12-23 02:41:48 +0000
commit62fb41c32bd97c4e9bc286a1db5d7126a06b8b91 (patch)
treefc1c7ab2bf1a29879d45235acaf0126ceae4d107 /src/libstd/sys
parent2f3cff6956d56048ef7afb6d33e17cbdb2dcf038 (diff)
parent3583d613b9c81855feb067aeeebb525cf8a4184c (diff)
downloadrust-62fb41c32bd97c4e9bc286a1db5d7126a06b8b91.tar.gz
rust-62fb41c32bd97c4e9bc286a1db5d7126a06b8b91.zip
auto merge of #20145 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/libstd/sys')
-rw-r--r--src/libstd/sys/common/backtrace.rs11
-rw-r--r--src/libstd/sys/unix/os.rs2
-rw-r--r--src/libstd/sys/windows/backtrace.rs2
-rw-r--r--src/libstd/sys/windows/fs.rs3
-rw-r--r--src/libstd/sys/windows/os.rs43
-rw-r--r--src/libstd/sys/windows/process.rs2
-rw-r--r--src/libstd/sys/windows/tty.rs2
7 files changed, 50 insertions, 15 deletions
diff --git a/src/libstd/sys/common/backtrace.rs b/src/libstd/sys/common/backtrace.rs
index a39c8d6d8fe..1d646eb06b1 100644
--- a/src/libstd/sys/common/backtrace.rs
+++ b/src/libstd/sys/common/backtrace.rs
@@ -8,12 +8,9 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use io::{IoResult, Writer};
-use iter::{Iterator, IteratorExt};
-use option::Option::{Some, None};
-use result::Result::{Ok, Err};
-use str::{StrPrelude, from_str};
-use unicode::char::UnicodeChar;
+use prelude::*;
+
+use io::IoResult;
 
 #[cfg(target_word_size = "64")] pub const HEX_WIDTH: uint = 18;
 #[cfg(target_word_size = "32")] pub const HEX_WIDTH: uint = 10;
@@ -85,7 +82,7 @@ pub fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> {
             while rest.char_at(0).is_numeric() {
                 rest = rest.slice_from(1);
             }
-            let i: uint = from_str(inner.slice_to(inner.len() - rest.len())).unwrap();
+            let i: uint = inner.slice_to(inner.len() - rest.len()).parse().unwrap();
             inner = rest.slice_from(i);
             rest = rest.slice_to(i);
             while rest.len() > 0 {
diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs
index 6c909d7562d..316d97064ee 100644
--- a/src/libstd/sys/unix/os.rs
+++ b/src/libstd/sys/unix/os.rs
@@ -189,7 +189,7 @@ pub fn load_self() -> Option<Vec<u8>> {
         if sz == 0 { return None; }
         let mut v: Vec<u8> = Vec::with_capacity(sz as uint);
         let err = sysctl(mib.as_mut_ptr(), mib.len() as ::libc::c_uint,
-                         v.as_mut_ptr() as *mut c_void, &mut sz,
+                         v.as_mut_ptr() as *mut libc::c_void, &mut sz,
                          ptr::null_mut(), 0u as libc::size_t);
         if err != 0 { return None; }
         if sz == 0 { return None; }
diff --git a/src/libstd/sys/windows/backtrace.rs b/src/libstd/sys/windows/backtrace.rs
index f2f543dd969..42c8f7705e1 100644
--- a/src/libstd/sys/windows/backtrace.rs
+++ b/src/libstd/sys/windows/backtrace.rs
@@ -32,7 +32,7 @@ use path::Path;
 use result::Result::{Ok, Err};
 use sync::{StaticMutex, MUTEX_INIT};
 use slice::SliceExt;
-use str::StrPrelude;
+use str::StrExt;
 use dynamic_lib::DynamicLibrary;
 
 use sys_common::backtrace::*;
diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs
index d5bf8c5b629..15eddd569be 100644
--- a/src/libstd/sys/windows/fs.rs
+++ b/src/libstd/sys/windows/fs.rs
@@ -23,6 +23,7 @@ use io;
 
 use prelude::*;
 use sys;
+use sys::os;
 use sys_common::{keep_going, eof, mkerr_libc};
 
 use io::{FilePermission, Write, UnstableFileStat, Open, FileAccess, FileMode};
@@ -262,7 +263,7 @@ pub fn readdir(p: &Path) -> IoResult<Vec<Path>> {
             let mut more_files = 1 as libc::BOOL;
             while more_files != 0 {
                 {
-                    let filename = str::truncate_utf16_at_nul(&wfd.cFileName);
+                    let filename = os::truncate_utf16_at_nul(&wfd.cFileName);
                     match String::from_utf16(filename) {
                         Some(filename) => paths.push(Path::new(filename)),
                         None => {
diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs
index e2220b7b67b..e007b46b261 100644
--- a/src/libstd/sys/windows/os.rs
+++ b/src/libstd/sys/windows/os.rs
@@ -31,6 +31,16 @@ use libc::types::os::arch::extra::DWORD;
 
 const BUF_BYTES : uint = 2048u;
 
+/// Return a slice of `v` ending at (and not including) the first NUL
+/// (0).
+pub fn truncate_utf16_at_nul<'a>(v: &'a [u16]) -> &'a [u16] {
+    match v.iter().position(|c| *c == 0) {
+        // don't include the 0
+        Some(i) => v[..i],
+        None => v
+    }
+}
+
 pub fn errno() -> uint {
     use libc::types::os::arch::extra::DWORD;
 
@@ -87,7 +97,7 @@ pub fn error_string(errnum: i32) -> String {
             return format!("OS Error {} (FormatMessageW() returned error {})", errnum, fm_err);
         }
 
-        let msg = String::from_utf16(::str::truncate_utf16_at_nul(&buf));
+        let msg = String::from_utf16(truncate_utf16_at_nul(&buf));
         match msg {
             Some(msg) => format!("OS Error {}: {}", errnum, msg),
             None => format!("OS Error {} (FormatMessageW() returned invalid UTF-16)", errnum),
@@ -158,7 +168,7 @@ pub fn getcwd() -> IoResult<Path> {
         }
     }
 
-    match String::from_utf16(::str::truncate_utf16_at_nul(&buf)) {
+    match String::from_utf16(truncate_utf16_at_nul(&buf)) {
         Some(ref cwd) => Ok(Path::new(cwd)),
         None => Err(IoError {
             kind: OtherIoError,
@@ -269,7 +279,7 @@ pub fn load_self() -> Option<Vec<u8>> {
     unsafe {
         fill_utf16_buf_and_decode(|buf, sz| {
             libc::GetModuleFileNameW(0u as libc::DWORD, buf, sz)
-        }).map(|s| s.into_string().into_bytes())
+        }).map(|s| s.to_string().into_bytes())
     }
 }
 
@@ -294,3 +304,30 @@ pub fn page_size() -> uint {
         return info.dwPageSize as uint;
     }
 }
+
+#[cfg(test)]
+mod tests {
+    use super::truncate_utf16_at_nul;
+
+    #[test]
+    fn test_truncate_utf16_at_nul() {
+        let v = [];
+        let b: &[u16] = &[];
+        assert_eq!(truncate_utf16_at_nul(&v), b);
+
+        let v = [0, 2, 3];
+        assert_eq!(truncate_utf16_at_nul(&v), b);
+
+        let v = [1, 0, 3];
+        let b: &[u16] = &[1];
+        assert_eq!(truncate_utf16_at_nul(&v), b);
+
+        let v = [1, 2, 0];
+        let b: &[u16] = &[1, 2];
+        assert_eq!(truncate_utf16_at_nul(&v), b);
+
+        let v = [1, 2, 3];
+        let b: &[u16] = &[1, 2, 3];
+        assert_eq!(truncate_utf16_at_nul(&v), b);
+    }
+}
diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs
index 8945c155e66..0c2c76077dd 100644
--- a/src/libstd/sys/windows/process.rs
+++ b/src/libstd/sys/windows/process.rs
@@ -122,7 +122,7 @@ impl Process {
 
         use mem;
         use iter::{Iterator, IteratorExt};
-        use str::StrPrelude;
+        use str::StrExt;
 
         if cfg.gid().is_some() || cfg.uid().is_some() {
             return Err(IoError {
diff --git a/src/libstd/sys/windows/tty.rs b/src/libstd/sys/windows/tty.rs
index 51679bb2003..f793de5bb57 100644
--- a/src/libstd/sys/windows/tty.rs
+++ b/src/libstd/sys/windows/tty.rs
@@ -111,7 +111,7 @@ impl TTY {
     }
 
     pub fn write(&mut self, buf: &[u8]) -> IoResult<()> {
-        let utf16 = match from_utf8(buf) {
+        let utf16 = match from_utf8(buf).ok() {
             Some(utf8) => {
                 utf8.utf16_units().collect::<Vec<u16>>()
             }