libcore: Remove ptr::mut_addr_of since &mut is coerced to *mut
This commit is contained in:
parent
af2f0ef088
commit
cc89029942
7 changed files with 17 additions and 27 deletions
|
@ -306,10 +306,9 @@ pub fn waitpid(pid: pid_t) -> c_int {
|
||||||
pub fn waitpid(pid: pid_t) -> c_int {
|
pub fn waitpid(pid: pid_t) -> c_int {
|
||||||
unsafe {
|
unsafe {
|
||||||
use libc::funcs::posix01::wait::*;
|
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),
|
assert (waitpid(pid, &mut status, 0 as c_int) != (-1 as c_int));
|
||||||
0 as c_int) != (-1 as c_int));
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -322,7 +321,7 @@ pub fn pipe() -> Pipe {
|
||||||
unsafe {
|
unsafe {
|
||||||
let mut fds = Pipe {mut in: 0 as c_int,
|
let mut fds = Pipe {mut in: 0 as c_int,
|
||||||
mut out: 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};
|
return Pipe {in: fds.in, out: fds.out};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,8 +338,7 @@ pub fn pipe() -> Pipe {
|
||||||
// first, as in rust_run_program.
|
// first, as in rust_run_program.
|
||||||
let mut fds = Pipe { mut in: 0 as c_int,
|
let mut fds = Pipe { mut in: 0 as c_int,
|
||||||
mut out: 0 as c_int };
|
mut out: 0 as c_int };
|
||||||
let res = libc::pipe(ptr::mut_addr_of(&(fds.in)),
|
let res = libc::pipe(&mut fds.in, 1024 as c_uint,
|
||||||
1024 as c_uint,
|
|
||||||
(libc::O_BINARY | libc::O_NOINHERIT) as c_int);
|
(libc::O_BINARY | libc::O_NOINHERIT) as c_int);
|
||||||
assert (res == 0 as c_int);
|
assert (res == 0 as c_int);
|
||||||
assert (fds.in != -1 as c_int && fds.in != 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 as c_int,
|
||||||
KERN_PROC_PATHNAME as c_int, -1 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,
|
sysctl(vec::raw::to_ptr(mib), vec::len(mib) as c_uint,
|
||||||
buf as *mut c_void, ptr::mut_addr_of(&sz),
|
buf, &mut sz, ptr::null(),
|
||||||
ptr::null(), 0u as size_t) == (0 as c_int)
|
0u as size_t) == (0 as c_int)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -407,7 +405,7 @@ pub fn self_exe_path() -> Option<Path> {
|
||||||
unsafe {
|
unsafe {
|
||||||
do fill_charp_buf() |buf, sz| {
|
do fill_charp_buf() |buf, sz| {
|
||||||
libc::funcs::extra::_NSGetExecutablePath(
|
libc::funcs::extra::_NSGetExecutablePath(
|
||||||
buf, ptr::mut_addr_of(&(sz as u32))) == (0 as c_int)
|
buf, &mut (sz as u32)) == (0 as c_int)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,7 +243,7 @@ impl Path {
|
||||||
unsafe {
|
unsafe {
|
||||||
do str::as_c_str(self.to_str()) |buf| {
|
do str::as_c_str(self.to_str()) |buf| {
|
||||||
let mut st = stat::arch::default_stat();
|
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 }
|
if r == 0 { Some(move st) } else { None }
|
||||||
}
|
}
|
||||||
|
@ -255,7 +255,7 @@ impl Path {
|
||||||
unsafe {
|
unsafe {
|
||||||
do str::as_c_str(self.to_str()) |buf| {
|
do str::as_c_str(self.to_str()) |buf| {
|
||||||
let mut st = stat::arch::default_stat();
|
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 }
|
if r == 0 { Some(move st) } else { None }
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,14 +44,6 @@ extern mod rusti {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn addr_of<T>(val: &T) -> *T { unsafe { rusti::addr_of(*val) } }
|
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
|
/// Calculate the offset from a pointer
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub pure fn offset<T>(ptr: *T, count: uint) -> *T {
|
pub pure fn offset<T>(ptr: *T, count: uint) -> *T {
|
||||||
|
@ -313,8 +305,8 @@ impl<T:Ord> Ord for &const T {
|
||||||
pub fn test() {
|
pub fn test() {
|
||||||
unsafe {
|
unsafe {
|
||||||
struct Pair {mut fst: int, mut snd: int};
|
struct Pair {mut fst: int, mut snd: int};
|
||||||
let p = Pair {mut fst: 10, mut snd: 20};
|
let mut p = Pair {mut fst: 10, mut snd: 20};
|
||||||
let pptr: *mut Pair = mut_addr_of(&p);
|
let pptr: *mut Pair = &mut p;
|
||||||
let iptr: *mut int = cast::reinterpret_cast(&pptr);
|
let iptr: *mut int = cast::reinterpret_cast(&pptr);
|
||||||
assert (*iptr == 10);;
|
assert (*iptr == 10);;
|
||||||
*iptr = 30;
|
*iptr = 30;
|
||||||
|
|
|
@ -2110,7 +2110,7 @@ pub mod raw {
|
||||||
let v: **vec::raw::VecRepr = cast::transmute(v);
|
let v: **vec::raw::VecRepr = cast::transmute(v);
|
||||||
let repr: *vec::raw::VecRepr = *v;
|
let repr: *vec::raw::VecRepr = *v;
|
||||||
(*repr).unboxed.fill = new_len + 1u;
|
(*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);
|
new_len);
|
||||||
*null = 0u8;
|
*null = 0u8;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,8 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let a = 0;
|
let mut a = 0;
|
||||||
let v = ptr::mut_addr_of(&a);
|
let v = &mut a;
|
||||||
f(v);
|
f(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
extern mod std;
|
extern mod std;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let a = ~[0];
|
let mut a = ~[0];
|
||||||
let v: *mut ~[int] = ptr::mut_addr_of(&a);
|
let v: *mut ~[int] = &mut a;
|
||||||
|
|
||||||
fn f(&&v: *mut ~[const int]) {
|
fn f(&&v: *mut ~[const int]) {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
|
@ -39,6 +39,6 @@ fn r(recursed: *mut bool) -> r {
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut recursed = false;
|
let mut recursed = false;
|
||||||
let _r = r(ptr::mut_addr_of(&recursed));
|
let _r = r(&mut recursed);
|
||||||
recurse();
|
recurse();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue