Skip to content

Commit 5a9da65

Browse files
committed
auto merge of #4937 : luqmana/rust/remove-mut-addr-of, r=catamorphism
2 parents 20fd0c5 + 206757f commit 5a9da65

File tree

7 files changed

+18
-27
lines changed

7 files changed

+18
-27
lines changed

src/libcore/os.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -306,10 +306,9 @@ pub fn waitpid(pid: pid_t) -> c_int {
306306
pub fn waitpid(pid: pid_t) -> c_int {
307307
unsafe {
308308
use libc::funcs::posix01::wait::*;
309-
let status = 0 as c_int;
309+
let mut status = 0 as c_int;
310310

311-
assert (waitpid(pid, ptr::mut_addr_of(&status),
312-
0 as c_int) != (-1 as c_int));
311+
assert (waitpid(pid, &mut status, 0 as c_int) != (-1 as c_int));
313312
return status;
314313
}
315314
}
@@ -322,7 +321,7 @@ pub fn pipe() -> Pipe {
322321
unsafe {
323322
let mut fds = Pipe {mut in: 0 as c_int,
324323
mut out: 0 as c_int };
325-
assert (libc::pipe(ptr::mut_addr_of(&(fds.in))) == (0 as c_int));
324+
assert (libc::pipe(&mut fds.in) == (0 as c_int));
326325
return Pipe {in: fds.in, out: fds.out};
327326
}
328327
}
@@ -339,8 +338,7 @@ pub fn pipe() -> Pipe {
339338
// first, as in rust_run_program.
340339
let mut fds = Pipe { mut in: 0 as c_int,
341340
mut out: 0 as c_int };
342-
let res = libc::pipe(ptr::mut_addr_of(&(fds.in)),
343-
1024 as c_uint,
341+
let res = libc::pipe(&mut fds.in, 1024 as c_uint,
344342
(libc::O_BINARY | libc::O_NOINHERIT) as c_int);
345343
assert (res == 0 as c_int);
346344
assert (fds.in != -1 as c_int && fds.in != 0 as c_int);
@@ -374,8 +372,8 @@ pub fn self_exe_path() -> Option<Path> {
374372
KERN_PROC as c_int,
375373
KERN_PROC_PATHNAME as c_int, -1 as c_int];
376374
sysctl(vec::raw::to_ptr(mib), vec::len(mib) as c_uint,
377-
buf as *mut c_void, ptr::mut_addr_of(&sz),
378-
ptr::null(), 0u as size_t) == (0 as c_int)
375+
buf, &mut sz, ptr::null(),
376+
0u as size_t) == (0 as c_int)
379377
}
380378
}
381379
}
@@ -406,8 +404,9 @@ pub fn self_exe_path() -> Option<Path> {
406404
fn load_self() -> Option<~str> {
407405
unsafe {
408406
do fill_charp_buf() |buf, sz| {
407+
let mut sz = sz as u32;
409408
libc::funcs::extra::_NSGetExecutablePath(
410-
buf, ptr::mut_addr_of(&(sz as u32))) == (0 as c_int)
409+
buf, &mut sz) == (0 as c_int)
411410
}
412411
}
413412
}

src/libcore/path.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl Path {
243243
unsafe {
244244
do str::as_c_str(self.to_str()) |buf| {
245245
let mut st = stat::arch::default_stat();
246-
let r = libc::stat(buf, ptr::mut_addr_of(&st));
246+
let r = libc::stat(buf, &mut st);
247247

248248
if r == 0 { Some(move st) } else { None }
249249
}
@@ -255,7 +255,7 @@ impl Path {
255255
unsafe {
256256
do str::as_c_str(self.to_str()) |buf| {
257257
let mut st = stat::arch::default_stat();
258-
let r = libc::lstat(buf, ptr::mut_addr_of(&st));
258+
let r = libc::lstat(buf, &mut st);
259259

260260
if r == 0 { Some(move st) } else { None }
261261
}

src/libcore/ptr.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,6 @@ extern mod rusti {
4444
#[inline(always)]
4545
pub pure fn addr_of<T>(val: &T) -> *T { unsafe { rusti::addr_of(*val) } }
4646

47-
/// Get an unsafe mut pointer to a value
48-
#[inline(always)]
49-
pub pure fn mut_addr_of<T>(val: &T) -> *mut T {
50-
unsafe {
51-
cast::reinterpret_cast(&rusti::addr_of(*val))
52-
}
53-
}
54-
5547
/// Calculate the offset from a pointer
5648
#[inline(always)]
5749
pub pure fn offset<T>(ptr: *T, count: uint) -> *T {
@@ -313,8 +305,8 @@ impl<T:Ord> Ord for &const T {
313305
pub fn test() {
314306
unsafe {
315307
struct Pair {mut fst: int, mut snd: int};
316-
let p = Pair {mut fst: 10, mut snd: 20};
317-
let pptr: *mut Pair = mut_addr_of(&p);
308+
let mut p = Pair {mut fst: 10, mut snd: 20};
309+
let pptr: *mut Pair = &mut p;
318310
let iptr: *mut int = cast::reinterpret_cast(&pptr);
319311
assert (*iptr == 10);;
320312
*iptr = 30;

src/libcore/str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2110,7 +2110,7 @@ pub mod raw {
21102110
let v: **vec::raw::VecRepr = cast::transmute(v);
21112111
let repr: *vec::raw::VecRepr = *v;
21122112
(*repr).unboxed.fill = new_len + 1u;
2113-
let null = ptr::mut_offset(ptr::mut_addr_of(&((*repr).unboxed.data)),
2113+
let null = ptr::mut_offset(cast::transmute(&((*repr).unboxed.data)),
21142114
new_len);
21152115
*null = 0u8;
21162116
}

src/test/compile-fail/mutable-huh-ptr-assign.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ fn main() {
1616
}
1717

1818
unsafe {
19-
let a = 0;
20-
let v = ptr::mut_addr_of(&a);
19+
let mut a = 0;
20+
let v = &mut a;
2121
f(v);
2222
}
2323
}

src/test/compile-fail/mutable-huh-variance-ptr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
extern mod std;
1414

1515
fn main() {
16-
let a = ~[0];
17-
let v: *mut ~[int] = ptr::mut_addr_of(&a);
16+
let mut a = ~[0];
17+
let v: *mut ~[int] = &mut a;
1818

1919
fn f(&&v: *mut ~[const int]) {
2020
unsafe {

src/test/run-fail/too-much-recursion-unwinding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ fn r(recursed: *mut bool) -> r {
3939

4040
fn main() {
4141
let mut recursed = false;
42-
let _r = r(ptr::mut_addr_of(&recursed));
42+
let _r = r(&mut recursed);
4343
recurse();
4444
}

0 commit comments

Comments
 (0)