1
Fork 0

Add a demoded version of ptr::addr_of

Currently, the new version is ptr::p2::addr_of and the old one is
ptr::addr_of. This is kind of cheesy, but I need a snapshot before I
can ditch the old version, since the pipe compiler generates calls to
addr_of.

core is converted over to use the new version, std is not.
This commit is contained in:
Tim Chevalier 2012-09-28 21:51:14 -07:00
parent f1014c43fd
commit 3639d38d5c
23 changed files with 110 additions and 94 deletions

View file

@ -5,7 +5,7 @@
#[forbid(deprecated_pattern)]; #[forbid(deprecated_pattern)];
use cast::transmute; use cast::transmute;
use ptr::addr_of; use ptr::p2::addr_of;
/// Code for dealing with @-vectors. This is pretty incomplete, and /// Code for dealing with @-vectors. This is pretty incomplete, and
/// contains a bunch of duplication from the code for ~-vectors. /// contains a bunch of duplication from the code for ~-vectors.
@ -29,7 +29,7 @@ extern mod rusti {
pub pure fn capacity<T>(v: @[const T]) -> uint { pub pure fn capacity<T>(v: @[const T]) -> uint {
unsafe { unsafe {
let repr: **raw::VecRepr = let repr: **raw::VecRepr =
::cast::reinterpret_cast(&addr_of(v)); ::cast::reinterpret_cast(&addr_of(&v));
(**repr).unboxed.alloc / sys::size_of::<T>() (**repr).unboxed.alloc / sys::size_of::<T>()
} }
} }
@ -161,7 +161,7 @@ pub mod raw {
*/ */
#[inline(always)] #[inline(always)]
pub unsafe fn set_len<T>(v: @[const T], new_len: uint) { pub unsafe fn set_len<T>(v: @[const T], new_len: uint) {
let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v)); let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(&v));
(**repr).unboxed.fill = new_len * sys::size_of::<T>(); (**repr).unboxed.fill = new_len * sys::size_of::<T>();
} }
@ -182,7 +182,7 @@ pub mod raw {
let repr: **VecRepr = ::cast::reinterpret_cast(&v); let repr: **VecRepr = ::cast::reinterpret_cast(&v);
let fill = (**repr).unboxed.fill; let fill = (**repr).unboxed.fill;
(**repr).unboxed.fill += sys::size_of::<T>(); (**repr).unboxed.fill += sys::size_of::<T>();
let p = ptr::addr_of((**repr).unboxed.data); let p = addr_of(&((**repr).unboxed.data));
let p = ptr::offset(p, fill) as *mut T; let p = ptr::offset(p, fill) as *mut T;
rusti::move_val_init(*p, move initval); rusti::move_val_init(*p, move initval);
} }

View file

@ -24,7 +24,7 @@ pub mod raw {
pub pure fn ptr_eq<T>(a: @T, b: @T) -> bool { pub pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
//! Determine if two shared boxes point to the same object //! Determine if two shared boxes point to the same object
unsafe { ptr::addr_of(*a) == ptr::addr_of(*b) } unsafe { ptr::p2::addr_of(&(*a)) == ptr::p2::addr_of(&(*b)) }
} }
impl<T:Eq> @const T : Eq { impl<T:Eq> @const T : Eq {

View file

@ -38,8 +38,7 @@ will once again be the preferred module for intertask communication.
use either::Either; use either::Either;
use libc::size_t; use libc::size_t;
// After snapshot, change p2::addr_of => addr_of
/** /**
* A communication endpoint that can receive messages * A communication endpoint that can receive messages
@ -104,7 +103,7 @@ struct PortPtr<T:Send> {
// Once the port is detached it's guaranteed not to receive further // Once the port is detached it's guaranteed not to receive further
// messages // messages
let yield = 0; let yield = 0;
let yieldp = ptr::addr_of(yield); let yieldp = ptr::p2::addr_of(&yield);
rustrt::rust_port_begin_detach(self.po, yieldp); rustrt::rust_port_begin_detach(self.po, yieldp);
if yield != 0 { if yield != 0 {
// Need to wait for the port to be detached // Need to wait for the port to be detached
@ -177,7 +176,7 @@ pub fn Chan<T: Send>(p: Port<T>) -> Chan<T> {
*/ */
pub fn send<T: Send>(ch: Chan<T>, +data: T) { pub fn send<T: Send>(ch: Chan<T>, +data: T) {
let Chan_(p) = ch; let Chan_(p) = ch;
let data_ptr = ptr::addr_of(data) as *(); let data_ptr = ptr::p2::addr_of(&data) as *();
let res = rustrt::rust_port_id_send(p, data_ptr); let res = rustrt::rust_port_id_send(p, data_ptr);
if res != 0 unsafe { if res != 0 unsafe {
// Data sent successfully // Data sent successfully
@ -207,10 +206,10 @@ fn peek_chan<T: Send>(ch: comm::Chan<T>) -> bool {
/// Receive on a raw port pointer /// Receive on a raw port pointer
fn recv_<T: Send>(p: *rust_port) -> T { fn recv_<T: Send>(p: *rust_port) -> T {
let yield = 0; let yield = 0;
let yieldp = ptr::addr_of(yield); let yieldp = ptr::p2::addr_of(&yield);
let mut res; let mut res;
res = rusti::init::<T>(); res = rusti::init::<T>();
rustrt::port_recv(ptr::addr_of(res) as *uint, p, yieldp); rustrt::port_recv(ptr::p2::addr_of(&res) as *uint, p, yieldp);
if yield != 0 { if yield != 0 {
// Data isn't available yet, so res has not been initialized. // Data isn't available yet, so res has not been initialized.
@ -234,12 +233,12 @@ fn peek_(p: *rust_port) -> bool {
pub fn select2<A: Send, B: Send>(p_a: Port<A>, p_b: Port<B>) pub fn select2<A: Send, B: Send>(p_a: Port<A>, p_b: Port<B>)
-> Either<A, B> { -> Either<A, B> {
let ports = ~[(**p_a).po, (**p_b).po]; let ports = ~[(**p_a).po, (**p_b).po];
let yield = 0, yieldp = ptr::addr_of(yield); let yield = 0, yieldp = ptr::p2::addr_of(&yield);
let mut resport: *rust_port; let mut resport: *rust_port;
resport = rusti::init::<*rust_port>(); resport = rusti::init::<*rust_port>();
do vec::as_imm_buf(ports) |ports, n_ports| { do vec::as_imm_buf(ports) |ports, n_ports| {
rustrt::rust_port_select(ptr::addr_of(resport), ports, rustrt::rust_port_select(ptr::p2::addr_of(&resport), ports,
n_ports as size_t, yieldp); n_ports as size_t, yieldp);
} }

View file

@ -39,6 +39,7 @@ Implicitly, all crates behave as if they included the following prologue:
#[legacy_modes]; #[legacy_modes];
#[legacy_exports]; #[legacy_exports];
#[warn(deprecated_mode)];
#[warn(deprecated_pattern)]; #[warn(deprecated_pattern)];
#[warn(vecs_implicitly_copyable)]; #[warn(vecs_implicitly_copyable)];

View file

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

View file

@ -889,8 +889,8 @@ mod tests {
#[test] #[test]
fn test_readchars_empty() { fn test_readchars_empty() {
do io::with_str_reader(~"") |inp| { do io::with_str_reader(~"") |inp| {
let res : ~[char] = inp.read_chars(128u); let res : ~[char] = inp.read_chars(128);
assert(vec::len(res) == 0u); assert(vec::len(res) == 0);
} }
} }
@ -903,7 +903,7 @@ mod tests {
104, 101, 108, 108, 111, 104, 101, 108, 108, 111,
29983, 38152, 30340, 27748, 29983, 38152, 30340, 27748,
21273, 20999, 32905, 27748]; 21273, 20999, 32905, 27748];
fn check_read_ln(len : uint, s: ~str, ivals: ~[int]) { fn check_read_ln(len : uint, s: &str, ivals: &[int]) {
do io::with_str_reader(s) |inp| { do io::with_str_reader(s) |inp| {
let res : ~[char] = inp.read_chars(len); let res : ~[char] = inp.read_chars(len);
if (len <= vec::len(ivals)) { if (len <= vec::len(ivals)) {
@ -913,13 +913,13 @@ mod tests {
vec::map(res, |x| *x as int)); vec::map(res, |x| *x as int));
} }
} }
let mut i = 0u; let mut i = 0;
while i < 8u { while i < 8 {
check_read_ln(i, wide_test, ivals); check_read_ln(i, wide_test, ivals);
i += 1u; i += 1;
} }
// check a long read for good measure // check a long read for good measure
check_read_ln(128u, wide_test, ivals); check_read_ln(128, wide_test, ivals);
} }
#[test] #[test]

View file

@ -19,13 +19,13 @@ impl<A> IMPL_T<A>: iter::ExtendedIter<A> {
pure fn foldl<B>(+b0: B, blk: fn(&B, &A) -> B) -> B { pure fn foldl<B>(+b0: B, blk: fn(&B, &A) -> B) -> B {
iter::foldl(&self, move b0, blk) iter::foldl(&self, move b0, blk)
} }
pure fn position(f: fn(A) -> bool) -> Option<uint> { pure fn position(f: fn(&A) -> bool) -> Option<uint> {
iter::position(self, f) iter::position(&self, f)
} }
} }
impl<A: Eq> IMPL_T<A>: iter::EqIter<A> { impl<A: Eq> IMPL_T<A>: iter::EqIter<A> {
pure fn contains(x: &A) -> bool { iter::contains(self, x) } pure fn contains(x: &A) -> bool { iter::contains(&self, x) }
pure fn count(x: &A) -> uint { iter::count(&self, x) } pure fn count(x: &A) -> uint { iter::count(&self, x) }
} }
@ -43,7 +43,7 @@ impl<A: Copy> IMPL_T<A>: iter::CopyableIter<A> {
iter::flat_map_to_vec(&self, op) iter::flat_map_to_vec(&self, op)
} }
pure fn find(p: fn(A) -> bool) -> Option<A> { iter::find(self, p) } pure fn find(p: fn(+a: A) -> bool) -> Option<A> { iter::find(&self, p) }
} }
impl<A: Copy Ord> IMPL_T<A>: iter::CopyableOrderedIter<A> { impl<A: Copy Ord> IMPL_T<A>: iter::CopyableOrderedIter<A> {

View file

@ -19,7 +19,7 @@ trait ExtendedIter<A> {
pure fn all(blk: fn(&A) -> bool) -> bool; pure fn all(blk: fn(&A) -> bool) -> bool;
pure fn any(blk: fn(&A) -> bool) -> bool; pure fn any(blk: fn(&A) -> bool) -> bool;
pure fn foldl<B>(+b0: B, blk: fn(&B, &A) -> B) -> B; pure fn foldl<B>(+b0: B, blk: fn(&B, &A) -> B) -> B;
pure fn position(f: fn(A) -> bool) -> Option<uint>; pure fn position(f: fn(&A) -> bool) -> Option<uint>;
} }
trait EqIter<A:Eq> { trait EqIter<A:Eq> {
@ -38,7 +38,7 @@ trait CopyableIter<A:Copy> {
pure fn filter_to_vec(pred: fn(+a: A) -> bool) -> ~[A]; pure fn filter_to_vec(pred: fn(+a: A) -> bool) -> ~[A];
pure fn map_to_vec<B>(op: fn(+v: A) -> B) -> ~[B]; pure fn map_to_vec<B>(op: fn(+v: A) -> B) -> ~[B];
pure fn to_vec() -> ~[A]; pure fn to_vec() -> ~[A];
pure fn find(p: fn(A) -> bool) -> Option<A>; pure fn find(p: fn(+a: A) -> bool) -> Option<A>;
} }
trait CopyableOrderedIter<A:Copy Ord> { trait CopyableOrderedIter<A:Copy Ord> {
@ -131,7 +131,7 @@ pure fn to_vec<A:Copy,IA:BaseIter<A>>(self: &IA) -> ~[A] {
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy (*r), ~[*a])) foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy (*r), ~[*a]))
} }
pure fn contains<A:Eq,IA:BaseIter<A>>(self: IA, x: &A) -> bool { pure fn contains<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> bool {
for self.each |a| { for self.each |a| {
if *a == *x { return true; } if *a == *x { return true; }
} }
@ -148,12 +148,12 @@ pure fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
} }
} }
pure fn position<A,IA:BaseIter<A>>(self: IA, f: fn(A) -> bool) pure fn position<A,IA:BaseIter<A>>(self: &IA, f: fn(&A) -> bool)
-> Option<uint> -> Option<uint>
{ {
let mut i = 0; let mut i = 0;
for self.each |a| { for self.each |a| {
if f(*a) { return Some(i); } if f(a) { return Some(i); }
i += 1; i += 1;
} }
return None; return None;
@ -164,10 +164,10 @@ pure fn position<A,IA:BaseIter<A>>(self: IA, f: fn(A) -> bool)
// it would have to be implemented with foldr, which is too inefficient. // it would have to be implemented with foldr, which is too inefficient.
pure fn repeat(times: uint, blk: fn() -> bool) { pure fn repeat(times: uint, blk: fn() -> bool) {
let mut i = 0u; let mut i = 0;
while i < times { while i < times {
if !blk() { break } if !blk() { break }
i += 1u; i += 1;
} }
} }
@ -199,8 +199,8 @@ pure fn max<A:Copy Ord,IA:BaseIter<A>>(self: &IA) -> A {
} }
} }
pure fn find<A: Copy,IA:BaseIter<A>>(self: IA, pure fn find<A: Copy,IA:BaseIter<A>>(self: &IA,
p: fn(A) -> bool) -> Option<A> { p: fn(+a: A) -> bool) -> Option<A> {
for self.each |i| { for self.each |i| {
if p(*i) { return Some(*i) } if p(*i) { return Some(*i) }
} }

View file

@ -252,20 +252,20 @@ impl<T: Eq> Option<T> : Eq {
#[test] #[test]
fn test_unwrap_ptr() { fn test_unwrap_ptr() {
let x = ~0; let x = ~0;
let addr_x = ptr::addr_of(*x); let addr_x = ptr::p2::addr_of(&(*x));
let opt = Some(x); let opt = Some(x);
let y = unwrap(opt); let y = unwrap(opt);
let addr_y = ptr::addr_of(*y); let addr_y = ptr::p2::addr_of(&(*y));
assert addr_x == addr_y; assert addr_x == addr_y;
} }
#[test] #[test]
fn test_unwrap_str() { fn test_unwrap_str() {
let x = ~"test"; let x = ~"test";
let addr_x = str::as_buf(x, |buf, _len| ptr::addr_of(buf)); let addr_x = str::as_buf(x, |buf, _len| ptr::p2::addr_of(&buf));
let opt = Some(x); let opt = Some(x);
let y = unwrap(opt); let y = unwrap(opt);
let addr_y = str::as_buf(y, |buf, _len| ptr::addr_of(buf)); let addr_y = str::as_buf(y, |buf, _len| ptr::p2::addr_of(&buf));
assert addr_x == addr_y; assert addr_x == addr_y;
} }

View file

@ -303,7 +303,7 @@ pub fn waitpid(pid: pid_t) -> c_int {
use libc::funcs::posix01::wait::*; use libc::funcs::posix01::wait::*;
let status = 0 as c_int; let status = 0 as c_int;
assert (waitpid(pid, ptr::mut_addr_of(status), assert (waitpid(pid, ptr::mut_addr_of(&status),
0 as c_int) != (-1 as c_int)); 0 as c_int) != (-1 as c_int));
return status; return status;
} }
@ -313,7 +313,7 @@ pub fn waitpid(pid: pid_t) -> c_int {
pub fn pipe() -> {in: c_int, out: c_int} { pub fn pipe() -> {in: c_int, out: c_int} {
let fds = {mut in: 0 as c_int, let fds = {mut in: 0 as c_int,
mut out: 0 as c_int }; mut out: 0 as c_int };
assert (libc::pipe(ptr::mut_addr_of(fds.in)) == (0 as c_int)); assert (libc::pipe(ptr::mut_addr_of(&(fds.in))) == (0 as c_int));
return {in: fds.in, out: fds.out}; return {in: fds.in, out: fds.out};
} }
@ -384,7 +384,7 @@ pub fn self_exe_path() -> Option<Path> {
#[cfg(target_os = "macos")] #[cfg(target_os = "macos")]
fn load_self() -> Option<~str> { fn load_self() -> Option<~str> {
do fill_charp_buf() |buf, sz| { do fill_charp_buf() |buf, sz| {
libc::_NSGetExecutablePath(buf, ptr::mut_addr_of(sz as u32)) libc::_NSGetExecutablePath(buf, ptr::mut_addr_of(&(sz as u32)))
== (0 as c_int) == (0 as c_int)
} }
} }

View file

@ -219,7 +219,7 @@ fn unibuffer<T: Send>() -> ~Buffer<Packet<T>> {
#[doc(hidden)] #[doc(hidden)]
pub fn packet<T: Send>() -> *Packet<T> { pub fn packet<T: Send>() -> *Packet<T> {
let b = unibuffer(); let b = unibuffer();
let p = ptr::addr_of(b.data); let p = ptr::p2::addr_of(&(b.data));
// We'll take over memory management from here. // We'll take over memory management from here.
unsafe { forget(move b) } unsafe { forget(move b) }
p p
@ -359,7 +359,7 @@ pub fn send<T: Send, Tbuffer: Send>(+p: SendPacketBuffered<T, Tbuffer>,
let header = p.header(); let header = p.header();
let p_ = p.unwrap(); let p_ = p.unwrap();
let p = unsafe { &*p_ }; let p = unsafe { &*p_ };
assert ptr::addr_of(p.header) == header; assert ptr::p2::addr_of(&(p.header)) == header;
assert p.payload.is_none(); assert p.payload.is_none();
p.payload <- Some(move payload); p.payload <- Some(move payload);
let old_state = swap_state_rel(&mut p.header.state, Full); let old_state = swap_state_rel(&mut p.header.state, Full);
@ -377,7 +377,7 @@ pub fn send<T: Send, Tbuffer: Send>(+p: SendPacketBuffered<T, Tbuffer>,
let old_task = swap_task(&mut p.header.blocked_task, ptr::null()); let old_task = swap_task(&mut p.header.blocked_task, ptr::null());
if !old_task.is_null() { if !old_task.is_null() {
rustrt::task_signal_event( rustrt::task_signal_event(
old_task, ptr::addr_of(p.header) as *libc::c_void); old_task, ptr::p2::addr_of(&(p.header)) as *libc::c_void);
rustrt::rust_task_deref(old_task); rustrt::rust_task_deref(old_task);
} }
@ -529,7 +529,7 @@ fn sender_terminate<T: Send>(p: *Packet<T>) {
if !old_task.is_null() { if !old_task.is_null() {
rustrt::task_signal_event( rustrt::task_signal_event(
old_task, old_task,
ptr::addr_of(p.header) as *libc::c_void); ptr::p2::addr_of(&(p.header)) as *libc::c_void);
rustrt::rust_task_deref(old_task); rustrt::rust_task_deref(old_task);
} }
// The receiver will eventually clean up. // The receiver will eventually clean up.
@ -744,7 +744,7 @@ pub fn SendPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
p: Some(p), p: Some(p),
buffer: unsafe { buffer: unsafe {
Some(BufferResource( Some(BufferResource(
get_buffer(ptr::addr_of((*p).header)))) get_buffer(ptr::p2::addr_of(&((*p).header)))))
} }
} }
} }
@ -760,7 +760,7 @@ impl<T: Send, Tbuffer: Send> SendPacketBuffered<T, Tbuffer> {
match self.p { match self.p {
Some(packet) => unsafe { Some(packet) => unsafe {
let packet = &*packet; let packet = &*packet;
let header = ptr::addr_of(packet.header); let header = ptr::p2::addr_of(&(packet.header));
//forget(packet); //forget(packet);
header header
}, },
@ -815,7 +815,7 @@ impl<T: Send, Tbuffer: Send> RecvPacketBuffered<T, Tbuffer> : Selectable {
match self.p { match self.p {
Some(packet) => unsafe { Some(packet) => unsafe {
let packet = &*packet; let packet = &*packet;
let header = ptr::addr_of(packet.header); let header = ptr::p2::addr_of(&(packet.header));
//forget(packet); //forget(packet);
header header
}, },
@ -838,7 +838,7 @@ pub fn RecvPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
p: Some(p), p: Some(p),
buffer: unsafe { buffer: unsafe {
Some(BufferResource( Some(BufferResource(
get_buffer(ptr::addr_of((*p).header)))) get_buffer(ptr::p2::addr_of(&((*p).header)))))
} }
} }
} }

View file

@ -108,8 +108,8 @@ pub fn test_from_global_chan1() {
// This is unreadable, right? // This is unreadable, right?
// The global channel // The global channel
let globchan = 0u; let globchan = 0;
let globchanp = ptr::addr_of(globchan); let globchanp = ptr::p2::addr_of(&globchan);
// Create the global channel, attached to a new task // Create the global channel, attached to a new task
let ch = unsafe { let ch = unsafe {
@ -142,23 +142,23 @@ pub fn test_from_global_chan1() {
#[test] #[test]
pub fn test_from_global_chan2() { pub fn test_from_global_chan2() {
for iter::repeat(100u) { for iter::repeat(100) {
// The global channel // The global channel
let globchan = 0u; let globchan = 0;
let globchanp = ptr::addr_of(globchan); let globchanp = ptr::p2::addr_of(&globchan);
let resultpo = comm::Port(); let resultpo = comm::Port();
let resultch = comm::Chan(resultpo); let resultch = comm::Chan(resultpo);
// Spawn a bunch of tasks that all want to compete to // Spawn a bunch of tasks that all want to compete to
// create the global channel // create the global channel
for uint::range(0u, 10u) |i| { for uint::range(0, 10) |i| {
do task::spawn { do task::spawn {
let ch = unsafe { let ch = unsafe {
do chan_from_global_ptr( do chan_from_global_ptr(
globchanp, task::task) |po| { globchanp, task::task) |po| {
for uint::range(0u, 10u) |_j| { for uint::range(0, 10) |_j| {
let ch = comm::recv(po); let ch = comm::recv(po);
comm::send(ch, {i}); comm::send(ch, {i});
} }

View file

@ -24,15 +24,24 @@ extern mod rusti {
fn addr_of<T>(val: T) -> *T; fn addr_of<T>(val: T) -> *T;
} }
/*
Remove this after snapshot; make p2::addr_of addr_of
*/
/// Get an unsafe pointer to a value /// Get an unsafe pointer to a value
#[inline(always)] #[inline(always)]
pub pure fn addr_of<T>(val: T) -> *T { unsafe { rusti::addr_of(val) } } pub pure fn addr_of<T>(val: T) -> *T { unsafe { rusti::addr_of(val) } }
pub mod p2 {
/// Get an unsafe pointer to a value
#[inline(always)]
pub pure fn addr_of<T>(val: &T) -> *T { unsafe { rusti::addr_of(*val) } }
}
/// Get an unsafe mut pointer to a value /// Get an unsafe mut pointer to a value
#[inline(always)] #[inline(always)]
pub pure fn mut_addr_of<T>(val: T) -> *mut T { pub pure fn mut_addr_of<T>(val: &T) -> *mut T {
unsafe { unsafe {
cast::reinterpret_cast(&rusti::addr_of(val)) cast::reinterpret_cast(&rusti::addr_of(*val))
} }
} }
@ -61,16 +70,16 @@ pub fn mut_offset<T>(ptr: *mut T, count: uint) -> *mut T {
/// Return the offset of the first null pointer in `buf`. /// Return the offset of the first null pointer in `buf`.
#[inline(always)] #[inline(always)]
pub unsafe fn buf_len<T>(buf: **T) -> uint { pub unsafe fn buf_len<T>(buf: **T) -> uint {
position(buf, |i| i == null()) position(buf, |i| *i == null())
} }
/// Return the first offset `i` such that `f(buf[i]) == true`. /// Return the first offset `i` such that `f(buf[i]) == true`.
#[inline(always)] #[inline(always)]
pub unsafe fn position<T>(buf: *T, f: fn(T) -> bool) -> uint { pub unsafe fn position<T>(buf: *T, f: fn(&T) -> bool) -> uint {
let mut i = 0u; let mut i = 0;
loop { loop {
if f(*offset(buf, i)) { return i; } if f(&(*offset(buf, i))) { return i; }
else { i += 1u; } else { i += 1; }
} }
} }
@ -234,7 +243,7 @@ pub fn test() {
unsafe { unsafe {
type Pair = {mut fst: int, mut snd: int}; type Pair = {mut fst: int, mut snd: int};
let p = {mut fst: 10, mut snd: 20}; let p = {mut fst: 10, mut snd: 20};
let pptr: *mut Pair = mut_addr_of(p); let pptr: *mut Pair = mut_addr_of(&p);
let iptr: *mut int = cast::reinterpret_cast(&pptr); let iptr: *mut int = cast::reinterpret_cast(&pptr);
assert (*iptr == 10);; assert (*iptr == 10);;
*iptr = 30; *iptr = 30;
@ -268,9 +277,9 @@ pub fn test_position() {
let s = ~"hello"; let s = ~"hello";
unsafe { unsafe {
assert 2u == as_c_str(s, |p| position(p, |c| c == 'l' as c_char)); assert 2u == as_c_str(s, |p| position(p, |c| *c == 'l' as c_char));
assert 4u == as_c_str(s, |p| position(p, |c| c == 'o' as c_char)); assert 4u == as_c_str(s, |p| position(p, |c| *c == 'o' as c_char));
assert 5u == as_c_str(s, |p| position(p, |c| c == 0 as c_char)); assert 5u == as_c_str(s, |p| position(p, |c| *c == 0 as c_char));
} }
} }

View file

@ -1780,7 +1780,7 @@ pub pure fn as_c_str<T>(s: &str, f: fn(*libc::c_char) -> T) -> T {
#[inline(always)] #[inline(always)]
pub pure fn as_buf<T>(s: &str, f: fn(*u8, uint) -> T) -> T { pub pure fn as_buf<T>(s: &str, f: fn(*u8, uint) -> T) -> T {
unsafe { unsafe {
let v : *(*u8,uint) = ::cast::reinterpret_cast(&ptr::addr_of(s)); let v : *(*u8,uint) = ::cast::reinterpret_cast(&ptr::p2::addr_of(&s));
let (buf,len) = *v; let (buf,len) = *v;
f(buf, len) f(buf, len)
} }
@ -2012,7 +2012,7 @@ pub mod raw {
let v: **vec::raw::VecRepr = cast::transmute(copy v); let v: **vec::raw::VecRepr = cast::transmute(copy v);
let repr: *vec::raw::VecRepr = *v; let repr: *vec::raw::VecRepr = *v;
(*repr).unboxed.fill = new_len + 1u; (*repr).unboxed.fill = new_len + 1u;
let null = ptr::mut_offset(ptr::mut_addr_of((*repr).unboxed.data), let null = ptr::mut_offset(ptr::mut_addr_of(&((*repr).unboxed.data)),
new_len); new_len);
*null = 0u8; *null = 0u8;
} }

View file

@ -1175,10 +1175,10 @@ fn avoid_copying_the_body(spawnfn: fn(+v: fn~())) {
let ch = comm::Chan(p); let ch = comm::Chan(p);
let x = ~1; let x = ~1;
let x_in_parent = ptr::addr_of(*x) as uint; let x_in_parent = ptr::p2::addr_of(&(*x)) as uint;
do spawnfn { do spawnfn {
let x_in_child = ptr::addr_of(*x) as uint; let x_in_child = ptr::p2::addr_of(&(*x)) as uint;
comm::send(ch, x_in_child); comm::send(ch, x_in_child);
} }

View file

@ -68,7 +68,7 @@ unsafe fn local_data_lookup<T: Owned>(
let key_value = key_to_key_value(key); let key_value = key_to_key_value(key);
let map_pos = (*map).position(|entry| let map_pos = (*map).position(|entry|
match entry { match *entry {
Some((k,_,_)) => k == key_value, Some((k,_,_)) => k == key_value,
None => false None => false
} }

View file

@ -66,7 +66,7 @@ use rt::rust_task;
use rt::rust_closure; use rt::rust_closure;
macro_rules! move_it ( macro_rules! move_it (
{ $x:expr } => { unsafe { let y <- *ptr::addr_of($x); move y } } { $x:expr } => { unsafe { let y <- *ptr::p2::addr_of(&($x)); move y } }
) )
type TaskSet = send_map::linear::LinearMap<*rust_task,()>; type TaskSet = send_map::linear::LinearMap<*rust_task,()>;
@ -511,7 +511,14 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) {
let child_wrapper = make_child_wrapper(new_task, move child_tg, let child_wrapper = make_child_wrapper(new_task, move child_tg,
move ancestors, is_main, move notify_chan, move f); move ancestors, is_main, move notify_chan, move f);
let fptr = ptr::addr_of(child_wrapper); /*
Truly awful, but otherwise the borrow checker complains about
the move in the last line of this block, for reasons I can't
understand. -- tjc
*/
let tmp: u64 = cast::reinterpret_cast(&(&child_wrapper));
let whatever: &~fn() = cast::reinterpret_cast(&tmp);
let fptr = ptr::p2::addr_of(whatever);
let closure: *rust_closure = cast::reinterpret_cast(&fptr); let closure: *rust_closure = cast::reinterpret_cast(&fptr);
// Getting killed between these two calls would free the child's // Getting killed between these two calls would free the child's

View file

@ -6,7 +6,7 @@
use cmp::{Eq, Ord}; use cmp::{Eq, Ord};
use option::{Some, None}; use option::{Some, None};
use ptr::addr_of; use ptr::p2::addr_of;
use libc::size_t; use libc::size_t;
export append; export append;
@ -582,7 +582,7 @@ unsafe fn push_fast<T>(+v: &mut ~[T], +initval: T) {
let repr: **raw::VecRepr = ::cast::transmute(v); let repr: **raw::VecRepr = ::cast::transmute(v);
let fill = (**repr).unboxed.fill; let fill = (**repr).unboxed.fill;
(**repr).unboxed.fill += sys::size_of::<T>(); (**repr).unboxed.fill += sys::size_of::<T>();
let p = ptr::addr_of((**repr).unboxed.data); let p = addr_of(&((**repr).unboxed.data));
let p = ptr::offset(p, fill) as *mut T; let p = ptr::offset(p, fill) as *mut T;
rusti::move_val_init(*p, move initval); rusti::move_val_init(*p, move initval);
} }
@ -1339,7 +1339,7 @@ pure fn as_imm_buf<T,U>(s: &[T], /* NB---this CANNOT be const, see below */
unsafe { unsafe {
let v : *(*T,uint) = let v : *(*T,uint) =
::cast::reinterpret_cast(&ptr::addr_of(s)); ::cast::reinterpret_cast(&addr_of(&s));
let (buf,len) = *v; let (buf,len) = *v;
f(buf, len / sys::size_of::<T>()) f(buf, len / sys::size_of::<T>())
} }
@ -1352,7 +1352,7 @@ pure fn as_const_buf<T,U>(s: &[const T],
unsafe { unsafe {
let v : *(*const T,uint) = let v : *(*const T,uint) =
::cast::reinterpret_cast(&ptr::addr_of(s)); ::cast::reinterpret_cast(&addr_of(&s));
let (buf,len) = *v; let (buf,len) = *v;
f(buf, len / sys::size_of::<T>()) f(buf, len / sys::size_of::<T>())
} }
@ -1365,7 +1365,7 @@ pure fn as_mut_buf<T,U>(s: &[mut T],
unsafe { unsafe {
let v : *(*mut T,uint) = let v : *(*mut T,uint) =
::cast::reinterpret_cast(&ptr::addr_of(s)); ::cast::reinterpret_cast(&addr_of(&s));
let (buf,len) = *v; let (buf,len) = *v;
f(buf, len / sys::size_of::<T>()) f(buf, len / sys::size_of::<T>())
} }
@ -1816,21 +1816,21 @@ mod raw {
#[inline(always)] #[inline(always)]
unsafe fn to_ptr<T>(+v: &[T]) -> *T { unsafe fn to_ptr<T>(+v: &[T]) -> *T {
let repr: **SliceRepr = ::cast::transmute(&v); let repr: **SliceRepr = ::cast::transmute(&v);
return ::cast::reinterpret_cast(&addr_of((**repr).data)); return ::cast::reinterpret_cast(&addr_of(&((**repr).data)));
} }
/** see `to_ptr()` */ /** see `to_ptr()` */
#[inline(always)] #[inline(always)]
unsafe fn to_const_ptr<T>(+v: &[const T]) -> *const T { unsafe fn to_const_ptr<T>(+v: &[const T]) -> *const T {
let repr: **SliceRepr = ::cast::transmute(&v); let repr: **SliceRepr = ::cast::transmute(&v);
return ::cast::reinterpret_cast(&addr_of((**repr).data)); return ::cast::reinterpret_cast(&addr_of(&((**repr).data)));
} }
/** see `to_ptr()` */ /** see `to_ptr()` */
#[inline(always)] #[inline(always)]
unsafe fn to_mut_ptr<T>(+v: &[mut T]) -> *mut T { unsafe fn to_mut_ptr<T>(+v: &[mut T]) -> *mut T {
let repr: **SliceRepr = ::cast::transmute(&v); let repr: **SliceRepr = ::cast::transmute(&v);
return ::cast::reinterpret_cast(&addr_of((**repr).data)); return ::cast::reinterpret_cast(&addr_of(&((**repr).data)));
} }
/** /**
@ -1841,7 +1841,7 @@ mod raw {
unsafe fn form_slice<T,U>(p: *T, len: uint, f: fn(v: &[T]) -> U) -> U { unsafe fn form_slice<T,U>(p: *T, len: uint, f: fn(v: &[T]) -> U) -> U {
let pair = (p, len * sys::size_of::<T>()); let pair = (p, len * sys::size_of::<T>());
let v : *(&blk/[T]) = let v : *(&blk/[T]) =
::cast::reinterpret_cast(&ptr::addr_of(pair)); ::cast::reinterpret_cast(&addr_of(&pair));
f(*v) f(*v)
} }
@ -1996,13 +1996,13 @@ impl<A> &[A]: iter::ExtendedIter<A> {
pure fn foldl<B>(+b0: B, blk: fn(&B, &A) -> B) -> B { pure fn foldl<B>(+b0: B, blk: fn(&B, &A) -> B) -> B {
iter::foldl(&self, move b0, blk) iter::foldl(&self, move b0, blk)
} }
pure fn position(f: fn(A) -> bool) -> Option<uint> { pure fn position(f: fn(&A) -> bool) -> Option<uint> {
iter::position(self, f) iter::position(&self, f)
} }
} }
impl<A: Eq> &[A]: iter::EqIter<A> { impl<A: Eq> &[A]: iter::EqIter<A> {
pure fn contains(x: &A) -> bool { iter::contains(self, x) } pure fn contains(x: &A) -> bool { iter::contains(&self, x) }
pure fn count(x: &A) -> uint { iter::count(&self, x) } pure fn count(x: &A) -> uint { iter::count(&self, x) }
} }
@ -2020,7 +2020,7 @@ impl<A: Copy> &[A]: iter::CopyableIter<A> {
// iter::flat_map_to_vec(self, op) // iter::flat_map_to_vec(self, op)
// } // }
pure fn find(p: fn(A) -> bool) -> Option<A> { iter::find(self, p) } pure fn find(p: fn(+a: A) -> bool) -> Option<A> { iter::find(&self, p) }
} }
impl<A: Copy Ord> &[A]: iter::CopyableOrderedIter<A> { impl<A: Copy Ord> &[A]: iter::CopyableOrderedIter<A> {

View file

@ -71,10 +71,10 @@ impl message: gen_send {
body += ~"let b = pipe.reuse_buffer();\n"; body += ~"let b = pipe.reuse_buffer();\n";
body += fmt!("let %s = pipes::SendPacketBuffered(\ body += fmt!("let %s = pipes::SendPacketBuffered(\
ptr::addr_of(b.buffer.data.%s));\n", ptr::p2::addr_of(&(b.buffer.data.%s)));\n",
sp, next.name); sp, next.name);
body += fmt!("let %s = pipes::RecvPacketBuffered(\ body += fmt!("let %s = pipes::RecvPacketBuffered(\
ptr::addr_of(b.buffer.data.%s));\n", ptr::p2::addr_of(&(b.buffer.data.%s)));\n",
rp, next.name); rp, next.name);
} }
else { else {
@ -351,7 +351,7 @@ impl protocol: gen_init {
fmt!("data.%s.set_buffer_(buffer)", fmt!("data.%s.set_buffer_(buffer)",
s.name))), s.name))),
ext_cx.parse_expr( ext_cx.parse_expr(
fmt!("ptr::addr_of(data.%s)", fmt!("ptr::p2::addr_of(&(data.%s))",
self.states[0].name)))); self.states[0].name))));
#ast {{ #ast {{

View file

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

View file

@ -7,7 +7,7 @@ fn main() {
unsafe { unsafe {
let a = 0; let a = 0;
let v = ptr::mut_addr_of(a); let v = ptr::mut_addr_of(&a);
f(v); f(v);
} }
} }

View file

@ -4,7 +4,7 @@ extern mod std;
fn main() { fn main() {
let a = ~[0]; let a = ~[0];
let v: *mut ~[int] = ptr::mut_addr_of(a); let v: *mut ~[int] = ptr::mut_addr_of(&a);
fn f(&&v: *mut ~[const int]) { fn f(&&v: *mut ~[const int]) {
unsafe { unsafe {

View file

@ -1,5 +1,5 @@
fn main() { fn main() {
let x : *~[int] = ptr::addr_of(~[1,2,3]); let x : *~[int] = ptr::p2::addr_of(&~[1,2,3]);
let y : *libc::c_void = x as *libc::c_void; let y : *libc::c_void = x as *libc::c_void;
unsafe { unsafe {
let _z = *y; let _z = *y;