Skip to content

libcore: Remove ptr::mut_addr_of since &mut is coerced to *mut #4937

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/libcore/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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};
}
}
Expand All @@ -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);
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand All @@ -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 }
}
Expand Down
12 changes: 2 additions & 10 deletions src/libcore/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/mutable-huh-ptr-assign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions src/test/compile-fail/mutable-huh-variance-ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-fail/too-much-recursion-unwinding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}