diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2014-05-05 18:56:44 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2014-05-06 23:12:54 -0700 |
| commit | 090040bf4037a094e50b03d79e4baf5cd89c912b (patch) | |
| tree | 27fa91d623889d59260d3db167abdfa8c4288849 /src/libnative | |
| parent | 24f6f26e633e50b5b59f9d0f6cca0b1e49e215d9 (diff) | |
| download | rust-090040bf4037a094e50b03d79e4baf5cd89c912b.tar.gz rust-090040bf4037a094e50b03d79e4baf5cd89c912b.zip | |
librustc: Remove `~EXPR`, `~TYPE`, and `~PAT` from the language, except
for `~str`/`~[]`. Note that `~self` still remains, since I forgot to add support for `Box<self>` before the snapshot. How to update your code: * Instead of `~EXPR`, you should write `box EXPR`. * Instead of `~TYPE`, you should write `Box<Type>`. * Instead of `~PATTERN`, you should write `box PATTERN`. [breaking-change]
Diffstat (limited to 'src/libnative')
| -rw-r--r-- | src/libnative/io/file_unix.rs | 8 | ||||
| -rw-r--r-- | src/libnative/io/file_win32.rs | 4 | ||||
| -rw-r--r-- | src/libnative/io/mod.rs | 75 | ||||
| -rw-r--r-- | src/libnative/io/net.rs | 22 | ||||
| -rw-r--r-- | src/libnative/io/pipe_unix.rs | 16 | ||||
| -rw-r--r-- | src/libnative/io/pipe_win32.rs | 14 | ||||
| -rw-r--r-- | src/libnative/io/timer_helper.rs | 2 | ||||
| -rw-r--r-- | src/libnative/io/timer_unix.rs | 15 | ||||
| -rw-r--r-- | src/libnative/task.rs | 27 |
9 files changed, 106 insertions, 77 deletions
diff --git a/src/libnative/io/file_unix.rs b/src/libnative/io/file_unix.rs index 94ca6027841..2727f9a0b09 100644 --- a/src/libnative/io/file_unix.rs +++ b/src/libnative/io/file_unix.rs @@ -10,12 +10,12 @@ //! Blocking posix-based file I/O +use libc::{c_int, c_void}; +use libc; use std::sync::arc::UnsafeArc; use std::c_str::CString; use std::io::IoError; use std::io; -use libc::{c_int, c_void}; -use libc; use std::mem; use std::rt::rtio; @@ -175,8 +175,8 @@ impl rtio::RtioPipe for FileDesc { fn write(&mut self, buf: &[u8]) -> Result<(), IoError> { self.inner_write(buf) } - fn clone(&self) -> ~rtio::RtioPipe:Send { - box FileDesc { inner: self.inner.clone() } as ~rtio::RtioPipe:Send + fn clone(&self) -> Box<rtio::RtioPipe:Send> { + box FileDesc { inner: self.inner.clone() } as Box<rtio::RtioPipe:Send> } } diff --git a/src/libnative/io/file_win32.rs b/src/libnative/io/file_win32.rs index 54bb2201314..018907303b8 100644 --- a/src/libnative/io/file_win32.rs +++ b/src/libnative/io/file_win32.rs @@ -207,8 +207,8 @@ impl rtio::RtioPipe for FileDesc { fn write(&mut self, buf: &[u8]) -> Result<(), IoError> { self.inner_write(buf) } - fn clone(&self) -> ~rtio::RtioPipe:Send { - box FileDesc { inner: self.inner.clone() } as ~rtio::RtioPipe:Send + fn clone(&self) -> Box<rtio::RtioPipe:Send> { + box FileDesc { inner: self.inner.clone() } as Box<rtio::RtioPipe:Send> } } diff --git a/src/libnative/io/mod.rs b/src/libnative/io/mod.rs index fb92d0d55cf..58fcd60f138 100644 --- a/src/libnative/io/mod.rs +++ b/src/libnative/io/mod.rs @@ -21,19 +21,19 @@ //! play. The only dependencies of these modules are the normal system libraries //! that you would find on the respective platform. +use libc::c_int; +use libc; use std::c_str::CString; use std::io; use std::io::IoError; use std::io::net::ip::SocketAddr; use std::io::process::ProcessConfig; use std::io::signal::Signum; -use libc::c_int; -use libc; use std::os; use std::rt::rtio; -use std::rt::rtio::{RtioTcpStream, RtioTcpListener, RtioUdpSocket, - RtioUnixListener, RtioPipe, RtioFileStream, RtioProcess, - RtioSignal, RtioTTY, CloseBehavior, RtioTimer}; +use std::rt::rtio::{RtioTcpStream, RtioTcpListener, RtioUdpSocket}; +use std::rt::rtio::{RtioUnixListener, RtioPipe, RtioFileStream, RtioProcess}; +use std::rt::rtio::{RtioSignal, RtioTTY, CloseBehavior, RtioTimer}; use ai = std::io::net::addrinfo; // Local re-exports @@ -166,21 +166,32 @@ impl IoFactory { impl rtio::IoFactory for IoFactory { // networking fn tcp_connect(&mut self, addr: SocketAddr, - timeout: Option<u64>) -> IoResult<~RtioTcpStream:Send> { - net::TcpStream::connect(addr, timeout).map(|s| box s as ~RtioTcpStream:Send) + timeout: Option<u64>) -> IoResult<Box<RtioTcpStream:Send>> { + net::TcpStream::connect(addr, timeout).map(|s| { + box s as Box<RtioTcpStream:Send> + }) } - fn tcp_bind(&mut self, addr: SocketAddr) -> IoResult<~RtioTcpListener:Send> { - net::TcpListener::bind(addr).map(|s| box s as ~RtioTcpListener:Send) + fn tcp_bind(&mut self, addr: SocketAddr) + -> IoResult<Box<RtioTcpListener:Send>> { + net::TcpListener::bind(addr).map(|s| { + box s as Box<RtioTcpListener:Send> + }) } - fn udp_bind(&mut self, addr: SocketAddr) -> IoResult<~RtioUdpSocket:Send> { - net::UdpSocket::bind(addr).map(|u| box u as ~RtioUdpSocket:Send) + fn udp_bind(&mut self, addr: SocketAddr) + -> IoResult<Box<RtioUdpSocket:Send>> { + net::UdpSocket::bind(addr).map(|u| box u as Box<RtioUdpSocket:Send>) } - fn unix_bind(&mut self, path: &CString) -> IoResult<~RtioUnixListener:Send> { - pipe::UnixListener::bind(path).map(|s| box s as ~RtioUnixListener:Send) + fn unix_bind(&mut self, path: &CString) + -> IoResult<Box<RtioUnixListener:Send>> { + pipe::UnixListener::bind(path).map(|s| { + box s as Box<RtioUnixListener:Send> + }) } fn unix_connect(&mut self, path: &CString, - timeout: Option<u64>) -> IoResult<~RtioPipe:Send> { - pipe::UnixStream::connect(path, timeout).map(|s| box s as ~RtioPipe:Send) + timeout: Option<u64>) -> IoResult<Box<RtioPipe:Send>> { + pipe::UnixStream::connect(path, timeout).map(|s| { + box s as Box<RtioPipe:Send> + }) } fn get_host_addresses(&mut self, host: Option<&str>, servname: Option<&str>, hint: Option<ai::Hint>) -> IoResult<~[ai::Info]> { @@ -188,17 +199,17 @@ impl rtio::IoFactory for IoFactory { } // filesystem operations - fn fs_from_raw_fd(&mut self, fd: c_int, - close: CloseBehavior) -> ~RtioFileStream:Send { + fn fs_from_raw_fd(&mut self, fd: c_int, close: CloseBehavior) + -> Box<RtioFileStream:Send> { let close = match close { rtio::CloseSynchronously | rtio::CloseAsynchronously => true, rtio::DontClose => false }; - box file::FileDesc::new(fd, close) as ~RtioFileStream:Send + box file::FileDesc::new(fd, close) as Box<RtioFileStream:Send> } fn fs_open(&mut self, path: &CString, fm: io::FileMode, fa: io::FileAccess) - -> IoResult<~RtioFileStream:Send> { - file::open(path, fm, fa).map(|fd| box fd as ~RtioFileStream:Send) + -> IoResult<Box<RtioFileStream:Send>> { + file::open(path, fm, fa).map(|fd| box fd as Box<RtioFileStream:Send>) } fn fs_unlink(&mut self, path: &CString) -> IoResult<()> { file::unlink(path) @@ -244,27 +255,29 @@ impl rtio::IoFactory for IoFactory { } // misc - fn timer_init(&mut self) -> IoResult<~RtioTimer:Send> { - timer::Timer::new().map(|t| box t as ~RtioTimer:Send) + fn timer_init(&mut self) -> IoResult<Box<RtioTimer:Send>> { + timer::Timer::new().map(|t| box t as Box<RtioTimer:Send>) } fn spawn(&mut self, config: ProcessConfig) - -> IoResult<(~RtioProcess:Send, ~[Option<~RtioPipe:Send>])> { + -> IoResult<(Box<RtioProcess:Send>, + ~[Option<Box<RtioPipe:Send>>])> { process::Process::spawn(config).map(|(p, io)| { - (box p as ~RtioProcess:Send, - io.move_iter().map(|p| p.map(|p| box p as ~RtioPipe:Send)).collect()) + (box p as Box<RtioProcess:Send>, + io.move_iter().map(|p| p.map(|p| { + box p as Box<RtioPipe:Send> + })).collect()) }) } fn kill(&mut self, pid: libc::pid_t, signum: int) -> IoResult<()> { process::Process::kill(pid, signum) } - fn pipe_open(&mut self, fd: c_int) -> IoResult<~RtioPipe:Send> { - Ok(box file::FileDesc::new(fd, true) as ~RtioPipe:Send) + fn pipe_open(&mut self, fd: c_int) -> IoResult<Box<RtioPipe:Send>> { + Ok(box file::FileDesc::new(fd, true) as Box<RtioPipe:Send>) } fn tty_open(&mut self, fd: c_int, _readable: bool) - -> IoResult<~RtioTTY:Send> - { + -> IoResult<Box<RtioTTY:Send>> { if unsafe { libc::isatty(fd) } != 0 { - Ok(box file::FileDesc::new(fd, true) as ~RtioTTY:Send) + Ok(box file::FileDesc::new(fd, true) as Box<RtioTTY:Send>) } else { Err(IoError { kind: io::MismatchedFileTypeForOperation, @@ -274,7 +287,7 @@ impl rtio::IoFactory for IoFactory { } } fn signal(&mut self, _signal: Signum, _channel: Sender<Signum>) - -> IoResult<~RtioSignal:Send> { + -> IoResult<Box<RtioSignal:Send>> { Err(unimpl()) } } diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs index c47e549b20a..880cbaabaf8 100644 --- a/src/libnative/io/net.rs +++ b/src/libnative/io/net.rs @@ -351,8 +351,10 @@ impl rtio::RtioTcpStream for TcpStream { self.set_keepalive(None) } - fn clone(&self) -> ~rtio::RtioTcpStream:Send { - box TcpStream { inner: self.inner.clone() } as ~rtio::RtioTcpStream:Send + fn clone(&self) -> Box<rtio::RtioTcpStream:Send> { + box TcpStream { + inner: self.inner.clone(), + } as Box<rtio::RtioTcpStream:Send> } fn close_write(&mut self) -> IoResult<()> { super::mkerr_libc(unsafe { @@ -418,8 +420,10 @@ impl TcpListener { } impl rtio::RtioTcpListener for TcpListener { - fn listen(~self) -> IoResult<~rtio::RtioTcpAcceptor:Send> { - self.native_listen(128).map(|a| box a as ~rtio::RtioTcpAcceptor:Send) + fn listen(~self) -> IoResult<Box<rtio::RtioTcpAcceptor:Send>> { + self.native_listen(128).map(|a| { + box a as Box<rtio::RtioTcpAcceptor:Send> + }) } } @@ -465,8 +469,8 @@ impl rtio::RtioSocket for TcpAcceptor { } impl rtio::RtioTcpAcceptor for TcpAcceptor { - fn accept(&mut self) -> IoResult<~rtio::RtioTcpStream:Send> { - self.native_accept().map(|s| box s as ~rtio::RtioTcpStream:Send) + fn accept(&mut self) -> IoResult<Box<rtio::RtioTcpStream:Send>> { + self.native_accept().map(|s| box s as Box<rtio::RtioTcpStream:Send>) } fn accept_simultaneously(&mut self) -> IoResult<()> { Ok(()) } @@ -637,7 +641,9 @@ impl rtio::RtioUdpSocket for UdpSocket { self.set_broadcast(false) } - fn clone(&self) -> ~rtio::RtioUdpSocket:Send { - box UdpSocket { inner: self.inner.clone() } as ~rtio::RtioUdpSocket:Send + fn clone(&self) -> Box<rtio::RtioUdpSocket:Send> { + box UdpSocket { + inner: self.inner.clone(), + } as Box<rtio::RtioUdpSocket:Send> } } diff --git a/src/libnative/io/pipe_unix.rs b/src/libnative/io/pipe_unix.rs index 178247f3190..65e9c7448c2 100644 --- a/src/libnative/io/pipe_unix.rs +++ b/src/libnative/io/pipe_unix.rs @@ -144,8 +144,10 @@ impl rtio::RtioPipe for UnixStream { } } - fn clone(&self) -> ~rtio::RtioPipe:Send { - box UnixStream { inner: self.inner.clone() } as ~rtio::RtioPipe:Send + fn clone(&self) -> Box<rtio::RtioPipe:Send> { + box UnixStream { + inner: self.inner.clone(), + } as Box<rtio::RtioPipe:Send> } } @@ -176,8 +178,10 @@ impl UnixListener { } impl rtio::RtioUnixListener for UnixListener { - fn listen(~self) -> IoResult<~rtio::RtioUnixAcceptor:Send> { - self.native_listen(128).map(|a| box a as ~rtio::RtioUnixAcceptor:Send) + fn listen(~self) -> IoResult<Box<rtio::RtioUnixAcceptor:Send>> { + self.native_listen(128).map(|a| { + box a as Box<rtio::RtioUnixAcceptor:Send> + }) } } @@ -209,8 +213,8 @@ impl UnixAcceptor { } impl rtio::RtioUnixAcceptor for UnixAcceptor { - fn accept(&mut self) -> IoResult<~rtio::RtioPipe:Send> { - self.native_accept().map(|s| box s as ~rtio::RtioPipe:Send) + fn accept(&mut self) -> IoResult<Box<rtio::RtioPipe:Send>> { + self.native_accept().map(|s| box s as Box<rtio::RtioPipe:Send>) } fn set_timeout(&mut self, timeout: Option<u64>) { self.deadline = timeout.map(|a| ::io::timer::now() + a).unwrap_or(0); diff --git a/src/libnative/io/pipe_win32.rs b/src/libnative/io/pipe_win32.rs index bf7f82ef662..f1239285434 100644 --- a/src/libnative/io/pipe_win32.rs +++ b/src/libnative/io/pipe_win32.rs @@ -353,12 +353,12 @@ impl rtio::RtioPipe for UnixStream { Ok(()) } - fn clone(&self) -> ~rtio::RtioPipe:Send { + fn clone(&self) -> Box<rtio::RtioPipe:Send> { box UnixStream { inner: self.inner.clone(), read: None, write: None, - } as ~rtio::RtioPipe:Send + } as Box<rtio::RtioPipe:Send> } } @@ -402,8 +402,10 @@ impl Drop for UnixListener { } impl rtio::RtioUnixListener for UnixListener { - fn listen(~self) -> IoResult<~rtio::RtioUnixAcceptor:Send> { - self.native_listen().map(|a| box a as ~rtio::RtioUnixAcceptor:Send) + fn listen(~self) -> IoResult<Box<rtio::RtioUnixAcceptor:Send>> { + self.native_listen().map(|a| { + box a as Box<rtio::RtioUnixAcceptor:Send> + }) } } @@ -526,8 +528,8 @@ impl UnixAcceptor { } impl rtio::RtioUnixAcceptor for UnixAcceptor { - fn accept(&mut self) -> IoResult<~rtio::RtioPipe:Send> { - self.native_accept().map(|s| box s as ~rtio::RtioPipe:Send) + fn accept(&mut self) -> IoResult<Box<rtio::RtioPipe:Send>> { + self.native_accept().map(|s| box s as Box<rtio::RtioPipe:Send>) } fn set_timeout(&mut self, timeout: Option<u64>) { self.deadline = timeout.map(|i| i + ::io::timer::now()).unwrap_or(0); diff --git a/src/libnative/io/timer_helper.rs b/src/libnative/io/timer_helper.rs index 298dd2f368d..3bf967cb426 100644 --- a/src/libnative/io/timer_helper.rs +++ b/src/libnative/io/timer_helper.rs @@ -86,7 +86,7 @@ fn shutdown() { // Clean up after ther helper thread unsafe { imp::close(HELPER_SIGNAL); - let _chan: ~Sender<Req> = cast::transmute(HELPER_CHAN); + let _chan: Box<Sender<Req>> = cast::transmute(HELPER_CHAN); HELPER_CHAN = 0 as *mut Sender<Req>; HELPER_SIGNAL = 0 as imp::signal; } diff --git a/src/libnative/io/timer_unix.rs b/src/libnative/io/timer_unix.rs index 8435c05c771..e008e6fb9e9 100644 --- a/src/libnative/io/timer_unix.rs +++ b/src/libnative/io/timer_unix.rs @@ -60,7 +60,7 @@ use io::timer_helper; pub struct Timer { id: uint, - inner: Option<~Inner>, + inner: Option<Box<Inner>>, } struct Inner { @@ -74,11 +74,11 @@ struct Inner { #[allow(visible_private_types)] pub enum Req { // Add a new timer to the helper thread. - NewTimer(~Inner), + NewTimer(Box<Inner>), // Remove a timer based on its id and then send it back on the channel // provided - RemoveTimer(uint, Sender<~Inner>), + RemoveTimer(uint, Sender<Box<Inner>>), // Shut down the loop and then ACK this channel once it's shut down Shutdown, @@ -102,11 +102,11 @@ fn helper(input: libc::c_int, messages: Receiver<Req>) { // active timers are those which are able to be selected upon (and it's a // sorted list, and dead timers are those which have expired, but ownership // hasn't yet been transferred back to the timer itself. - let mut active: Vec<~Inner> = vec![]; + let mut active: Vec<Box<Inner>> = vec![]; let mut dead = vec![]; // inserts a timer into an array of timers (sorted by firing time) - fn insert(t: ~Inner, active: &mut Vec<~Inner>) { + fn insert(t: Box<Inner>, active: &mut Vec<Box<Inner>>) { match active.iter().position(|tm| tm.target > t.target) { Some(pos) => { active.insert(pos, t); } None => { active.push(t); } @@ -114,7 +114,8 @@ 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<~Inner>, dead: &mut Vec<(uint, ~Inner)>) { + fn signal(active: &mut Vec<Box<Inner>>, + dead: &mut Vec<(uint, Box<Inner>)>) { let mut timer = match active.shift() { Some(timer) => timer, None => return }; @@ -229,7 +230,7 @@ impl Timer { } } - fn inner(&mut self) -> ~Inner { + fn inner(&mut self) -> Box<Inner> { match self.inner.take() { Some(i) => i, None => { diff --git a/src/libnative/task.rs b/src/libnative/task.rs index 512080e4204..d5b02dc007b 100644 --- a/src/libnative/task.rs +++ b/src/libnative/task.rs @@ -31,7 +31,7 @@ use io; use task; /// Creates a new Task which is ready to execute as a 1:1 task. -pub fn new(stack_bounds: (uint, uint)) -> ~Task { +pub fn new(stack_bounds: (uint, uint)) -> Box<Task> { let mut task = box Task::new(); let mut ops = ops(); ops.stack_bounds = stack_bounds; @@ -39,7 +39,7 @@ pub fn new(stack_bounds: (uint, uint)) -> ~Task { return task; } -fn ops() -> ~Ops { +fn ops() -> Box<Ops> { box Ops { lock: unsafe { NativeMutex::new() }, awoken: false, @@ -119,22 +119,22 @@ struct Ops { } impl rt::Runtime for Ops { - fn yield_now(~self, mut cur_task: ~Task) { + fn yield_now(~self, mut cur_task: Box<Task>) { // put the task back in TLS and then invoke the OS thread yield cur_task.put_runtime(self); Local::put(cur_task); Thread::yield_now(); } - fn maybe_yield(~self, mut cur_task: ~Task) { + fn maybe_yield(~self, mut cur_task: Box<Task>) { // just put the task back in TLS, on OS threads we never need to // opportunistically yield b/c the OS will do that for us (preemption) cur_task.put_runtime(self); Local::put(cur_task); } - fn wrap(~self) -> ~Any { - self as ~Any + fn wrap(~self) -> Box<Any> { + self as Box<Any> } fn stack_bounds(&self) -> (uint, uint) { self.stack_bounds } @@ -159,8 +159,8 @@ impl rt::Runtime for Ops { // from the wakeup thread back to this thread about the task pointer, and // there's really no need to. In order to get around this, we cast the task // to a `uint` which is then used at the end of this function to cast back - // to a `~Task` object. Naturally, this looks like it violates ownership - // semantics in that there may be two `~Task` objects. + // to a `Box<Task>` object. Naturally, this looks like it violates + // ownership semantics in that there may be two `Box<Task>` objects. // // The fun part is that the wakeup half of this implementation knows to // "forget" the task on the other end. This means that the awakening half of @@ -180,7 +180,7 @@ impl rt::Runtime for Ops { // `awoken` field which indicates whether we were actually woken up via some // invocation of `reawaken`. This flag is only ever accessed inside the // lock, so there's no need to make it atomic. - fn deschedule(mut ~self, times: uint, mut cur_task: ~Task, + fn deschedule(mut ~self, times: uint, mut cur_task: Box<Task>, f: |BlockedTask| -> Result<(), BlockedTask>) { let me = &mut *self as *mut Ops; cur_task.put_runtime(self); @@ -238,7 +238,7 @@ impl rt::Runtime for Ops { // See the comments on `deschedule` for why the task is forgotten here, and // why it's valid to do so. - fn reawaken(mut ~self, mut to_wake: ~Task) { + fn reawaken(mut ~self, mut to_wake: Box<Task>) { unsafe { let me = &mut *self as *mut Ops; to_wake.put_runtime(self); @@ -249,7 +249,10 @@ impl rt::Runtime for Ops { } } - fn spawn_sibling(~self, mut cur_task: ~Task, opts: TaskOpts, f: proc():Send) { + fn spawn_sibling(~self, + mut cur_task: Box<Task>, + opts: TaskOpts, + f: proc():Send) { cur_task.put_runtime(self); Local::put(cur_task); @@ -342,7 +345,7 @@ mod tests { let (tx, rx) = channel(); spawn(proc() { spawn(proc() { - let mut task: ~Task = Local::take(); + let mut task: Box<Task> = Local::take(); match task.maybe_take_runtime::<Ops>() { Some(ops) => { task.put_runtime(ops); |
