mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 03:38:29 +00:00
Replaced many instances of reinterpret_cast with transmute
This commit is contained in:
parent
f2b0ef147a
commit
51a68eb9b1
@ -41,7 +41,7 @@ pub mod rustrt {
|
|||||||
pub fn capacity<T>(v: @[T]) -> uint {
|
pub fn capacity<T>(v: @[T]) -> uint {
|
||||||
unsafe {
|
unsafe {
|
||||||
let repr: **raw::VecRepr =
|
let repr: **raw::VecRepr =
|
||||||
::cast::reinterpret_cast(&addr_of(&v));
|
::cast::transmute(addr_of(&v));
|
||||||
(**repr).unboxed.alloc / sys::size_of::<T>()
|
(**repr).unboxed.alloc / sys::size_of::<T>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -208,7 +208,7 @@ pub mod raw {
|
|||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn set_len<T>(v: @[T], new_len: uint) {
|
pub unsafe fn set_len<T>(v: @[T], new_len: uint) {
|
||||||
let repr: **mut VecRepr = ::cast::reinterpret_cast(&addr_of(&v));
|
let repr: **mut VecRepr = ::cast::transmute(addr_of(&v));
|
||||||
(**repr).unboxed.fill = new_len * sys::size_of::<T>();
|
(**repr).unboxed.fill = new_len * sys::size_of::<T>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -226,7 +226,7 @@ pub mod raw {
|
|||||||
|
|
||||||
#[inline(always)] // really pretty please
|
#[inline(always)] // really pretty please
|
||||||
pub unsafe fn push_fast<T>(v: &mut @[T], initval: T) {
|
pub unsafe fn push_fast<T>(v: &mut @[T], initval: T) {
|
||||||
let repr: **mut VecRepr = ::cast::reinterpret_cast(&v);
|
let repr: **mut VecRepr = ::cast::transmute(v);
|
||||||
let fill = (**repr).unboxed.fill;
|
let fill = (**repr).unboxed.fill;
|
||||||
(**repr).unboxed.fill += sys::size_of::<T>();
|
(**repr).unboxed.fill += sys::size_of::<T>();
|
||||||
let p = addr_of(&((**repr).unboxed.data));
|
let p = addr_of(&((**repr).unboxed.data));
|
||||||
@ -322,4 +322,4 @@ mod test {
|
|||||||
assert!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]);
|
assert!(from_slice([@"abc", @"123"]) == @[@"abc", @"123"]);
|
||||||
assert!(from_slice([@[42]]) == @[@[42]]);
|
assert!(from_slice([@[42]]) == @[@[42]]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,14 +77,14 @@ pub mod rustrt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn bump<T, U>(ptr: *T, count: uint) -> *U {
|
unsafe fn bump<T, U>(ptr: *T, count: uint) -> *U {
|
||||||
return cast::reinterpret_cast(&ptr::offset(ptr, count));
|
return cast::transmute(ptr::offset(ptr, count));
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn align_to_pointer<T>(ptr: *T) -> *T {
|
unsafe fn align_to_pointer<T>(ptr: *T) -> *T {
|
||||||
let align = sys::min_align_of::<*T>();
|
let align = sys::min_align_of::<*T>();
|
||||||
let ptr: uint = cast::reinterpret_cast(&ptr);
|
let ptr: uint = cast::transmute(ptr);
|
||||||
let ptr = (ptr + (align - 1)) & -align;
|
let ptr = (ptr + (align - 1)) & -align;
|
||||||
return cast::reinterpret_cast(&ptr);
|
return cast::transmute(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn get_safe_point_count() -> uint {
|
unsafe fn get_safe_point_count() -> uint {
|
||||||
@ -129,8 +129,8 @@ type Visitor<'self> = &'self fn(root: **Word, tydesc: *Word) -> bool;
|
|||||||
// Walks the list of roots for the given safe point, and calls visitor
|
// Walks the list of roots for the given safe point, and calls visitor
|
||||||
// on each root.
|
// on each root.
|
||||||
unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) {
|
unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) {
|
||||||
let fp_bytes: *u8 = cast::reinterpret_cast(&fp);
|
let fp_bytes: *u8 = cast::transmute(fp);
|
||||||
let sp_meta: *u32 = cast::reinterpret_cast(&sp.sp_meta);
|
let sp_meta: *u32 = cast::transmute(sp.sp_meta);
|
||||||
|
|
||||||
let num_stack_roots = *sp_meta as uint;
|
let num_stack_roots = *sp_meta as uint;
|
||||||
let num_reg_roots = *ptr::offset(sp_meta, 1) as uint;
|
let num_reg_roots = *ptr::offset(sp_meta, 1) as uint;
|
||||||
@ -171,9 +171,9 @@ unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) {
|
|||||||
|
|
||||||
// Is fp contained in segment?
|
// Is fp contained in segment?
|
||||||
unsafe fn is_frame_in_segment(fp: *Word, segment: *StackSegment) -> bool {
|
unsafe fn is_frame_in_segment(fp: *Word, segment: *StackSegment) -> bool {
|
||||||
let begin: Word = cast::reinterpret_cast(&segment);
|
let begin: Word = cast::transmute(segment);
|
||||||
let end: Word = cast::reinterpret_cast(&(*segment).end);
|
let end: Word = cast::transmute((*segment).end);
|
||||||
let frame: Word = cast::reinterpret_cast(&fp);
|
let frame: Word = cast::transmute(fp);
|
||||||
|
|
||||||
return begin <= frame && frame <= end;
|
return begin <= frame && frame <= end;
|
||||||
}
|
}
|
||||||
@ -339,7 +339,7 @@ pub fn cleanup_stack_for_failure() {
|
|||||||
// own stack roots on the stack anyway.
|
// own stack roots on the stack anyway.
|
||||||
let sentinel_box = ~0;
|
let sentinel_box = ~0;
|
||||||
let sentinel: **Word = if expect_sentinel() {
|
let sentinel: **Word = if expect_sentinel() {
|
||||||
cast::reinterpret_cast(&ptr::addr_of(&sentinel_box))
|
cast::transmute(ptr::addr_of(&sentinel_box))
|
||||||
} else {
|
} else {
|
||||||
ptr::null()
|
ptr::null()
|
||||||
};
|
};
|
||||||
|
@ -239,10 +239,10 @@ pub fn getenv(n: &str) -> Option<~str> {
|
|||||||
unsafe {
|
unsafe {
|
||||||
do with_env_lock {
|
do with_env_lock {
|
||||||
let s = str::as_c_str(n, |s| libc::getenv(s));
|
let s = str::as_c_str(n, |s| libc::getenv(s));
|
||||||
if ptr::null::<u8>() == cast::reinterpret_cast(&s) {
|
if ptr::null::<u8>() == cast::transmute(s) {
|
||||||
option::None::<~str>
|
option::None::<~str>
|
||||||
} else {
|
} else {
|
||||||
let s = cast::reinterpret_cast(&s);
|
let s = cast::transmute(s);
|
||||||
option::Some::<~str>(str::raw::from_buf(s))
|
option::Some::<~str>(str::raw::from_buf(s))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -644,7 +644,7 @@ pub fn make_dir(p: &Path, mode: c_int) -> bool {
|
|||||||
// FIXME: turn mode into something useful? #2623
|
// FIXME: turn mode into something useful? #2623
|
||||||
do as_utf16_p(p.to_str()) |buf| {
|
do as_utf16_p(p.to_str()) |buf| {
|
||||||
libc::CreateDirectoryW(buf, unsafe {
|
libc::CreateDirectoryW(buf, unsafe {
|
||||||
cast::reinterpret_cast(&0)
|
cast::transmute(0)
|
||||||
})
|
})
|
||||||
!= (0 as libc::BOOL)
|
!= (0 as libc::BOOL)
|
||||||
}
|
}
|
||||||
|
@ -86,11 +86,11 @@ pub unsafe fn position<T>(buf: *T, f: &fn(&T) -> bool) -> uint {
|
|||||||
|
|
||||||
/// Create an unsafe null pointer
|
/// Create an unsafe null pointer
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn null<T>() -> *T { unsafe { cast::reinterpret_cast(&0u) } }
|
pub fn null<T>() -> *T { unsafe { cast::transmute(0u) } }
|
||||||
|
|
||||||
/// Create an unsafe mutable null pointer
|
/// Create an unsafe mutable null pointer
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn mut_null<T>() -> *mut T { unsafe { cast::reinterpret_cast(&0u) } }
|
pub fn mut_null<T>() -> *mut T { unsafe { cast::transmute(0u) } }
|
||||||
|
|
||||||
/// Returns true if the pointer is equal to the null pointer.
|
/// Returns true if the pointer is equal to the null pointer.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
@ -134,7 +134,7 @@ pub unsafe fn set_memory<T>(dst: *mut T, c: int, count: uint) {
|
|||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_unsafe_ptr<T>(thing: &T) -> *T {
|
pub fn to_unsafe_ptr<T>(thing: &T) -> *T {
|
||||||
unsafe { cast::reinterpret_cast(&thing) }
|
unsafe { cast::transmute(thing) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -144,7 +144,7 @@ pub fn to_unsafe_ptr<T>(thing: &T) -> *T {
|
|||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
|
pub fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
|
||||||
unsafe { cast::reinterpret_cast(&thing) }
|
unsafe { cast::transmute(thing) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -154,7 +154,7 @@ pub fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T {
|
|||||||
*/
|
*/
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
|
pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
|
||||||
unsafe { cast::reinterpret_cast(&thing) }
|
unsafe { cast::transmute(thing) }
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -167,7 +167,7 @@ pub fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn to_uint<T>(thing: &T) -> uint {
|
pub fn to_uint<T>(thing: &T) -> uint {
|
||||||
unsafe {
|
unsafe {
|
||||||
cast::reinterpret_cast(&thing)
|
cast::transmute(thing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,8 +259,8 @@ impl<T> Eq for *const T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn eq(&self, other: &*const T) -> bool {
|
fn eq(&self, other: &*const T) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let a: uint = cast::reinterpret_cast(&(*self));
|
let a: uint = cast::transmute(*self);
|
||||||
let b: uint = cast::reinterpret_cast(&(*other));
|
let b: uint = cast::transmute(*other);
|
||||||
return a == b;
|
return a == b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -274,32 +274,32 @@ impl<T> Ord for *const T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn lt(&self, other: &*const T) -> bool {
|
fn lt(&self, other: &*const T) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let a: uint = cast::reinterpret_cast(&(*self));
|
let a: uint = cast::transmute(*self);
|
||||||
let b: uint = cast::reinterpret_cast(&(*other));
|
let b: uint = cast::transmute(*other);
|
||||||
return a < b;
|
return a < b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn le(&self, other: &*const T) -> bool {
|
fn le(&self, other: &*const T) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let a: uint = cast::reinterpret_cast(&(*self));
|
let a: uint = cast::transmute(*self);
|
||||||
let b: uint = cast::reinterpret_cast(&(*other));
|
let b: uint = cast::transmute(*other);
|
||||||
return a <= b;
|
return a <= b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn ge(&self, other: &*const T) -> bool {
|
fn ge(&self, other: &*const T) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let a: uint = cast::reinterpret_cast(&(*self));
|
let a: uint = cast::transmute(*self);
|
||||||
let b: uint = cast::reinterpret_cast(&(*other));
|
let b: uint = cast::transmute(*other);
|
||||||
return a >= b;
|
return a >= b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn gt(&self, other: &*const T) -> bool {
|
fn gt(&self, other: &*const T) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let a: uint = cast::reinterpret_cast(&(*self));
|
let a: uint = cast::transmute(*self);
|
||||||
let b: uint = cast::reinterpret_cast(&(*other));
|
let b: uint = cast::transmute(*other);
|
||||||
return a > b;
|
return a > b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -350,7 +350,7 @@ pub mod ptr_tests {
|
|||||||
struct Pair {mut fst: int, mut snd: int};
|
struct Pair {mut fst: int, mut snd: int};
|
||||||
let mut p = Pair {fst: 10, snd: 20};
|
let mut p = Pair {fst: 10, snd: 20};
|
||||||
let pptr: *mut Pair = &mut p;
|
let pptr: *mut Pair = &mut p;
|
||||||
let iptr: *mut int = cast::reinterpret_cast(&pptr);
|
let iptr: *mut int = cast::transmute(pptr);
|
||||||
assert!((*iptr == 10));;
|
assert!((*iptr == 10));;
|
||||||
*iptr = 30;
|
*iptr = 30;
|
||||||
assert!((*iptr == 30));
|
assert!((*iptr == 30));
|
||||||
|
@ -147,7 +147,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
|
|||||||
}
|
}
|
||||||
ptrs.push(ptr::null());
|
ptrs.push(ptr::null());
|
||||||
vec::as_imm_buf(ptrs, |p, _len|
|
vec::as_imm_buf(ptrs, |p, _len|
|
||||||
unsafe { cb(::cast::reinterpret_cast(&p)) }
|
unsafe { cb(::cast::transmute(p)) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
_ => cb(ptr::null())
|
_ => cb(ptr::null())
|
||||||
@ -167,12 +167,12 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>,
|
|||||||
for vec::each(*es) |e| {
|
for vec::each(*es) |e| {
|
||||||
let (k,v) = copy *e;
|
let (k,v) = copy *e;
|
||||||
let t = fmt!("%s=%s", k, v);
|
let t = fmt!("%s=%s", k, v);
|
||||||
let mut v : ~[u8] = ::cast::reinterpret_cast(&t);
|
let mut v : ~[u8] = ::cast::transmute(t);
|
||||||
blk += v;
|
blk += v;
|
||||||
::cast::forget(v);
|
::cast::forget(v);
|
||||||
}
|
}
|
||||||
blk += ~[0_u8];
|
blk += ~[0_u8];
|
||||||
vec::as_imm_buf(blk, |p, _len| cb(::cast::reinterpret_cast(&p)))
|
vec::as_imm_buf(blk, |p, _len| cb(::cast::transmute(p)))
|
||||||
}
|
}
|
||||||
_ => cb(ptr::null())
|
_ => cb(ptr::null())
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
#[doc(hidden)]; // FIXME #3538
|
#[doc(hidden)]; // FIXME #3538
|
||||||
|
|
||||||
use cast::reinterpret_cast;
|
use cast::transmute;
|
||||||
|
|
||||||
pub type Word = uint;
|
pub type Word = uint;
|
||||||
|
|
||||||
@ -30,16 +30,16 @@ pub fn walk_stack(visit: &fn(Frame) -> bool) {
|
|||||||
|
|
||||||
do frame_address |frame_pointer| {
|
do frame_address |frame_pointer| {
|
||||||
let mut frame_address: *Word = unsafe {
|
let mut frame_address: *Word = unsafe {
|
||||||
reinterpret_cast(&frame_pointer)
|
transmute(frame_pointer)
|
||||||
};
|
};
|
||||||
loop {
|
loop {
|
||||||
let fr = Frame(frame_address);
|
let fr = Frame(frame_address);
|
||||||
|
|
||||||
debug!("frame: %x", unsafe { reinterpret_cast(&fr.fp) });
|
debug!("frame: %x", unsafe { transmute(fr.fp) });
|
||||||
visit(fr);
|
visit(fr);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let next_fp: **Word = reinterpret_cast(&frame_address);
|
let next_fp: **Word = transmute(frame_address);
|
||||||
frame_address = *next_fp;
|
frame_address = *next_fp;
|
||||||
if *frame_address == 0u {
|
if *frame_address == 0u {
|
||||||
debug!("encountered task_start_wrapper. ending walk");
|
debug!("encountered task_start_wrapper. ending walk");
|
||||||
|
@ -121,7 +121,7 @@ pub fn push_char(s: &mut ~str, ch: char) {
|
|||||||
reserve_at_least(&mut *s, new_len);
|
reserve_at_least(&mut *s, new_len);
|
||||||
let off = len;
|
let off = len;
|
||||||
do as_buf(*s) |buf, _len| {
|
do as_buf(*s) |buf, _len| {
|
||||||
let buf: *mut u8 = ::cast::reinterpret_cast(&buf);
|
let buf: *mut u8 = ::cast::transmute(buf);
|
||||||
if nb == 1u {
|
if nb == 1u {
|
||||||
*ptr::mut_offset(buf, off) =
|
*ptr::mut_offset(buf, off) =
|
||||||
code as u8;
|
code as u8;
|
||||||
@ -2023,9 +2023,9 @@ pub fn as_bytes<T>(s: &const ~str, f: &fn(&~[u8]) -> T) -> T {
|
|||||||
*/
|
*/
|
||||||
pub fn as_bytes_slice<'a>(s: &'a str) -> &'a [u8] {
|
pub fn as_bytes_slice<'a>(s: &'a str) -> &'a [u8] {
|
||||||
unsafe {
|
unsafe {
|
||||||
let (ptr, len): (*u8, uint) = ::cast::reinterpret_cast(&s);
|
let (ptr, len): (*u8, uint) = ::cast::transmute(s);
|
||||||
let outgoing_tuple: (*u8, uint) = (ptr, len - 1);
|
let outgoing_tuple: (*u8, uint) = (ptr, len - 1);
|
||||||
return ::cast::reinterpret_cast(&outgoing_tuple);
|
return ::cast::transmute(outgoing_tuple);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2067,7 +2067,7 @@ pub fn as_c_str<T>(s: &str, f: &fn(*libc::c_char) -> T) -> T {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn as_buf<T>(s: &str, f: &fn(*u8, uint) -> T) -> T {
|
pub fn as_buf<T>(s: &str, f: &fn(*u8, uint) -> T) -> T {
|
||||||
unsafe {
|
unsafe {
|
||||||
let v : *(*u8,uint) = ::cast::reinterpret_cast(&ptr::addr_of(&s));
|
let v : *(*u8,uint) = ::cast::transmute(ptr::addr_of(&s));
|
||||||
let (buf,len) = *v;
|
let (buf,len) = *v;
|
||||||
f(buf, len)
|
f(buf, len)
|
||||||
}
|
}
|
||||||
@ -2217,12 +2217,12 @@ pub mod raw {
|
|||||||
|
|
||||||
/// Create a Rust string from a null-terminated C string
|
/// Create a Rust string from a null-terminated C string
|
||||||
pub unsafe fn from_c_str(c_str: *libc::c_char) -> ~str {
|
pub unsafe fn from_c_str(c_str: *libc::c_char) -> ~str {
|
||||||
from_buf(::cast::reinterpret_cast(&c_str))
|
from_buf(::cast::transmute(c_str))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a Rust string from a `*c_char` buffer of the given length
|
/// Create a Rust string from a `*c_char` buffer of the given length
|
||||||
pub unsafe fn from_c_str_len(c_str: *libc::c_char, len: uint) -> ~str {
|
pub unsafe fn from_c_str_len(c_str: *libc::c_char, len: uint) -> ~str {
|
||||||
from_buf_len(::cast::reinterpret_cast(&c_str), len)
|
from_buf_len(::cast::transmute(c_str), len)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a vector of bytes to a new owned string.
|
/// Converts a vector of bytes to a new owned string.
|
||||||
@ -2246,7 +2246,7 @@ pub mod raw {
|
|||||||
pub unsafe fn buf_as_slice<T>(buf: *u8, len: uint,
|
pub unsafe fn buf_as_slice<T>(buf: *u8, len: uint,
|
||||||
f: &fn(v: &str) -> T) -> T {
|
f: &fn(v: &str) -> T) -> T {
|
||||||
let v = (buf, len + 1);
|
let v = (buf, len + 1);
|
||||||
assert!(is_utf8(::cast::reinterpret_cast(&v)));
|
assert!(is_utf8(::cast::transmute(v)));
|
||||||
f(::cast::transmute(v))
|
f(::cast::transmute(v))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2294,7 +2294,7 @@ pub mod raw {
|
|||||||
assert!((end <= n));
|
assert!((end <= n));
|
||||||
|
|
||||||
let tuple = (ptr::offset(sbuf, begin), end - begin + 1);
|
let tuple = (ptr::offset(sbuf, begin), end - begin + 1);
|
||||||
::cast::reinterpret_cast(&tuple)
|
::cast::transmute(tuple)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2303,7 +2303,7 @@ pub mod raw {
|
|||||||
let new_len = s.len() + 1;
|
let new_len = s.len() + 1;
|
||||||
reserve_at_least(&mut *s, new_len);
|
reserve_at_least(&mut *s, new_len);
|
||||||
do as_buf(*s) |buf, len| {
|
do as_buf(*s) |buf, len| {
|
||||||
let buf: *mut u8 = ::cast::reinterpret_cast(&buf);
|
let buf: *mut u8 = ::cast::transmute(buf);
|
||||||
*ptr::mut_offset(buf, len) = b;
|
*ptr::mut_offset(buf, len) = b;
|
||||||
}
|
}
|
||||||
set_len(&mut *s, new_len);
|
set_len(&mut *s, new_len);
|
||||||
|
@ -25,8 +25,8 @@ impl<T:Durable> LocalData for @T { }
|
|||||||
impl Eq for @LocalData {
|
impl Eq for @LocalData {
|
||||||
fn eq(&self, other: &@LocalData) -> bool {
|
fn eq(&self, other: &@LocalData) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr_a: (uint, uint) = cast::reinterpret_cast(&(*self));
|
let ptr_a: (uint, uint) = cast::transmute(*self);
|
||||||
let ptr_b: (uint, uint) = cast::reinterpret_cast(other);
|
let ptr_b: (uint, uint) = cast::transmute(*other);
|
||||||
return ptr_a == ptr_b;
|
return ptr_a == ptr_b;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -44,7 +44,7 @@ extern fn cleanup_task_local_map(map_ptr: *libc::c_void) {
|
|||||||
assert!(!map_ptr.is_null());
|
assert!(!map_ptr.is_null());
|
||||||
// Get and keep the single reference that was created at the
|
// Get and keep the single reference that was created at the
|
||||||
// beginning.
|
// beginning.
|
||||||
let _map: TaskLocalMap = cast::reinterpret_cast(&map_ptr);
|
let _map: TaskLocalMap = cast::transmute(map_ptr);
|
||||||
// All local_data will be destroyed along with the map.
|
// All local_data will be destroyed along with the map.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap {
|
|||||||
let map: TaskLocalMap = @mut ~[];
|
let map: TaskLocalMap = @mut ~[];
|
||||||
// Use reinterpret_cast -- transmute would take map away from us also.
|
// Use reinterpret_cast -- transmute would take map away from us also.
|
||||||
rt::rust_set_task_local_data(
|
rt::rust_set_task_local_data(
|
||||||
task, cast::reinterpret_cast(&map));
|
task, cast::transmute(map));
|
||||||
rt::rust_task_local_data_atexit(task, cleanup_task_local_map);
|
rt::rust_task_local_data_atexit(task, cleanup_task_local_map);
|
||||||
// Also need to reference it an extra time to keep it for now.
|
// Also need to reference it an extra time to keep it for now.
|
||||||
let nonmut = cast::transmute::<TaskLocalMap,
|
let nonmut = cast::transmute::<TaskLocalMap,
|
||||||
@ -152,7 +152,7 @@ pub unsafe fn local_set<T:Durable>(
|
|||||||
// own on it can be dropped when the box is destroyed. The unsafe pointer
|
// 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
|
// does not have a reference associated with it, so it may become invalid
|
||||||
// when the box is destroyed.
|
// when the box is destroyed.
|
||||||
let data_ptr = cast::reinterpret_cast(&data);
|
let data_ptr = cast::transmute(data);
|
||||||
let data_box = @data as @LocalData;
|
let data_box = @data as @LocalData;
|
||||||
// Construct new entry to store in the map.
|
// Construct new entry to store in the map.
|
||||||
let new_entry = Some((keyval, data_ptr, data_box));
|
let new_entry = Some((keyval, data_ptr, data_box));
|
||||||
|
@ -121,7 +121,7 @@ impl<T> Drop for ArcDestruct<T>{
|
|||||||
fn finalize(&self) {
|
fn finalize(&self) {
|
||||||
unsafe {
|
unsafe {
|
||||||
do task::unkillable {
|
do task::unkillable {
|
||||||
let mut data: ~ArcData<T> = cast::reinterpret_cast(&self.data);
|
let mut data: ~ArcData<T> = cast::transmute(self.data);
|
||||||
let new_count =
|
let new_count =
|
||||||
intrinsics::atomic_xsub(&mut data.count, 1) - 1;
|
intrinsics::atomic_xsub(&mut data.count, 1) - 1;
|
||||||
assert!(new_count >= 0);
|
assert!(new_count >= 0);
|
||||||
@ -160,7 +160,7 @@ pub unsafe fn shared_mutable_state<T:Owned>(data: T) ->
|
|||||||
pub unsafe fn get_shared_mutable_state<T:Owned>(
|
pub unsafe fn get_shared_mutable_state<T:Owned>(
|
||||||
rc: *SharedMutableState<T>) -> *mut T
|
rc: *SharedMutableState<T>) -> *mut T
|
||||||
{
|
{
|
||||||
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
let ptr: ~ArcData<T> = cast::transmute((*rc).data);
|
||||||
assert!(ptr.count > 0);
|
assert!(ptr.count > 0);
|
||||||
let r = cast::transmute(ptr.data.get_ref());
|
let r = cast::transmute(ptr.data.get_ref());
|
||||||
cast::forget(ptr);
|
cast::forget(ptr);
|
||||||
@ -169,7 +169,7 @@ pub unsafe fn get_shared_mutable_state<T:Owned>(
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn get_shared_immutable_state<'a,T:Owned>(
|
pub unsafe fn get_shared_immutable_state<'a,T:Owned>(
|
||||||
rc: &'a SharedMutableState<T>) -> &'a T {
|
rc: &'a SharedMutableState<T>) -> &'a T {
|
||||||
let ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
let ptr: ~ArcData<T> = cast::transmute((*rc).data);
|
||||||
assert!(ptr.count > 0);
|
assert!(ptr.count > 0);
|
||||||
// Cast us back into the correct region
|
// Cast us back into the correct region
|
||||||
let r = cast::transmute_region(ptr.data.get_ref());
|
let r = cast::transmute_region(ptr.data.get_ref());
|
||||||
@ -179,7 +179,7 @@ pub unsafe fn get_shared_immutable_state<'a,T:Owned>(
|
|||||||
|
|
||||||
pub unsafe fn clone_shared_mutable_state<T:Owned>(rc: &SharedMutableState<T>)
|
pub unsafe fn clone_shared_mutable_state<T:Owned>(rc: &SharedMutableState<T>)
|
||||||
-> SharedMutableState<T> {
|
-> SharedMutableState<T> {
|
||||||
let mut ptr: ~ArcData<T> = cast::reinterpret_cast(&(*rc).data);
|
let mut ptr: ~ArcData<T> = cast::transmute((*rc).data);
|
||||||
let new_count = intrinsics::atomic_xadd(&mut ptr.count, 1) + 1;
|
let new_count = intrinsics::atomic_xadd(&mut ptr.count, 1) + 1;
|
||||||
assert!(new_count >= 2);
|
assert!(new_count >= 2);
|
||||||
cast::forget(ptr);
|
cast::forget(ptr);
|
||||||
|
@ -25,7 +25,7 @@ which case the value should be cached locally whenever possible to
|
|||||||
avoid hitting the mutex.
|
avoid hitting the mutex.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use cast::{transmute, reinterpret_cast};
|
use cast::{transmute};
|
||||||
use clone::Clone;
|
use clone::Clone;
|
||||||
use kinds::Owned;
|
use kinds::Owned;
|
||||||
use libc::{c_void};
|
use libc::{c_void};
|
||||||
@ -223,7 +223,7 @@ fn get_global_state() -> Exclusive<GlobalState> {
|
|||||||
|
|
||||||
fn key_ptr<T:Owned>(key: GlobalDataKey<T>) -> uint {
|
fn key_ptr<T:Owned>(key: GlobalDataKey<T>) -> uint {
|
||||||
unsafe {
|
unsafe {
|
||||||
let closure: Closure = reinterpret_cast(&key);
|
let closure: Closure = transmute(key);
|
||||||
return transmute(closure.code);
|
return transmute(closure.code);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -279,8 +279,8 @@ pub fn slice<'r,T>(v: &'r [T], start: uint, end: uint) -> &'r [T] {
|
|||||||
assert!(end <= len(v));
|
assert!(end <= len(v));
|
||||||
do as_imm_buf(v) |p, _len| {
|
do as_imm_buf(v) |p, _len| {
|
||||||
unsafe {
|
unsafe {
|
||||||
::cast::reinterpret_cast(
|
::cast::transmute(
|
||||||
&(ptr::offset(p, start),
|
(ptr::offset(p, start),
|
||||||
(end - start) * sys::nonzero_size_of::<T>()))
|
(end - start) * sys::nonzero_size_of::<T>()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -294,8 +294,8 @@ pub fn mut_slice<'r,T>(v: &'r mut [T], start: uint, end: uint)
|
|||||||
assert!(end <= v.len());
|
assert!(end <= v.len());
|
||||||
do as_mut_buf(v) |p, _len| {
|
do as_mut_buf(v) |p, _len| {
|
||||||
unsafe {
|
unsafe {
|
||||||
::cast::reinterpret_cast(
|
::cast::transmute(
|
||||||
&(ptr::mut_offset(p, start),
|
(ptr::mut_offset(p, start),
|
||||||
(end - start) * sys::nonzero_size_of::<T>()))
|
(end - start) * sys::nonzero_size_of::<T>()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,8 +309,8 @@ pub fn const_slice<'r,T>(v: &'r const [T], start: uint, end: uint)
|
|||||||
assert!(end <= len(v));
|
assert!(end <= len(v));
|
||||||
do as_const_buf(v) |p, _len| {
|
do as_const_buf(v) |p, _len| {
|
||||||
unsafe {
|
unsafe {
|
||||||
::cast::reinterpret_cast(
|
::cast::transmute(
|
||||||
&(ptr::const_offset(p, start),
|
(ptr::const_offset(p, start),
|
||||||
(end - start) * sys::nonzero_size_of::<T>()))
|
(end - start) * sys::nonzero_size_of::<T>()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1617,7 +1617,7 @@ pub fn as_imm_buf<T,U>(s: &[T],
|
|||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let v : *(*T,uint) =
|
let v : *(*T,uint) =
|
||||||
::cast::reinterpret_cast(&addr_of(&s));
|
::cast::transmute(addr_of(&s));
|
||||||
let (buf,len) = *v;
|
let (buf,len) = *v;
|
||||||
f(buf, len / sys::nonzero_size_of::<T>())
|
f(buf, len / sys::nonzero_size_of::<T>())
|
||||||
}
|
}
|
||||||
@ -1628,7 +1628,7 @@ pub fn as_imm_buf<T,U>(s: &[T],
|
|||||||
pub fn as_const_buf<T,U>(s: &const [T], f: &fn(*const T, uint) -> U) -> U {
|
pub fn as_const_buf<T,U>(s: &const [T], f: &fn(*const T, uint) -> U) -> U {
|
||||||
unsafe {
|
unsafe {
|
||||||
let v : *(*const T,uint) =
|
let v : *(*const T,uint) =
|
||||||
::cast::reinterpret_cast(&addr_of(&s));
|
::cast::transmute(addr_of(&s));
|
||||||
let (buf,len) = *v;
|
let (buf,len) = *v;
|
||||||
f(buf, len / sys::nonzero_size_of::<T>())
|
f(buf, len / sys::nonzero_size_of::<T>())
|
||||||
}
|
}
|
||||||
@ -1639,7 +1639,7 @@ pub fn as_const_buf<T,U>(s: &const [T], f: &fn(*const T, uint) -> U) -> U {
|
|||||||
pub fn as_mut_buf<T,U>(s: &mut [T], f: &fn(*mut T, uint) -> U) -> U {
|
pub fn as_mut_buf<T,U>(s: &mut [T], f: &fn(*mut T, uint) -> U) -> U {
|
||||||
unsafe {
|
unsafe {
|
||||||
let v : *(*mut T,uint) =
|
let v : *(*mut T,uint) =
|
||||||
::cast::reinterpret_cast(&addr_of(&s));
|
::cast::transmute(addr_of(&s));
|
||||||
let (buf,len) = *v;
|
let (buf,len) = *v;
|
||||||
f(buf, len / sys::nonzero_size_of::<T>())
|
f(buf, len / sys::nonzero_size_of::<T>())
|
||||||
}
|
}
|
||||||
@ -2468,21 +2468,21 @@ pub mod raw {
|
|||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn to_ptr<T>(v: &[T]) -> *T {
|
pub unsafe fn to_ptr<T>(v: &[T]) -> *T {
|
||||||
let repr: **SliceRepr = ::cast::transmute(&v);
|
let repr: **SliceRepr = ::cast::transmute(&v);
|
||||||
::cast::reinterpret_cast(&addr_of(&((**repr).data)))
|
::cast::transmute(addr_of(&((**repr).data)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** see `to_ptr()` */
|
/** see `to_ptr()` */
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn to_const_ptr<T>(v: &const [T]) -> *const T {
|
pub unsafe fn to_const_ptr<T>(v: &const [T]) -> *const T {
|
||||||
let repr: **SliceRepr = ::cast::transmute(&v);
|
let repr: **SliceRepr = ::cast::transmute(&v);
|
||||||
::cast::reinterpret_cast(&addr_of(&((**repr).data)))
|
::cast::transmute(addr_of(&((**repr).data)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/** see `to_ptr()` */
|
/** see `to_ptr()` */
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub unsafe fn to_mut_ptr<T>(v: &mut [T]) -> *mut T {
|
pub unsafe fn to_mut_ptr<T>(v: &mut [T]) -> *mut T {
|
||||||
let repr: **SliceRepr = ::cast::transmute(&v);
|
let repr: **SliceRepr = ::cast::transmute(&v);
|
||||||
::cast::reinterpret_cast(&addr_of(&((**repr).data)))
|
::cast::transmute(addr_of(&((**repr).data)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -2495,7 +2495,7 @@ pub mod raw {
|
|||||||
f: &fn(v: &[T]) -> U) -> U {
|
f: &fn(v: &[T]) -> U) -> U {
|
||||||
let pair = (p, len * sys::nonzero_size_of::<T>());
|
let pair = (p, len * sys::nonzero_size_of::<T>());
|
||||||
let v : *(&'blk [T]) =
|
let v : *(&'blk [T]) =
|
||||||
::cast::reinterpret_cast(&addr_of(&pair));
|
::cast::transmute(addr_of(&pair));
|
||||||
f(*v)
|
f(*v)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2509,7 +2509,7 @@ pub mod raw {
|
|||||||
f: &fn(v: &mut [T]) -> U) -> U {
|
f: &fn(v: &mut [T]) -> U) -> U {
|
||||||
let pair = (p, len * sys::nonzero_size_of::<T>());
|
let pair = (p, len * sys::nonzero_size_of::<T>());
|
||||||
let v : *(&'blk mut [T]) =
|
let v : *(&'blk mut [T]) =
|
||||||
::cast::reinterpret_cast(&addr_of(&pair));
|
::cast::transmute(addr_of(&pair));
|
||||||
f(*v)
|
f(*v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -212,7 +212,7 @@ fn get_metadata_section(os: os,
|
|||||||
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
|
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
|
||||||
let mut found = None;
|
let mut found = None;
|
||||||
unsafe {
|
unsafe {
|
||||||
let cvbuf: *u8 = cast::reinterpret_cast(&cbuf);
|
let cvbuf: *u8 = cast::transmute(cbuf);
|
||||||
let vlen = vec::len(encoder::metadata_encoding_version);
|
let vlen = vec::len(encoder::metadata_encoding_version);
|
||||||
debug!("checking %u bytes of metadata-version stamp",
|
debug!("checking %u bytes of metadata-version stamp",
|
||||||
vlen);
|
vlen);
|
||||||
|
@ -177,7 +177,7 @@ pub fn IndirectBr(cx: block, Addr: ValueRef, NumDests: uint) {
|
|||||||
pub fn noname() -> *libc::c_char {
|
pub fn noname() -> *libc::c_char {
|
||||||
unsafe {
|
unsafe {
|
||||||
static cnull: uint = 0u;
|
static cnull: uint = 0u;
|
||||||
return cast::reinterpret_cast(&ptr::addr_of(&cnull));
|
return cast::transmute(ptr::addr_of(&cnull));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -834,8 +834,8 @@ pub fn Phi(cx: block, Ty: TypeRef, vals: &[ValueRef], bbs: &[BasicBlockRef])
|
|||||||
pub fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) {
|
pub fn AddIncomingToPhi(phi: ValueRef, val: ValueRef, bb: BasicBlockRef) {
|
||||||
unsafe {
|
unsafe {
|
||||||
if llvm::LLVMIsUndef(phi) == lib::llvm::True { return; }
|
if llvm::LLVMIsUndef(phi) == lib::llvm::True { return; }
|
||||||
let valptr = cast::reinterpret_cast(&ptr::addr_of(&val));
|
let valptr = cast::transmute(ptr::addr_of(&val));
|
||||||
let bbptr = cast::reinterpret_cast(&ptr::addr_of(&bb));
|
let bbptr = cast::transmute(ptr::addr_of(&bb));
|
||||||
llvm::LLVMAddIncoming(phi, valptr, bbptr, 1 as c_uint);
|
llvm::LLVMAddIncoming(phi, valptr, bbptr, 1 as c_uint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1239,7 +1239,7 @@ pub fn C_array(ty: TypeRef, elts: &[ValueRef]) -> ValueRef {
|
|||||||
pub fn C_bytes(bytes: &[u8]) -> ValueRef {
|
pub fn C_bytes(bytes: &[u8]) -> ValueRef {
|
||||||
unsafe {
|
unsafe {
|
||||||
return llvm::LLVMConstString(
|
return llvm::LLVMConstString(
|
||||||
cast::reinterpret_cast(&vec::raw::to_ptr(bytes)),
|
cast::transmute(vec::raw::to_ptr(bytes)),
|
||||||
bytes.len() as c_uint, True);
|
bytes.len() as c_uint, True);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1247,7 +1247,7 @@ pub fn C_bytes(bytes: &[u8]) -> ValueRef {
|
|||||||
pub fn C_bytes_plus_null(bytes: &[u8]) -> ValueRef {
|
pub fn C_bytes_plus_null(bytes: &[u8]) -> ValueRef {
|
||||||
unsafe {
|
unsafe {
|
||||||
return llvm::LLVMConstString(
|
return llvm::LLVMConstString(
|
||||||
cast::reinterpret_cast(&vec::raw::to_ptr(bytes)),
|
cast::transmute(vec::raw::to_ptr(bytes)),
|
||||||
bytes.len() as c_uint, False);
|
bytes.len() as c_uint, False);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,7 @@ fn llunused() -> ValueRef {
|
|||||||
}
|
}
|
||||||
fn llnull() -> ValueRef {
|
fn llnull() -> ValueRef {
|
||||||
unsafe {
|
unsafe {
|
||||||
cast::reinterpret_cast(&ptr::null::<ValueRef>())
|
cast::transmute(ptr::null::<ValueRef>())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -337,10 +337,8 @@ pub type t = *t_opaque;
|
|||||||
|
|
||||||
pub fn get(t: t) -> t_box {
|
pub fn get(t: t) -> t_box {
|
||||||
unsafe {
|
unsafe {
|
||||||
let t2 = cast::reinterpret_cast::<t, t_box>(&t);
|
let t2: t_box = cast::transmute(t);
|
||||||
let t3 = t2;
|
t2
|
||||||
cast::forget(t2);
|
|
||||||
t3
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,7 @@ use list;
|
|||||||
use list::{List, Cons, Nil};
|
use list::{List, Cons, Nil};
|
||||||
|
|
||||||
use core::at_vec;
|
use core::at_vec;
|
||||||
use core::cast::reinterpret_cast;
|
use core::cast::transmute;
|
||||||
use core::cast;
|
use core::cast;
|
||||||
use core::libc::size_t;
|
use core::libc::size_t;
|
||||||
use core::prelude::*;
|
use core::prelude::*;
|
||||||
@ -135,7 +135,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
|
|||||||
let fill = chunk.fill;
|
let fill = chunk.fill;
|
||||||
|
|
||||||
while idx < fill {
|
while idx < fill {
|
||||||
let tydesc_data: *uint = reinterpret_cast(&ptr::offset(buf, idx));
|
let tydesc_data: *uint = transmute(ptr::offset(buf, idx));
|
||||||
let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data);
|
let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data);
|
||||||
let size = (*tydesc).size, align = (*tydesc).align;
|
let size = (*tydesc).size, align = (*tydesc).align;
|
||||||
|
|
||||||
@ -161,12 +161,12 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
|
|||||||
// during an initializer.
|
// during an initializer.
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
unsafe fn bitpack_tydesc_ptr(p: *TypeDesc, is_done: bool) -> uint {
|
unsafe fn bitpack_tydesc_ptr(p: *TypeDesc, is_done: bool) -> uint {
|
||||||
let p_bits: uint = reinterpret_cast(&p);
|
let p_bits: uint = transmute(p);
|
||||||
p_bits | (is_done as uint)
|
p_bits | (is_done as uint)
|
||||||
}
|
}
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) {
|
unsafe fn un_bitpack_tydesc_ptr(p: uint) -> (*TypeDesc, bool) {
|
||||||
(reinterpret_cast(&(p & !1)), p & 1 == 1)
|
(transmute(p & !1), p & 1 == 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl Arena {
|
pub impl Arena {
|
||||||
@ -207,9 +207,9 @@ pub impl Arena {
|
|||||||
unsafe {
|
unsafe {
|
||||||
let tydesc = sys::get_type_desc::<T>();
|
let tydesc = sys::get_type_desc::<T>();
|
||||||
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
|
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
|
||||||
let ptr: *mut T = reinterpret_cast(&ptr);
|
let ptr: *mut T = transmute(ptr);
|
||||||
rusti::move_val_init(&mut (*ptr), op());
|
rusti::move_val_init(&mut (*ptr), op());
|
||||||
return reinterpret_cast(&ptr);
|
return transmute(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,9 +221,9 @@ pub impl Arena {
|
|||||||
unsafe {
|
unsafe {
|
||||||
let tydesc = sys::get_type_desc::<T>();
|
let tydesc = sys::get_type_desc::<T>();
|
||||||
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
|
let ptr = self.alloc_pod_inner((*tydesc).size, (*tydesc).align);
|
||||||
let ptr: *mut T = reinterpret_cast(&ptr);
|
let ptr: *mut T = transmute(ptr);
|
||||||
rusti::move_val_init(&mut (*ptr), op());
|
rusti::move_val_init(&mut (*ptr), op());
|
||||||
return reinterpret_cast(&ptr);
|
return transmute(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,18 +268,18 @@ pub impl Arena {
|
|||||||
let tydesc = sys::get_type_desc::<T>();
|
let tydesc = sys::get_type_desc::<T>();
|
||||||
let (ty_ptr, ptr) =
|
let (ty_ptr, ptr) =
|
||||||
self.alloc_nonpod_inner((*tydesc).size, (*tydesc).align);
|
self.alloc_nonpod_inner((*tydesc).size, (*tydesc).align);
|
||||||
let ty_ptr: *mut uint = reinterpret_cast(&ty_ptr);
|
let ty_ptr: *mut uint = transmute(ty_ptr);
|
||||||
let ptr: *mut T = reinterpret_cast(&ptr);
|
let ptr: *mut T = transmute(ptr);
|
||||||
// Write in our tydesc along with a bit indicating that it
|
// Write in our tydesc along with a bit indicating that it
|
||||||
// has *not* been initialized yet.
|
// has *not* been initialized yet.
|
||||||
*ty_ptr = reinterpret_cast(&tydesc);
|
*ty_ptr = transmute(tydesc);
|
||||||
// Actually initialize it
|
// Actually initialize it
|
||||||
rusti::move_val_init(&mut(*ptr), op());
|
rusti::move_val_init(&mut(*ptr), op());
|
||||||
// Now that we are done, update the tydesc to indicate that
|
// Now that we are done, update the tydesc to indicate that
|
||||||
// the object is there.
|
// the object is there.
|
||||||
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);
|
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);
|
||||||
|
|
||||||
return reinterpret_cast(&ptr);
|
return transmute(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,18 +292,18 @@ pub impl Arena {
|
|||||||
let tydesc = sys::get_type_desc::<T>();
|
let tydesc = sys::get_type_desc::<T>();
|
||||||
let (ty_ptr, ptr) =
|
let (ty_ptr, ptr) =
|
||||||
self.alloc_nonpod_inner((*tydesc).size, (*tydesc).align);
|
self.alloc_nonpod_inner((*tydesc).size, (*tydesc).align);
|
||||||
let ty_ptr: *mut uint = reinterpret_cast(&ty_ptr);
|
let ty_ptr: *mut uint = transmute(ty_ptr);
|
||||||
let ptr: *mut T = reinterpret_cast(&ptr);
|
let ptr: *mut T = transmute(ptr);
|
||||||
// Write in our tydesc along with a bit indicating that it
|
// Write in our tydesc along with a bit indicating that it
|
||||||
// has *not* been initialized yet.
|
// has *not* been initialized yet.
|
||||||
*ty_ptr = reinterpret_cast(&tydesc);
|
*ty_ptr = transmute(tydesc);
|
||||||
// Actually initialize it
|
// Actually initialize it
|
||||||
rusti::move_val_init(&mut(*ptr), op());
|
rusti::move_val_init(&mut(*ptr), op());
|
||||||
// Now that we are done, update the tydesc to indicate that
|
// Now that we are done, update the tydesc to indicate that
|
||||||
// the object is there.
|
// the object is there.
|
||||||
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);
|
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);
|
||||||
|
|
||||||
return reinterpret_cast(&ptr);
|
return transmute(ptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
//! Unsafe debugging functions for inspecting values.
|
//! Unsafe debugging functions for inspecting values.
|
||||||
|
|
||||||
use core::cast::reinterpret_cast;
|
use core::cast::transmute;
|
||||||
use core::ptr;
|
use core::ptr;
|
||||||
use core::sys;
|
use core::sys;
|
||||||
|
|
||||||
@ -64,9 +64,9 @@ pub fn debug_fn<T>(x: T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn ptr_cast<T, U>(x: @T) -> @U {
|
pub unsafe fn ptr_cast<T, U>(x: @T) -> @U {
|
||||||
reinterpret_cast(
|
transmute(
|
||||||
&rustrt::debug_ptrcast(sys::get_type_desc::<T>(),
|
rustrt::debug_ptrcast(sys::get_type_desc::<T>(),
|
||||||
reinterpret_cast(&x)))
|
transmute(x)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Triggers a debugger breakpoint
|
/// Triggers a debugger breakpoint
|
||||||
|
@ -65,7 +65,7 @@ fn map_slices<A:Copy + Owned,B:Copy + Owned>(
|
|||||||
len * sys::size_of::<A>());
|
len * sys::size_of::<A>());
|
||||||
info!("pre-slice: %?", (base, slice));
|
info!("pre-slice: %?", (base, slice));
|
||||||
let slice : &[A] =
|
let slice : &[A] =
|
||||||
cast::reinterpret_cast(&slice);
|
cast::transmute(slice);
|
||||||
info!("slice: %?",
|
info!("slice: %?",
|
||||||
(base, vec::len(slice), end - base));
|
(base, vec::len(slice), end - base));
|
||||||
assert!((vec::len(slice) == end - base));
|
assert!((vec::len(slice) == end - base));
|
||||||
|
@ -839,7 +839,7 @@ pub mod node {
|
|||||||
option::Some(x) => {
|
option::Some(x) => {
|
||||||
//FIXME (#2744): Replace with memcpy or something similar
|
//FIXME (#2744): Replace with memcpy or something similar
|
||||||
let mut local_buf: ~[u8] =
|
let mut local_buf: ~[u8] =
|
||||||
cast::reinterpret_cast(&*x.content);
|
cast::transmute(*x.content);
|
||||||
let mut i = x.byte_offset;
|
let mut i = x.byte_offset;
|
||||||
while i < x.byte_len {
|
while i < x.byte_len {
|
||||||
buf[offset] = local_buf[i];
|
buf[offset] = local_buf[i];
|
||||||
|
@ -833,7 +833,7 @@ mod tests {
|
|||||||
let ptr = ptr::addr_of(&(*sharedstate));
|
let ptr = ptr::addr_of(&(*sharedstate));
|
||||||
do task::spawn || {
|
do task::spawn || {
|
||||||
let sharedstate: &mut int =
|
let sharedstate: &mut int =
|
||||||
unsafe { cast::reinterpret_cast(&ptr) };
|
unsafe { cast::transmute(ptr) };
|
||||||
access_shared(sharedstate, m2, 10);
|
access_shared(sharedstate, m2, 10);
|
||||||
c.send(());
|
c.send(());
|
||||||
|
|
||||||
@ -1111,7 +1111,7 @@ mod tests {
|
|||||||
let ptr = ptr::addr_of(&(*sharedstate));
|
let ptr = ptr::addr_of(&(*sharedstate));
|
||||||
do task::spawn || {
|
do task::spawn || {
|
||||||
let sharedstate: &mut int =
|
let sharedstate: &mut int =
|
||||||
unsafe { cast::reinterpret_cast(&ptr) };
|
unsafe { cast::transmute(ptr) };
|
||||||
access_shared(sharedstate, &x2, mode1, 10);
|
access_shared(sharedstate, &x2, mode1, 10);
|
||||||
c.send(());
|
c.send(());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user