about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-02-14 19:16:07 -0800
committerbors <bors@rust-lang.org>2013-02-14 19:16:07 -0800
commit5a9da65dc9b3225e0278faedba71eb8b5cfb237d (patch)
tree5f4f277a3aea706423dcdff14add8fd288d2f7c8
parent20fd0c53edd2cc5ef5d413b8698b2c5860aa4926 (diff)
parent206757f8688bfe9958854952e7f1f21b5374a508 (diff)
downloadrust-5a9da65dc9b3225e0278faedba71eb8b5cfb237d.tar.gz
rust-5a9da65dc9b3225e0278faedba71eb8b5cfb237d.zip
auto merge of #4937 : luqmana/rust/remove-mut-addr-of, r=catamorphism
-rw-r--r--src/libcore/os.rs17
-rw-r--r--src/libcore/path.rs4
-rw-r--r--src/libcore/ptr.rs12
-rw-r--r--src/libcore/str.rs2
-rw-r--r--src/test/compile-fail/mutable-huh-ptr-assign.rs4
-rw-r--r--src/test/compile-fail/mutable-huh-variance-ptr.rs4
-rw-r--r--src/test/run-fail/too-much-recursion-unwinding.rs2
7 files changed, 18 insertions, 27 deletions
diff --git a/src/libcore/os.rs b/src/libcore/os.rs
index 8a6a241d870..91cc20d97f3 100644
--- a/src/libcore/os.rs
+++ b/src/libcore/os.rs
@@ -306,10 +306,9 @@ pub fn waitpid(pid: pid_t) -> c_int {
 pub fn waitpid(pid: pid_t) -> c_int {
     unsafe {
         use libc::funcs::posix01::wait::*;
-        let status = 0 as c_int;
+        let mut status = 0 as c_int;
 
-        assert (waitpid(pid, ptr::mut_addr_of(&status),
-                        0 as c_int) != (-1 as c_int));
+        assert (waitpid(pid, &mut status, 0 as c_int) != (-1 as c_int));
         return status;
     }
 }
@@ -322,7 +321,7 @@ pub fn pipe() -> Pipe {
     unsafe {
         let mut fds = Pipe {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(&mut fds.in) == (0 as c_int));
         return Pipe {in: fds.in, out: fds.out};
     }
 }
@@ -339,8 +338,7 @@ pub fn pipe() -> Pipe {
         // first, as in rust_run_program.
         let mut fds = Pipe { mut in: 0 as c_int,
                     mut out: 0 as c_int };
-        let res = libc::pipe(ptr::mut_addr_of(&(fds.in)),
-                             1024 as c_uint,
+        let res = libc::pipe(&mut fds.in, 1024 as c_uint,
                              (libc::O_BINARY | libc::O_NOINHERIT) as c_int);
         assert (res == 0 as c_int);
         assert (fds.in != -1 as c_int && fds.in != 0 as c_int);
@@ -374,8 +372,8 @@ pub fn self_exe_path() -> Option<Path> {
                            KERN_PROC as c_int,
                            KERN_PROC_PATHNAME as c_int, -1 as c_int];
                 sysctl(vec::raw::to_ptr(mib), vec::len(mib) as c_uint,
-                       buf as *mut c_void, ptr::mut_addr_of(&sz),
-                       ptr::null(), 0u as size_t) == (0 as c_int)
+                       buf, &mut sz, ptr::null(),
+                       0u as size_t) == (0 as c_int)
             }
         }
     }
@@ -406,8 +404,9 @@ pub fn self_exe_path() -> Option<Path> {
     fn load_self() -> Option<~str> {
         unsafe {
             do fill_charp_buf() |buf, sz| {
+                let mut sz = sz as u32;
                 libc::funcs::extra::_NSGetExecutablePath(
-                    buf, ptr::mut_addr_of(&(sz as u32))) == (0 as c_int)
+                    buf, &mut sz) == (0 as c_int)
             }
         }
     }
diff --git a/src/libcore/path.rs b/src/libcore/path.rs
index 91690b6b5b0..f196b97e5e5 100644
--- a/src/libcore/path.rs
+++ b/src/libcore/path.rs
@@ -243,7 +243,7 @@ impl Path {
         unsafe {
              do str::as_c_str(self.to_str()) |buf| {
                 let mut st = stat::arch::default_stat();
-                let r = libc::stat(buf, ptr::mut_addr_of(&st));
+                let r = libc::stat(buf, &mut st);
 
                 if r == 0 { Some(move st) } else { None }
             }
@@ -255,7 +255,7 @@ impl Path {
         unsafe {
             do str::as_c_str(self.to_str()) |buf| {
                 let mut st = stat::arch::default_stat();
-                let r = libc::lstat(buf, ptr::mut_addr_of(&st));
+                let r = libc::lstat(buf, &mut st);
 
                 if r == 0 { Some(move st) } else { None }
             }
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs
index acadf079b3b..c6617bdd516 100644
--- a/src/libcore/ptr.rs
+++ b/src/libcore/ptr.rs
@@ -44,14 +44,6 @@ extern mod rusti {
 #[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 {
-    unsafe {
-        cast::reinterpret_cast(&rusti::addr_of(*val))
-    }
-}
-
 /// Calculate the offset from a pointer
 #[inline(always)]
 pub pure fn offset<T>(ptr: *T, count: uint) -> *T {
@@ -313,8 +305,8 @@ impl<T:Ord> Ord for &const T {
 pub fn test() {
     unsafe {
         struct Pair {mut fst: int, mut snd: int};
-        let p = Pair {mut fst: 10, mut snd: 20};
-        let pptr: *mut Pair = mut_addr_of(&p);
+        let mut p = Pair {mut fst: 10, mut snd: 20};
+        let pptr: *mut Pair = &mut p;
         let iptr: *mut int = cast::reinterpret_cast(&pptr);
         assert (*iptr == 10);;
         *iptr = 30;
diff --git a/src/libcore/str.rs b/src/libcore/str.rs
index 7e7a34f1bab..a95d4236ce9 100644
--- a/src/libcore/str.rs
+++ b/src/libcore/str.rs
@@ -2110,7 +2110,7 @@ pub mod raw {
         let v: **vec::raw::VecRepr = cast::transmute(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(cast::transmute(&((*repr).unboxed.data)),
                                    new_len);
         *null = 0u8;
     }
diff --git a/src/test/compile-fail/mutable-huh-ptr-assign.rs b/src/test/compile-fail/mutable-huh-ptr-assign.rs
index d0e7c2339bc..ed356f4001d 100644
--- a/src/test/compile-fail/mutable-huh-ptr-assign.rs
+++ b/src/test/compile-fail/mutable-huh-ptr-assign.rs
@@ -16,8 +16,8 @@ fn main() {
     }
 
     unsafe {
-        let a = 0;
-        let v = ptr::mut_addr_of(&a);
+        let mut a = 0;
+        let v = &mut a;
         f(v);
     }
 }
diff --git a/src/test/compile-fail/mutable-huh-variance-ptr.rs b/src/test/compile-fail/mutable-huh-variance-ptr.rs
index e2299597c2f..dba6f9ae3fa 100644
--- a/src/test/compile-fail/mutable-huh-variance-ptr.rs
+++ b/src/test/compile-fail/mutable-huh-variance-ptr.rs
@@ -13,8 +13,8 @@
 extern mod std;
 
 fn main() {
-    let a = ~[0];
-    let v: *mut ~[int] = ptr::mut_addr_of(&a);
+    let mut a = ~[0];
+    let v: *mut ~[int] = &mut a;
 
     fn f(&&v: *mut ~[const int]) {
         unsafe {
diff --git a/src/test/run-fail/too-much-recursion-unwinding.rs b/src/test/run-fail/too-much-recursion-unwinding.rs
index b6a9bce934f..fbea8022cfc 100644
--- a/src/test/run-fail/too-much-recursion-unwinding.rs
+++ b/src/test/run-fail/too-much-recursion-unwinding.rs
@@ -39,6 +39,6 @@ fn r(recursed: *mut bool) -> r {
 
 fn main() {
     let mut recursed = false;
-    let _r = r(ptr::mut_addr_of(&recursed));
+    let _r = r(&mut recursed);
     recurse();
 }