1
Fork 0

librustc: Remove ptr::addr_of.

This commit is contained in:
Patrick Walton 2013-04-22 14:27:30 -07:00
parent 58791c2fd8
commit b0522a497c
61 changed files with 276 additions and 300 deletions

View file

@ -14,7 +14,6 @@ use cast::transmute;
use kinds::Copy;
use old_iter;
use option::Option;
use ptr::addr_of;
use sys;
use uint;
use vec;
@ -40,8 +39,7 @@ pub mod rustrt {
#[inline(always)]
pub fn capacity<T>(v: @[T]) -> uint {
unsafe {
let repr: **raw::VecRepr =
::cast::transmute(addr_of(&v));
let repr: **raw::VecRepr = transmute(&v);
(**repr).unboxed.alloc / sys::size_of::<T>()
}
}
@ -189,11 +187,10 @@ pub mod raw {
use at_vec::{capacity, rustrt};
use cast::transmute;
use libc;
use unstable::intrinsics::{move_val_init};
use ptr::addr_of;
use ptr;
use sys;
use uint;
use unstable::intrinsics::{move_val_init};
use vec;
pub type VecRepr = vec::raw::VecRepr;
@ -208,7 +205,7 @@ pub mod raw {
*/
#[inline(always)]
pub unsafe fn set_len<T>(v: @[T], new_len: uint) {
let repr: **mut VecRepr = ::cast::transmute(addr_of(&v));
let repr: **mut VecRepr = transmute(&v);
(**repr).unboxed.fill = new_len * sys::size_of::<T>();
}
@ -229,7 +226,7 @@ pub mod raw {
let repr: **mut VecRepr = ::cast::transmute(v);
let fill = (**repr).unboxed.fill;
(**repr).unboxed.fill += sys::size_of::<T>();
let p = addr_of(&((**repr).unboxed.data));
let p = &((**repr).unboxed.data);
let p = ptr::offset(p, fill) as *mut T;
move_val_init(&mut(*p), initval);
}

View file

@ -327,6 +327,7 @@ impl<T: Owned> ::clone::Clone for SharedChan<T> {
#[allow(non_camel_case_types)]
pub mod oneshot {
priv use core::kinds::Owned;
use ptr::to_unsafe_ptr;
pub fn init<T: Owned>() -> (client::Oneshot<T>, server::Oneshot<T>) {
pub use core::pipes::HasBuffer;
@ -341,7 +342,7 @@ pub mod oneshot {
do ::core::pipes::entangle_buffer(buffer) |buffer, data| {
{
data.Oneshot.set_buffer(buffer);
::ptr::addr_of(&(data.Oneshot))
to_unsafe_ptr(&data.Oneshot)
}
}
}

View file

@ -53,7 +53,7 @@ pub fn deflate_bytes(bytes: &const [u8]) -> ~[u8] {
let res =
rustrt::tdefl_compress_mem_to_heap(b as *c_void,
len as size_t,
ptr::addr_of(&outsz),
&outsz,
lz_norm);
assert!(res as int != 0);
let out = vec::raw::from_buf_raw(res as *u8,
@ -71,7 +71,7 @@ pub fn inflate_bytes(bytes: &const [u8]) -> ~[u8] {
let res =
rustrt::tinfl_decompress_mem_to_heap(b as *c_void,
len as size_t,
ptr::addr_of(&outsz),
&outsz,
0);
assert!(res as int != 0);
let out = vec::raw::from_buf_raw(res as *u8,

View file

@ -338,7 +338,7 @@ pub fn cleanup_stack_for_failure() {
// own stack roots on the stack anyway.
let sentinel_box = ~0;
let sentinel: **Word = if expect_sentinel() {
cast::transmute(ptr::addr_of(&sentinel_box))
cast::transmute(&sentinel_box)
} else {
ptr::null()
};

View file

@ -10,7 +10,7 @@
//! Operations on managed box types
use ptr;
use ptr::to_unsafe_ptr;
#[cfg(notest)] use cmp::{Eq, Ord};
@ -38,13 +38,15 @@ pub mod raw {
#[inline(always)]
pub fn ptr_eq<T>(a: @T, b: @T) -> bool {
//! Determine if two shared boxes point to the same object
ptr::addr_of(&(*a)) == ptr::addr_of(&(*b))
let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
a_ptr == b_ptr
}
#[inline(always)]
pub fn mut_ptr_eq<T>(a: @mut T, b: @mut T) -> bool {
//! Determine if two mutable shared boxes point to the same object
ptr::addr_of(&(*a)) == ptr::addr_of(&(*b))
let a_ptr: *T = to_unsafe_ptr(&*a), b_ptr: *T = to_unsafe_ptr(&*b);
a_ptr == b_ptr
}
#[cfg(notest)]

View file

@ -49,7 +49,6 @@ use num::Zero;
use old_iter::{BaseIter, MutableIter, ExtendedIter};
use old_iter;
#[cfg(test)] use ptr;
#[cfg(test)] use str;
/// The option type
@ -481,12 +480,14 @@ pub impl<T:Copy + Zero> Option<T> {
#[test]
fn test_unwrap_ptr() {
let x = ~0;
let addr_x = ptr::addr_of(&(*x));
let opt = Some(x);
let y = opt.unwrap();
let addr_y = ptr::addr_of(&(*y));
assert!(addr_x == addr_y);
unsafe {
let x = ~0;
let addr_x: *int = transmute(&*x);
let opt = Some(x);
let y = opt.unwrap();
let addr_y: *int = transmute(&*y);
assert!(addr_x == addr_y);
}
}
#[test]

View file

@ -95,7 +95,7 @@ use vec;
static SPIN_COUNT: uint = 0;
macro_rules! move_it (
{ $x:expr } => ( unsafe { let y = *ptr::addr_of(&($x)); y } )
{ $x:expr } => ( unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } )
)
#[deriving(Eq)]
@ -218,7 +218,7 @@ fn unibuffer<T>() -> ~Buffer<Packet<T>> {
pub fn packet<T>() -> *Packet<T> {
let b = unibuffer();
let p = ptr::addr_of(&(b.data));
let p = ptr::to_unsafe_ptr(&(b.data));
// We'll take over memory management from here.
unsafe { forget(b) }
p
@ -305,7 +305,7 @@ impl<T> ::ops::Drop for BufferResource<T> {
fn finalize(&self) {
unsafe {
let b = move_it!(self.buffer);
//let p = ptr::addr_of(*b);
//let p = ptr::to_unsafe_ptr(*b);
//error!("drop %?", p);
let old_count = intrinsics::atomic_xsub_rel(&mut b.header.ref_count, 1);
//let old_count = atomic_xchng_rel(b.header.ref_count, 0);
@ -322,7 +322,7 @@ impl<T> ::ops::Drop for BufferResource<T> {
}
fn BufferResource<T>(b: ~Buffer<T>) -> BufferResource<T> {
//let p = ptr::addr_of(*b);
//let p = ptr::to_unsafe_ptr(*b);
//error!("take %?", p);
unsafe { intrinsics::atomic_xadd_acq(&mut b.header.ref_count, 1) };
@ -336,7 +336,7 @@ pub fn send<T,Tbuffer>(p: SendPacketBuffered<T,Tbuffer>, payload: T) -> bool {
let header = p.header();
let p_ = p.unwrap();
let p = unsafe { &*p_ };
assert!(ptr::addr_of(&(p.header)) == header);
assert!(ptr::to_unsafe_ptr(&(p.header)) == header);
assert!(p.payload.is_none());
p.payload = Some(payload);
let old_state = swap_state_rel(&mut p.header.state, Full);
@ -356,7 +356,7 @@ pub fn send<T,Tbuffer>(p: SendPacketBuffered<T,Tbuffer>, payload: T) -> bool {
unsafe {
rustrt::task_signal_event(
old_task,
ptr::addr_of(&(p.header)) as *libc::c_void);
ptr::to_unsafe_ptr(&(p.header)) as *libc::c_void);
rustrt::rust_task_deref(old_task);
}
}
@ -521,7 +521,7 @@ fn sender_terminate<T:Owned>(p: *Packet<T>) {
unsafe {
rustrt::task_signal_event(
old_task,
ptr::addr_of(&(p.header)) as *libc::c_void);
ptr::to_unsafe_ptr(&(p.header)) as *libc::c_void);
rustrt::rust_task_deref(old_task);
}
}
@ -665,7 +665,7 @@ pub fn SendPacketBuffered<T,Tbuffer>(p: *Packet<T>)
p: Some(p),
buffer: unsafe {
Some(BufferResource(
get_buffer(ptr::addr_of(&((*p).header)))))
get_buffer(ptr::to_unsafe_ptr(&((*p).header)))))
}
}
}
@ -681,7 +681,7 @@ pub impl<T,Tbuffer> SendPacketBuffered<T,Tbuffer> {
match self.p {
Some(packet) => unsafe {
let packet = &*packet;
let header = ptr::addr_of(&(packet.header));
let header = ptr::to_unsafe_ptr(&(packet.header));
//forget(packet);
header
},
@ -747,7 +747,7 @@ impl<T:Owned,Tbuffer:Owned> Selectable for RecvPacketBuffered<T, Tbuffer> {
match self.p {
Some(packet) => unsafe {
let packet = &*packet;
let header = ptr::addr_of(&(packet.header));
let header = ptr::to_unsafe_ptr(&(packet.header));
//forget(packet);
header
},
@ -763,7 +763,7 @@ pub fn RecvPacketBuffered<T,Tbuffer>(p: *Packet<T>)
p: Some(p),
buffer: unsafe {
Some(BufferResource(
get_buffer(ptr::addr_of(&((*p).header)))))
get_buffer(ptr::to_unsafe_ptr(&((*p).header)))))
}
}
}

View file

@ -39,17 +39,6 @@ pub mod libc_ {
}
}
pub mod rusti {
#[abi = "rust-intrinsic"]
pub extern "rust-intrinsic" {
fn addr_of<T>(&&val: T) -> *T;
}
}
/// Get an unsafe pointer to a value
#[inline(always)]
pub fn addr_of<T>(val: &T) -> *T { unsafe { rusti::addr_of(*val) } }
/// Calculate the offset from a pointer
#[inline(always)]
pub fn offset<T>(ptr: *T, count: uint) -> *T {

View file

@ -252,7 +252,7 @@ pub unsafe fn async_send(async_handle: *uv_async_t) {
}
pub unsafe fn buf_init(input: *u8, len: uint) -> uv_buf_t {
let out_buf = uv_buf_t { base: ptr::null(), len: 0 as size_t };
let out_buf_ptr = ptr::addr_of(&out_buf);
let out_buf_ptr = ptr::to_unsafe_ptr(&out_buf);
rust_uv_buf_init(out_buf_ptr, input, len as size_t);
return out_buf;
}
@ -330,7 +330,7 @@ pub unsafe fn free_base_of_buf(buf: uv_buf_t) {
pub unsafe fn get_last_err_info(uv_loop: *c_void) -> ~str {
let err = last_error(uv_loop);
let err_ptr = ptr::addr_of(&err);
let err_ptr = ptr::to_unsafe_ptr(&err);
let err_name = str::raw::from_c_str(err_name(err_ptr));
let err_msg = str::raw::from_c_str(strerror(err_ptr));
return fmt!("LIBUV ERROR: name: %s msg: %s",
@ -339,7 +339,7 @@ pub unsafe fn get_last_err_info(uv_loop: *c_void) -> ~str {
pub unsafe fn get_last_err_data(uv_loop: *c_void) -> uv_err_data {
let err = last_error(uv_loop);
let err_ptr = ptr::addr_of(&err);
let err_ptr = ptr::to_unsafe_ptr(&err);
let err_name = str::raw::from_c_str(err_name(err_ptr));
let err_msg = str::raw::from_c_str(strerror(err_ptr));
uv_err_data { err_name: err_name, err_msg: err_msg }

View file

@ -18,6 +18,7 @@
*/
use at_vec;
use cast::transmute;
use cast;
use char;
use clone::Clone;
@ -2045,7 +2046,7 @@ pub fn as_c_str<T>(s: &str, f: &fn(*libc::c_char) -> T) -> T {
#[inline(always)]
pub fn as_buf<T>(s: &str, f: &fn(*u8, uint) -> T) -> T {
unsafe {
let v : *(*u8,uint) = ::cast::transmute(ptr::addr_of(&s));
let v : *(*u8,uint) = transmute(&s);
let (buf,len) = *v;
f(buf, len)
}

View file

@ -1028,10 +1028,10 @@ fn avoid_copying_the_body(spawnfn: &fn(v: ~fn())) {
let (p, ch) = stream::<uint>();
let x = ~1;
let x_in_parent = ptr::addr_of(&(*x)) as uint;
let x_in_parent = ptr::to_unsafe_ptr(&*x) as uint;
do spawnfn || {
let x_in_child = ptr::addr_of(&(*x)) as uint;
let x_in_child = ptr::to_unsafe_ptr(&*x) as uint;
ch.send(x_in_child);
}

View file

@ -93,7 +93,7 @@ use util;
#[cfg(test)] use task::default_task_opts;
macro_rules! move_it (
{ $x:expr } => ( unsafe { let y = *ptr::addr_of(&($x)); y } )
{ $x:expr } => ( unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } )
)
type TaskSet = HashSet<*rust_task>;

View file

@ -48,8 +48,6 @@ pub extern "rust-intrinsic" {
// XXX: intrinsic uses legacy modes
fn reinterpret_cast<T,U>(&&src: T) -> U;
// XXX: intrinsic uses legacy modes
fn addr_of<T>(&&scr: T) -> *T;
pub fn needs_drop<T>() -> bool;

View file

@ -26,11 +26,11 @@ use iterator::Iterator;
use kinds::Copy;
use libc;
use option::{None, Option, Some};
use unstable::intrinsics;
use ptr::to_unsafe_ptr;
use ptr;
use ptr::addr_of;
use sys;
use uint;
use unstable::intrinsics;
use vec;
#[cfg(notest)] use cmp::Equiv;
@ -117,7 +117,7 @@ pub fn reserve_at_least<T>(v: &mut ~[T], n: uint) {
#[inline(always)]
pub fn capacity<T>(v: &const ~[T]) -> uint {
unsafe {
let repr: **raw::VecRepr = ::cast::transmute(v);
let repr: **raw::VecRepr = transmute(v);
(**repr).unboxed.alloc / sys::nonzero_size_of::<T>()
}
}
@ -131,7 +131,7 @@ pub fn len<T>(v: &const [T]) -> uint {
// A botch to tide us over until core and std are fully demuted.
pub fn uniq_len<T>(v: &const ~[T]) -> uint {
unsafe {
let v: &~[T] = ::cast::transmute(v);
let v: &~[T] = transmute(v);
as_const_buf(*v, |_p, len| len)
}
}
@ -280,9 +280,8 @@ pub fn slice<'r,T>(v: &'r [T], start: uint, end: uint) -> &'r [T] {
assert!(end <= len(v));
do as_imm_buf(v) |p, _len| {
unsafe {
::cast::transmute(
(ptr::offset(p, start),
(end - start) * sys::nonzero_size_of::<T>()))
transmute((ptr::offset(p, start),
(end - start) * sys::nonzero_size_of::<T>()))
}
}
}
@ -295,9 +294,8 @@ pub fn mut_slice<'r,T>(v: &'r mut [T], start: uint, end: uint)
assert!(end <= v.len());
do as_mut_buf(v) |p, _len| {
unsafe {
::cast::transmute(
(ptr::mut_offset(p, start),
(end - start) * sys::nonzero_size_of::<T>()))
transmute((ptr::mut_offset(p, start),
(end - start) * sys::nonzero_size_of::<T>()))
}
}
}
@ -310,9 +308,8 @@ pub fn const_slice<'r,T>(v: &'r const [T], start: uint, end: uint)
assert!(end <= len(v));
do as_const_buf(v) |p, _len| {
unsafe {
::cast::transmute(
(ptr::const_offset(p, start),
(end - start) * sys::nonzero_size_of::<T>()))
transmute((ptr::const_offset(p, start),
(end - start) * sys::nonzero_size_of::<T>()))
}
}
}
@ -489,14 +486,14 @@ pub fn shift<T>(v: &mut ~[T]) -> T {
{
let first_slice = slice(*v, 0, 1);
let last_slice = slice(*v, next_ln, ln);
raw::copy_memory(::cast::transmute(last_slice), first_slice, 1);
raw::copy_memory(transmute(last_slice), first_slice, 1);
}
// Memcopy everything to the left one element
{
let init_slice = slice(*v, 0, next_ln);
let tail_slice = slice(*v, 1, ln);
raw::copy_memory(::cast::transmute(init_slice),
raw::copy_memory(transmute(init_slice),
tail_slice,
next_ln);
}
@ -626,7 +623,7 @@ pub fn swap_remove<T>(v: &mut ~[T], index: uint) -> T {
#[inline(always)]
pub fn push<T>(v: &mut ~[T], initval: T) {
unsafe {
let repr: **raw::VecRepr = ::cast::transmute(&mut *v);
let repr: **raw::VecRepr = transmute(&mut *v);
let fill = (**repr).unboxed.fill;
if (**repr).unboxed.alloc > fill {
push_fast(v, initval);
@ -640,10 +637,10 @@ pub fn push<T>(v: &mut ~[T], initval: T) {
// This doesn't bother to make sure we have space.
#[inline(always)] // really pretty please
unsafe fn push_fast<T>(v: &mut ~[T], initval: T) {
let repr: **mut raw::VecRepr = ::cast::transmute(v);
let repr: **mut raw::VecRepr = transmute(v);
let fill = (**repr).unboxed.fill;
(**repr).unboxed.fill += sys::nonzero_size_of::<T>();
let p = addr_of(&((**repr).unboxed.data));
let p = to_unsafe_ptr(&((**repr).unboxed.data));
let p = ptr::offset(p, fill) as *mut T;
intrinsics::move_val_init(&mut(*p), initval);
}
@ -1622,8 +1619,7 @@ pub fn as_imm_buf<T,U>(s: &[T],
// instead!
unsafe {
let v : *(*T,uint) =
::cast::transmute(addr_of(&s));
let v : *(*T,uint) = transmute(&s);
let (buf,len) = *v;
f(buf, len / sys::nonzero_size_of::<T>())
}
@ -1633,8 +1629,7 @@ pub fn as_imm_buf<T,U>(s: &[T],
#[inline(always)]
pub fn as_const_buf<T,U>(s: &const [T], f: &fn(*const T, uint) -> U) -> U {
unsafe {
let v : *(*const T,uint) =
::cast::transmute(addr_of(&s));
let v : *(*const T,uint) = transmute(&s);
let (buf,len) = *v;
f(buf, len / sys::nonzero_size_of::<T>())
}
@ -1644,8 +1639,7 @@ pub fn as_const_buf<T,U>(s: &const [T], f: &fn(*const T, uint) -> U) -> U {
#[inline(always)]
pub fn as_mut_buf<T,U>(s: &mut [T], f: &fn(*mut T, uint) -> U) -> U {
unsafe {
let v : *(*mut T,uint) =
::cast::transmute(addr_of(&s));
let v : *(*mut T,uint) = transmute(&s);
let (buf,len) = *v;
f(buf, len / sys::nonzero_size_of::<T>())
}
@ -2429,13 +2423,13 @@ pub struct UnboxedVecRepr {
/// Unsafe operations
pub mod raw {
use cast::transmute;
use kinds::Copy;
use managed;
use option::{None, Some};
use unstable::intrinsics;
use ptr::addr_of;
use ptr;
use sys;
use unstable::intrinsics;
use vec::{UnboxedVecRepr, as_const_buf, as_mut_buf, len, with_capacity};
/// The internal representation of a (boxed) vector
@ -2458,7 +2452,7 @@ pub mod raw {
*/
#[inline(always)]
pub unsafe fn set_len<T>(v: &mut ~[T], new_len: uint) {
let repr: **mut VecRepr = ::cast::transmute(v);
let repr: **mut VecRepr = transmute(v);
(**repr).unboxed.fill = new_len * sys::nonzero_size_of::<T>();
}
@ -2473,22 +2467,22 @@ pub mod raw {
*/
#[inline(always)]
pub unsafe fn to_ptr<T>(v: &[T]) -> *T {
let repr: **SliceRepr = ::cast::transmute(&v);
::cast::transmute(addr_of(&((**repr).data)))
let repr: **SliceRepr = transmute(&v);
transmute(&((**repr).data))
}
/** see `to_ptr()` */
#[inline(always)]
pub unsafe fn to_const_ptr<T>(v: &const [T]) -> *const T {
let repr: **SliceRepr = ::cast::transmute(&v);
::cast::transmute(addr_of(&((**repr).data)))
let repr: **SliceRepr = transmute(&v);
transmute(&((**repr).data))
}
/** see `to_ptr()` */
#[inline(always)]
pub unsafe fn to_mut_ptr<T>(v: &mut [T]) -> *mut T {
let repr: **SliceRepr = ::cast::transmute(&v);
::cast::transmute(addr_of(&((**repr).data)))
let repr: **SliceRepr = transmute(&v);
transmute(&((**repr).data))
}
/**
@ -2500,8 +2494,7 @@ pub mod raw {
len: uint,
f: &fn(v: &[T]) -> U) -> U {
let pair = (p, len * sys::nonzero_size_of::<T>());
let v : *(&'blk [T]) =
::cast::transmute(addr_of(&pair));
let v : *(&'blk [T]) = transmute(&pair);
f(*v)
}
@ -2514,8 +2507,7 @@ pub mod raw {
len: uint,
f: &fn(v: &mut [T]) -> U) -> U {
let pair = (p, len * sys::nonzero_size_of::<T>());
let v : *(&'blk mut [T]) =
::cast::transmute(addr_of(&pair));
let v : *(&'blk mut [T]) = transmute(&pair);
f(*v)
}

View file

@ -28,8 +28,8 @@ use syntax::ast_util::local_def;
use syntax::visit::{default_simple_visitor, mk_simple_visitor, SimpleVisitor};
use syntax::visit::visit_crate;
use core::cast::transmute;
use core::hashmap::HashMap;
use core::ptr;
pub enum LangItem {
ConstTraitLangItem, // 0
@ -366,20 +366,22 @@ pub impl<'self> LanguageItemCollector<'self> {
}
fn collect_local_language_items(&self) {
let this = ptr::addr_of(&self);
visit_crate(self.crate, (), mk_simple_visitor(@SimpleVisitor {
visit_item: |item| {
for item.attrs.each |attribute| {
unsafe {
(*this).match_and_collect_meta_item(
local_def(item.id),
attribute.node.value
);
unsafe {
let this: *LanguageItemCollector<'self> = transmute(self);
visit_crate(self.crate, (), mk_simple_visitor(@SimpleVisitor {
visit_item: |item| {
for item.attrs.each |attribute| {
unsafe {
(*this).match_and_collect_meta_item(
local_def(item.id),
attribute.node.value
);
}
}
}
},
.. *default_simple_visitor()
}));
},
.. *default_simple_visitor()
}));
}
}
fn collect_external_language_items(&self) {

View file

@ -110,6 +110,7 @@ use middle::typeck;
use middle::moves;
use util::ppaux::ty_to_str;
use core::cast::transmute;
use core::hashmap::HashMap;
use core::util::with;
use syntax::ast::*;
@ -418,7 +419,9 @@ fn visit_fn(fk: &visit::fn_kind,
self.last_use_map,
self.cur_item);
debug!("creating fn_maps: %x", ptr::addr_of(&(*fn_maps)) as uint);
unsafe {
debug!("creating fn_maps: %x", transmute(&*fn_maps));
}
for decl.inputs.each |arg| {
let mode = ty::resolved_mode(self.tcx, arg.mode);

View file

@ -170,7 +170,7 @@ pub fn IndirectBr(cx: block, Addr: ValueRef, NumDests: uint) {
pub fn noname() -> *c_char {
unsafe {
static cnull: uint = 0u;
return cast::transmute(ptr::addr_of(&cnull));
return cast::transmute(&cnull);
}
}
@ -827,8 +827,8 @@ pub fn Phi(cx: block, Ty: TypeRef, vals: &[ValueRef], bbs: &[BasicBlockRef])
pub fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) {
unsafe {
if llvm::LLVMIsUndef(phi) == lib::llvm::True { return; }
let valptr = cast::transmute(ptr::addr_of(&val));
let bbptr = cast::transmute(ptr::addr_of(&bb));
let valptr = cast::transmute(&val);
let bbptr = cast::transmute(&bb);
llvm::LLVMAddIncoming(phi, valptr, bbptr, 1 as c_uint);
}
}

View file

@ -750,13 +750,11 @@ pub impl block_ {
t.repr(self.tcx())
}
fn to_str(@mut self) -> ~str {
match self.node_info {
Some(node_info) => {
fmt!("[block %d]", node_info.id)
}
None => {
fmt!("[block %x]", ptr::addr_of(&(*self)) as uint)
}
unsafe {
match self.node_info {
Some(node_info) => fmt!("[block %d]", node_info.id),
None => fmt!("[block %x]", transmute(&*self)),
}
}
}
}

View file

@ -745,9 +745,6 @@ pub fn trans_intrinsic(ccx: @CrateContext,
call_memcpy(bcx, llretptr, llcast, llsize_of(ccx, lltp_ty));
}
}
~"addr_of" => {
Store(bcx, get_param(decl, first_real_arg), fcx.llretptr.get());
}
~"needs_drop" => {
let tp_ty = substs.tys[0];
Store(bcx,

View file

@ -135,8 +135,8 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
~"atomic_xsub_acq" | ~"atomic_xchg_rel" |
~"atomic_xadd_rel" | ~"atomic_xsub_rel" => 0,
~"visit_tydesc" | ~"forget" | ~"addr_of" |
~"frame_address" | ~"morestack_addr" => 0,
~"visit_tydesc" | ~"forget" | ~"frame_address" |
~"morestack_addr" => 0,
~"memmove32" | ~"memmove64" => 0,

View file

@ -107,6 +107,7 @@ use util::common::{block_query, indenter, loop_query};
use util::ppaux::{bound_region_to_str};
use util::ppaux;
use core::cast::transmute;
use core::hashmap::HashMap;
use core::util::replace;
use std::list::Nil;
@ -706,7 +707,11 @@ impl region_scope for FnCtxt {
}
pub impl FnCtxt {
fn tag(&self) -> ~str { fmt!("%x", ptr::addr_of(&(*self)) as uint) }
fn tag(&self) -> ~str {
unsafe {
fmt!("%x", transmute(self))
}
}
fn local_ty(&self, span: span, nid: ast::node_id) -> ty::t {
match self.inh.locals.find(&nid) {
@ -3436,8 +3441,6 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
ty::mk_nil()),
~"reinterpret_cast" => (2u, ~[arg(ast::by_ref, param(ccx, 0u))],
param(ccx, 1u)),
~"addr_of" => (1u, ~[arg(ast::by_ref, param(ccx, 0u))],
ty::mk_imm_ptr(tcx, param(ccx, 0u))),
~"move_val" | ~"move_val_init" => {
(1u, ~[arg(ast::by_copy,
ty::mk_mut_rptr(tcx, ty::re_bound(ty::br_anon(0)),

View file

@ -11,7 +11,6 @@
//! Unsafe debugging functions for inspecting values.
use core::cast::transmute;
use core::ptr;
use core::sys;
pub mod rustrt {
@ -37,36 +36,31 @@ pub fn debug_tydesc<T>() {
pub fn debug_opaque<T>(x: T) {
unsafe {
rustrt::debug_opaque(sys::get_type_desc::<T>(),
ptr::addr_of(&x) as *());
rustrt::debug_opaque(sys::get_type_desc::<T>(), transmute(&x));
}
}
pub fn debug_box<T>(x: @T) {
unsafe {
rustrt::debug_box(sys::get_type_desc::<T>(),
ptr::addr_of(&x) as *());
rustrt::debug_box(sys::get_type_desc::<T>(), transmute(&x));
}
}
pub fn debug_tag<T>(x: T) {
unsafe {
rustrt::debug_tag(sys::get_type_desc::<T>(),
ptr::addr_of(&x) as *());
rustrt::debug_tag(sys::get_type_desc::<T>(), transmute(&x));
}
}
pub fn debug_fn<T>(x: T) {
unsafe {
rustrt::debug_fn(sys::get_type_desc::<T>(),
ptr::addr_of(&x) as *());
rustrt::debug_fn(sys::get_type_desc::<T>(), transmute(&x));
}
}
pub unsafe fn ptr_cast<T, U>(x: @T) -> @U {
transmute(
rustrt::debug_ptrcast(sys::get_type_desc::<T>(),
transmute(x)))
rustrt::debug_ptrcast(sys::get_type_desc::<T>(), transmute(x)))
}
/// Triggers a debugger breakpoint

View file

@ -110,18 +110,18 @@ enum IpGetAddrErr {
* object in the case of failure
*/
pub fn get_addr(node: &str, iotask: &iotask)
-> result::Result<~[IpAddr], IpGetAddrErr> {
-> result::Result<~[IpAddr], IpGetAddrErr> {
let (output_po, output_ch) = stream();
let mut output_ch = Some(SharedChan::new(output_ch));
do str::as_buf(node) |node_ptr, len| {
let output_ch = output_ch.swap_unwrap();
debug!("slice len %?", len);
let handle = create_uv_getaddrinfo_t();
let handle_ptr = ptr::addr_of(&handle);
let handle_ptr: *uv_getaddrinfo_t = &handle;
let handle_data = GetAddrData {
output_ch: output_ch.clone()
};
let handle_data_ptr = ptr::addr_of(&handle_data);
let handle_data_ptr: *GetAddrData = &handle_data;
do interact(iotask) |loop_ptr| {
unsafe {
let result = uv_getaddrinfo(
@ -189,7 +189,8 @@ pub mod v4 {
impl AsUnsafeU32 for Ipv4Rep {
// this is pretty dastardly, i know
unsafe fn as_u32(&self) -> u32 {
*((ptr::addr_of(self)) as *u32)
let this: &mut u32 = transmute(self);
*this
}
}
pub fn parse_to_ipv4_rep(ip: &str) -> result::Result<Ipv4Rep, ~str> {
@ -297,7 +298,8 @@ struct GetAddrData {
output_ch: SharedChan<result::Result<~[IpAddr],IpGetAddrErr>>
}
extern fn get_addr_cb(handle: *uv_getaddrinfo_t, status: libc::c_int,
extern fn get_addr_cb(handle: *uv_getaddrinfo_t,
status: libc::c_int,
res: *addrinfo) {
unsafe {
debug!("in get_addr_cb");

View file

@ -156,7 +156,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint,
result_ch: result_ch,
closed_signal_ch: closed_signal_ch
};
let conn_data_ptr = ptr::addr_of(&conn_data);
let conn_data_ptr: *ConnectReqData = &conn_data;
let (reader_po, reader_ch) = stream::<Result<~[u8], TcpErrData>>();
let reader_ch = SharedChan::new(reader_ch);
let stream_handle_ptr = malloc_uv_tcp_t();
@ -173,7 +173,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint,
},
iotask: iotask.clone()
};
let socket_data_ptr = ptr::addr_of(&(*socket_data));
let socket_data_ptr: *TcpSocketData = &*socket_data;
// get an unsafe representation of our stream_handle_ptr that
// we can send into the interact cb to be handled in libuv..
debug!("stream_handle_ptr outside interact %?",
@ -187,8 +187,8 @@ pub fn connect(input_ip: ip::IpAddr, port: uint,
0i32 => {
debug!("tcp_init successful");
debug!("dealing w/ ipv4 connection..");
let connect_req_ptr =
ptr::addr_of(&((*socket_data_ptr).connect_req));
let connect_req_ptr: *uv::ll::uv_connect_t =
&(*socket_data_ptr).connect_req;
let addr_str = ip::format_addr(&input_ip);
let connect_result = match input_ip {
ip::Ipv4(ref addr) => {
@ -205,7 +205,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint,
uv::ll::tcp_connect(
connect_req_ptr,
stream_handle_ptr,
ptr::addr_of(&in_addr),
&in_addr,
tcp_connect_on_connect_cb)
}
ip::Ipv6(ref addr) => {
@ -215,7 +215,7 @@ pub fn connect(input_ip: ip::IpAddr, port: uint,
uv::ll::tcp_connect6(
connect_req_ptr,
stream_handle_ptr,
ptr::addr_of(&in_addr),
&in_addr,
tcp_connect_on_connect_cb)
}
};
@ -303,9 +303,8 @@ pub fn connect(input_ip: ip::IpAddr, port: uint,
* `TcpErrData` value as the `Err` variant
*/
pub fn write(sock: &TcpSocket, raw_write_data: ~[u8])
-> result::Result<(), TcpErrData>
{
let socket_data_ptr = ptr::addr_of(&(*(sock.socket_data)));
-> result::Result<(), TcpErrData> {
let socket_data_ptr: *TcpSocketData = &*sock.socket_data;
write_common_impl(socket_data_ptr, raw_write_data)
}
@ -343,7 +342,7 @@ pub fn write(sock: &TcpSocket, raw_write_data: ~[u8])
pub fn write_future(sock: &TcpSocket, raw_write_data: ~[u8])
-> future::Future<result::Result<(), TcpErrData>>
{
let socket_data_ptr = ptr::addr_of(&(*(sock.socket_data)));
let socket_data_ptr: *TcpSocketData = &*sock.socket_data;
do future_spawn {
let data_copy = copy(raw_write_data);
write_common_impl(socket_data_ptr, data_copy)
@ -366,9 +365,10 @@ pub fn write_future(sock: &TcpSocket, raw_write_data: ~[u8])
* `TcpErrData` record
*/
pub fn read_start(sock: &TcpSocket)
-> result::Result<@Port<
result::Result<~[u8], TcpErrData>>, TcpErrData> {
let socket_data = ptr::addr_of(&(*(sock.socket_data)));
-> result::Result<@Port<result::Result<~[u8],
TcpErrData>>,
TcpErrData> {
let socket_data: *TcpSocketData = &*sock.socket_data;
read_start_common_impl(socket_data)
}
@ -380,7 +380,7 @@ pub fn read_start(sock: &TcpSocket)
* * `sock` - a `net::tcp::TcpSocket` that you wish to stop reading on
*/
pub fn read_stop(sock: &TcpSocket) -> result::Result<(), TcpErrData> {
let socket_data = ptr::addr_of(&(*sock.socket_data));
let socket_data: *TcpSocketData = &*sock.socket_data;
read_stop_common_impl(socket_data)
}
@ -400,8 +400,8 @@ pub fn read_stop(sock: &TcpSocket) -> result::Result<(), TcpErrData> {
* read attempt. Pass `0u` to wait indefinitely
*/
pub fn read(sock: &TcpSocket, timeout_msecs: uint)
-> result::Result<~[u8],TcpErrData> {
let socket_data = ptr::addr_of(&(*(sock.socket_data)));
-> result::Result<~[u8],TcpErrData> {
let socket_data: *TcpSocketData = &*sock.socket_data;
read_common_impl(socket_data, timeout_msecs)
}
@ -435,8 +435,8 @@ pub fn read(sock: &TcpSocket, timeout_msecs: uint)
* read attempt. Pass `0u` to wait indefinitely
*/
fn read_future(sock: &TcpSocket, timeout_msecs: uint)
-> future::Future<result::Result<~[u8],TcpErrData>> {
let socket_data = ptr::addr_of(&(*(sock.socket_data)));
-> future::Future<result::Result<~[u8],TcpErrData>> {
let socket_data: *TcpSocketData = &*sock.socket_data;
do future_spawn {
read_common_impl(socket_data, timeout_msecs)
}
@ -534,8 +534,8 @@ pub fn accept(new_conn: TcpNewConnection)
ipv6: (*server_data_ptr).ipv6,
iotask : iotask.clone()
};
let client_socket_data_ptr = ptr::addr_of(
&(*client_socket_data));
let client_socket_data_ptr: *TcpSocketData =
&*client_socket_data;
let client_stream_handle_ptr =
(*client_socket_data_ptr).stream_handle_ptr;
@ -661,7 +661,7 @@ fn listen_common(host_ip: ip::IpAddr,
let (kill_po, kill_ch) = stream::<Option<TcpErrData>>();
let kill_ch = SharedChan::new(kill_ch);
let server_stream = uv::ll::tcp_t();
let server_stream_ptr = ptr::addr_of(&server_stream);
let server_stream_ptr: *uv::ll::uv_tcp_t = &server_stream;
let server_data: TcpListenFcData = TcpListenFcData {
server_stream_ptr: server_stream_ptr,
stream_closed_ch: stream_closed_ch,
@ -674,7 +674,7 @@ fn listen_common(host_ip: ip::IpAddr,
},
mut active: true
};
let server_data_ptr = ptr::addr_of(&server_data);
let server_data_ptr: *TcpListenFcData = &server_data;
let (setup_po, setup_ch) = stream();
@ -699,16 +699,14 @@ fn listen_common(host_ip: ip::IpAddr,
let in_addr = uv::ll::ip4_addr(
addr_str,
port as int);
uv::ll::tcp_bind(server_stream_ptr,
ptr::addr_of(&in_addr))
uv::ll::tcp_bind(server_stream_ptr, &in_addr)
}
ip::Ipv6(ref addr) => {
debug!("addr: %?", addr);
let in_addr = uv::ll::ip6_addr(
addr_str,
port as int);
uv::ll::tcp_bind6(server_stream_ptr,
ptr::addr_of(&in_addr))
uv::ll::tcp_bind6(server_stream_ptr, &in_addr)
}
};
match bind_result {
@ -856,12 +854,12 @@ pub impl TcpSocket {
if self.socket_data.ipv6 {
let addr = uv::ll::ip6_addr("", 0);
uv::ll::tcp_getpeername6(self.socket_data.stream_handle_ptr,
ptr::addr_of(&addr));
&addr);
ip::Ipv6(addr)
} else {
let addr = uv::ll::ip4_addr("", 0);
uv::ll::tcp_getpeername(self.socket_data.stream_handle_ptr,
ptr::addr_of(&addr));
&addr);
ip::Ipv4(addr)
}
}
@ -973,13 +971,12 @@ impl io::Reader for TcpSocketBuf {
impl io::Writer for TcpSocketBuf {
pub fn write(&self, data: &const [u8]) {
unsafe {
let socket_data_ptr =
ptr::addr_of(&(*((*(self.data)).sock).socket_data));
let socket_data_ptr: *TcpSocketData =
&(*((*(self.data)).sock).socket_data);
let w_result = write_common_impl(socket_data_ptr,
vec::slice(data,
0,
vec::len(data)
).to_vec());
vec::slice(data,
0,
data.len()).to_vec());
if w_result.is_err() {
let err_data = w_result.get_err();
debug!(
@ -1012,7 +1009,7 @@ fn tear_down_socket_data(socket_data: @TcpSocketData) {
let close_data = TcpSocketCloseData {
closed_ch: closed_ch
};
let close_data_ptr = ptr::addr_of(&close_data);
let close_data_ptr: *TcpSocketCloseData = &close_data;
let stream_handle_ptr = (*socket_data).stream_handle_ptr;
do iotask::interact(&(*socket_data).iotask) |loop_ptr| {
unsafe {
@ -1150,19 +1147,21 @@ fn write_common_impl(socket_data_ptr: *TcpSocketData,
raw_write_data: ~[u8])
-> result::Result<(), TcpErrData> {
unsafe {
let write_req_ptr = ptr::addr_of(&((*socket_data_ptr).write_req));
let write_req_ptr: *uv::ll::uv_write_t =
&(*socket_data_ptr).write_req;
let stream_handle_ptr =
(*socket_data_ptr).stream_handle_ptr;
let write_buf_vec = ~[ uv::ll::buf_init(
vec::raw::to_ptr(raw_write_data),
vec::len(raw_write_data)) ];
let write_buf_vec_ptr = ptr::addr_of(&write_buf_vec);
let write_buf_vec = ~[
uv::ll::buf_init(vec::raw::to_ptr(raw_write_data),
raw_write_data.len())
];
let write_buf_vec_ptr: *~[uv::ll::uv_buf_t] = &write_buf_vec;
let (result_po, result_ch) = stream::<TcpWriteResult>();
let result_ch = SharedChan::new(result_ch);
let write_data = WriteReqData {
result_ch: result_ch
};
let write_data_ptr = ptr::addr_of(&write_data);
let write_data_ptr: *WriteReqData = &write_data;
do iotask::interact(&(*socket_data_ptr).iotask) |loop_ptr| {
unsafe {
debug!("in interact cb for tcp::write %?",

View file

@ -151,7 +151,7 @@ pub impl <T:Ord> PriorityQueue<T> {
priv fn siftup(&mut self, start: uint, mut pos: uint) {
unsafe {
let new = *addr_of(&self.data[pos]);
let new = *ptr::to_unsafe_ptr(&self.data[pos]);
while pos > start {
let parent = (pos - 1) >> 1;
@ -171,7 +171,7 @@ pub impl <T:Ord> PriorityQueue<T> {
priv fn siftdown_range(&mut self, mut pos: uint, end: uint) {
unsafe {
let start = pos;
let new = *addr_of(&self.data[pos]);
let new = *ptr::to_unsafe_ptr(&self.data[pos]);
let mut child = 2 * pos + 1;
while child < end {

View file

@ -828,7 +828,7 @@ mod tests {
let m = ~Mutex();
let m2 = m.clone();
let mut sharedstate = ~0;
let ptr = ptr::addr_of(&(*sharedstate));
let ptr: *int = &*sharedstate;
do task::spawn || {
let sharedstate: &mut int =
unsafe { cast::transmute(ptr) };
@ -1106,7 +1106,7 @@ mod tests {
let (p,c) = comm::stream();
let x2 = (*x).clone();
let mut sharedstate = ~0;
let ptr = ptr::addr_of(&(*sharedstate));
let ptr: *int = &*sharedstate;
do task::spawn || {
let sharedstate: &mut int =
unsafe { cast::transmute(ptr) };

View file

@ -42,7 +42,7 @@ pub fn delayed_send<T:Owned>(iotask: &IoTask,
let (timer_done_po, timer_done_ch) = stream::<()>();
let timer_done_ch = SharedChan::new(timer_done_ch);
let timer = uv::ll::timer_t();
let timer_ptr = ptr::addr_of(&timer);
let timer_ptr: *uv::ll::uv_timer_t = &timer;
do iotask::interact(iotask) |loop_ptr| {
unsafe {
let init_result = uv::ll::timer_init(loop_ptr, timer_ptr);

View file

@ -162,7 +162,7 @@ mod test {
debug!("EXIT_CH_PTR newly created exit_ch_ptr: %?",
exit_ch_ptr);
let timer_handle = ll::timer_t();
let timer_ptr = ptr::addr_of(&timer_handle);
let timer_ptr: *ll::uv_timer_t = &timer_handle;
do iotask::interact(iotask) |loop_ptr| {
unsafe {
debug!(~"user code inside interact loop!!!");

View file

@ -17,10 +17,9 @@
use ll = uv_ll;
use core::comm::{stream, Port, Chan, SharedChan};
use core::libc::c_void;
use core::libc;
use core::comm::{stream, Port, Chan, SharedChan};
use core::ptr::addr_of;
/// Used to abstract-away direct interaction with a libuv loop.
pub struct IoTask {
@ -106,7 +105,7 @@ fn run_loop(iotask_ch: &Chan<IoTask>) {
// set up the special async handle we'll use to allow multi-task
// communication with this loop
let async = ll::async_t();
let async_handle = addr_of(&async);
let async_handle: *ll::uv_async_t = &async;
// associate the async handle with the loop
ll::async_init(loop_ptr, async_handle, wake_up_cb);
@ -118,11 +117,11 @@ fn run_loop(iotask_ch: &Chan<IoTask>) {
async_handle: async_handle,
msg_po: msg_po
};
ll::set_data_for_uv_handle(async_handle, addr_of(&data));
ll::set_data_for_uv_handle(async_handle, &data);
// Send out a handle through which folks can talk to us
// while we dwell in the I/O loop
let iotask = IoTask{
let iotask = IoTask {
async_handle: async_handle,
op_chan: SharedChan::new(msg_ch)
};
@ -223,7 +222,7 @@ struct AhData {
#[cfg(test)]
fn impl_uv_iotask_async(iotask: &IoTask) {
let async_handle = ll::async_t();
let ah_ptr = ptr::addr_of(&async_handle);
let ah_ptr: *ll::uv_async_t = &async_handle;
let (exit_po, exit_ch) = stream::<()>();
let ah_data = AhData {
iotask: iotask.clone(),

View file

@ -1021,19 +1021,17 @@ pub unsafe fn async_send(async_handle: *uv_async_t) {
}
pub unsafe fn buf_init(input: *u8, len: uint) -> uv_buf_t {
let out_buf = uv_buf_t { base: ptr::null(), len: 0 as libc::size_t };
let out_buf_ptr = ptr::addr_of(&out_buf);
let out_buf_ptr: *uv_buf_t = &out_buf;
rustrt::rust_uv_buf_init(out_buf_ptr, input, len as size_t);
return out_buf;
}
pub unsafe fn ip4_addr(ip: &str, port: int)
-> sockaddr_in {
pub unsafe fn ip4_addr(ip: &str, port: int) -> sockaddr_in {
do str::as_c_str(ip) |ip_buf| {
rustrt::rust_uv_ip4_addr(ip_buf as *u8,
port as libc::c_int)
}
}
pub unsafe fn ip6_addr(ip: &str, port: int)
-> sockaddr_in6 {
pub unsafe fn ip6_addr(ip: &str, port: int) -> sockaddr_in6 {
do str::as_c_str(ip) |ip_buf| {
rustrt::rust_uv_ip6_addr(ip_buf as *u8,
port as libc::c_int)
@ -1183,7 +1181,7 @@ pub unsafe fn free_base_of_buf(buf: uv_buf_t) {
pub unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> ~str {
let err = last_error(uv_loop);
let err_ptr = ptr::addr_of(&err);
let err_ptr: *uv_err_t = &err;
let err_name = str::raw::from_c_str(err_name(err_ptr));
let err_msg = str::raw::from_c_str(strerror(err_ptr));
return fmt!("LIBUV ERROR: name: %s msg: %s",
@ -1192,7 +1190,7 @@ pub unsafe fn get_last_err_info(uv_loop: *libc::c_void) -> ~str {
pub unsafe fn get_last_err_data(uv_loop: *libc::c_void) -> uv_err_data {
let err = last_error(uv_loop);
let err_ptr = ptr::addr_of(&err);
let err_ptr: *uv_err_t = &err;
let err_name = str::raw::from_c_str(err_name(err_ptr));
let err_msg = str::raw::from_c_str(strerror(err_ptr));
uv_err_data { err_name: err_name, err_msg: err_msg }
@ -1347,9 +1345,9 @@ mod test {
unsafe {
let test_loop = loop_new();
let tcp_handle = tcp_t();
let tcp_handle_ptr = ptr::addr_of(&tcp_handle);
let tcp_handle_ptr: *uv_tcp_t = &tcp_handle;
let connect_handle = connect_t();
let connect_req_ptr = ptr::addr_of(&connect_handle);
let connect_req_ptr: *uv_connect_t = &connect_handle;
// this is the persistent payload of data that we
// need to pass around to get this example to work.
@ -1365,43 +1363,42 @@ mod test {
// this is the enclosing record, we'll pass a ptr to
// this to C..
let write_handle = write_t();
let write_handle_ptr = ptr::addr_of(&write_handle);
let write_handle_ptr: *uv_write_t = &write_handle;
debug!("tcp req: tcp stream: %d write_handle: %d",
tcp_handle_ptr as int,
write_handle_ptr as int);
let client_data = request_wrapper {
write_req: write_handle_ptr,
req_buf: ptr::addr_of(&req_msg),
req_buf: &req_msg,
read_chan: client_chan
};
let tcp_init_result = tcp_init(
test_loop as *libc::c_void, tcp_handle_ptr);
if (tcp_init_result == 0i32) {
let tcp_init_result = tcp_init(test_loop as *libc::c_void,
tcp_handle_ptr);
if (tcp_init_result == 0) {
debug!(~"sucessful tcp_init_result");
debug!(~"building addr...");
let addr = ip4_addr(ip, port);
// FIXME ref #2064
let addr_ptr = ptr::addr_of(&addr);
let addr_ptr: *sockaddr_in = &addr;
debug!("after build addr in rust. port: %u",
addr.sin_port as uint);
addr.sin_port as uint);
// this should set up the connection request..
debug!("b4 call tcp_connect connect cb: %u ",
on_connect_cb as uint);
let tcp_connect_result = tcp_connect(
connect_req_ptr, tcp_handle_ptr,
addr_ptr, on_connect_cb);
if (tcp_connect_result == 0i32) {
on_connect_cb as uint);
let tcp_connect_result = tcp_connect(connect_req_ptr,
tcp_handle_ptr,
addr_ptr,
on_connect_cb);
if (tcp_connect_result == 0) {
// not set the data on the connect_req
// until its initialized
set_data_for_req(
connect_req_ptr as *libc::c_void,
ptr::addr_of(&client_data) as *libc::c_void);
set_data_for_uv_handle(
tcp_handle_ptr as *libc::c_void,
ptr::addr_of(&client_data) as *libc::c_void);
set_data_for_req(connect_req_ptr as *libc::c_void,
transmute(&client_data));
set_data_for_uv_handle(tcp_handle_ptr as *libc::c_void,
transmute(&client_data));
debug!(~"before run tcp req loop");
run(test_loop);
debug!(~"after run tcp req loop");
@ -1607,37 +1604,37 @@ mod test {
unsafe {
let test_loop = loop_new();
let tcp_server = tcp_t();
let tcp_server_ptr = ptr::addr_of(&tcp_server);
let tcp_server_ptr: *uv_tcp_t = &tcp_server;
let tcp_client = tcp_t();
let tcp_client_ptr = ptr::addr_of(&tcp_client);
let tcp_client_ptr: *uv_tcp_t = &tcp_client;
let server_write_req = write_t();
let server_write_req_ptr = ptr::addr_of(&server_write_req);
let server_write_req_ptr: *uv_write_t = &server_write_req;
let resp_str_bytes = str::to_bytes(server_resp_msg);
let resp_msg_ptr: *u8 = vec::raw::to_ptr(resp_str_bytes);
debug!("resp_msg ptr: %u", resp_msg_ptr as uint);
let resp_msg = ~[
buf_init(resp_msg_ptr, vec::len(resp_str_bytes))
buf_init(resp_msg_ptr, resp_str_bytes.len())
];
let continue_async_handle = async_t();
let continue_async_handle_ptr =
ptr::addr_of(&continue_async_handle);
let continue_async_handle_ptr: *uv_async_t =
&continue_async_handle;
let async_data =
async_handle_data { continue_chan: continue_chan };
let async_data_ptr = ptr::addr_of(&async_data);
let async_data_ptr: *async_handle_data = &async_data;
let server_data = tcp_server_data {
client: tcp_client_ptr,
server: tcp_server_ptr,
server_kill_msg: kill_server_msg,
server_resp_buf: ptr::addr_of(&resp_msg),
server_resp_buf: &resp_msg,
server_chan: server_chan,
server_write_req: server_write_req_ptr
};
let server_data_ptr = ptr::addr_of(&server_data);
let server_data_ptr: *tcp_server_data = &server_data;
set_data_for_uv_handle(tcp_server_ptr as *libc::c_void,
server_data_ptr as *libc::c_void);
@ -1647,11 +1644,10 @@ mod test {
if (tcp_init_result == 0i32) {
let server_addr = ip4_addr(server_ip, server_port);
// FIXME ref #2064
let server_addr_ptr = ptr::addr_of(&server_addr);
let server_addr_ptr: *sockaddr_in = &server_addr;
// uv_tcp_bind()
let bind_result = tcp_bind(tcp_server_ptr,
server_addr_ptr);
let bind_result = tcp_bind(tcp_server_ptr, server_addr_ptr);
if (bind_result == 0i32) {
debug!(~"successful uv_tcp_bind, listening");

View file

@ -75,10 +75,10 @@ impl gen_send for message {
body += ~"let b = pipe.reuse_buffer();\n";
body += fmt!("let %s = ::core::pipes::SendPacketBuffered(\
::ptr::addr_of(&(b.buffer.data.%s)));\n",
&(b.buffer.data.%s));\n",
sp, next.name);
body += fmt!("let %s = ::core::pipes::RecvPacketBuffered(\
::ptr::addr_of(&(b.buffer.data.%s)));\n",
&(b.buffer.data.%s));\n",
rp, next.name);
}
else {
@ -365,9 +365,7 @@ impl gen_init for protocol {
|s| ext_cx.parse_stmt(
fmt!("data.%s.set_buffer(buffer)",
s.name))),
ext_cx.parse_expr(
fmt!("::ptr::addr_of(&(data.%s))",
self.states[0].name))));
ext_cx.parse_expr(fmt!("&(data.%s)", self.states[0].name))));
quote_expr!({
let buffer = $buffer;

View file

@ -27,7 +27,7 @@ use core::io::WriterUtil;
use core::comm::{Port, Chan, SharedChan};
macro_rules! move_out (
{ $x:expr } => { unsafe { let y = *ptr::addr_of(&($x)); y } }
{ $x:expr } => { unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } }
)
enum request {

View file

@ -23,7 +23,7 @@ use core::io::WriterUtil;
use core::comm::{Port, PortSet, Chan, stream};
macro_rules! move_out (
{ $x:expr } => { unsafe { let y = *ptr::addr_of(&($x)); y } }
{ $x:expr } => { unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } }
)
enum request {

View file

@ -30,7 +30,7 @@ proto! ring (
)
macro_rules! move_out (
($x:expr) => { unsafe { let y = *ptr::addr_of(&$x); y } }
($x:expr) => { unsafe { let y = *ptr::to_unsafe_ptr(&$x); y } }
)
fn thread_ring(i: uint,

View file

@ -44,7 +44,7 @@ proto! pingpong_unbounded (
// This stuff should go in libcore::pipes
macro_rules! move_it (
{ $x:expr } => { let t = *ptr::addr_of(&($x)); t }
{ $x:expr } => { let t = *ptr::to_unsafe_ptr(&($x)); t }
)
macro_rules! follow (

View file

@ -11,6 +11,6 @@
enum bottom { }
fn main() {
let x = ptr::addr_of(&()) as *bottom;
let x = ptr::to_unsafe_ptr(&()) as *bottom;
match x { } //~ ERROR non-exhaustive patterns
}

View file

@ -9,7 +9,7 @@
// except according to those terms.
fn main() {
let x : *~[int] = ptr::addr_of(&~[1,2,3]);
let x : *~[int] = &~[1,2,3];
let y : *libc::c_void = x as *libc::c_void;
unsafe {
let _z = copy *y;

View file

@ -107,8 +107,8 @@ fn test_class() {
unsafe {
error!("q = %x, r = %x",
(::core::cast::reinterpret_cast::<*p, uint>(&ptr::addr_of(&q))),
(::core::cast::reinterpret_cast::<*p, uint>(&ptr::addr_of(&r))));
(::core::cast::reinterpret_cast::<*p, uint>(& &q)),
(::core::cast::reinterpret_cast::<*p, uint>(& &r)));
}
assert!((q == r));
r.y = 17;

View file

@ -14,7 +14,7 @@ fn borrow(x: &int, f: &fn(x: &int)) {
fn test1(x: @~int) {
do borrow(&*(*x).clone()) |p| {
let x_a = ptr::addr_of(&(**x));
let x_a = ptr::to_unsafe_ptr(&**x);
assert!((x_a as uint) != ptr::to_uint(p));
assert!(unsafe{*x_a} == *p);
}

View file

@ -17,13 +17,14 @@ pub fn main() {
match x {
@F {f: ref b_x} => {
assert!(**b_x == 3);
assert!(ptr::addr_of(&(*x.f)) == ptr::addr_of(&(**b_x)));
assert!(ptr::to_unsafe_ptr(&(*x.f)) == ptr::to_unsafe_ptr(&(**b_x)));
x = @F {f: ~4};
debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(**b_x)) as uint);
debug!("ptr::to_unsafe_ptr(*b_x) = %x",
ptr::to_unsafe_ptr(&(**b_x)) as uint);
assert!(**b_x == 3);
assert!(ptr::addr_of(&(*x.f)) != ptr::addr_of(&(**b_x)));
assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(**b_x)));
}
}
}

View file

@ -23,11 +23,12 @@ pub fn main() {
let mut x = @F {f: ~3};
do borrow(x.f) |b_x| {
assert!(*b_x == 3);
assert!(ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x)));
assert!(ptr::to_unsafe_ptr(&(*x.f)) == ptr::to_unsafe_ptr(&(*b_x)));
x = @F {f: ~4};
debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint);
debug!("ptr::to_unsafe_ptr(*b_x) = %x",
ptr::to_unsafe_ptr(&(*b_x)) as uint);
assert!(*b_x == 3);
assert!(ptr::addr_of(&(*x.f)) != ptr::addr_of(&(*b_x)));
assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x)));
}
}

View file

@ -17,13 +17,14 @@ pub fn main() {
match x {
@@F{f: ref b_x} => {
assert!(**b_x == 3);
assert!(ptr::addr_of(&(x.f)) == ptr::addr_of(b_x));
assert!(ptr::to_unsafe_ptr(&(x.f)) == ptr::to_unsafe_ptr(b_x));
*x = @F {f: ~4};
debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(**b_x)) as uint);
debug!("ptr::to_unsafe_ptr(*b_x) = %x",
ptr::to_unsafe_ptr(&(**b_x)) as uint);
assert!(**b_x == 3);
assert!(ptr::addr_of(&(*x.f)) != ptr::addr_of(&(**b_x)));
assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(**b_x)));
}
}
}

View file

@ -23,11 +23,12 @@ pub fn main() {
let mut x = ~@F{f: ~3};
do borrow(x.f) |b_x| {
assert!(*b_x == 3);
assert!(ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x)));
assert!(ptr::to_unsafe_ptr(&(*x.f)) == ptr::to_unsafe_ptr(&(*b_x)));
*x = @F{f: ~4};
debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint);
debug!("ptr::to_unsafe_ptr(*b_x) = %x",
ptr::to_unsafe_ptr(&(*b_x)) as uint);
assert!(*b_x == 3);
assert!(ptr::addr_of(&(*x.f)) != ptr::addr_of(&(*b_x)));
assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x)));
}
}

View file

@ -21,11 +21,12 @@ pub fn main() {
let mut x = @3;
do borrow(x) |b_x| {
assert!(*b_x == 3);
assert!(ptr::addr_of(&(*x)) == ptr::addr_of(&(*b_x)));
assert!(ptr::to_unsafe_ptr(&(*x)) == ptr::to_unsafe_ptr(&(*b_x)));
x = @22;
debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint);
debug!("ptr::to_unsafe_ptr(*b_x) = %x",
ptr::to_unsafe_ptr(&(*b_x)) as uint);
assert!(*b_x == 3);
assert!(ptr::addr_of(&(*x)) != ptr::addr_of(&(*b_x)));
assert!(ptr::to_unsafe_ptr(&(*x)) != ptr::to_unsafe_ptr(&(*b_x)));
}
}

View file

@ -23,11 +23,12 @@ pub fn main() {
let mut x = @F {f: ~3};
do borrow((*x).f) |b_x| {
assert!(*b_x == 3);
assert!(ptr::addr_of(&(*x.f)) == ptr::addr_of(&(*b_x)));
assert!(ptr::to_unsafe_ptr(&(*x.f)) == ptr::to_unsafe_ptr(&(*b_x)));
x = @F {f: ~4};
debug!("ptr::addr_of(*b_x) = %x", ptr::addr_of(&(*b_x)) as uint);
debug!("ptr::to_unsafe_ptr(*b_x) = %x",
ptr::to_unsafe_ptr(&(*b_x)) as uint);
assert!(*b_x == 3);
assert!(ptr::addr_of(&(*x.f)) != ptr::addr_of(&(*b_x)));
assert!(ptr::to_unsafe_ptr(&(*x.f)) != ptr::to_unsafe_ptr(&(*b_x)));
}
}

View file

@ -10,22 +10,22 @@
pub fn main() {
let x = ~1;
let y = ptr::addr_of(&(*x)) as uint;
let lam_move: @fn() -> uint = || ptr::addr_of(&(*x)) as uint;
let y = ptr::to_unsafe_ptr(&(*x)) as uint;
let lam_move: @fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint;
assert!(lam_move() == y);
let x = ~2;
let y = ptr::addr_of(&(*x)) as uint;
let lam_move: @fn() -> uint = || ptr::addr_of(&(*x)) as uint;
let y = ptr::to_unsafe_ptr(&(*x)) as uint;
let lam_move: @fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint;
assert!(lam_move() == y);
let x = ~3;
let y = ptr::addr_of(&(*x)) as uint;
let snd_move: ~fn() -> uint = || ptr::addr_of(&(*x)) as uint;
let y = ptr::to_unsafe_ptr(&(*x)) as uint;
let snd_move: ~fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint;
assert!(snd_move() == y);
let x = ~4;
let y = ptr::addr_of(&(*x)) as uint;
let lam_move: ~fn() -> uint = || ptr::addr_of(&(*x)) as uint;
let y = ptr::to_unsafe_ptr(&(*x)) as uint;
let lam_move: ~fn() -> uint = || ptr::to_unsafe_ptr(&(*x)) as uint;
assert!(lam_move() == y);
}

View file

@ -14,5 +14,5 @@ static x: &'static Big = &([13, 14, 10, 13, 11, 14, 14, 15]);
static y: &'static Pair<'static> = &Pair {a: 15, b: x};
pub fn main() {
assert!(ptr::addr_of(x) == ptr::addr_of(y.b));
assert!(ptr::to_unsafe_ptr(x) == ptr::to_unsafe_ptr(y.b));
}

View file

@ -9,12 +9,12 @@
// except according to those terms.
fn addr_of<T>(ptr: &T) -> uint {
let ptr = ptr::addr_of(ptr);
let ptr = ptr::to_unsafe_ptr(ptr);
unsafe { ptr as uint }
}
fn is_aligned<T>(ptr: &T) -> bool {
(addr_of(ptr) % sys::min_align_of::<T>()) == 0
(to_unsafe_ptr(ptr) % sys::min_align_of::<T>()) == 0
}
pub fn main() {

View file

@ -232,7 +232,7 @@ pub mod pingpong {
pub fn liberate_ping(+p: ping) -> ::pipes::send_packet<pong> {
unsafe {
let addr : *::pipes::send_packet<pong> = match &p {
&ping(ref x) => { cast::transmute(ptr::addr_of(x)) }
&ping(ref x) => { cast::transmute(x) }
};
let liberated_value = *addr;
cast::forget(p);
@ -243,7 +243,7 @@ pub mod pingpong {
pub fn liberate_pong(+p: pong) -> ::pipes::send_packet<ping> {
unsafe {
let addr : *::pipes::send_packet<ping> = match &p {
&pong(ref x) => { cast::transmute(ptr::addr_of(x)) }
&pong(ref x) => { cast::transmute(x) }
};
let liberated_value = *addr;
cast::forget(p);

View file

@ -45,7 +45,7 @@ proto! bank (
)
macro_rules! move_it (
{ $x:expr } => { unsafe { let y = *ptr::addr_of(&($x)); y } }
{ $x:expr } => { unsafe { let y = *ptr::to_unsafe_ptr(&($x)); y } }
)
fn switch<T:Owned,U>(+endp: pipes::RecvPacket<T>,

View file

@ -40,7 +40,7 @@ mod pingpong {
do pipes::entangle_buffer(buffer) |buffer, data| {
data.ping.set_buffer(buffer);
data.pong.set_buffer(buffer);
ptr::addr_of(&(data.ping))
ptr::to_unsafe_ptr(&(data.ping))
}
}
pub struct ping(server::pong);
@ -53,8 +53,8 @@ mod pingpong {
pub fn ping(+pipe: ping) -> pong {
{
let b = pipe.reuse_buffer();
let s = SendPacketBuffered(ptr::addr_of(&(b.buffer.data.pong)));
let c = RecvPacketBuffered(ptr::addr_of(&(b.buffer.data.pong)));
let s = SendPacketBuffered(&b.buffer.data.pong);
let c = RecvPacketBuffered(&b.buffer.data.pong);
let message = ::pingpong::ping(s);
send(pipe, message);
c
@ -75,8 +75,8 @@ mod pingpong {
pub fn pong(+pipe: pong) -> ping {
{
let b = pipe.reuse_buffer();
let s = SendPacketBuffered(ptr::addr_of(&(b.buffer.data.ping)));
let c = RecvPacketBuffered(ptr::addr_of(&(b.buffer.data.ping)));
let s = SendPacketBuffered(&b.buffer.data.ping);
let c = RecvPacketBuffered(&b.buffer.data.ping);
let message = ::pingpong::pong(s);
send(pipe, message);
c

View file

@ -642,7 +642,7 @@ struct Triple { x: int, y: int, z: int }
pub fn main() {
unsafe {
let r = (1,2,3,true,false, Triple {x:5,y:4,z:3}, (12,));
let p = ptr::addr_of(&r) as *c_void;
let p = ptr::to_unsafe_ptr(&r) as *c_void;
let u = my_visitor(@mut Stuff {ptr1: p,
ptr2: p,
vals: ~[]});

View file

@ -18,8 +18,8 @@ impl Drop for r {
fn finalize(&self) {
unsafe {
debug!("r's dtor: self = %x, self.v = %x, self.v's value = %x",
cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(self)),
cast::reinterpret_cast::<**int, uint>(&ptr::addr_of(&(self.v))),
cast::reinterpret_cast::<*r, uint>(&self),
cast::reinterpret_cast::<**int, uint>(& &(self.v)),
cast::reinterpret_cast::<*int, uint>(&self.v));
let v2: ~int = cast::reinterpret_cast(&self.v);
}
@ -54,28 +54,26 @@ pub fn main() {
next: None,
r: {
let rs = r(i1p);
debug!("r = %x",
cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&rs)));
debug!("r = %x", cast::reinterpret_cast::<*r, uint>(& &rs));
rs }
});
debug!("x1 = %x, x1.r = %x",
cast::reinterpret_cast::<@mut t, uint>(&x1),
cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&(x1.r))));
cast::reinterpret_cast::<*r, uint>(& &(x1.r)));
let mut x2 = @mut t(Node{
next: None,
r: {
let rs = r(i2p);
debug!("r2 = %x",
cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&rs)));
debug!("r2 = %x", cast::reinterpret_cast::<*r, uint>(& &rs));
rs
}
});
debug!("x2 = %x, x2.r = %x",
cast::reinterpret_cast::<@mut t, uint>(&x2),
cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(&(x2.r))));
cast::reinterpret_cast::<*r, uint>(& &(x2.r)));
x1.next = Some(x2);
x2.next = Some(x1);

View file

@ -48,7 +48,7 @@ pub fn main() {
ch.send(());
}
};
let fptr = cast::reinterpret_cast(&ptr::addr_of(&f));
let fptr = cast::reinterpret_cast(& &f);
rustrt::start_task(new_task_id, fptr);
cast::forget(f);
po.recv();

View file

@ -12,5 +12,5 @@
pub fn main() {
let foo = 1;
assert!(ptr::addr_of(&foo) == ptr::addr_of(&foo));
assert!(ptr::to_unsafe_ptr(&foo) == ptr::to_unsafe_ptr(&foo));
}

View file

@ -24,7 +24,7 @@ fn mk_rec() -> t_rec {
}
fn is_8_byte_aligned(&&u: a_tag<u64>) -> bool {
let p = ptr::addr_of(u) as uint;
let p = ptr::to_unsafe_ptr(u) as uint;
return (p & 7u) == 0u;
}

View file

@ -27,7 +27,7 @@ fn mk_rec<A:copy,B:copy>(a: A, b: B) -> t_rec<A,B> {
}
fn is_aligned<A>(amnt: uint, &&u: A) -> bool {
let p = ptr::addr_of(u) as uint;
let p = ptr::to_unsafe_ptr(u) as uint;
return (p & (amnt-1u)) == 0u;
}

View file

@ -24,7 +24,7 @@ fn mk_rec() -> t_rec {
}
fn is_8_byte_aligned(&&u: a_tag) -> bool {
let p = ptr::addr_of(u) as u64;
let p = ptr::to_unsafe_ptr(u) as u64;
return (p & 7u64) == 0u64;
}

View file

@ -26,7 +26,7 @@ impl Drop for notify {
unsafe {
error!("notify: task=%? v=%x unwinding=%b b=%b",
task::get_task(),
ptr::addr_of(&(*(self.v))) as uint,
ptr::to_unsafe_ptr(&(*(self.v))) as uint,
task::failing(),
*(self.v));
let b = *(self.v);
@ -47,7 +47,7 @@ fn joinable(f: ~fn()) -> Port<bool> {
let b = @mut false;
error!("wrapper: task=%? allocated v=%x",
task::get_task(),
ptr::addr_of(&(*b)) as uint);
ptr::to_unsafe_ptr(&(*b)) as uint);
let _r = notify(c, b);
f();
*b = true;

View file

@ -14,10 +14,10 @@ pub fn main() {
let (p, ch) = stream::<uint>();
let x = ~1;
let x_in_parent = ptr::addr_of(&(*x)) as uint;
let x_in_parent = ptr::to_unsafe_ptr(&(*x)) as uint;
task::spawn(|| {
let x_in_child = ptr::addr_of(&(*x)) as uint;
let x_in_child = ptr::to_unsafe_ptr(&(*x)) as uint;
ch.send(x_in_child);
});

View file

@ -19,7 +19,7 @@ struct Pointy {
}
fn make_uniq_closure<A:Owned + Copy>(a: A) -> ~fn() -> uint {
let result: ~fn() -> uint = || ptr::addr_of(&a) as uint;
let result: ~fn() -> uint = || ptr::to_unsafe_ptr(&a) as uint;
result
}