提交 7fd23e4f 编写于 作者: A Alex Crichton

Convert uses of transmute which don't need it

上级 467d381d
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
use libc::c_void; use libc::c_void;
use ptr::{mut_null}; use ptr::{mut_null};
use repr::BoxRepr; use repr::BoxRepr;
use cast::transmute;
use unstable::intrinsics::TyDesc; use unstable::intrinsics::TyDesc;
type DropGlue<'self> = &'self fn(**TyDesc, *c_void); type DropGlue<'self> = &'self fn(**TyDesc, *c_void);
...@@ -40,18 +39,17 @@ unsafe fn each_live_alloc(read_next_before: bool, ...@@ -40,18 +39,17 @@ unsafe fn each_live_alloc(read_next_before: bool,
let box = local_heap::live_allocs(); let box = local_heap::live_allocs();
let mut box: *mut BoxRepr = transmute(box); let mut box: *mut BoxRepr = transmute(box);
while box != mut_null() { while box != mut_null() {
let next_before = transmute((*box).header.next); let next_before = (*box).next;
let uniq = let uniq = (*box).ref_count == managed::RC_MANAGED_UNIQUE;
(*box).header.ref_count == managed::raw::RC_MANAGED_UNIQUE;
if !f(box, uniq) { if !f(box as *mut raw::Box<()>, uniq) {
return false; return false;
} }
if read_next_before { if read_next_before {
box = next_before; box = next_before;
} else { } else {
box = transmute((*box).header.next); box = (*box).next;
} }
} }
return true; return true;
...@@ -113,9 +111,9 @@ pub unsafe fn annihilate() { ...@@ -113,9 +111,9 @@ pub unsafe fn annihilate() {
// callback, as the original value may have been freed. // callback, as the original value may have been freed.
for each_live_alloc(false) |box, uniq| { for each_live_alloc(false) |box, uniq| {
if !uniq { if !uniq {
let tydesc: *TyDesc = transmute((*box).header.type_desc); let tydesc = (*box).type_desc;
let data = transmute(&(*box).data); let data = &(*box).data as *();
((*tydesc).drop_glue)(data); ((*tydesc).drop_glue)(data as *i8);
} }
} }
...@@ -130,7 +128,7 @@ pub unsafe fn annihilate() { ...@@ -130,7 +128,7 @@ pub unsafe fn annihilate() {
stats.n_bytes_freed += stats.n_bytes_freed +=
(*((*box).header.type_desc)).size (*((*box).header.type_desc)).size
+ sys::size_of::<BoxRepr>(); + sys::size_of::<BoxRepr>();
local_free(transmute(box)); local_free(box as *u8);
} }
} }
......
...@@ -74,14 +74,14 @@ pub mod rustrt { ...@@ -74,14 +74,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::transmute(ptr::offset(ptr, count)); return ptr::offset(ptr, count) as *U;
} }
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::transmute(ptr); let ptr = ptr as uint;
let ptr = (ptr + (align - 1)) & -align; let ptr = (ptr + (align - 1)) & -align;
return cast::transmute(ptr); return ptr as *T;
} }
unsafe fn get_safe_point_count() -> uint { unsafe fn get_safe_point_count() -> uint {
...@@ -126,8 +126,8 @@ unsafe fn is_safe_point(pc: *Word) -> Option<SafePoint> { ...@@ -126,8 +126,8 @@ unsafe fn is_safe_point(pc: *Word) -> Option<SafePoint> {
// 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) -> bool { unsafe fn _walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) -> bool {
let fp_bytes: *u8 = cast::transmute(fp); let fp_bytes = fp as *u8;
let sp_meta: *u32 = cast::transmute(sp.sp_meta); let sp_meta = sp.sp_meta as *u32;
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;
...@@ -173,9 +173,9 @@ unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) -> bool { ...@@ -173,9 +173,9 @@ unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) -> bool {
// 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::transmute(segment); let begin = segment as Word;
let end: Word = cast::transmute((*segment).end); let end = (*segment).end as Word;
let frame: Word = cast::transmute(fp); let frame = fp as Word;
return begin <= frame && frame <= end; return begin <= frame && frame <= end;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册