Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Surface some common intrinsics in std::mem #12124

Merged
merged 4 commits into from
Feb 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/doc/guide-ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ and `free`:
~~~~
use std::cast;
use std::libc::{c_void, size_t, malloc, free};
use std::mem;
use std::ptr;
use std::unstable::intrinsics;

// Define a wrapper around the handle returned by the foreign code.
// Unique<T> has the same semantics as ~T
Expand All @@ -199,7 +199,7 @@ impl<T: Send> Unique<T> {
// `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it
// move_val_init moves a value into this memory without
// attempting to drop the original value.
intrinsics::move_val_init(&mut *ptr, value);
mem::move_val_init(&mut *ptr, value);
Unique{ptr: ptr}
}
}
Expand All @@ -226,7 +226,7 @@ impl<T: Send> Unique<T> {
impl<T: Send> Drop for Unique<T> {
fn drop(&mut self) {
unsafe {
let x = intrinsics::uninit(); // dummy value to swap in
let x = mem::uninit(); // dummy value to swap in
// We need to move the object out of the box, so that
// the destructor is called (at the end of this scope.)
ptr::replace_ptr(self.ptr, x);
Expand Down
10 changes: 5 additions & 5 deletions src/libarena/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ use collections::list;
use std::cast::{transmute, transmute_mut, transmute_mut_region};
use std::cast;
use std::cell::{Cell, RefCell};
use std::mem;
use std::num;
use std::ptr;
use std::kinds::marker;
use std::mem;
use std::rc::Rc;
use std::rt::global_heap;
use std::unstable::intrinsics::{TyDesc, get_tydesc};
Expand Down Expand Up @@ -216,7 +216,7 @@ impl Arena {
unsafe {
let ptr = self.alloc_pod_inner(mem::size_of::<T>(), mem::min_align_of::<T>());
let ptr: *mut T = transmute(ptr);
intrinsics::move_val_init(&mut (*ptr), op());
mem::move_val_init(&mut (*ptr), op());
return transmute(ptr);
}
}
Expand Down Expand Up @@ -278,7 +278,7 @@ impl Arena {
// has *not* been initialized yet.
*ty_ptr = transmute(tydesc);
// Actually initialize it
intrinsics::move_val_init(&mut(*ptr), op());
mem::move_val_init(&mut(*ptr), op());
// Now that we are done, update the tydesc to indicate that
// the object is there.
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);
Expand Down Expand Up @@ -379,7 +379,7 @@ impl TypedArenaChunk {
let mut chunk = unsafe {
let chunk = global_heap::exchange_malloc(size);
let mut chunk: ~TypedArenaChunk = cast::transmute(chunk);
intrinsics::move_val_init(&mut chunk.next, next);
mem::move_val_init(&mut chunk.next, next);
chunk
};

Expand Down Expand Up @@ -466,7 +466,7 @@ impl<T> TypedArena<T> {
}

let ptr: &'a mut T = cast::transmute(this.ptr);
intrinsics::move_val_init(ptr, object);
mem::move_val_init(ptr, object);
this.ptr = this.ptr.offset(1);
let ptr: &'a T = ptr;
ptr
Expand Down
2 changes: 1 addition & 1 deletion src/libcollections/priority_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#[allow(missing_doc)];

use std::clone::Clone;
use std::unstable::intrinsics::{move_val_init, init};
use std::mem::{move_val_init, init};
use std::util::{replace, swap};
use std::vec;

Expand Down
12 changes: 6 additions & 6 deletions src/libnative/io/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ use std::io::IoError;
use std::io;
use std::libc::{c_int, c_void};
use std::libc;
use std::mem;
use std::os;
use std::rt::rtio;
use std::unstable::intrinsics;
use std::vec;

use io::{IoResult, retry};
Expand Down Expand Up @@ -147,7 +147,7 @@ impl rtio::RtioFileStream for FileDesc {
#[cfg(windows)]
fn os_pread(fd: c_int, buf: *u8, amt: uint, offset: u64) -> IoResult<int> {
unsafe {
let mut overlap: libc::OVERLAPPED = intrinsics::init();
let mut overlap: libc::OVERLAPPED = mem::init();
let handle = libc::get_osfhandle(fd) as libc::HANDLE;
let mut bytes_read = 0;
overlap.Offset = offset as libc::DWORD;
Expand Down Expand Up @@ -179,7 +179,7 @@ impl rtio::RtioFileStream for FileDesc {
#[cfg(windows)]
fn os_pwrite(fd: c_int, buf: *u8, amt: uint, offset: u64) -> IoResult<()> {
unsafe {
let mut overlap: libc::OVERLAPPED = intrinsics::init();
let mut overlap: libc::OVERLAPPED = mem::init();
let handle = libc::get_osfhandle(fd) as libc::HANDLE;
overlap.Offset = offset as libc::DWORD;
overlap.OffsetHigh = (offset >> 32) as libc::DWORD;
Expand Down Expand Up @@ -867,7 +867,7 @@ pub fn stat(p: &CString) -> IoResult<io::FileStat> {

#[cfg(windows)]
fn os_stat(p: &CString) -> IoResult<io::FileStat> {
let mut stat: libc::stat = unsafe { intrinsics::uninit() };
let mut stat: libc::stat = unsafe { mem::uninit() };
as_utf16_p(p.as_str().unwrap(), |up| {
match retry(|| unsafe { libc::wstat(up, &mut stat) }) {
0 => Ok(mkstat(&stat, p)),
Expand All @@ -878,7 +878,7 @@ pub fn stat(p: &CString) -> IoResult<io::FileStat> {

#[cfg(unix)]
fn os_stat(p: &CString) -> IoResult<io::FileStat> {
let mut stat: libc::stat = unsafe { intrinsics::uninit() };
let mut stat: libc::stat = unsafe { mem::uninit() };
match retry(|| unsafe { libc::stat(p.with_ref(|p| p), &mut stat) }) {
0 => Ok(mkstat(&stat, p)),
_ => Err(super::last_error()),
Expand All @@ -897,7 +897,7 @@ pub fn lstat(p: &CString) -> IoResult<io::FileStat> {

#[cfg(unix)]
fn os_lstat(p: &CString) -> IoResult<io::FileStat> {
let mut stat: libc::stat = unsafe { intrinsics::uninit() };
let mut stat: libc::stat = unsafe { mem::uninit() };
match retry(|| unsafe { libc::lstat(p.with_ref(|p| p), &mut stat) }) {
0 => Ok(mkstat(&stat, p)),
_ => Err(super::last_error()),
Expand Down
15 changes: 7 additions & 8 deletions src/libnative/io/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use std::libc;
use std::mem;
use std::rt::rtio;
use std::sync::arc::UnsafeArc;
use std::unstable::intrinsics;

use super::{IoResult, retry};
use super::file::keep_going;
Expand All @@ -28,10 +27,10 @@ use super::file::keep_going;
#[cfg(unix)] pub type sock_t = super::file::fd_t;

pub fn htons(u: u16) -> u16 {
intrinsics::to_be16(u as i16) as u16
mem::to_be16(u as i16) as u16
}
pub fn ntohs(u: u16) -> u16 {
intrinsics::from_be16(u as i16) as u16
mem::from_be16(u as i16) as u16
}

enum InAddr {
Expand Down Expand Up @@ -68,7 +67,7 @@ fn ip_to_inaddr(ip: ip::IpAddr) -> InAddr {

fn addr_to_sockaddr(addr: ip::SocketAddr) -> (libc::sockaddr_storage, uint) {
unsafe {
let storage: libc::sockaddr_storage = intrinsics::init();
let storage: libc::sockaddr_storage = mem::init();
let len = match ip_to_inaddr(addr.ip) {
InAddr(inaddr) => {
let storage: *mut libc::sockaddr_in = cast::transmute(&storage);
Expand Down Expand Up @@ -138,7 +137,7 @@ fn sockname(fd: sock_t,
*mut libc::socklen_t) -> libc::c_int)
-> IoResult<ip::SocketAddr>
{
let mut storage: libc::sockaddr_storage = unsafe { intrinsics::init() };
let mut storage: libc::sockaddr_storage = unsafe { mem::init() };
let mut len = mem::size_of::<libc::sockaddr_storage>() as libc::socklen_t;
unsafe {
let storage = &mut storage as *mut libc::sockaddr_storage;
Expand Down Expand Up @@ -225,7 +224,7 @@ pub fn init() {

LOCK.lock();
if !INITIALIZED {
let mut data: WSADATA = intrinsics::init();
let mut data: WSADATA = mem::init();
let ret = WSAStartup(0x202, // version 2.2
&mut data);
assert_eq!(ret, 0);
Expand Down Expand Up @@ -438,7 +437,7 @@ impl TcpAcceptor {

pub fn native_accept(&mut self) -> IoResult<TcpStream> {
unsafe {
let mut storage: libc::sockaddr_storage = intrinsics::init();
let mut storage: libc::sockaddr_storage = mem::init();
let storagep = &mut storage as *mut libc::sockaddr_storage;
let size = mem::size_of::<libc::sockaddr_storage>();
let mut size = size as libc::socklen_t;
Expand Down Expand Up @@ -543,7 +542,7 @@ impl rtio::RtioSocket for UdpSocket {
impl rtio::RtioUdpSocket for UdpSocket {
fn recvfrom(&mut self, buf: &mut [u8]) -> IoResult<(uint, ip::SocketAddr)> {
unsafe {
let mut storage: libc::sockaddr_storage = intrinsics::init();
let mut storage: libc::sockaddr_storage = mem::init();
let storagep = &mut storage as *mut libc::sockaddr_storage;
let mut addrlen: libc::socklen_t =
mem::size_of::<libc::sockaddr_storage>() as libc::socklen_t;
Expand Down
8 changes: 4 additions & 4 deletions src/libnative/io/timer_other.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
use std::comm::Data;
use std::hashmap::HashMap;
use std::libc;
use std::mem;
use std::os;
use std::ptr;
use std::rt::rtio;
use std::sync::atomics;
use std::unstable::intrinsics;

use io::file::FileDesc;
use io::IoResult;
Expand Down Expand Up @@ -87,17 +87,17 @@ pub enum Req {
// returns the current time (in milliseconds)
fn now() -> u64 {
unsafe {
let mut now: libc::timeval = intrinsics::init();
let mut now: libc::timeval = mem::init();
assert_eq!(imp::gettimeofday(&mut now, ptr::null()), 0);
return (now.tv_sec as u64) * 1000 + (now.tv_usec as u64) / 1000;
}
}

fn helper(input: libc::c_int, messages: Port<Req>) {
let mut set: imp::fd_set = unsafe { intrinsics::init() };
let mut set: imp::fd_set = unsafe { mem::init() };

let mut fd = FileDesc::new(input, true);
let mut timeout: libc::timeval = unsafe { intrinsics::init() };
let mut timeout: libc::timeval = unsafe { mem::init() };

// 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
Expand Down
4 changes: 2 additions & 2 deletions src/libnative/io/timer_timerfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use std::ptr;
use std::os;
use std::rt::rtio;
use std::hashmap::HashMap;
use std::unstable::intrinsics;
use std::mem;

use io::file::FileDesc;
use io::IoResult;
Expand Down Expand Up @@ -75,7 +75,7 @@ fn helper(input: libc::c_int, messages: Port<Req>) {
}

add(efd, input);
let events: [imp::epoll_event, ..16] = unsafe { intrinsics::init() };
let events: [imp::epoll_event, ..16] = unsafe { mem::init() };
let mut map: HashMap<libc::c_int, (Chan<()>, bool)> = HashMap::new();
'outer: loop {
let n = match unsafe {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/util/sha2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use extra::hex::ToHex;
/// format.
fn write_u32_be(dst: &mut[u8], input: u32) {
use std::cast::transmute;
use std::unstable::intrinsics::to_be32;
use std::mem::to_be32;
assert!(dst.len() == 4);
unsafe {
let x: *mut i32 = transmute(dst.unsafe_mut_ref(0));
Expand All @@ -33,7 +33,7 @@ fn write_u32_be(dst: &mut[u8], input: u32) {
/// Read a vector of bytes into a vector of u32s. The values are read in big-endian format.
fn read_u32v_be(dst: &mut[u32], input: &[u8]) {
use std::cast::transmute;
use std::unstable::intrinsics::to_be32;
use std::mem::to_be32;
assert!(dst.len() * 4 == input.len());
unsafe {
let mut x: *mut i32 = transmute(dst.unsafe_mut_ref(0));
Expand Down
5 changes: 3 additions & 2 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use std::cast;
use std::fmt;
use std::io;
use std::libc;
use std::mem;
use std::str;
use std::unstable::intrinsics;
use std::vec;
Expand Down Expand Up @@ -144,7 +145,7 @@ pub fn render(w: &mut io::Writer, s: &str) -> fmt::Result {
flags: 0,
link_attributes: None,
};
let mut callbacks: sd_callbacks = intrinsics::init();
let mut callbacks: sd_callbacks = mem::init();

sdhtml_renderer(&callbacks, &options, 0);
let opaque = my_opaque {
Expand Down Expand Up @@ -197,7 +198,7 @@ pub fn find_testable_code(doc: &str, tests: &mut ::test::Collector) {
MKDEXT_STRIKETHROUGH;
let callbacks = sd_callbacks {
blockcode: block,
other: intrinsics::init()
other: mem::init()
};

let tests = tests as *mut ::test::Collector as *libc::c_void;
Expand Down
9 changes: 4 additions & 5 deletions src/librustuv/net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use std::mem;
use std::ptr;
use std::rt::rtio;
use std::rt::task::BlockedTask;
use std::unstable::intrinsics;

use access::Access;
use homing::{HomingIO, HomeHandle};
Expand All @@ -33,8 +32,8 @@ use uvll;
/// Generic functions related to dealing with sockaddr things
////////////////////////////////////////////////////////////////////////////////

pub fn htons(u: u16) -> u16 { intrinsics::to_be16(u as i16) as u16 }
pub fn ntohs(u: u16) -> u16 { intrinsics::from_be16(u as i16) as u16 }
pub fn htons(u: u16) -> u16 { mem::to_be16(u as i16) as u16 }
pub fn ntohs(u: u16) -> u16 { mem::from_be16(u as i16) as u16 }

pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
len: uint) -> ip::SocketAddr {
Expand Down Expand Up @@ -80,7 +79,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,

fn addr_to_sockaddr(addr: ip::SocketAddr) -> (libc::sockaddr_storage, uint) {
unsafe {
let mut storage: libc::sockaddr_storage = intrinsics::init();
let mut storage: libc::sockaddr_storage = mem::init();
let len = match addr.ip {
ip::Ipv4Addr(a, b, c, d) => {
let storage: &mut libc::sockaddr_in =
Expand Down Expand Up @@ -134,7 +133,7 @@ fn socket_name(sk: SocketNameKind,
};

// Allocate a sockaddr_storage since we don't know if it's ipv4 or ipv6
let mut sockaddr: libc::sockaddr_storage = unsafe { intrinsics::init() };
let mut sockaddr: libc::sockaddr_storage = unsafe { mem::init() };
let mut namelen = mem::size_of::<libc::sockaddr_storage>() as c_int;

let sockaddr_p = &mut sockaddr as *mut libc::sockaddr_storage;
Expand Down
2 changes: 1 addition & 1 deletion src/libserialize/ebml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub mod reader {

pub fn vuint_at(data: &[u8], start: uint) -> Res {
use std::ptr::offset;
use std::unstable::intrinsics::from_be32;
use std::mem::from_be32;

if data.len() - start < 4 {
return vuint_at_slow(data, start);
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ use kinds::marker;
use ops::Drop;
use cmp::Eq;
use clone::Clone;
use mem;
use option::{Option, Some, None};
use ptr::RawPtr;
use ptr;
use str::StrSlice;
use str;
use vec::{ImmutableVector, MutableVector};
use vec;
use unstable::intrinsics;
use rt::global_heap::malloc_raw;

/// The representation of a C String.
Expand Down Expand Up @@ -327,7 +327,7 @@ impl<'a> ToCStr for &'a [u8] {
// Unsafe function that handles possibly copying the &[u8] into a stack array.
unsafe fn with_c_str<T>(v: &[u8], checked: bool, f: |*libc::c_char| -> T) -> T {
if v.len() < BUF_LEN {
let mut buf: [u8, .. BUF_LEN] = intrinsics::uninit();
let mut buf: [u8, .. BUF_LEN] = mem::uninit();
vec::bytes::copy_memory(buf, v);
buf[v.len()] = 0;

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use ptr::copy_nonoverlapping_memory;
/// Casts the value at `src` to U. The two types must have the same length.
#[inline]
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
let mut dest: U = intrinsics::uninit();
let mut dest: U = mem::uninit();
let dest_ptr: *mut u8 = transmute(&mut dest);
let src_ptr: *u8 = transmute(src);
copy_nonoverlapping_memory(dest_ptr, src_ptr, mem::size_of::<U>());
Expand Down
Loading