about summary refs log tree commit diff
path: root/src/libnative
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-10-14 23:05:01 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-10-19 12:59:40 -0700
commit9d5d97b55d6487ee23b805bc1acbaa0669b82116 (patch)
treeb72dcf7045e331e94ea0f8658d088ab42d917935 /src/libnative
parentfb169d5543c84e11038ba2d07b538ec88fb49ca6 (diff)
downloadrust-9d5d97b55d6487ee23b805bc1acbaa0669b82116.tar.gz
rust-9d5d97b55d6487ee23b805bc1acbaa0669b82116.zip
Remove a large amount of deprecated functionality
Spring cleaning is here! In the Fall! This commit removes quite a large amount
of deprecated functionality from the standard libraries. I tried to ensure that
only old deprecated functionality was removed.

This is removing lots and lots of deprecated features, so this is a breaking
change. Please consult the deprecation messages of the deleted code to see how
to migrate code forward if it still needs migration.

[breaking-change]
Diffstat (limited to 'src/libnative')
-rw-r--r--src/libnative/io/addrinfo.rs10
-rw-r--r--src/libnative/io/c_windows.rs4
-rw-r--r--src/libnative/io/file_windows.rs6
-rw-r--r--src/libnative/io/helper_thread.rs7
-rw-r--r--src/libnative/io/pipe_windows.rs4
-rw-r--r--src/libnative/io/process.rs21
-rw-r--r--src/libnative/io/timer_unix.rs6
-rw-r--r--src/libnative/io/tty_windows.rs8
-rw-r--r--src/libnative/lib.rs2
-rw-r--r--src/libnative/task.rs100
10 files changed, 81 insertions, 87 deletions
diff --git a/src/libnative/io/addrinfo.rs b/src/libnative/io/addrinfo.rs
index 7a07b622127..d40438e4272 100644
--- a/src/libnative/io/addrinfo.rs
+++ b/src/libnative/io/addrinfo.rs
@@ -11,7 +11,7 @@
 use libc::{c_char, c_int};
 use libc;
 use std::mem;
-use std::ptr::{null, mut_null};
+use std::ptr::{null, null_mut};
 use std::rt::rtio;
 use std::rt::rtio::IoError;
 
@@ -38,16 +38,16 @@ impl GetAddrInfoRequest {
                 ai_socktype: 0,
                 ai_protocol: 0,
                 ai_addrlen: 0,
-                ai_canonname: mut_null(),
-                ai_addr: mut_null(),
-                ai_next: mut_null()
+                ai_canonname: null_mut(),
+                ai_addr: null_mut(),
+                ai_next: null_mut()
             }
         });
 
         let hint_ptr = hint.as_ref().map_or(null(), |x| {
             x as *const libc::addrinfo
         });
-        let mut res = mut_null();
+        let mut res = null_mut();
 
         // Make the call
         let s = unsafe {
diff --git a/src/libnative/io/c_windows.rs b/src/libnative/io/c_windows.rs
index 067a31166a5..eed3df28b8f 100644
--- a/src/libnative/io/c_windows.rs
+++ b/src/libnative/io/c_windows.rs
@@ -141,8 +141,8 @@ pub mod compat {
     // layer (after it's loaded) shouldn't be any slower than a regular DLL
     // call.
     unsafe fn store_func(ptr: *mut uint, module: &str, symbol: &str, fallback: uint) {
-        let module: Vec<u16> = module.utf16_units().collect();
-        let module = module.append_one(0);
+        let mut module: Vec<u16> = module.utf16_units().collect();
+        module.push(0);
         symbol.with_c_str(|symbol| {
             let handle = GetModuleHandleW(module.as_ptr());
             let func: uint = transmute(GetProcAddress(handle, symbol));
diff --git a/src/libnative/io/file_windows.rs b/src/libnative/io/file_windows.rs
index 6aa965948fd..eb4d4f22132 100644
--- a/src/libnative/io/file_windows.rs
+++ b/src/libnative/io/file_windows.rs
@@ -253,7 +253,11 @@ impl Drop for Inner {
 
 pub fn to_utf16(s: &CString) -> IoResult<Vec<u16>> {
     match s.as_str() {
-        Some(s) => Ok(s.utf16_units().collect::<Vec<u16>>().append_one(0)),
+        Some(s) => Ok({
+            let mut s = s.utf16_units().collect::<Vec<u16>>();
+            s.push(0);
+            s
+        }),
         None => Err(IoError {
             code: libc::ERROR_INVALID_NAME as uint,
             extra: 0,
diff --git a/src/libnative/io/helper_thread.rs b/src/libnative/io/helper_thread.rs
index 8aff1732a41..d1368ad31f4 100644
--- a/src/libnative/io/helper_thread.rs
+++ b/src/libnative/io/helper_thread.rs
@@ -22,13 +22,14 @@
 
 #![macro_escape]
 
+use std::cell::UnsafeCell;
 use std::mem;
 use std::rt::bookkeeping;
 use std::rt::mutex::StaticNativeMutex;
 use std::rt;
-use std::cell::UnsafeCell;
+use std::task::TaskBuilder;
 
-use task;
+use NativeTaskBuilder;
 
 /// A structure for management of a helper thread.
 ///
@@ -86,7 +87,7 @@ impl<M: Send> Helper<M> {
                 *self.signal.get() = send as uint;
 
                 let t = f();
-                task::spawn(proc() {
+                TaskBuilder::new().native().spawn(proc() {
                     bookkeeping::decrement();
                     helper(receive, rx, t);
                     self.lock.lock().signal()
diff --git a/src/libnative/io/pipe_windows.rs b/src/libnative/io/pipe_windows.rs
index 5475de6d7e1..bc08ede39f7 100644
--- a/src/libnative/io/pipe_windows.rs
+++ b/src/libnative/io/pipe_windows.rs
@@ -359,7 +359,7 @@ impl rtio::RtioPipe for UnixStream {
 
         let mut bytes_read = 0;
         let mut overlapped: libc::OVERLAPPED = unsafe { mem::zeroed() };
-        overlapped.hEvent = self.read.get_ref().handle();
+        overlapped.hEvent = self.read.as_ref().unwrap().handle();
 
         // Pre-flight check to see if the reading half has been closed. This
         // must be done before issuing the ReadFile request, but after we
@@ -431,7 +431,7 @@ impl rtio::RtioPipe for UnixStream {
 
         let mut offset = 0;
         let mut overlapped: libc::OVERLAPPED = unsafe { mem::zeroed() };
-        overlapped.hEvent = self.write.get_ref().handle();
+        overlapped.hEvent = self.write.as_ref().unwrap().handle();
 
         while offset < buf.len() {
             let mut bytes_written = 0;
diff --git a/src/libnative/io/process.rs b/src/libnative/io/process.rs
index 2ca25f1eeb9..b94d81cff95 100644
--- a/src/libnative/io/process.rs
+++ b/src/libnative/io/process.rs
@@ -350,8 +350,8 @@ fn spawn_process_os(cfg: ProcessConfig,
                         lpSecurityDescriptor: ptr::null_mut(),
                         bInheritHandle: 1,
                     };
-                    let filename: Vec<u16> = "NUL".utf16_units().collect();
-                    let filename = filename.append_one(0);
+                    let mut filename: Vec<u16> = "NUL".utf16_units().collect();
+                    filename.push(0);
                     *slot = libc::CreateFileW(filename.as_ptr(),
                                               access,
                                               libc::FILE_SHARE_READ |
@@ -396,7 +396,7 @@ fn spawn_process_os(cfg: ProcessConfig,
         with_envp(cfg.env, |envp| {
             with_dirp(cfg.cwd, |dirp| {
                 let mut cmd_str: Vec<u16> = cmd_str.as_slice().utf16_units().collect();
-                cmd_str = cmd_str.append_one(0);
+                cmd_str.push(0);
                 let created = CreateProcessW(ptr::null(),
                                              cmd_str.as_mut_ptr(),
                                              ptr::null_mut(),
@@ -473,7 +473,7 @@ fn make_command_line(prog: &CString, args: &[CString]) -> String {
     append_arg(&mut cmd, prog.as_str()
                              .expect("expected program name to be utf-8 encoded"));
     for arg in args.iter() {
-        cmd.push_char(' ');
+        cmd.push(' ');
         append_arg(&mut cmd, arg.as_str()
                                 .expect("expected argument to be utf-8 encoded"));
     }
@@ -485,14 +485,14 @@ fn make_command_line(prog: &CString, args: &[CString]) -> String {
         // it will be dropped entirely when parsed on the other end.
         let quote = arg.chars().any(|c| c == ' ' || c == '\t') || arg.len() == 0;
         if quote {
-            cmd.push_char('"');
+            cmd.push('"');
         }
         let argvec: Vec<char> = arg.chars().collect();
         for i in range(0u, argvec.len()) {
             append_char_at(cmd, &argvec, i);
         }
         if quote {
-            cmd.push_char('"');
+            cmd.push('"');
         }
     }
 
@@ -508,11 +508,11 @@ fn make_command_line(prog: &CString, args: &[CString]) -> String {
                     cmd.push_str("\\\\");
                 } else {
                     // Pass other backslashes through unescaped.
-                    cmd.push_char('\\');
+                    cmd.push('\\');
                 }
             }
             c => {
-                cmd.push_char(c);
+                cmd.push(c);
             }
         }
     }
@@ -817,9 +817,8 @@ fn with_dirp<T>(d: Option<&CString>, cb: |*const u16| -> T) -> T {
       Some(dir) => {
           let dir_str = dir.as_str()
                            .expect("expected workingdirectory to be utf-8 encoded");
-          let dir_str: Vec<u16> = dir_str.utf16_units().collect();
-          let dir_str = dir_str.append_one(0);
-
+          let mut dir_str: Vec<u16> = dir_str.utf16_units().collect();
+          dir_str.push(0);
           cb(dir_str.as_ptr())
       },
       None => cb(ptr::null())
diff --git a/src/libnative/io/timer_unix.rs b/src/libnative/io/timer_unix.rs
index 4d4ba33aec4..6f57a5e88ba 100644
--- a/src/libnative/io/timer_unix.rs
+++ b/src/libnative/io/timer_unix.rs
@@ -115,7 +115,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) {
     // signals the first requests in the queue, possible re-enqueueing it.
     fn signal(active: &mut Vec<Box<Inner>>,
               dead: &mut Vec<(uint, Box<Inner>)>) {
-        let mut timer = match active.shift() {
+        let mut timer = match active.remove(0) {
             Some(timer) => timer, None => return
         };
         let mut cb = timer.cb.take().unwrap();
@@ -137,7 +137,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) {
             let now = now();
             // If this request has already expired, then signal it and go
             // through another iteration
-            if active.get(0).target <= now {
+            if active[0].target <= now {
                 signal(&mut active, &mut dead);
                 continue;
             }
@@ -145,7 +145,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>, _: ()) {
             // The actual timeout listed in the requests array is an
             // absolute date, so here we translate the absolute time to a
             // relative time.
-            let tm = active.get(0).target - now;
+            let tm = active[0].target - now;
             timeout.tv_sec = (tm / 1000) as libc::time_t;
             timeout.tv_usec = ((tm % 1000) * 1000) as libc::suseconds_t;
             &mut timeout as *mut libc::timeval
diff --git a/src/libnative/io/tty_windows.rs b/src/libnative/io/tty_windows.rs
index 1c3904a8943..cf2a0f9dda4 100644
--- a/src/libnative/io/tty_windows.rs
+++ b/src/libnative/io/tty_windows.rs
@@ -36,7 +36,7 @@ use libc::types::os::arch::extra::LPCVOID;
 use std::io::MemReader;
 use std::ptr;
 use std::rt::rtio::{IoResult, IoError, RtioTTY};
-use std::str::{from_utf16, from_utf8};
+use std::str::from_utf8;
 
 fn invalid_encoding() -> IoError {
     IoError {
@@ -103,7 +103,7 @@ impl RtioTTY for WindowsTTY {
                 _ => (),
             };
             utf16.truncate(num as uint);
-            let utf8 = match from_utf16(utf16.as_slice()) {
+            let utf8 = match String::from_utf16(utf16.as_slice()) {
                 Some(utf8) => utf8.into_bytes(),
                 None => return Err(invalid_encoding()),
             };
@@ -115,7 +115,9 @@ impl RtioTTY for WindowsTTY {
 
     fn write(&mut self, buf: &[u8]) -> IoResult<()> {
         let utf16 = match from_utf8(buf) {
-            Some(utf8) => utf8.to_utf16(),
+            Some(utf8) => {
+                utf8.as_slice().utf16_units().collect::<Vec<u16>>()
+            }
             None => return Err(invalid_encoding()),
         };
         let mut num: DWORD = 0;
diff --git a/src/libnative/lib.rs b/src/libnative/lib.rs
index 71a1645f9ff..656c7e4103c 100644
--- a/src/libnative/lib.rs
+++ b/src/libnative/lib.rs
@@ -56,7 +56,7 @@
        html_root_url = "http://doc.rust-lang.org/nightly/")]
 
 #![deny(unused_result, unused_must_use)]
-#![allow(non_camel_case_types, deprecated)]
+#![allow(non_camel_case_types)]
 #![allow(unknown_features)]
 #![feature(default_type_params, lang_items, slicing_syntax)]
 
diff --git a/src/libnative/task.rs b/src/libnative/task.rs
index ba3f101720f..48e2c440dfc 100644
--- a/src/libnative/task.rs
+++ b/src/libnative/task.rs
@@ -26,7 +26,6 @@ use std::rt::thread::Thread;
 use std::rt;
 
 use io;
-use task;
 use std::task::{TaskBuilder, Spawner};
 
 /// Creates a new Task which is ready to execute as a 1:1 task.
@@ -48,61 +47,49 @@ fn ops() -> Box<Ops> {
     }
 }
 
-/// Spawns a function with the default configuration
-#[deprecated = "use the native method of NativeTaskBuilder instead"]
-pub fn spawn(f: proc():Send) {
-    spawn_opts(TaskOpts { name: None, stack_size: None, on_exit: None }, f)
-}
-
-/// Spawns a new task given the configuration options and a procedure to run
-/// inside the task.
-#[deprecated = "use the native method of NativeTaskBuilder instead"]
-pub fn spawn_opts(opts: TaskOpts, f: proc():Send) {
-    let TaskOpts { name, stack_size, on_exit } = opts;
-
-    let mut task = box Task::new();
-    task.name = name;
-    task.death.on_exit = on_exit;
-
-    let stack = stack_size.unwrap_or(rt::min_stack());
-    let task = task;
-    let ops = ops();
-
-    // Note that this increment must happen *before* the spawn in order to
-    // guarantee that if this task exits it will always end up waiting for the
-    // spawned task to exit.
-    let token = bookkeeping::increment();
-
-    // Spawning a new OS thread guarantees that __morestack will never get
-    // triggered, but we must manually set up the actual stack bounds once this
-    // function starts executing. This raises the lower limit by a bit because
-    // by the time that this function is executing we've already consumed at
-    // least a little bit of stack (we don't know the exact byte address at
-    // which our stack started).
-    Thread::spawn_stack(stack, proc() {
-        let something_around_the_top_of_the_stack = 1;
-        let addr = &something_around_the_top_of_the_stack as *const int;
-        let my_stack = addr as uint;
-        unsafe {
-            stack::record_os_managed_stack_bounds(my_stack - stack + 1024, my_stack);
-        }
-        let mut ops = ops;
-        ops.stack_bounds = (my_stack - stack + 1024, my_stack);
-
-        let mut f = Some(f);
-        let mut task = task;
-        task.put_runtime(ops);
-        drop(task.run(|| { f.take().unwrap()() }).destroy());
-        drop(token);
-    })
-}
-
 /// A spawner for native tasks
 pub struct NativeSpawner;
 
 impl Spawner for NativeSpawner {
     fn spawn(self, opts: TaskOpts, f: proc():Send) {
-        spawn_opts(opts, f)
+        let TaskOpts { name, stack_size, on_exit } = opts;
+
+        let mut task = box Task::new();
+        task.name = name;
+        task.death.on_exit = on_exit;
+
+        let stack = stack_size.unwrap_or(rt::min_stack());
+        let task = task;
+        let ops = ops();
+
+        // Note that this increment must happen *before* the spawn in order to
+        // guarantee that if this task exits it will always end up waiting for
+        // the spawned task to exit.
+        let token = bookkeeping::increment();
+
+        // Spawning a new OS thread guarantees that __morestack will never get
+        // triggered, but we must manually set up the actual stack bounds once
+        // this function starts executing. This raises the lower limit by a bit
+        // because by the time that this function is executing we've already
+        // consumed at least a little bit of stack (we don't know the exact byte
+        // address at which our stack started).
+        Thread::spawn_stack(stack, proc() {
+            let something_around_the_top_of_the_stack = 1;
+            let addr = &something_around_the_top_of_the_stack as *const int;
+            let my_stack = addr as uint;
+            unsafe {
+                stack::record_os_managed_stack_bounds(my_stack - stack + 1024,
+                                                      my_stack);
+            }
+            let mut ops = ops;
+            ops.stack_bounds = (my_stack - stack + 1024, my_stack);
+
+            let mut f = Some(f);
+            let mut task = task;
+            task.put_runtime(ops);
+            drop(task.run(|| { f.take().unwrap()() }).destroy());
+            drop(token);
+        })
     }
 }
 
@@ -270,7 +257,7 @@ impl rt::Runtime for Ops {
         cur_task.put_runtime(self);
         Local::put(cur_task);
 
-        task::spawn_opts(opts, f);
+        NativeSpawner.spawn(opts, f);
     }
 
     fn local_io<'a>(&'a mut self) -> Option<rtio::LocalIo<'a>> {
@@ -283,8 +270,9 @@ mod tests {
     use std::rt::local::Local;
     use std::rt::task::{Task, TaskOpts};
     use std::task;
-    use std::task::TaskBuilder;
-    use super::{spawn, spawn_opts, Ops, NativeTaskBuilder};
+    use std::task::{TaskBuilder, Spawner};
+
+    use super::{Ops, NativeTaskBuilder, NativeSpawner};
 
     #[test]
     fn smoke() {
@@ -312,7 +300,7 @@ mod tests {
         opts.stack_size = Some(20 * 4096);
         let (tx, rx) = channel();
         opts.on_exit = Some(proc(r) tx.send(r));
-        spawn_opts(opts, proc() {});
+        NativeSpawner.spawn(opts, proc() {});
         assert!(rx.recv().is_ok());
     }
 
@@ -321,7 +309,7 @@ mod tests {
         let mut opts = TaskOpts::new();
         let (tx, rx) = channel();
         opts.on_exit = Some(proc(r) tx.send(r));
-        spawn_opts(opts, proc() { fail!() });
+        NativeSpawner.spawn(opts, proc() { fail!() });
         assert!(rx.recv().is_err());
     }