diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-05-19 18:00:52 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-05-19 18:12:18 -0700 |
| commit | 88b322c5fdcdf5b3dc2bb635dd9696a58ec48ea2 (patch) | |
| tree | fbf52d87c8b84dc407d459324414141c6f95ddb0 /src/libnative | |
| parent | 4c8a4d241a984fdc0b8a015dceca2a006f2b7146 (diff) | |
| download | rust-88b322c5fdcdf5b3dc2bb635dd9696a58ec48ea2.tar.gz rust-88b322c5fdcdf5b3dc2bb635dd9696a58ec48ea2.zip | |
native: Remove UnsafeArc in favor of just Arc
Diffstat (limited to 'src/libnative')
| -rw-r--r-- | src/libnative/io/file_unix.rs | 12 | ||||
| -rw-r--r-- | src/libnative/io/file_win32.rs | 16 | ||||
| -rw-r--r-- | src/libnative/io/net.rs | 20 | ||||
| -rw-r--r-- | src/libnative/io/pipe_unix.rs | 14 | ||||
| -rw-r--r-- | src/libnative/io/pipe_win32.rs | 10 | ||||
| -rw-r--r-- | src/libnative/lib.rs | 1 |
6 files changed, 30 insertions, 43 deletions
diff --git a/src/libnative/io/file_unix.rs b/src/libnative/io/file_unix.rs index 046d2875d55..5e357ec9cca 100644 --- a/src/libnative/io/file_unix.rs +++ b/src/libnative/io/file_unix.rs @@ -10,6 +10,7 @@ //! Blocking posix-based file I/O +use alloc::arc::Arc; use libc::{c_int, c_void}; use libc; use std::c_str::CString; @@ -17,7 +18,6 @@ use std::io::IoError; use std::io; use std::mem; use std::rt::rtio; -use std::sync::arc::UnsafeArc; use io::{IoResult, retry, keep_going}; @@ -29,7 +29,7 @@ struct Inner { } pub struct FileDesc { - inner: UnsafeArc<Inner> + inner: Arc<Inner> } impl FileDesc { @@ -42,7 +42,7 @@ impl FileDesc { /// Note that all I/O operations done on this object will be *blocking*, but /// they do not require the runtime to be active. pub fn new(fd: fd_t, close_on_drop: bool) -> FileDesc { - FileDesc { inner: UnsafeArc::new(Inner { + FileDesc { inner: Arc::new(Inner { fd: fd, close_on_drop: close_on_drop }) } @@ -79,11 +79,7 @@ impl FileDesc { } } - pub fn fd(&self) -> fd_t { - // This unsafety is fine because we're just reading off the file - // descriptor, no one is modifying this. - unsafe { (*self.inner.get()).fd } - } + pub fn fd(&self) -> fd_t { self.inner.fd } } impl io::Reader for FileDesc { diff --git a/src/libnative/io/file_win32.rs b/src/libnative/io/file_win32.rs index 3222c912dd0..3cc6cc2f47c 100644 --- a/src/libnative/io/file_win32.rs +++ b/src/libnative/io/file_win32.rs @@ -10,17 +10,17 @@ //! Blocking win32-based file I/O +use alloc::arc::Arc; +use libc::{c_int, c_void}; +use libc; 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::os::win32::{as_utf16_p, fill_utf16_buf_and_decode}; use std::ptr; use std::rt::rtio; use std::str; -use std::sync::arc::UnsafeArc; use std::vec; use io::IoResult; @@ -33,7 +33,7 @@ struct Inner { } pub struct FileDesc { - inner: UnsafeArc<Inner> + inner: Arc<Inner> } impl FileDesc { @@ -46,7 +46,7 @@ impl FileDesc { /// Note that all I/O operations done on this object will be *blocking*, but /// they do not require the runtime to be active. pub fn new(fd: fd_t, close_on_drop: bool) -> FileDesc { - FileDesc { inner: UnsafeArc::new(Inner { + FileDesc { inner: Arc::new(Inner { fd: fd, close_on_drop: close_on_drop }) } @@ -85,11 +85,7 @@ impl FileDesc { Ok(()) } - pub fn fd(&self) -> fd_t { - // This unsafety is fine because we're just reading off the file - // descriptor, no one is modifying this. - unsafe { (*self.inner.get()).fd } - } + pub fn fd(&self) -> fd_t { self.inner.fd } pub fn handle(&self) -> libc::HANDLE { unsafe { libc::get_osfhandle(self.fd()) as libc::HANDLE } diff --git a/src/libnative/io/net.rs b/src/libnative/io/net.rs index 40b66cc526f..a67d0439dbf 100644 --- a/src/libnative/io/net.rs +++ b/src/libnative/io/net.rs @@ -8,12 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use alloc::arc::Arc; use libc; use std::io::net::ip; use std::io; use std::mem; use std::rt::rtio; -use std::sync::arc::UnsafeArc; use std::unstable::mutex; use super::{IoResult, retry, keep_going}; @@ -235,7 +235,7 @@ pub fn init() { //////////////////////////////////////////////////////////////////////////////// pub struct TcpStream { - inner: UnsafeArc<Inner>, + inner: Arc<Inner>, read_deadline: u64, write_deadline: u64, } @@ -282,16 +282,13 @@ impl TcpStream { fn new(inner: Inner) -> TcpStream { TcpStream { - inner: UnsafeArc::new(inner), + inner: Arc::new(inner), read_deadline: 0, write_deadline: 0, } } - pub fn fd(&self) -> sock_t { - // This unsafety is fine because it's just a read-only arc - unsafe { (*self.inner.get()).fd } - } + pub fn fd(&self) -> sock_t { self.inner.fd } fn set_nodelay(&mut self, nodelay: bool) -> IoResult<()> { setsockopt(self.fd(), libc::IPPROTO_TCP, libc::TCP_NODELAY, @@ -536,7 +533,7 @@ impl rtio::RtioTcpAcceptor for TcpAcceptor { //////////////////////////////////////////////////////////////////////////////// pub struct UdpSocket { - inner: UnsafeArc<Inner>, + inner: Arc<Inner>, read_deadline: u64, write_deadline: u64, } @@ -545,7 +542,7 @@ impl UdpSocket { pub fn bind(addr: ip::SocketAddr) -> IoResult<UdpSocket> { let fd = try!(socket(addr, libc::SOCK_DGRAM)); let ret = UdpSocket { - inner: UnsafeArc::new(Inner::new(fd)), + inner: Arc::new(Inner::new(fd)), read_deadline: 0, write_deadline: 0, }; @@ -560,10 +557,7 @@ impl UdpSocket { } } - pub fn fd(&self) -> sock_t { - // unsafety is fine because it's just a read-only arc - unsafe { (*self.inner.get()).fd } - } + pub fn fd(&self) -> sock_t { self.inner.fd } pub fn set_broadcast(&mut self, on: bool) -> IoResult<()> { setsockopt(self.fd(), libc::SOL_SOCKET, libc::SO_BROADCAST, diff --git a/src/libnative/io/pipe_unix.rs b/src/libnative/io/pipe_unix.rs index d66075f4419..8742fc58af1 100644 --- a/src/libnative/io/pipe_unix.rs +++ b/src/libnative/io/pipe_unix.rs @@ -8,13 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use alloc::arc::Arc; use libc; use std::c_str::CString; use std::intrinsics; use std::io; use std::mem; use std::rt::rtio; -use std::sync::arc::UnsafeArc; use std::unstable::mutex; use super::{IoResult, retry}; @@ -108,7 +108,7 @@ fn bind(addr: &CString, ty: libc::c_int) -> IoResult<Inner> { //////////////////////////////////////////////////////////////////////////////// pub struct UnixStream { - inner: UnsafeArc<Inner>, + inner: Arc<Inner>, read_deadline: u64, write_deadline: u64, } @@ -117,11 +117,11 @@ impl UnixStream { pub fn connect(addr: &CString, timeout: Option<u64>) -> IoResult<UnixStream> { connect(addr, libc::SOCK_STREAM, timeout).map(|inner| { - UnixStream::new(UnsafeArc::new(inner)) + UnixStream::new(Arc::new(inner)) }) } - fn new(inner: UnsafeArc<Inner>) -> UnixStream { + fn new(inner: Arc<Inner>) -> UnixStream { UnixStream { inner: inner, read_deadline: 0, @@ -129,7 +129,7 @@ impl UnixStream { } } - fn fd(&self) -> fd_t { unsafe { (*self.inner.get()).fd } } + fn fd(&self) -> fd_t { self.inner.fd } #[cfg(target_os = "linux")] fn lock_nonblocking(&self) {} @@ -138,7 +138,7 @@ impl UnixStream { fn lock_nonblocking<'a>(&'a self) -> net::Guard<'a> { let ret = net::Guard { fd: self.fd(), - guard: unsafe { (*self.inner.get()).lock.lock() }, + guard: self.inner.lock.lock(), }; assert!(util::set_nonblocking(self.fd(), true).is_ok()); ret @@ -254,7 +254,7 @@ impl UnixAcceptor { &mut size as *mut libc::socklen_t) as libc::c_int }) { -1 => Err(super::last_error()), - fd => Ok(UnixStream::new(UnsafeArc::new(Inner::new(fd)))) + fd => Ok(UnixStream::new(Arc::new(Inner::new(fd)))) } } } diff --git a/src/libnative/io/pipe_win32.rs b/src/libnative/io/pipe_win32.rs index af80c7174f2..c90c3824bba 100644 --- a/src/libnative/io/pipe_win32.rs +++ b/src/libnative/io/pipe_win32.rs @@ -84,6 +84,7 @@ //! the test suite passing (the suite is in libstd), and that's good enough for //! me! +use alloc::arc::Arc; use libc; use std::c_str::CString; use std::intrinsics; @@ -92,7 +93,6 @@ use std::os::win32::as_utf16_p; use std::os; use std::ptr; use std::rt::rtio; -use std::sync::arc::UnsafeArc; use std::sync::atomics; use std::unstable::mutex; @@ -195,7 +195,7 @@ pub fn await(handle: libc::HANDLE, deadline: u64, //////////////////////////////////////////////////////////////////////////////// pub struct UnixStream { - inner: UnsafeArc<Inner>, + inner: Arc<Inner>, write: Option<Event>, read: Option<Event>, read_deadline: u64, @@ -273,7 +273,7 @@ impl UnixStream { Err(super::last_error()) } else { Ok(UnixStream { - inner: UnsafeArc::new(inner), + inner: Arc::new(inner), read: None, write: None, read_deadline: 0, @@ -317,7 +317,7 @@ impl UnixStream { }) } - fn handle(&self) -> libc::HANDLE { unsafe { (*self.inner.get()).handle } } + fn handle(&self) -> libc::HANDLE { self.inner.handle } fn read_closed(&self) -> bool { unsafe { (*self.inner.get()).read_closed.load(atomics::SeqCst) } @@ -683,7 +683,7 @@ impl UnixAcceptor { // Transfer ownership of our handle into this stream Ok(UnixStream { - inner: UnsafeArc::new(Inner::new(handle)), + inner: Arc::new(Inner::new(handle)), read: None, write: None, read_deadline: 0, diff --git a/src/libnative/lib.rs b/src/libnative/lib.rs index 8ba06133369..634bf1dcedb 100644 --- a/src/libnative/lib.rs +++ b/src/libnative/lib.rs @@ -57,6 +57,7 @@ // answer is that you don't need them) #![feature(macro_rules)] +extern crate alloc; extern crate libc; use std::os; |
