Skip to content

Commit 3639d38

Browse files
committed
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.
1 parent f1014c4 commit 3639d38

23 files changed

+110
-94
lines changed

src/libcore/at_vec.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#[forbid(deprecated_pattern)];
66

77
use cast::transmute;
8-
use ptr::addr_of;
8+
use ptr::p2::addr_of;
99

1010
/// Code for dealing with @-vectors. This is pretty incomplete, and
1111
/// contains a bunch of duplication from the code for ~-vectors.
@@ -29,7 +29,7 @@ extern mod rusti {
2929
pub pure fn capacity<T>(v: @[const T]) -> uint {
3030
unsafe {
3131
let repr: **raw::VecRepr =
32-
::cast::reinterpret_cast(&addr_of(v));
32+
::cast::reinterpret_cast(&addr_of(&v));
3333
(**repr).unboxed.alloc / sys::size_of::<T>()
3434
}
3535
}
@@ -161,7 +161,7 @@ pub mod raw {
161161
*/
162162
#[inline(always)]
163163
pub unsafe fn set_len<T>(v: @[const T], new_len: uint) {
164-
let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(v));
164+
let repr: **VecRepr = ::cast::reinterpret_cast(&addr_of(&v));
165165
(**repr).unboxed.fill = new_len * sys::size_of::<T>();
166166
}
167167

@@ -182,7 +182,7 @@ pub mod raw {
182182
let repr: **VecRepr = ::cast::reinterpret_cast(&v);
183183
let fill = (**repr).unboxed.fill;
184184
(**repr).unboxed.fill += sys::size_of::<T>();
185-
let p = ptr::addr_of((**repr).unboxed.data);
185+
let p = addr_of(&((**repr).unboxed.data));
186186
let p = ptr::offset(p, fill) as *mut T;
187187
rusti::move_val_init(*p, move initval);
188188
}

src/libcore/box.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub mod raw {
2424

2525
pub pure fn ptr_eq<T>(a: @T, b: @T) -> bool {
2626
//! Determine if two shared boxes point to the same object
27-
unsafe { ptr::addr_of(*a) == ptr::addr_of(*b) }
27+
unsafe { ptr::p2::addr_of(&(*a)) == ptr::p2::addr_of(&(*b)) }
2828
}
2929

3030
impl<T:Eq> @const T : Eq {

src/libcore/comm.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ will once again be the preferred module for intertask communication.
3838

3939
use either::Either;
4040
use libc::size_t;
41-
42-
41+
// After snapshot, change p2::addr_of => addr_of
4342

4443
/**
4544
* A communication endpoint that can receive messages
@@ -104,7 +103,7 @@ struct PortPtr<T:Send> {
104103
// Once the port is detached it's guaranteed not to receive further
105104
// messages
106105
let yield = 0;
107-
let yieldp = ptr::addr_of(yield);
106+
let yieldp = ptr::p2::addr_of(&yield);
108107
rustrt::rust_port_begin_detach(self.po, yieldp);
109108
if yield != 0 {
110109
// Need to wait for the port to be detached
@@ -177,7 +176,7 @@ pub fn Chan<T: Send>(p: Port<T>) -> Chan<T> {
177176
*/
178177
pub fn send<T: Send>(ch: Chan<T>, +data: T) {
179178
let Chan_(p) = ch;
180-
let data_ptr = ptr::addr_of(data) as *();
179+
let data_ptr = ptr::p2::addr_of(&data) as *();
181180
let res = rustrt::rust_port_id_send(p, data_ptr);
182181
if res != 0 unsafe {
183182
// Data sent successfully
@@ -207,10 +206,10 @@ fn peek_chan<T: Send>(ch: comm::Chan<T>) -> bool {
207206
/// Receive on a raw port pointer
208207
fn recv_<T: Send>(p: *rust_port) -> T {
209208
let yield = 0;
210-
let yieldp = ptr::addr_of(yield);
209+
let yieldp = ptr::p2::addr_of(&yield);
211210
let mut res;
212211
res = rusti::init::<T>();
213-
rustrt::port_recv(ptr::addr_of(res) as *uint, p, yieldp);
212+
rustrt::port_recv(ptr::p2::addr_of(&res) as *uint, p, yieldp);
214213

215214
if yield != 0 {
216215
// Data isn't available yet, so res has not been initialized.
@@ -234,12 +233,12 @@ fn peek_(p: *rust_port) -> bool {
234233
pub fn select2<A: Send, B: Send>(p_a: Port<A>, p_b: Port<B>)
235234
-> Either<A, B> {
236235
let ports = ~[(**p_a).po, (**p_b).po];
237-
let yield = 0, yieldp = ptr::addr_of(yield);
236+
let yield = 0, yieldp = ptr::p2::addr_of(&yield);
238237

239238
let mut resport: *rust_port;
240239
resport = rusti::init::<*rust_port>();
241240
do vec::as_imm_buf(ports) |ports, n_ports| {
242-
rustrt::rust_port_select(ptr::addr_of(resport), ports,
241+
rustrt::rust_port_select(ptr::p2::addr_of(&resport), ports,
243242
n_ports as size_t, yieldp);
244243
}
245244

src/libcore/core.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ Implicitly, all crates behave as if they included the following prologue:
3939
#[legacy_modes];
4040
#[legacy_exports];
4141

42+
#[warn(deprecated_mode)];
4243
#[warn(deprecated_pattern)];
4344

4445
#[warn(vecs_implicitly_copyable)];

src/libcore/gc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ pub fn cleanup_stack_for_failure() {
316316
// own stack roots on the stack anyway.
317317
let sentinel_box = ~0;
318318
let sentinel: **Word = if expect_sentinel() {
319-
cast::reinterpret_cast(&ptr::addr_of(sentinel_box))
319+
cast::reinterpret_cast(&ptr::p2::addr_of(&sentinel_box))
320320
} else {
321321
ptr::null()
322322
};

src/libcore/io.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -889,8 +889,8 @@ mod tests {
889889
#[test]
890890
fn test_readchars_empty() {
891891
do io::with_str_reader(~"") |inp| {
892-
let res : ~[char] = inp.read_chars(128u);
893-
assert(vec::len(res) == 0u);
892+
let res : ~[char] = inp.read_chars(128);
893+
assert(vec::len(res) == 0);
894894
}
895895
}
896896

@@ -903,7 +903,7 @@ mod tests {
903903
104, 101, 108, 108, 111,
904904
29983, 38152, 30340, 27748,
905905
21273, 20999, 32905, 27748];
906-
fn check_read_ln(len : uint, s: ~str, ivals: ~[int]) {
906+
fn check_read_ln(len : uint, s: &str, ivals: &[int]) {
907907
do io::with_str_reader(s) |inp| {
908908
let res : ~[char] = inp.read_chars(len);
909909
if (len <= vec::len(ivals)) {
@@ -913,13 +913,13 @@ mod tests {
913913
vec::map(res, |x| *x as int));
914914
}
915915
}
916-
let mut i = 0u;
917-
while i < 8u {
916+
let mut i = 0;
917+
while i < 8 {
918918
check_read_ln(i, wide_test, ivals);
919-
i += 1u;
919+
i += 1;
920920
}
921921
// check a long read for good measure
922-
check_read_ln(128u, wide_test, ivals);
922+
check_read_ln(128, wide_test, ivals);
923923
}
924924

925925
#[test]

src/libcore/iter-trait.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ impl<A> IMPL_T<A>: iter::ExtendedIter<A> {
1919
pure fn foldl<B>(+b0: B, blk: fn(&B, &A) -> B) -> B {
2020
iter::foldl(&self, move b0, blk)
2121
}
22-
pure fn position(f: fn(A) -> bool) -> Option<uint> {
23-
iter::position(self, f)
22+
pure fn position(f: fn(&A) -> bool) -> Option<uint> {
23+
iter::position(&self, f)
2424
}
2525
}
2626

2727
impl<A: Eq> IMPL_T<A>: iter::EqIter<A> {
28-
pure fn contains(x: &A) -> bool { iter::contains(self, x) }
28+
pure fn contains(x: &A) -> bool { iter::contains(&self, x) }
2929
pure fn count(x: &A) -> uint { iter::count(&self, x) }
3030
}
3131

@@ -43,7 +43,7 @@ impl<A: Copy> IMPL_T<A>: iter::CopyableIter<A> {
4343
iter::flat_map_to_vec(&self, op)
4444
}
4545

46-
pure fn find(p: fn(A) -> bool) -> Option<A> { iter::find(self, p) }
46+
pure fn find(p: fn(+a: A) -> bool) -> Option<A> { iter::find(&self, p) }
4747
}
4848

4949
impl<A: Copy Ord> IMPL_T<A>: iter::CopyableOrderedIter<A> {

src/libcore/iter.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ trait ExtendedIter<A> {
1919
pure fn all(blk: fn(&A) -> bool) -> bool;
2020
pure fn any(blk: fn(&A) -> bool) -> bool;
2121
pure fn foldl<B>(+b0: B, blk: fn(&B, &A) -> B) -> B;
22-
pure fn position(f: fn(A) -> bool) -> Option<uint>;
22+
pure fn position(f: fn(&A) -> bool) -> Option<uint>;
2323
}
2424

2525
trait EqIter<A:Eq> {
@@ -38,7 +38,7 @@ trait CopyableIter<A:Copy> {
3838
pure fn filter_to_vec(pred: fn(+a: A) -> bool) -> ~[A];
3939
pure fn map_to_vec<B>(op: fn(+v: A) -> B) -> ~[B];
4040
pure fn to_vec() -> ~[A];
41-
pure fn find(p: fn(A) -> bool) -> Option<A>;
41+
pure fn find(p: fn(+a: A) -> bool) -> Option<A>;
4242
}
4343

4444
trait CopyableOrderedIter<A:Copy Ord> {
@@ -131,7 +131,7 @@ pure fn to_vec<A:Copy,IA:BaseIter<A>>(self: &IA) -> ~[A] {
131131
foldl::<A,~[A],IA>(self, ~[], |r, a| vec::append(copy (*r), ~[*a]))
132132
}
133133

134-
pure fn contains<A:Eq,IA:BaseIter<A>>(self: IA, x: &A) -> bool {
134+
pure fn contains<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> bool {
135135
for self.each |a| {
136136
if *a == *x { return true; }
137137
}
@@ -148,12 +148,12 @@ pure fn count<A:Eq,IA:BaseIter<A>>(self: &IA, x: &A) -> uint {
148148
}
149149
}
150150

151-
pure fn position<A,IA:BaseIter<A>>(self: IA, f: fn(A) -> bool)
151+
pure fn position<A,IA:BaseIter<A>>(self: &IA, f: fn(&A) -> bool)
152152
-> Option<uint>
153153
{
154154
let mut i = 0;
155155
for self.each |a| {
156-
if f(*a) { return Some(i); }
156+
if f(a) { return Some(i); }
157157
i += 1;
158158
}
159159
return None;
@@ -164,10 +164,10 @@ pure fn position<A,IA:BaseIter<A>>(self: IA, f: fn(A) -> bool)
164164
// it would have to be implemented with foldr, which is too inefficient.
165165

166166
pure fn repeat(times: uint, blk: fn() -> bool) {
167-
let mut i = 0u;
167+
let mut i = 0;
168168
while i < times {
169169
if !blk() { break }
170-
i += 1u;
170+
i += 1;
171171
}
172172
}
173173

@@ -199,8 +199,8 @@ pure fn max<A:Copy Ord,IA:BaseIter<A>>(self: &IA) -> A {
199199
}
200200
}
201201

202-
pure fn find<A: Copy,IA:BaseIter<A>>(self: IA,
203-
p: fn(A) -> bool) -> Option<A> {
202+
pure fn find<A: Copy,IA:BaseIter<A>>(self: &IA,
203+
p: fn(+a: A) -> bool) -> Option<A> {
204204
for self.each |i| {
205205
if p(*i) { return Some(*i) }
206206
}

src/libcore/option.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,20 +252,20 @@ impl<T: Eq> Option<T> : Eq {
252252
#[test]
253253
fn test_unwrap_ptr() {
254254
let x = ~0;
255-
let addr_x = ptr::addr_of(*x);
255+
let addr_x = ptr::p2::addr_of(&(*x));
256256
let opt = Some(x);
257257
let y = unwrap(opt);
258-
let addr_y = ptr::addr_of(*y);
258+
let addr_y = ptr::p2::addr_of(&(*y));
259259
assert addr_x == addr_y;
260260
}
261261

262262
#[test]
263263
fn test_unwrap_str() {
264264
let x = ~"test";
265-
let addr_x = str::as_buf(x, |buf, _len| ptr::addr_of(buf));
265+
let addr_x = str::as_buf(x, |buf, _len| ptr::p2::addr_of(&buf));
266266
let opt = Some(x);
267267
let y = unwrap(opt);
268-
let addr_y = str::as_buf(y, |buf, _len| ptr::addr_of(buf));
268+
let addr_y = str::as_buf(y, |buf, _len| ptr::p2::addr_of(&buf));
269269
assert addr_x == addr_y;
270270
}
271271

src/libcore/os.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ pub fn waitpid(pid: pid_t) -> c_int {
303303
use libc::funcs::posix01::wait::*;
304304
let status = 0 as c_int;
305305

306-
assert (waitpid(pid, ptr::mut_addr_of(status),
306+
assert (waitpid(pid, ptr::mut_addr_of(&status),
307307
0 as c_int) != (-1 as c_int));
308308
return status;
309309
}
@@ -313,7 +313,7 @@ pub fn waitpid(pid: pid_t) -> c_int {
313313
pub fn pipe() -> {in: c_int, out: c_int} {
314314
let fds = {mut in: 0 as c_int,
315315
mut out: 0 as c_int };
316-
assert (libc::pipe(ptr::mut_addr_of(fds.in)) == (0 as c_int));
316+
assert (libc::pipe(ptr::mut_addr_of(&(fds.in))) == (0 as c_int));
317317
return {in: fds.in, out: fds.out};
318318
}
319319

@@ -384,7 +384,7 @@ pub fn self_exe_path() -> Option<Path> {
384384
#[cfg(target_os = "macos")]
385385
fn load_self() -> Option<~str> {
386386
do fill_charp_buf() |buf, sz| {
387-
libc::_NSGetExecutablePath(buf, ptr::mut_addr_of(sz as u32))
387+
libc::_NSGetExecutablePath(buf, ptr::mut_addr_of(&(sz as u32)))
388388
== (0 as c_int)
389389
}
390390
}

src/libcore/pipes.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ fn unibuffer<T: Send>() -> ~Buffer<Packet<T>> {
219219
#[doc(hidden)]
220220
pub fn packet<T: Send>() -> *Packet<T> {
221221
let b = unibuffer();
222-
let p = ptr::addr_of(b.data);
222+
let p = ptr::p2::addr_of(&(b.data));
223223
// We'll take over memory management from here.
224224
unsafe { forget(move b) }
225225
p
@@ -359,7 +359,7 @@ pub fn send<T: Send, Tbuffer: Send>(+p: SendPacketBuffered<T, Tbuffer>,
359359
let header = p.header();
360360
let p_ = p.unwrap();
361361
let p = unsafe { &*p_ };
362-
assert ptr::addr_of(p.header) == header;
362+
assert ptr::p2::addr_of(&(p.header)) == header;
363363
assert p.payload.is_none();
364364
p.payload <- Some(move payload);
365365
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>,
377377
let old_task = swap_task(&mut p.header.blocked_task, ptr::null());
378378
if !old_task.is_null() {
379379
rustrt::task_signal_event(
380-
old_task, ptr::addr_of(p.header) as *libc::c_void);
380+
old_task, ptr::p2::addr_of(&(p.header)) as *libc::c_void);
381381
rustrt::rust_task_deref(old_task);
382382
}
383383

@@ -529,7 +529,7 @@ fn sender_terminate<T: Send>(p: *Packet<T>) {
529529
if !old_task.is_null() {
530530
rustrt::task_signal_event(
531531
old_task,
532-
ptr::addr_of(p.header) as *libc::c_void);
532+
ptr::p2::addr_of(&(p.header)) as *libc::c_void);
533533
rustrt::rust_task_deref(old_task);
534534
}
535535
// The receiver will eventually clean up.
@@ -744,7 +744,7 @@ pub fn SendPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
744744
p: Some(p),
745745
buffer: unsafe {
746746
Some(BufferResource(
747-
get_buffer(ptr::addr_of((*p).header))))
747+
get_buffer(ptr::p2::addr_of(&((*p).header)))))
748748
}
749749
}
750750
}
@@ -760,7 +760,7 @@ impl<T: Send, Tbuffer: Send> SendPacketBuffered<T, Tbuffer> {
760760
match self.p {
761761
Some(packet) => unsafe {
762762
let packet = &*packet;
763-
let header = ptr::addr_of(packet.header);
763+
let header = ptr::p2::addr_of(&(packet.header));
764764
//forget(packet);
765765
header
766766
},
@@ -815,7 +815,7 @@ impl<T: Send, Tbuffer: Send> RecvPacketBuffered<T, Tbuffer> : Selectable {
815815
match self.p {
816816
Some(packet) => unsafe {
817817
let packet = &*packet;
818-
let header = ptr::addr_of(packet.header);
818+
let header = ptr::p2::addr_of(&(packet.header));
819819
//forget(packet);
820820
header
821821
},
@@ -838,7 +838,7 @@ pub fn RecvPacketBuffered<T: Send, Tbuffer: Send>(p: *Packet<T>)
838838
p: Some(p),
839839
buffer: unsafe {
840840
Some(BufferResource(
841-
get_buffer(ptr::addr_of((*p).header))))
841+
get_buffer(ptr::p2::addr_of(&((*p).header)))))
842842
}
843843
}
844844
}

0 commit comments

Comments
 (0)