auto merge of #4937 : luqmana/rust/remove-mut-addr-of, r=catamorphism
This commit is contained in:
commit
5a9da65dc9
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 }
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user