Demode reinterpret_cast
This commit is contained in:
parent
6bfc80f8fb
commit
d777e51333
32 changed files with 148 additions and 147 deletions
|
@ -29,7 +29,7 @@ extern mod rusti {
|
|||
pure fn capacity<T>(&&v: @[const T]) -> uint {
|
||||
unsafe {
|
||||
let repr: **unsafe::VecRepr =
|
||||
::unsafe::reinterpret_cast(addr_of(v));
|
||||
::unsafe::reinterpret_cast(&addr_of(v));
|
||||
(**repr).alloc / sys::size_of::<T>()
|
||||
}
|
||||
}
|
||||
|
@ -154,13 +154,13 @@ mod unsafe {
|
|||
*/
|
||||
#[inline(always)]
|
||||
unsafe fn set_len<T>(&&v: @[const T], new_len: uint) {
|
||||
let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
|
||||
(**repr).fill = new_len * sys::size_of::<T>();
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
unsafe fn push<T>(&v: @[const T], +initval: T) {
|
||||
let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
|
||||
let fill = (**repr).fill;
|
||||
if (**repr).alloc > fill {
|
||||
push_fast(v, initval);
|
||||
|
@ -172,7 +172,7 @@ mod unsafe {
|
|||
// This doesn't bother to make sure we have space.
|
||||
#[inline(always)] // really pretty please
|
||||
unsafe fn push_fast<T>(&v: @[const T], +initval: T) {
|
||||
let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
|
||||
let fill = (**repr).fill;
|
||||
(**repr).fill += sys::size_of::<T>();
|
||||
let p = ptr::addr_of((**repr).data);
|
||||
|
|
|
@ -81,7 +81,7 @@ fn unwrap<A>(+d: DVec<A>) -> ~[mut A] {
|
|||
priv impl<A> DVec<A> {
|
||||
pure fn check_not_borrowed() {
|
||||
unsafe {
|
||||
let data: *() = unsafe::reinterpret_cast(self.data);
|
||||
let data: *() = unsafe::reinterpret_cast(&self.data);
|
||||
if data.is_null() {
|
||||
fail ~"Recursive use of dvec";
|
||||
}
|
||||
|
@ -91,9 +91,9 @@ priv impl<A> DVec<A> {
|
|||
#[inline(always)]
|
||||
fn check_out<B>(f: fn(-~[mut A]) -> B) -> B {
|
||||
unsafe {
|
||||
let mut data = unsafe::reinterpret_cast(null::<()>());
|
||||
let mut data = unsafe::reinterpret_cast(&null::<()>());
|
||||
data <-> self.data;
|
||||
let data_ptr: *() = unsafe::reinterpret_cast(data);
|
||||
let data_ptr: *() = unsafe::reinterpret_cast(&data);
|
||||
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
|
||||
return f(data);
|
||||
}
|
||||
|
@ -156,9 +156,9 @@ impl<A> DVec<A> {
|
|||
/// Insert a single item at the front of the list
|
||||
fn unshift(-t: A) {
|
||||
unsafe {
|
||||
let mut data = unsafe::reinterpret_cast(null::<()>());
|
||||
let mut data = unsafe::reinterpret_cast(&null::<()>());
|
||||
data <-> self.data;
|
||||
let data_ptr: *() = unsafe::reinterpret_cast(data);
|
||||
let data_ptr: *() = unsafe::reinterpret_cast(&data);
|
||||
if data_ptr.is_null() { fail ~"Recursive use of dvec"; }
|
||||
log(error, ~"a");
|
||||
self.data <- ~[mut t];
|
||||
|
|
|
@ -222,10 +222,10 @@ mod global_env {
|
|||
fn getenv(n: &str) -> Option<~str> {
|
||||
unsafe {
|
||||
let s = str::as_c_str(n, libc::getenv);
|
||||
return if ptr::null::<u8>() == unsafe::reinterpret_cast(s) {
|
||||
return if ptr::null::<u8>() == unsafe::reinterpret_cast(&s) {
|
||||
option::None::<~str>
|
||||
} else {
|
||||
let s = unsafe::reinterpret_cast(s);
|
||||
let s = unsafe::reinterpret_cast(&s);
|
||||
option::Some::<~str>(str::unsafe::from_buf(s))
|
||||
};
|
||||
}
|
||||
|
@ -595,7 +595,7 @@ fn make_dir(p: &Path, mode: c_int) -> bool {
|
|||
import win32::*;
|
||||
// FIXME: turn mode into something useful? #2623
|
||||
do as_utf16_p(p.to_str()) |buf| {
|
||||
CreateDirectoryW(buf, unsafe { unsafe::reinterpret_cast(0) })
|
||||
CreateDirectoryW(buf, unsafe { unsafe::reinterpret_cast(&0) })
|
||||
!= (0 as BOOL)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,11 +189,11 @@ struct PacketHeader {
|
|||
// thing. You'll proobably want to forget them when you're done.
|
||||
unsafe fn buf_header() -> ~BufferHeader {
|
||||
assert self.buffer.is_not_null();
|
||||
reinterpret_cast(self.buffer)
|
||||
reinterpret_cast(&self.buffer)
|
||||
}
|
||||
|
||||
fn set_buffer<T: send>(b: ~Buffer<T>) unsafe {
|
||||
self.buffer = reinterpret_cast(b);
|
||||
self.buffer = reinterpret_cast(&b);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -253,7 +253,7 @@ fn unibuffer<T: send>() -> ~Buffer<Packet<T>> {
|
|||
};
|
||||
|
||||
unsafe {
|
||||
b.data.header.buffer = reinterpret_cast(b);
|
||||
b.data.header.buffer = reinterpret_cast(&b);
|
||||
}
|
||||
|
||||
b
|
||||
|
@ -274,7 +274,7 @@ fn entangle_buffer<T: send, Tstart: send>(
|
|||
init: fn(*libc::c_void, x: &T) -> *Packet<Tstart>)
|
||||
-> (SendPacketBuffered<Tstart, T>, RecvPacketBuffered<Tstart, T>)
|
||||
{
|
||||
let p = init(unsafe { reinterpret_cast(buffer) }, &buffer.data);
|
||||
let p = init(unsafe { reinterpret_cast(&buffer) }, &buffer.data);
|
||||
unsafe { forget(buffer) }
|
||||
(SendPacketBuffered(p), RecvPacketBuffered(p))
|
||||
}
|
||||
|
|
|
@ -63,12 +63,12 @@ unsafe fn chan_from_global_ptr<T: send>(
|
|||
// This is the proposed global channel
|
||||
let ch = comm::recv(setup_po);
|
||||
// 0 is our sentinal value. It is not a valid channel
|
||||
assert unsafe::reinterpret_cast(ch) != 0u;
|
||||
assert unsafe::reinterpret_cast(&ch) != 0u;
|
||||
|
||||
// Install the channel
|
||||
log(debug,~"BEFORE COMPARE AND SWAP");
|
||||
let swapped = compare_and_swap(
|
||||
global, 0u, unsafe::reinterpret_cast(ch));
|
||||
global, 0u, unsafe::reinterpret_cast(&ch));
|
||||
log(debug,fmt!("AFTER .. swapped? %?", swapped));
|
||||
|
||||
if swapped {
|
||||
|
@ -78,11 +78,11 @@ unsafe fn chan_from_global_ptr<T: send>(
|
|||
} else {
|
||||
// Somebody else got in before we did
|
||||
comm::send(setup_ch, Abort);
|
||||
unsafe::reinterpret_cast(*global)
|
||||
unsafe::reinterpret_cast(&*global)
|
||||
}
|
||||
} else {
|
||||
log(debug, ~"global != 0");
|
||||
unsafe::reinterpret_cast(*global)
|
||||
unsafe::reinterpret_cast(&*global)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -189,7 +189,7 @@ unsafe fn weaken_task(f: fn(comm::Port<()>)) {
|
|||
let po = comm::Port();
|
||||
let ch = comm::Chan(po);
|
||||
unsafe {
|
||||
rustrt::rust_task_weaken(unsafe::reinterpret_cast(ch));
|
||||
rustrt::rust_task_weaken(unsafe::reinterpret_cast(&ch));
|
||||
}
|
||||
let _unweaken = Unweaken(ch);
|
||||
f(po);
|
||||
|
@ -198,7 +198,7 @@ unsafe fn weaken_task(f: fn(comm::Port<()>)) {
|
|||
let ch: comm::Chan<()>;
|
||||
new(ch: comm::Chan<()>) { self.ch = ch; }
|
||||
drop unsafe {
|
||||
rustrt::rust_task_unweaken(unsafe::reinterpret_cast(self.ch));
|
||||
rustrt::rust_task_unweaken(unsafe::reinterpret_cast(&self.ch));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ pure fn addr_of<T>(val: T) -> *T { unchecked { rusti::addr_of(val) } }
|
|||
#[inline(always)]
|
||||
pure fn mut_addr_of<T>(val: T) -> *mut T {
|
||||
unsafe {
|
||||
unsafe::reinterpret_cast(rusti::addr_of(val))
|
||||
unsafe::reinterpret_cast(&rusti::addr_of(val))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -89,7 +89,7 @@ unsafe fn position<T>(buf: *T, f: fn(T) -> bool) -> uint {
|
|||
|
||||
/// Create an unsafe null pointer
|
||||
#[inline(always)]
|
||||
pure fn null<T>() -> *T { unsafe { unsafe::reinterpret_cast(0u) } }
|
||||
pure fn null<T>() -> *T { unsafe { unsafe::reinterpret_cast(&0u) } }
|
||||
|
||||
/// Returns true if the pointer is equal to the null pointer.
|
||||
pure fn is_null<T>(ptr: *const T) -> bool { ptr == null() }
|
||||
|
@ -137,7 +137,7 @@ unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
|
|||
*/
|
||||
#[inline(always)]
|
||||
fn to_unsafe_ptr<T>(thing: &T) -> *T unsafe {
|
||||
unsafe::reinterpret_cast(thing)
|
||||
unsafe::reinterpret_cast(&thing)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -149,7 +149,7 @@ fn to_unsafe_ptr<T>(thing: &T) -> *T unsafe {
|
|||
*/
|
||||
#[inline(always)]
|
||||
fn to_uint<T>(thing: &T) -> uint unsafe {
|
||||
unsafe::reinterpret_cast(thing)
|
||||
unsafe::reinterpret_cast(&thing)
|
||||
}
|
||||
|
||||
/// Determine if two borrowed pointers point to the same thing.
|
||||
|
@ -175,8 +175,8 @@ impl<T> *T: Ptr {
|
|||
// Equality for pointers
|
||||
impl<T> *const T : Eq {
|
||||
pure fn eq(&&other: *const T) -> bool unsafe {
|
||||
let a: uint = unsafe::reinterpret_cast(self);
|
||||
let b: uint = unsafe::reinterpret_cast(other);
|
||||
let a: uint = unsafe::reinterpret_cast(&self);
|
||||
let b: uint = unsafe::reinterpret_cast(&other);
|
||||
return a == b;
|
||||
}
|
||||
}
|
||||
|
@ -184,23 +184,23 @@ impl<T> *const T : Eq {
|
|||
// Comparison for pointers
|
||||
impl<T> *const T : Ord {
|
||||
pure fn lt(&&other: *const T) -> bool unsafe {
|
||||
let a: uint = unsafe::reinterpret_cast(self);
|
||||
let b: uint = unsafe::reinterpret_cast(other);
|
||||
let a: uint = unsafe::reinterpret_cast(&self);
|
||||
let b: uint = unsafe::reinterpret_cast(&other);
|
||||
return a < b;
|
||||
}
|
||||
pure fn le(&&other: *const T) -> bool unsafe {
|
||||
let a: uint = unsafe::reinterpret_cast(self);
|
||||
let b: uint = unsafe::reinterpret_cast(other);
|
||||
let a: uint = unsafe::reinterpret_cast(&self);
|
||||
let b: uint = unsafe::reinterpret_cast(&other);
|
||||
return a <= b;
|
||||
}
|
||||
pure fn ge(&&other: *const T) -> bool unsafe {
|
||||
let a: uint = unsafe::reinterpret_cast(self);
|
||||
let b: uint = unsafe::reinterpret_cast(other);
|
||||
let a: uint = unsafe::reinterpret_cast(&self);
|
||||
let b: uint = unsafe::reinterpret_cast(&other);
|
||||
return a >= b;
|
||||
}
|
||||
pure fn gt(&&other: *const T) -> bool unsafe {
|
||||
let a: uint = unsafe::reinterpret_cast(self);
|
||||
let b: uint = unsafe::reinterpret_cast(other);
|
||||
let a: uint = unsafe::reinterpret_cast(&self);
|
||||
let b: uint = unsafe::reinterpret_cast(&other);
|
||||
return a > b;
|
||||
}
|
||||
}
|
||||
|
@ -226,7 +226,7 @@ fn test() {
|
|||
type Pair = {mut fst: int, mut snd: int};
|
||||
let p = {mut fst: 10, mut snd: 20};
|
||||
let pptr: *mut Pair = mut_addr_of(p);
|
||||
let iptr: *mut int = unsafe::reinterpret_cast(pptr);
|
||||
let iptr: *mut int = unsafe::reinterpret_cast(&pptr);
|
||||
assert (*iptr == 10);;
|
||||
*iptr = 30;
|
||||
assert (*iptr == 30);
|
||||
|
|
|
@ -113,7 +113,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
|
|||
}
|
||||
vec::push(ptrs, ptr::null());
|
||||
vec::as_buf(ptrs, |p, _len|
|
||||
unsafe { cb(::unsafe::reinterpret_cast(p)) }
|
||||
unsafe { cb(::unsafe::reinterpret_cast(&p)) }
|
||||
)
|
||||
}
|
||||
_ => cb(ptr::null())
|
||||
|
@ -133,12 +133,12 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
|
|||
for vec::each(es) |e| {
|
||||
let (k,v) = e;
|
||||
let t = fmt!("%s=%s", k, v);
|
||||
let mut v : ~[u8] = ::unsafe::reinterpret_cast(t);
|
||||
let mut v : ~[u8] = ::unsafe::reinterpret_cast(&t);
|
||||
blk += v;
|
||||
::unsafe::forget(v);
|
||||
}
|
||||
blk += ~[0_u8];
|
||||
vec::as_buf(blk, |p, _len| cb(::unsafe::reinterpret_cast(p)))
|
||||
vec::as_buf(blk, |p, _len| cb(::unsafe::reinterpret_cast(&p)))
|
||||
}
|
||||
_ => cb(ptr::null())
|
||||
}
|
||||
|
|
|
@ -20,16 +20,16 @@ fn walk_stack(visit: fn(Frame) -> bool) {
|
|||
|
||||
do frame_address |frame_pointer| {
|
||||
let mut frame_address: *Word = unsafe {
|
||||
reinterpret_cast(frame_pointer)
|
||||
reinterpret_cast(&frame_pointer)
|
||||
};
|
||||
loop {
|
||||
let fr = Frame(frame_address);
|
||||
|
||||
debug!("frame: %x", unsafe { reinterpret_cast(fr.fp) });
|
||||
debug!("frame: %x", unsafe { reinterpret_cast(&fr.fp) });
|
||||
visit(fr);
|
||||
|
||||
unsafe {
|
||||
let next_fp: **Word = reinterpret_cast(frame_address);
|
||||
let next_fp: **Word = reinterpret_cast(&frame_address);
|
||||
frame_address = *next_fp;
|
||||
if *frame_address == 0u {
|
||||
debug!("encountered task_start_wrapper. ending walk");
|
||||
|
|
|
@ -164,7 +164,7 @@ fn push_char(&s: ~str, ch: char) {
|
|||
reserve_at_least(s, new_len);
|
||||
let off = len;
|
||||
do as_buf(s) |buf, _len| {
|
||||
let buf: *mut u8 = ::unsafe::reinterpret_cast(buf);
|
||||
let buf: *mut u8 = ::unsafe::reinterpret_cast(&buf);
|
||||
if nb == 1u {
|
||||
*ptr::mut_offset(buf, off) =
|
||||
code as u8;
|
||||
|
@ -1746,7 +1746,7 @@ const tag_six_b: uint = 252u;
|
|||
*/
|
||||
pure fn as_bytes<T>(s: ~str, f: fn(~[u8]) -> T) -> T {
|
||||
unsafe {
|
||||
let v: *~[u8] = ::unsafe::reinterpret_cast(ptr::addr_of(s));
|
||||
let v: *~[u8] = ::unsafe::reinterpret_cast(&ptr::addr_of(s));
|
||||
f(*v)
|
||||
}
|
||||
}
|
||||
|
@ -1790,7 +1790,7 @@ pure fn as_c_str<T>(s: &str, f: fn(*libc::c_char) -> T) -> T {
|
|||
#[inline(always)]
|
||||
pure fn as_buf<T>(s: &str, f: fn(*u8, uint) -> T) -> T {
|
||||
unsafe {
|
||||
let v : *(*u8,uint) = ::unsafe::reinterpret_cast(ptr::addr_of(s));
|
||||
let v : *(*u8,uint) = ::unsafe::reinterpret_cast(&ptr::addr_of(s));
|
||||
let (buf,len) = *v;
|
||||
f(buf, len)
|
||||
}
|
||||
|
@ -1814,7 +1814,7 @@ pure fn as_buf<T>(s: &str, f: fn(*u8, uint) -> T) -> T {
|
|||
*/
|
||||
fn reserve(&s: ~str, n: uint) {
|
||||
unsafe {
|
||||
let v: *mut ~[u8] = ::unsafe::reinterpret_cast(ptr::addr_of(s));
|
||||
let v: *mut ~[u8] = ::unsafe::reinterpret_cast(&ptr::addr_of(s));
|
||||
vec::reserve(*v, n + 1);
|
||||
}
|
||||
}
|
||||
|
@ -1917,18 +1917,18 @@ mod unsafe {
|
|||
/// without copying
|
||||
unsafe fn from_buf_len_nocopy(buf: &a / *u8, len: uint) -> &a / str {
|
||||
let v = (*buf, len + 1);
|
||||
assert is_utf8(::unsafe::reinterpret_cast(v));
|
||||
assert is_utf8(::unsafe::reinterpret_cast(&v));
|
||||
return ::unsafe::transmute(v);
|
||||
}
|
||||
|
||||
/// Create a Rust string from a null-terminated C string
|
||||
unsafe fn from_c_str(c_str: *libc::c_char) -> ~str {
|
||||
from_buf(::unsafe::reinterpret_cast(c_str))
|
||||
from_buf(::unsafe::reinterpret_cast(&c_str))
|
||||
}
|
||||
|
||||
/// Create a Rust string from a `*c_char` buffer of the given length
|
||||
unsafe fn from_c_str_len(c_str: *libc::c_char, len: uint) -> ~str {
|
||||
from_buf_len(::unsafe::reinterpret_cast(c_str), len)
|
||||
from_buf_len(::unsafe::reinterpret_cast(&c_str), len)
|
||||
}
|
||||
|
||||
/// Converts a vector of bytes to a string.
|
||||
|
@ -1987,7 +1987,7 @@ mod unsafe {
|
|||
assert (end <= n);
|
||||
|
||||
let tuple = (ptr::offset(sbuf, begin), end - begin + 1);
|
||||
::unsafe::reinterpret_cast(tuple)
|
||||
::unsafe::reinterpret_cast(&tuple)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1995,7 +1995,7 @@ mod unsafe {
|
|||
unsafe fn push_byte(&s: ~str, b: u8) {
|
||||
reserve_at_least(s, s.len() + 1);
|
||||
do as_buf(s) |buf, len| {
|
||||
let buf: *mut u8 = ::unsafe::reinterpret_cast(buf);
|
||||
let buf: *mut u8 = ::unsafe::reinterpret_cast(&buf);
|
||||
*ptr::mut_offset(buf, len) = b;
|
||||
}
|
||||
set_len(s, s.len() + 1);
|
||||
|
@ -2027,7 +2027,7 @@ mod unsafe {
|
|||
|
||||
/// Sets the length of the string and adds the null terminator
|
||||
unsafe fn set_len(&v: ~str, new_len: uint) {
|
||||
let repr: *vec::unsafe::VecRepr = ::unsafe::reinterpret_cast(v);
|
||||
let repr: *vec::unsafe::VecRepr = ::unsafe::reinterpret_cast(&v);
|
||||
(*repr).fill = new_len + 1u;
|
||||
let null = ptr::mut_offset(ptr::mut_addr_of((*repr).data), new_len);
|
||||
*null = 0u8;
|
||||
|
|
|
@ -88,14 +88,14 @@ pure fn pref_align_of<T>() -> uint {
|
|||
/// Returns the refcount of a shared box (as just before calling this)
|
||||
pure fn refcount<T>(+t: @T) -> uint {
|
||||
unsafe {
|
||||
let ref_ptr: *uint = unsafe::reinterpret_cast(t);
|
||||
let ref_ptr: *uint = unsafe::reinterpret_cast(&t);
|
||||
*ref_ptr - 1
|
||||
}
|
||||
}
|
||||
|
||||
pure fn log_str<T>(t: T) -> ~str {
|
||||
unsafe {
|
||||
let data_ptr: *() = unsafe::reinterpret_cast(ptr::addr_of(t));
|
||||
let data_ptr: *() = unsafe::reinterpret_cast(&ptr::addr_of(t));
|
||||
rustrt::shape_log_str(get_type_desc::<T>(), data_ptr)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1154,7 +1154,7 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) {
|
|||
make_child_wrapper(new_task, child_tg, ancestors, is_main,
|
||||
opts.notify_chan, f);
|
||||
let fptr = ptr::addr_of(child_wrapper);
|
||||
let closure: *rust_closure = unsafe::reinterpret_cast(fptr);
|
||||
let closure: *rust_closure = unsafe::reinterpret_cast(&fptr);
|
||||
|
||||
// Getting killed between these two calls would free the child's
|
||||
// closure. (Reordering them wouldn't help - then getting killed
|
||||
|
@ -1295,8 +1295,8 @@ impl<T: owned> @T: LocalData { }
|
|||
|
||||
impl LocalData: Eq {
|
||||
pure fn eq(&&other: LocalData) -> bool unsafe {
|
||||
let ptr_a: (uint, uint) = unsafe::reinterpret_cast(self);
|
||||
let ptr_b: (uint, uint) = unsafe::reinterpret_cast(other);
|
||||
let ptr_a: (uint, uint) = unsafe::reinterpret_cast(&self);
|
||||
let ptr_b: (uint, uint) = unsafe::reinterpret_cast(&other);
|
||||
return ptr_a == ptr_b;
|
||||
}
|
||||
}
|
||||
|
@ -1310,7 +1310,7 @@ type TaskLocalMap = @dvec::DVec<Option<TaskLocalElement>>;
|
|||
extern fn cleanup_task_local_map(map_ptr: *libc::c_void) unsafe {
|
||||
assert !map_ptr.is_null();
|
||||
// Get and keep the single reference that was created at the beginning.
|
||||
let _map: TaskLocalMap = unsafe::reinterpret_cast(map_ptr);
|
||||
let _map: TaskLocalMap = unsafe::reinterpret_cast(&map_ptr);
|
||||
// All local_data will be destroyed along with the map.
|
||||
}
|
||||
|
||||
|
@ -1325,7 +1325,8 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
|
|||
if map_ptr.is_null() {
|
||||
let map: TaskLocalMap = @dvec::DVec();
|
||||
// Use reinterpret_cast -- transmute would take map away from us also.
|
||||
rustrt::rust_set_task_local_data(task, unsafe::reinterpret_cast(map));
|
||||
rustrt::rust_set_task_local_data(
|
||||
task, unsafe::reinterpret_cast(&map));
|
||||
rustrt::rust_task_local_data_atexit(task, cleanup_task_local_map);
|
||||
// Also need to reference it an extra time to keep it for now.
|
||||
unsafe::bump_box_refcount(map);
|
||||
|
@ -1342,7 +1343,7 @@ unsafe fn key_to_key_value<T: owned>(
|
|||
|
||||
// Keys are closures, which are (fnptr,envptr) pairs. Use fnptr.
|
||||
// Use reintepret_cast -- transmute would leak (forget) the closure.
|
||||
let pair: (*libc::c_void, *libc::c_void) = unsafe::reinterpret_cast(key);
|
||||
let pair: (*libc::c_void, *libc::c_void) = unsafe::reinterpret_cast(&key);
|
||||
pair.first()
|
||||
}
|
||||
|
||||
|
@ -1411,7 +1412,7 @@ unsafe fn local_set<T: owned>(
|
|||
// own on it can be dropped when the box is destroyed. The unsafe pointer
|
||||
// does not have a reference associated with it, so it may become invalid
|
||||
// when the box is destroyed.
|
||||
let data_ptr = unsafe::reinterpret_cast(data);
|
||||
let data_ptr = unsafe::reinterpret_cast(&data);
|
||||
let data_box = data as LocalData;
|
||||
// Construct new entry to store in the map.
|
||||
let new_entry = Some((keyval, data_ptr, data_box));
|
||||
|
|
|
@ -19,8 +19,8 @@ extern mod rusti {
|
|||
|
||||
/// Casts the value at `src` to U. The two types must have the same length.
|
||||
#[inline(always)]
|
||||
unsafe fn reinterpret_cast<T, U>(src: T) -> U {
|
||||
rusti::reinterpret_cast(src)
|
||||
unsafe fn reinterpret_cast<T, U>(src: &T) -> U {
|
||||
rusti::reinterpret_cast(*src)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -51,7 +51,7 @@ unsafe fn bump_box_refcount<T>(+t: @T) { forget(t); }
|
|||
* assert transmute("L") == ~[76u8, 0u8];
|
||||
*/
|
||||
unsafe fn transmute<L, G>(-thing: L) -> G {
|
||||
let newthing = reinterpret_cast(thing);
|
||||
let newthing = reinterpret_cast(&thing);
|
||||
forget(thing);
|
||||
return newthing;
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ struct ArcDestruct<T> {
|
|||
return; // Happens when destructing an unwrapper's handle.
|
||||
}
|
||||
do task::unkillable {
|
||||
let data: ~ArcData<T> = unsafe::reinterpret_cast(self.data);
|
||||
let data: ~ArcData<T> = unsafe::reinterpret_cast(&self.data);
|
||||
let new_count = rustrt::rust_atomic_decrement(&mut data.count);
|
||||
assert new_count >= 0;
|
||||
if new_count == 0 {
|
||||
|
@ -111,7 +111,7 @@ struct ArcDestruct<T> {
|
|||
// being here means we're the only *awake* task with the data.
|
||||
if data.unwrapper != 0 {
|
||||
let p: UnwrapProto =
|
||||
unsafe::reinterpret_cast(data.unwrapper);
|
||||
unsafe::reinterpret_cast(&data.unwrapper);
|
||||
let (message, response) = option::swap_unwrap(p);
|
||||
// Send 'ready' and wait for a response.
|
||||
pipes::send_one(message, ());
|
||||
|
@ -154,7 +154,7 @@ unsafe fn unwrap_shared_mutable_state<T: send>(+rc: SharedMutableState<T>)
|
|||
}
|
||||
|
||||
do task::unkillable {
|
||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(rc.data);
|
||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&rc.data);
|
||||
let (c1,p1) = pipes::oneshot(); // ()
|
||||
let (c2,p2) = pipes::oneshot(); // bool
|
||||
let server: UnwrapProto = ~mut Some((c1,p2));
|
||||
|
@ -216,7 +216,7 @@ unsafe fn shared_mutable_state<T: send>(+data: T) -> SharedMutableState<T> {
|
|||
unsafe fn get_shared_mutable_state<T: send>(rc: &a/SharedMutableState<T>)
|
||||
-> &a/mut T {
|
||||
unsafe {
|
||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast((*rc).data);
|
||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
|
||||
assert ptr.count > 0;
|
||||
// Cast us back into the correct region
|
||||
let r = unsafe::transmute_region(option::get_ref(&ptr.data));
|
||||
|
@ -228,7 +228,7 @@ unsafe fn get_shared_mutable_state<T: send>(rc: &a/SharedMutableState<T>)
|
|||
unsafe fn get_shared_immutable_state<T: send>(rc: &a/SharedMutableState<T>)
|
||||
-> &a/T {
|
||||
unsafe {
|
||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast((*rc).data);
|
||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
|
||||
assert ptr.count > 0;
|
||||
// Cast us back into the correct region
|
||||
let r = unsafe::transmute_region(option::get_ref(&ptr.data));
|
||||
|
@ -240,7 +240,7 @@ unsafe fn get_shared_immutable_state<T: send>(rc: &a/SharedMutableState<T>)
|
|||
unsafe fn clone_shared_mutable_state<T: send>(rc: &SharedMutableState<T>)
|
||||
-> SharedMutableState<T> {
|
||||
unsafe {
|
||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast((*rc).data);
|
||||
let ptr: ~ArcData<T> = unsafe::reinterpret_cast(&(*rc).data);
|
||||
let new_count = rustrt::rust_atomic_increment(&mut ptr.count);
|
||||
assert new_count >= 2;
|
||||
unsafe::forget(ptr);
|
||||
|
@ -356,7 +356,7 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_reinterpret_cast() {
|
||||
assert unsafe { reinterpret_cast(1) } == 1u;
|
||||
assert unsafe { reinterpret_cast(&1) } == 1u;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -365,8 +365,8 @@ mod tests {
|
|||
let box = @~"box box box"; // refcount 1
|
||||
bump_box_refcount(box); // refcount 2
|
||||
let ptr: *int = transmute(box); // refcount 2
|
||||
let _box1: @~str = reinterpret_cast(ptr);
|
||||
let _box2: @~str = reinterpret_cast(ptr);
|
||||
let _box1: @~str = reinterpret_cast(&ptr);
|
||||
let _box2: @~str = reinterpret_cast(&ptr);
|
||||
assert *_box1 == ~"box box box";
|
||||
assert *_box2 == ~"box box box";
|
||||
// Will destroy _box1 and _box2. Without the bump, this would
|
||||
|
|
|
@ -167,7 +167,7 @@ fn reserve_at_least<T>(&v: ~[const T], n: uint) {
|
|||
#[inline(always)]
|
||||
pure fn capacity<T>(&&v: ~[const T]) -> uint {
|
||||
unsafe {
|
||||
let repr: **unsafe::VecRepr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||
let repr: **unsafe::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
|
||||
(**repr).alloc / sys::size_of::<T>()
|
||||
}
|
||||
}
|
||||
|
@ -335,7 +335,7 @@ pure fn view<T>(v: &[T], start: uint, end: uint) -> &[T] {
|
|||
do as_buf(v) |p, _len| {
|
||||
unsafe {
|
||||
::unsafe::reinterpret_cast(
|
||||
(ptr::offset(p, start), (end - start) * sys::size_of::<T>()))
|
||||
&(ptr::offset(p, start), (end - start) * sys::size_of::<T>()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ pure fn mut_view<T>(v: &[mut T], start: uint, end: uint) -> &[mut T] {
|
|||
do as_buf(v) |p, _len| {
|
||||
unsafe {
|
||||
::unsafe::reinterpret_cast(
|
||||
(ptr::offset(p, start), (end - start) * sys::size_of::<T>()))
|
||||
&(ptr::offset(p, start), (end - start) * sys::size_of::<T>()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ pure fn const_view<T>(v: &[const T], start: uint, end: uint) -> &[const T] {
|
|||
do as_buf(v) |p, _len| {
|
||||
unsafe {
|
||||
::unsafe::reinterpret_cast(
|
||||
(ptr::offset(p, start), (end - start) * sys::size_of::<T>()))
|
||||
&(ptr::offset(p, start), (end - start) * sys::size_of::<T>()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -558,7 +558,7 @@ fn swap_remove<T>(&v: ~[const T], index: uint) -> T {
|
|||
#[inline(always)]
|
||||
fn push<T>(&v: ~[const T], +initval: T) {
|
||||
unsafe {
|
||||
let repr: **unsafe::VecRepr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||
let repr: **unsafe::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
|
||||
let fill = (**repr).fill;
|
||||
if (**repr).alloc > fill {
|
||||
push_fast(v, initval);
|
||||
|
@ -572,7 +572,7 @@ fn push<T>(&v: ~[const T], +initval: T) {
|
|||
// This doesn't bother to make sure we have space.
|
||||
#[inline(always)] // really pretty please
|
||||
unsafe fn push_fast<T>(&v: ~[const T], +initval: T) {
|
||||
let repr: **unsafe::VecRepr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||
let repr: **unsafe::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
|
||||
let fill = (**repr).fill;
|
||||
(**repr).fill += sys::size_of::<T>();
|
||||
let p = ptr::addr_of((**repr).data);
|
||||
|
@ -1357,7 +1357,7 @@ pure fn windowed<TT: copy>(nn: uint, xx: &[TT]) -> ~[~[TT]] {
|
|||
pure fn as_buf<T,U>(s: &[const T],
|
||||
f: fn(*T, uint) -> U) -> U {
|
||||
unsafe {
|
||||
let v : *(*T,uint) = ::unsafe::reinterpret_cast(ptr::addr_of(s));
|
||||
let v : *(*T,uint) = ::unsafe::reinterpret_cast(&ptr::addr_of(s));
|
||||
let (buf,len) = *v;
|
||||
f(buf, len / sys::size_of::<T>())
|
||||
}
|
||||
|
@ -1369,7 +1369,7 @@ pure fn as_const_buf<T,U>(s: &[const T],
|
|||
f: fn(*const T, uint) -> U) -> U {
|
||||
do as_buf(s) |p, len| {
|
||||
unsafe {
|
||||
let pp : *const T = ::unsafe::reinterpret_cast(p);
|
||||
let pp : *const T = ::unsafe::reinterpret_cast(&p);
|
||||
f(pp, len)
|
||||
}
|
||||
}
|
||||
|
@ -1381,7 +1381,7 @@ pure fn as_mut_buf<T,U>(s: &[mut T],
|
|||
f: fn(*mut T, uint) -> U) -> U {
|
||||
do as_buf(s) |p, len| {
|
||||
unsafe {
|
||||
let pp : *mut T = ::unsafe::reinterpret_cast(p);
|
||||
let pp : *mut T = ::unsafe::reinterpret_cast(&p);
|
||||
f(pp, len)
|
||||
}
|
||||
}
|
||||
|
@ -1740,7 +1740,7 @@ mod unsafe {
|
|||
*/
|
||||
#[inline(always)]
|
||||
unsafe fn set_len<T>(&&v: ~[const T], new_len: uint) {
|
||||
let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
|
||||
(**repr).fill = new_len * sys::size_of::<T>();
|
||||
}
|
||||
|
||||
|
@ -1755,15 +1755,15 @@ mod unsafe {
|
|||
*/
|
||||
#[inline(always)]
|
||||
unsafe fn to_ptr<T>(v: ~[const T]) -> *T {
|
||||
let repr: **VecRepr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||
return ::unsafe::reinterpret_cast(addr_of((**repr).data));
|
||||
let repr: **VecRepr = ::unsafe::reinterpret_cast(&addr_of(v));
|
||||
return ::unsafe::reinterpret_cast(&addr_of((**repr).data));
|
||||
}
|
||||
|
||||
|
||||
#[inline(always)]
|
||||
unsafe fn to_ptr_slice<T>(v: &[const T]) -> *T {
|
||||
let repr: **SliceRepr = ::unsafe::reinterpret_cast(addr_of(v));
|
||||
return ::unsafe::reinterpret_cast(addr_of((**repr).data));
|
||||
let repr: **SliceRepr = ::unsafe::reinterpret_cast(&addr_of(v));
|
||||
return ::unsafe::reinterpret_cast(&addr_of((**repr).data));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1775,7 +1775,7 @@ mod unsafe {
|
|||
unsafe fn form_slice<T,U>(p: *T, len: uint, f: fn(&& &[T]) -> U) -> U {
|
||||
let pair = (p, len * sys::size_of::<T>());
|
||||
let v : *(&blk/[T]) =
|
||||
::unsafe::reinterpret_cast(ptr::addr_of(pair));
|
||||
::unsafe::reinterpret_cast(&ptr::addr_of(pair));
|
||||
f(*v)
|
||||
}
|
||||
|
||||
|
|
|
@ -95,7 +95,7 @@ unsafe fn destroy_chunk(chunk: Chunk) {
|
|||
let fill = chunk.fill;
|
||||
|
||||
while idx < fill {
|
||||
let tydesc_data: *uint = reinterpret_cast(ptr::offset(buf, idx));
|
||||
let tydesc_data: *uint = reinterpret_cast(&ptr::offset(buf, idx));
|
||||
let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data);
|
||||
let size = (*tydesc).size, align = (*tydesc).align;
|
||||
|
||||
|
@ -121,12 +121,12 @@ unsafe fn destroy_chunk(chunk: Chunk) {
|
|||
// during an initializer.
|
||||
#[inline(always)]
|
||||
unsafe fn bitpack_tydesc_ptr(p: *TypeDesc, is_done: bool) -> uint {
|
||||
let p_bits: uint = reinterpret_cast(p);
|
||||
let p_bits: uint = reinterpret_cast(&p);
|
||||
p_bits | (is_done as uint)
|
||||
}
|
||||
#[inline(always)]
|
||||
unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) {
|
||||
(reinterpret_cast(p & !1), p & 1 == 1)
|
||||
(reinterpret_cast(&(p & !1)), p & 1 == 1)
|
||||
}
|
||||
|
||||
// The duplication between the POD and non-POD functions is annoying.
|
||||
|
@ -167,9 +167,9 @@ impl &Arena {
|
|||
unsafe {
|
||||
let tydesc = sys::get_type_desc::<T>();
|
||||
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
|
||||
let ptr: *mut T = reinterpret_cast(ptr);
|
||||
let ptr: *mut T = reinterpret_cast(&ptr);
|
||||
rusti::move_val_init(*ptr, op());
|
||||
return reinterpret_cast(ptr);
|
||||
return reinterpret_cast(&ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,18 +213,18 @@ impl &Arena {
|
|||
let tydesc = sys::get_type_desc::<T>();
|
||||
let (ty_ptr, ptr) =
|
||||
self.alloc_nonpod_inner((*tydesc).size, (*tydesc).align);
|
||||
let ty_ptr: *mut uint = reinterpret_cast(ty_ptr);
|
||||
let ptr: *mut T = reinterpret_cast(ptr);
|
||||
let ty_ptr: *mut uint = reinterpret_cast(&ty_ptr);
|
||||
let ptr: *mut T = reinterpret_cast(&ptr);
|
||||
// Write in our tydesc along with a bit indicating that it
|
||||
// has *not* been initialized yet.
|
||||
*ty_ptr = reinterpret_cast(tydesc);
|
||||
*ty_ptr = reinterpret_cast(&tydesc);
|
||||
// Actually initialize it
|
||||
rusti::move_val_init(*ptr, op());
|
||||
// Now that we are done, update the tydesc to indicate that
|
||||
// the object is there.
|
||||
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);
|
||||
|
||||
return reinterpret_cast(ptr);
|
||||
return reinterpret_cast(&ptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,8 +46,8 @@ fn debug_fn<T>(+x: T) {
|
|||
|
||||
unsafe fn ptr_cast<T, U>(x: @T) -> @U {
|
||||
reinterpret_cast(
|
||||
rustrt::debug_ptrcast(sys::get_type_desc::<T>(),
|
||||
reinterpret_cast(x)))
|
||||
&rustrt::debug_ptrcast(sys::get_type_desc::<T>(),
|
||||
reinterpret_cast(&x)))
|
||||
}
|
||||
|
||||
/// Triggers a debugger breakpoint
|
||||
|
|
|
@ -48,7 +48,7 @@ fn map_slices<A: copy send, B: copy send>(
|
|||
len * sys::size_of::<A>());
|
||||
log(info, fmt!("pre-slice: %?", (base, slice)));
|
||||
let slice : &[A] =
|
||||
unsafe::reinterpret_cast(slice);
|
||||
unsafe::reinterpret_cast(&slice);
|
||||
log(info, fmt!("slice: %?",
|
||||
(base, vec::len(slice), end - base)));
|
||||
assert(vec::len(slice) == end - base);
|
||||
|
|
|
@ -807,7 +807,7 @@ mod node {
|
|||
option::Some(x) => {
|
||||
//FIXME (#2744): Replace with memcpy or something similar
|
||||
let mut local_buf: ~[u8] =
|
||||
unsafe::reinterpret_cast(*x.content);
|
||||
unsafe::reinterpret_cast(&*x.content);
|
||||
let mut i = x.byte_offset;
|
||||
while i < x.byte_len {
|
||||
buf[offset] = local_buf[i];
|
||||
|
|
|
@ -751,7 +751,7 @@ mod tests {
|
|||
let ptr = ptr::addr_of(*sharedstate);
|
||||
do task::spawn {
|
||||
let sharedstate: &mut int =
|
||||
unsafe { unsafe::reinterpret_cast(ptr) };
|
||||
unsafe { unsafe::reinterpret_cast(&ptr) };
|
||||
access_shared(sharedstate, m2, 10);
|
||||
c.send(());
|
||||
|
||||
|
@ -1018,7 +1018,7 @@ mod tests {
|
|||
let ptr = ptr::addr_of(*sharedstate);
|
||||
do task::spawn {
|
||||
let sharedstate: &mut int =
|
||||
unsafe { unsafe::reinterpret_cast(ptr) };
|
||||
unsafe { unsafe::reinterpret_cast(&ptr) };
|
||||
access_shared(sharedstate, x2, mode1, 10);
|
||||
c.send(());
|
||||
}
|
||||
|
|
|
@ -186,7 +186,7 @@ fn get_metadata_section(os: os,
|
|||
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
|
||||
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
|
||||
unsafe {
|
||||
let cvbuf: *u8 = unsafe::reinterpret_cast(cbuf);
|
||||
let cvbuf: *u8 = unsafe::reinterpret_cast(&cbuf);
|
||||
let v = vec::unsafe::from_buf(cvbuf, csz);
|
||||
let inflated = flate::inflate_buf(v);
|
||||
return Some(@inflated);
|
||||
|
|
|
@ -134,7 +134,7 @@ fn IndirectBr(cx: block, Addr: ValueRef, NumDests: uint) {
|
|||
// lot more efficient) than doing str::as_c_str("", ...) every time.
|
||||
fn noname() -> *libc::c_char unsafe {
|
||||
const cnull: uint = 0u;
|
||||
return unsafe::reinterpret_cast(ptr::addr_of(cnull));
|
||||
return unsafe::reinterpret_cast(&ptr::addr_of(cnull));
|
||||
}
|
||||
|
||||
fn Invoke(cx: block, Fn: ValueRef, Args: ~[ValueRef],
|
||||
|
@ -629,8 +629,8 @@ fn Phi(cx: block, Ty: TypeRef, vals: ~[ValueRef], bbs: ~[BasicBlockRef])
|
|||
fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) {
|
||||
if llvm::LLVMIsUndef(phi) == lib::llvm::True { return; }
|
||||
unsafe {
|
||||
let valptr = unsafe::reinterpret_cast(ptr::addr_of(val));
|
||||
let bbptr = unsafe::reinterpret_cast(ptr::addr_of(bb));
|
||||
let valptr = unsafe::reinterpret_cast(&ptr::addr_of(val));
|
||||
let bbptr = unsafe::reinterpret_cast(&ptr::addr_of(bb));
|
||||
llvm::LLVMAddIncoming(phi, valptr, bbptr, 1 as c_uint);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -971,7 +971,7 @@ fn C_array(ty: TypeRef, elts: ~[ValueRef]) -> ValueRef unsafe {
|
|||
|
||||
fn C_bytes(bytes: ~[u8]) -> ValueRef unsafe {
|
||||
return llvm::LLVMConstString(
|
||||
unsafe::reinterpret_cast(vec::unsafe::to_ptr(bytes)),
|
||||
unsafe::reinterpret_cast(&vec::unsafe::to_ptr(bytes)),
|
||||
bytes.len() as c_uint, False);
|
||||
}
|
||||
|
||||
|
|
|
@ -73,7 +73,7 @@ fn llunused() -> ValueRef {
|
|||
lli32(0x0)
|
||||
}
|
||||
fn llnull() -> ValueRef unsafe {
|
||||
unsafe::reinterpret_cast(ptr::null::<ValueRef>())
|
||||
unsafe::reinterpret_cast(&ptr::null::<ValueRef>())
|
||||
}
|
||||
|
||||
fn add_named_metadata(cx: @crate_ctxt, name: ~str, val: ValueRef) {
|
||||
|
|
|
@ -338,7 +338,7 @@ enum t_opaque {}
|
|||
type t = *t_opaque;
|
||||
|
||||
pure fn get(t: t) -> t_box unsafe {
|
||||
let t2 = unsafe::reinterpret_cast::<t, t_box>(t);
|
||||
let t2 = unsafe::reinterpret_cast::<t, t_box>(&t);
|
||||
let t3 = t2;
|
||||
unsafe::forget(t2);
|
||||
t3
|
||||
|
@ -712,7 +712,7 @@ fn mk_t(cx: ctxt, +st: sty) -> t { mk_t_with_id(cx, st, None) }
|
|||
fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option<ast::def_id>) -> t {
|
||||
let key = {struct: st, o_def_id: o_def_id};
|
||||
match cx.interner.find(key) {
|
||||
Some(t) => unsafe { return unsafe::reinterpret_cast(t); },
|
||||
Some(t) => unsafe { return unsafe::reinterpret_cast(&t); },
|
||||
_ => ()
|
||||
}
|
||||
let mut flags = 0u;
|
||||
|
@ -770,7 +770,7 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option<ast::def_id>) -> t {
|
|||
let t = @{struct: st, id: cx.next_id, flags: flags, o_def_id: o_def_id};
|
||||
cx.interner.insert(key, t);
|
||||
cx.next_id += 1u;
|
||||
unsafe { unsafe::reinterpret_cast(t) }
|
||||
unsafe { unsafe::reinterpret_cast(&t) }
|
||||
}
|
||||
|
||||
fn mk_nil(cx: ctxt) -> t { mk_t(cx, ty_nil) }
|
||||
|
|
|
@ -8,13 +8,13 @@ struct r {
|
|||
let v: *int;
|
||||
new(v: *int) { self.v = v; }
|
||||
drop unsafe {
|
||||
let _v2: ~int = unsafe::reinterpret_cast(self.v);
|
||||
let _v2: ~int = unsafe::reinterpret_cast(&self.v);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() unsafe {
|
||||
let i1 = ~0;
|
||||
let i1p = unsafe::reinterpret_cast(i1);
|
||||
let i1p = unsafe::reinterpret_cast(&i1);
|
||||
unsafe::forget(i1);
|
||||
let x = @r(i1p);
|
||||
failfn();
|
||||
|
|
|
@ -58,9 +58,9 @@ fn test_box() {
|
|||
}
|
||||
|
||||
fn test_ptr() unsafe {
|
||||
let p1: *u8 = unsafe::reinterpret_cast(0);
|
||||
let p2: *u8 = unsafe::reinterpret_cast(0);
|
||||
let p3: *u8 = unsafe::reinterpret_cast(1);
|
||||
let p1: *u8 = unsafe::reinterpret_cast(&0);
|
||||
let p2: *u8 = unsafe::reinterpret_cast(&0);
|
||||
let p3: *u8 = unsafe::reinterpret_cast(&1);
|
||||
|
||||
assert p1 == p2;
|
||||
assert p1 != p3;
|
||||
|
@ -97,8 +97,8 @@ fn test_class() {
|
|||
|
||||
unsafe {
|
||||
error!("q = %x, r = %x",
|
||||
(unsafe::reinterpret_cast::<*p, uint>(ptr::addr_of(q))),
|
||||
(unsafe::reinterpret_cast::<*p, uint>(ptr::addr_of(r))));
|
||||
(unsafe::reinterpret_cast::<*p, uint>(&ptr::addr_of(q))),
|
||||
(unsafe::reinterpret_cast::<*p, uint>(&ptr::addr_of(r))));
|
||||
}
|
||||
assert(q == r);
|
||||
r.y = 17;
|
||||
|
|
|
@ -2,7 +2,7 @@ import libc::{c_double, c_int};
|
|||
import f64::*;
|
||||
|
||||
fn to_c_int(v: &mut int) -> &mut c_int unsafe {
|
||||
unsafe::reinterpret_cast(v)
|
||||
unsafe::reinterpret_cast(&v)
|
||||
}
|
||||
|
||||
fn lgamma(n: c_double, value: &mut int) -> c_double {
|
||||
|
|
|
@ -17,7 +17,7 @@ type ccx = {
|
|||
|
||||
fn alloc(_bcx : &arena) -> &bcx unsafe {
|
||||
return unsafe::reinterpret_cast(
|
||||
libc::malloc(sys::size_of::<bcx/&blk>() as libc::size_t));
|
||||
&libc::malloc(sys::size_of::<bcx/&blk>() as libc::size_t));
|
||||
}
|
||||
|
||||
fn h(bcx : &bcx) -> &bcx {
|
||||
|
@ -28,7 +28,7 @@ fn g(fcx : &fcx) {
|
|||
let bcx = { fcx: fcx };
|
||||
let bcx2 = h(&bcx);
|
||||
unsafe {
|
||||
libc::free(unsafe::reinterpret_cast(bcx2));
|
||||
libc::free(unsafe::reinterpret_cast(&bcx2));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,16 +5,16 @@ struct r {
|
|||
new(v: *int) unsafe {
|
||||
self.v = v;
|
||||
debug!("r's ctor: v = %x, self = %x, self.v = %x",
|
||||
unsafe::reinterpret_cast::<*int, uint>(v),
|
||||
unsafe::reinterpret_cast::<*r, uint>(ptr::addr_of(self)),
|
||||
unsafe::reinterpret_cast::<**int, uint>(ptr::addr_of(self.v)));
|
||||
unsafe::reinterpret_cast::<*int, uint>(&v),
|
||||
unsafe::reinterpret_cast::<*r, uint>(&ptr::addr_of(self)),
|
||||
unsafe::reinterpret_cast::<**int, uint>(&ptr::addr_of(self.v)));
|
||||
}
|
||||
drop unsafe {
|
||||
debug!("r's dtor: self = %x, self.v = %x, self.v's value = %x",
|
||||
unsafe::reinterpret_cast::<*r, uint>(ptr::addr_of(self)),
|
||||
unsafe::reinterpret_cast::<**int, uint>(ptr::addr_of(self.v)),
|
||||
unsafe::reinterpret_cast::<*int, uint>(self.v));
|
||||
let v2: ~int = unsafe::reinterpret_cast(self.v); }
|
||||
unsafe::reinterpret_cast::<*r, uint>(&ptr::addr_of(self)),
|
||||
unsafe::reinterpret_cast::<**int, uint>(&ptr::addr_of(self.v)),
|
||||
unsafe::reinterpret_cast::<*int, uint>(&self.v));
|
||||
let v2: ~int = unsafe::reinterpret_cast(&self.v); }
|
||||
}
|
||||
|
||||
enum t = {
|
||||
|
@ -24,10 +24,10 @@ enum t = {
|
|||
|
||||
fn main() unsafe {
|
||||
let i1 = ~0;
|
||||
let i1p = unsafe::reinterpret_cast(i1);
|
||||
let i1p = unsafe::reinterpret_cast(&i1);
|
||||
unsafe::forget(i1);
|
||||
let i2 = ~0;
|
||||
let i2p = unsafe::reinterpret_cast(i2);
|
||||
let i2p = unsafe::reinterpret_cast(&i2);
|
||||
unsafe::forget(i2);
|
||||
|
||||
let x1 = @t({
|
||||
|
@ -35,27 +35,27 @@ fn main() unsafe {
|
|||
r: {
|
||||
let rs = r(i1p);
|
||||
debug!("r = %x",
|
||||
unsafe::reinterpret_cast::<*r, uint>(ptr::addr_of(rs)));
|
||||
unsafe::reinterpret_cast::<*r, uint>(&ptr::addr_of(rs)));
|
||||
rs }
|
||||
});
|
||||
|
||||
debug!("x1 = %x, x1.r = %x",
|
||||
unsafe::reinterpret_cast::<@t, uint>(x1),
|
||||
unsafe::reinterpret_cast::<*r, uint>(ptr::addr_of(x1.r)));
|
||||
unsafe::reinterpret_cast::<@t, uint>(&x1),
|
||||
unsafe::reinterpret_cast::<*r, uint>(&ptr::addr_of(x1.r)));
|
||||
|
||||
let x2 = @t({
|
||||
mut next: None,
|
||||
r: {
|
||||
let rs = r(i2p);
|
||||
debug!("r2 = %x",
|
||||
unsafe::reinterpret_cast::<*r, uint>(ptr::addr_of(rs)));
|
||||
unsafe::reinterpret_cast::<*r, uint>(&ptr::addr_of(rs)));
|
||||
rs
|
||||
}
|
||||
});
|
||||
|
||||
debug!("x2 = %x, x2.r = %x",
|
||||
unsafe::reinterpret_cast::<@t, uint>(x2),
|
||||
unsafe::reinterpret_cast::<*r, uint>(ptr::addr_of(x2.r)));
|
||||
unsafe::reinterpret_cast::<@t, uint>(&x2),
|
||||
unsafe::reinterpret_cast::<*r, uint>(&ptr::addr_of(x2.r)));
|
||||
|
||||
x1.next = Some(x2);
|
||||
x2.next = Some(x1);
|
||||
|
|
|
@ -10,7 +10,7 @@ struct r {
|
|||
let v: u;
|
||||
new(v: u) { self.v = v; }
|
||||
drop unsafe {
|
||||
let v2: ~int = unsafe::reinterpret_cast(self.v.c);
|
||||
let v2: ~int = unsafe::reinterpret_cast(&self.v.c);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,10 @@ enum t = {
|
|||
|
||||
fn main() unsafe {
|
||||
let i1 = ~0xA;
|
||||
let i1p = unsafe::reinterpret_cast(i1);
|
||||
let i1p = unsafe::reinterpret_cast(&i1);
|
||||
unsafe::forget(i1);
|
||||
let i2 = ~0xA;
|
||||
let i2p = unsafe::reinterpret_cast(i2);
|
||||
let i2p = unsafe::reinterpret_cast(&i2);
|
||||
unsafe::forget(i2);
|
||||
|
||||
let u1 = {a: 0xB, b: 0xC, c: i1p};
|
||||
|
|
|
@ -13,10 +13,10 @@ struct r {
|
|||
let w: int;
|
||||
let x: *int;
|
||||
new(v: u, w: int, _x: *int) unsafe { self.v = v; self.w = w;
|
||||
self.x = unsafe::reinterpret_cast(0);
|
||||
self.x = unsafe::reinterpret_cast(&0);
|
||||
/* self.x = x; */ }
|
||||
drop unsafe {
|
||||
let _v2: ~int = unsafe::reinterpret_cast(self.v.c);
|
||||
let _v2: ~int = unsafe::reinterpret_cast(&self.v.c);
|
||||
// let _v3: ~int = unsafe::reinterpret_cast(self.x);
|
||||
}
|
||||
}
|
||||
|
@ -28,10 +28,10 @@ enum t = {
|
|||
|
||||
fn main() unsafe {
|
||||
let i1 = ~0xA;
|
||||
let i1p = unsafe::reinterpret_cast(i1);
|
||||
let i1p = unsafe::reinterpret_cast(&i1);
|
||||
unsafe::forget(i1);
|
||||
let i2 = ~0xA;
|
||||
let i2p = unsafe::reinterpret_cast(i2);
|
||||
let i2p = unsafe::reinterpret_cast(&i2);
|
||||
unsafe::forget(i2);
|
||||
|
||||
let u1 = {a: 0xB, b: 0xC, c: i1p};
|
||||
|
|
|
@ -32,7 +32,7 @@ fn main() unsafe {
|
|||
assert child_sched_id == new_sched_id;
|
||||
comm::send(ch, ());
|
||||
};
|
||||
let fptr = unsafe::reinterpret_cast(ptr::addr_of(f));
|
||||
let fptr = unsafe::reinterpret_cast(&ptr::addr_of(f));
|
||||
rustrt::start_task(new_task_id, fptr);
|
||||
unsafe::forget(f);
|
||||
comm::recv(po);
|
||||
|
|
|
@ -4,6 +4,6 @@
|
|||
use std;
|
||||
import unsafe;
|
||||
|
||||
fn null<T>() -> *T unsafe { unsafe::reinterpret_cast(0) }
|
||||
fn null<T>() -> *T unsafe { unsafe::reinterpret_cast(&0) }
|
||||
|
||||
fn main() { null::<int>(); }
|
||||
|
|
Loading…
Add table
Reference in a new issue