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:
parent
f1014c43fd
commit
3639d38d5c
|
@ -5,7 +5,7 @@
|
|||
#[forbid(deprecated_pattern)];
|
||||
|
||||
use cast::transmute;
|
||||
use ptr::addr_of;
|
||||
use ptr::p2::addr_of;
|
||||
|
||||
/// Code for dealing with @-vectors. This is pretty incomplete, and
|
||||
/// 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 {
|
||||
unsafe {
|
||||
let repr: **raw::VecRepr =
|
||||
::cast::reinterpret_cast(&addr_of(v));
|
||||
::cast::reinterpret_cast(&addr_of(&v));
|
||||
(**repr).unboxed.alloc / sys::size_of::<T>()
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ pub mod raw {
|
|||
*/
|
||||
#[inline(always)]
|
||||
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>();
|
||||
}
|
||||
|
||||
|
@ -182,7 +182,7 @@ pub mod raw {
|
|||
let repr: **VecRepr = ::cast::reinterpret_cast(&v);
|
||||
let fill = (**repr).unboxed.fill;
|
||||
(**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;
|
||||
rusti::move_val_init(*p, move initval);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ pub mod raw {
|
|||
|
||||
pub pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
|
||||
//! 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 {
|
||||
|
|
|
@ -38,8 +38,7 @@ will once again be the preferred module for intertask communication.
|
|||
|
||||
use either::Either;
|
||||
use libc::size_t;
|
||||
|
||||
|
||||
// After snapshot, change p2::addr_of => addr_of
|
||||
|
||||
/**
|
||||
* 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
|
||||
// messages
|
||||
let yield = 0;
|
||||
let yieldp = ptr::addr_of(yield);
|
||||
let yieldp = ptr::p2::addr_of(&yield);
|
||||
rustrt::rust_port_begin_detach(self.po, yieldp);
|
||||
if yield != 0 {
|
||||
// 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) {
|
||||
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);
|
||||
if res != 0 unsafe {
|
||||
// Data sent successfully
|
||||
|
@ -207,10 +206,10 @@ fn peek_chan<T: Send>(ch: comm::Chan<T>) -> bool {
|
|||
/// Receive on a raw port pointer
|
||||
fn recv_<T: Send>(p: *rust_port) -> T {
|
||||
let yield = 0;
|
||||
let yieldp = ptr::addr_of(yield);
|
||||
let yieldp = ptr::p2::addr_of(&yield);
|
||||
let mut res;
|
||||
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 {
|
||||
// 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>)
|
||||
-> Either<A, B> {
|
||||
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;
|
||||
resport = rusti::init::<*rust_port>();
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ Implicitly, all crates behave as if they included the following prologue:
|
|||
#[legacy_modes];
|
||||
#[legacy_exports];
|
||||
|
||||
#[warn(deprecated_mode)];
|
||||
#[warn(deprecated_pattern)];
|
||||
|
||||
#[warn(vecs_implicitly_copyable)];
|
||||
|
|
|
@ -316,7 +316,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::reinterpret_cast(&ptr::addr_of(sentinel_box))
|
||||
cast::reinterpret_cast(&ptr::p2::addr_of(&sentinel_box))
|
||||
} else {
|
||||
ptr::null()
|
||||
};
|
||||
|
|
|
@ -889,8 +889,8 @@ mod tests {
|
|||
#[test]
|
||||
fn test_readchars_empty() {
|
||||
do io::with_str_reader(~"") |inp| {
|
||||
let res : ~[char] = inp.read_chars(128u);
|
||||
assert(vec::len(res) == 0u);
|
||||
let res : ~[char] = inp.read_chars(128);
|
||||
assert(vec::len(res) == 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -903,7 +903,7 @@ mod tests {
|
|||
104, 101, 108, 108, 111,
|
||||
29983, 38152, 30340, 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| {
|
||||
let res : ~[char] = inp.read_chars(len);
|
||||
if (len <= vec::len(ivals)) {
|
||||
|
@ -913,13 +913,13 @@ mod tests {
|
|||
vec::map(res, |x| *x as int));
|
||||
}
|
||||
}
|
||||
let mut i = 0u;
|
||||
while i < 8u {
|
||||
let mut i = 0;
|
||||
while i < 8 {
|
||||
check_read_ln(i, wide_test, ivals);
|
||||
i += 1u;
|
||||
i += 1;
|
||||
}
|
||||
// check a long read for good measure
|
||||
check_read_ln(128u, wide_test, ivals);
|
||||
check_read_ln(128, wide_test, ivals);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -19,13 +19,13 @@ impl<A> IMPL_T<A>: iter::ExtendedIter<A> {
|
|||
pure fn foldl<B>(+b0: B, blk: fn(&B, &A) -> B) -> B {
|
||||
iter::foldl(&self, move b0, blk)
|
||||
}
|
||||
pure fn position(f: fn(A) -> bool) -> Option<uint> {
|
||||
iter::position(self, f)
|
||||
pure fn position(f: fn(&A) -> bool) -> Option<uint> {
|
||||
iter::position(&self, f)
|
||||
}
|
||||
}
|
||||
|
||||
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) }
|
||||
}
|
||||
|
||||
|
@ -43,7 +43,7 @@ impl<A: Copy> IMPL_T<A>: iter::CopyableIter<A> {
|
|||
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> {
|
||||
|
|
|
@ -19,7 +19,7 @@ trait ExtendedIter<A> {
|
|||
pure fn all(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 position(f: fn(A) -> bool) -> Option<uint>;
|
||||
pure fn position(f: fn(&A) -> bool) -> Option<uint>;
|
||||
}
|
||||
|
||||
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 map_to_vec<B>(op: fn(+v: A) -> B) -> ~[B];
|
||||
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> {
|
||||
|
@ -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]))
|
||||
}
|
||||
|
||||
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| {
|
||||
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>
|
||||
{
|
||||
let mut i = 0;
|
||||
for self.each |a| {
|
||||
if f(*a) { return Some(i); }
|
||||
if f(a) { return Some(i); }
|
||||
i += 1;
|
||||
}
|
||||
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.
|
||||
|
||||
pure fn repeat(times: uint, blk: fn() -> bool) {
|
||||
let mut i = 0u;
|
||||
let mut i = 0;
|
||||
while i < times {
|
||||
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,
|
||||
p: fn(A) -> bool) -> Option<A> {
|
||||
pure fn find<A: Copy,IA:BaseIter<A>>(self: &IA,
|
||||
p: fn(+a: A) -> bool) -> Option<A> {
|
||||
for self.each |i| {
|
||||
if p(*i) { return Some(*i) }
|
||||
}
|
||||
|
|
|
@ -252,20 +252,20 @@ impl<T: Eq> Option<T> : Eq {
|
|||
#[test]
|
||||
fn test_unwrap_ptr() {
|
||||
let x = ~0;
|
||||
let addr_x = ptr::addr_of(*x);
|
||||
let addr_x = ptr::p2::addr_of(&(*x));
|
||||
let opt = Some(x);
|
||||
let y = unwrap(opt);
|
||||
let addr_y = ptr::addr_of(*y);
|
||||
let addr_y = ptr::p2::addr_of(&(*y));
|
||||
assert addr_x == addr_y;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_unwrap_str() {
|
||||
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 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -303,7 +303,7 @@ pub fn waitpid(pid: pid_t) -> c_int {
|
|||
use libc::funcs::posix01::wait::*;
|
||||
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));
|
||||
return status;
|
||||
}
|
||||
|
@ -313,7 +313,7 @@ pub fn waitpid(pid: pid_t) -> c_int {
|
|||
pub fn pipe() -> {in: c_int, out: c_int} {
|
||||
let fds = {mut in: 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};
|
||||
}
|
||||
|
||||
|
@ -384,7 +384,7 @@ pub fn self_exe_path() -> Option<Path> {
|
|||
#[cfg(target_os = "macos")]
|
||||
fn load_self() -> Option<~str> {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -219,7 +219,7 @@ fn unibuffer<T: Send>() -> ~Buffer<Packet<T>> {
|
|||
#[doc(hidden)]
|
||||
pub fn packet<T: Send>() -> *Packet<T> {
|
||||
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.
|
||||
unsafe { forget(move b) }
|
||||
p
|
||||
|
@ -359,7 +359,7 @@ pub fn send<T: Send, Tbuffer: Send>(+p: SendPacketBuffered<T, Tbuffer>,
|
|||
let header = p.header();
|
||||
let p_ = p.unwrap();
|
||||
let p = unsafe { &*p_ };
|
||||
assert ptr::addr_of(p.header) == header;
|
||||
assert ptr::p2::addr_of(&(p.header)) == header;
|
||||
assert p.payload.is_none();
|
||||
p.payload <- Some(move payload);
|
||||
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());
|
||||
if !old_task.is_null() {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -529,7 +529,7 @@ fn sender_terminate<T: Send>(p: *Packet<T>) {
|
|||
if !old_task.is_null() {
|
||||
rustrt::task_signal_event(
|
||||
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);
|
||||
}
|
||||
// The receiver will eventually clean up.
|
||||
|
@ -744,7 +744,7 @@ pub fn SendPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
|
|||
p: Some(p),
|
||||
buffer: unsafe {
|
||||
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 {
|
||||
Some(packet) => unsafe {
|
||||
let packet = &*packet;
|
||||
let header = ptr::addr_of(packet.header);
|
||||
let header = ptr::p2::addr_of(&(packet.header));
|
||||
//forget(packet);
|
||||
header
|
||||
},
|
||||
|
@ -815,7 +815,7 @@ impl<T: Send, Tbuffer: Send> RecvPacketBuffered<T, Tbuffer> : Selectable {
|
|||
match self.p {
|
||||
Some(packet) => unsafe {
|
||||
let packet = &*packet;
|
||||
let header = ptr::addr_of(packet.header);
|
||||
let header = ptr::p2::addr_of(&(packet.header));
|
||||
//forget(packet);
|
||||
header
|
||||
},
|
||||
|
@ -838,7 +838,7 @@ pub fn RecvPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
|
|||
p: Some(p),
|
||||
buffer: unsafe {
|
||||
Some(BufferResource(
|
||||
get_buffer(ptr::addr_of((*p).header))))
|
||||
get_buffer(ptr::p2::addr_of(&((*p).header)))))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,8 +108,8 @@ pub fn test_from_global_chan1() {
|
|||
// This is unreadable, right?
|
||||
|
||||
// The global channel
|
||||
let globchan = 0u;
|
||||
let globchanp = ptr::addr_of(globchan);
|
||||
let globchan = 0;
|
||||
let globchanp = ptr::p2::addr_of(&globchan);
|
||||
|
||||
// Create the global channel, attached to a new task
|
||||
let ch = unsafe {
|
||||
|
@ -142,23 +142,23 @@ pub fn test_from_global_chan1() {
|
|||
#[test]
|
||||
pub fn test_from_global_chan2() {
|
||||
|
||||
for iter::repeat(100u) {
|
||||
for iter::repeat(100) {
|
||||
// The global channel
|
||||
let globchan = 0u;
|
||||
let globchanp = ptr::addr_of(globchan);
|
||||
let globchan = 0;
|
||||
let globchanp = ptr::p2::addr_of(&globchan);
|
||||
|
||||
let resultpo = comm::Port();
|
||||
let resultch = comm::Chan(resultpo);
|
||||
|
||||
// Spawn a bunch of tasks that all want to compete to
|
||||
// create the global channel
|
||||
for uint::range(0u, 10u) |i| {
|
||||
for uint::range(0, 10) |i| {
|
||||
do task::spawn {
|
||||
let ch = unsafe {
|
||||
do chan_from_global_ptr(
|
||||
globchanp, task::task) |po| {
|
||||
|
||||
for uint::range(0u, 10u) |_j| {
|
||||
for uint::range(0, 10) |_j| {
|
||||
let ch = comm::recv(po);
|
||||
comm::send(ch, {i});
|
||||
}
|
||||
|
|
|
@ -24,15 +24,24 @@ extern mod rusti {
|
|||
fn addr_of<T>(val: T) -> *T;
|
||||
}
|
||||
|
||||
/*
|
||||
Remove this after snapshot; make p2::addr_of addr_of
|
||||
*/
|
||||
/// Get an unsafe pointer to a value
|
||||
#[inline(always)]
|
||||
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
|
||||
#[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 {
|
||||
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`.
|
||||
#[inline(always)]
|
||||
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`.
|
||||
#[inline(always)]
|
||||
pub unsafe fn position<T>(buf: *T, f: fn(T) -> bool) -> uint {
|
||||
let mut i = 0u;
|
||||
pub unsafe fn position<T>(buf: *T, f: fn(&T) -> bool) -> uint {
|
||||
let mut i = 0;
|
||||
loop {
|
||||
if f(*offset(buf, i)) { return i; }
|
||||
else { i += 1u; }
|
||||
if f(&(*offset(buf, i))) { return i; }
|
||||
else { i += 1; }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -234,7 +243,7 @@ pub fn test() {
|
|||
unsafe {
|
||||
type Pair = {mut fst: int, mut snd: int};
|
||||
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);
|
||||
assert (*iptr == 10);;
|
||||
*iptr = 30;
|
||||
|
@ -268,9 +277,9 @@ pub fn test_position() {
|
|||
|
||||
let s = ~"hello";
|
||||
unsafe {
|
||||
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 5u == as_c_str(s, |p| position(p, |c| c == 0 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 5u == as_c_str(s, |p| position(p, |c| *c == 0 as c_char));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1780,7 +1780,7 @@ pub pure fn as_c_str<T>(s: &str, f: fn(*libc::c_char) -> T) -> T {
|
|||
#[inline(always)]
|
||||
pub pure fn as_buf<T>(s: &str, f: fn(*u8, uint) -> T) -> T {
|
||||
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;
|
||||
f(buf, len)
|
||||
}
|
||||
|
@ -2012,7 +2012,7 @@ pub mod raw {
|
|||
let v: **vec::raw::VecRepr = cast::transmute(copy v);
|
||||
let repr: *vec::raw::VecRepr = *v;
|
||||
(*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);
|
||||
*null = 0u8;
|
||||
}
|
||||
|
|
|
@ -1175,10 +1175,10 @@ fn avoid_copying_the_body(spawnfn: fn(+v: fn~())) {
|
|||
let ch = comm::Chan(p);
|
||||
|
||||
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 {
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -68,7 +68,7 @@ unsafe fn local_data_lookup<T: Owned>(
|
|||
|
||||
let key_value = key_to_key_value(key);
|
||||
let map_pos = (*map).position(|entry|
|
||||
match entry {
|
||||
match *entry {
|
||||
Some((k,_,_)) => k == key_value,
|
||||
None => false
|
||||
}
|
||||
|
|
|
@ -66,7 +66,7 @@ use rt::rust_task;
|
|||
use rt::rust_closure;
|
||||
|
||||
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,()>;
|
||||
|
@ -511,7 +511,14 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) {
|
|||
|
||||
let child_wrapper = make_child_wrapper(new_task, move child_tg,
|
||||
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);
|
||||
|
||||
// Getting killed between these two calls would free the child's
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
use cmp::{Eq, Ord};
|
||||
use option::{Some, None};
|
||||
use ptr::addr_of;
|
||||
use ptr::p2::addr_of;
|
||||
use libc::size_t;
|
||||
|
||||
export append;
|
||||
|
@ -582,7 +582,7 @@ unsafe fn push_fast<T>(+v: &mut ~[T], +initval: T) {
|
|||
let repr: **raw::VecRepr = ::cast::transmute(v);
|
||||
let fill = (**repr).unboxed.fill;
|
||||
(**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;
|
||||
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 {
|
||||
let v : *(*T,uint) =
|
||||
::cast::reinterpret_cast(&ptr::addr_of(s));
|
||||
::cast::reinterpret_cast(&addr_of(&s));
|
||||
let (buf,len) = *v;
|
||||
f(buf, len / sys::size_of::<T>())
|
||||
}
|
||||
|
@ -1352,7 +1352,7 @@ pure fn as_const_buf<T,U>(s: &[const T],
|
|||
|
||||
unsafe {
|
||||
let v : *(*const T,uint) =
|
||||
::cast::reinterpret_cast(&ptr::addr_of(s));
|
||||
::cast::reinterpret_cast(&addr_of(&s));
|
||||
let (buf,len) = *v;
|
||||
f(buf, len / sys::size_of::<T>())
|
||||
}
|
||||
|
@ -1365,7 +1365,7 @@ pure fn as_mut_buf<T,U>(s: &[mut T],
|
|||
|
||||
unsafe {
|
||||
let v : *(*mut T,uint) =
|
||||
::cast::reinterpret_cast(&ptr::addr_of(s));
|
||||
::cast::reinterpret_cast(&addr_of(&s));
|
||||
let (buf,len) = *v;
|
||||
f(buf, len / sys::size_of::<T>())
|
||||
}
|
||||
|
@ -1816,21 +1816,21 @@ mod raw {
|
|||
#[inline(always)]
|
||||
unsafe fn to_ptr<T>(+v: &[T]) -> *T {
|
||||
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()` */
|
||||
#[inline(always)]
|
||||
unsafe fn to_const_ptr<T>(+v: &[const T]) -> *const T {
|
||||
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()` */
|
||||
#[inline(always)]
|
||||
unsafe fn to_mut_ptr<T>(+v: &[mut T]) -> *mut T {
|
||||
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 {
|
||||
let pair = (p, len * sys::size_of::<T>());
|
||||
let v : *(&blk/[T]) =
|
||||
::cast::reinterpret_cast(&ptr::addr_of(pair));
|
||||
::cast::reinterpret_cast(&addr_of(&pair));
|
||||
f(*v)
|
||||
}
|
||||
|
||||
|
@ -1996,13 +1996,13 @@ impl<A> &[A]: iter::ExtendedIter<A> {
|
|||
pure fn foldl<B>(+b0: B, blk: fn(&B, &A) -> B) -> B {
|
||||
iter::foldl(&self, move b0, blk)
|
||||
}
|
||||
pure fn position(f: fn(A) -> bool) -> Option<uint> {
|
||||
iter::position(self, f)
|
||||
pure fn position(f: fn(&A) -> bool) -> Option<uint> {
|
||||
iter::position(&self, f)
|
||||
}
|
||||
}
|
||||
|
||||
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) }
|
||||
}
|
||||
|
||||
|
@ -2020,7 +2020,7 @@ impl<A: Copy> &[A]: iter::CopyableIter<A> {
|
|||
// 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> {
|
||||
|
|
|
@ -71,10 +71,10 @@ impl message: gen_send {
|
|||
|
||||
body += ~"let b = pipe.reuse_buffer();\n";
|
||||
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);
|
||||
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);
|
||||
}
|
||||
else {
|
||||
|
@ -351,7 +351,7 @@ impl protocol: gen_init {
|
|||
fmt!("data.%s.set_buffer_(buffer)",
|
||||
s.name))),
|
||||
ext_cx.parse_expr(
|
||||
fmt!("ptr::addr_of(data.%s)",
|
||||
fmt!("ptr::p2::addr_of(&(data.%s))",
|
||||
self.states[0].name))));
|
||||
|
||||
#ast {{
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
enum bottom { }
|
||||
|
||||
fn main() {
|
||||
let x = ptr::addr_of(()) as *bottom;
|
||||
let x = ptr::p2::addr_of(&()) as *bottom;
|
||||
match x { } //~ ERROR non-exhaustive patterns
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ fn main() {
|
|||
|
||||
unsafe {
|
||||
let a = 0;
|
||||
let v = ptr::mut_addr_of(a);
|
||||
let v = ptr::mut_addr_of(&a);
|
||||
f(v);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ extern mod std;
|
|||
|
||||
fn main() {
|
||||
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]) {
|
||||
unsafe {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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;
|
||||
unsafe {
|
||||
let _z = *y;
|
||||
|
|
Loading…
Reference in New Issue