diff options
| author | Brian Anderson <banderson@mozilla.com> | 2012-09-18 17:34:08 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2012-09-18 19:36:25 -0700 |
| commit | 2906f2de31d3a4709a2e028c5cefe3274df1edd2 (patch) | |
| tree | 608d302d2da9538bc12cdf286437a6cd654c7535 /src/libcore | |
| parent | 77480e8e44d9c5a6858172faeb291496314cf739 (diff) | |
core: Rename 'unsafe' mod to 'cast'
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/at_vec.rs | 8 | ||||
| -rw-r--r-- | src/libcore/cast.rs (renamed from src/libcore/unsafe.rs) | 0 | ||||
| -rw-r--r-- | src/libcore/cleanup.rs | 2 | ||||
| -rw-r--r-- | src/libcore/comm.rs | 2 | ||||
| -rw-r--r-- | src/libcore/core.rc | 4 | ||||
| -rw-r--r-- | src/libcore/dvec.rs | 12 | ||||
| -rw-r--r-- | src/libcore/future.rs | 2 | ||||
| -rw-r--r-- | src/libcore/gc.rs | 18 | ||||
| -rw-r--r-- | src/libcore/io.rs | 2 | ||||
| -rw-r--r-- | src/libcore/mutable.rs | 2 | ||||
| -rw-r--r-- | src/libcore/os.rs | 4 | ||||
| -rw-r--r-- | src/libcore/pipes.rs | 2 | ||||
| -rw-r--r-- | src/libcore/private.rs | 54 | ||||
| -rw-r--r-- | src/libcore/ptr.rs | 36 | ||||
| -rw-r--r-- | src/libcore/repr.rs | 4 | ||||
| -rw-r--r-- | src/libcore/run.rs | 2 | ||||
| -rw-r--r-- | src/libcore/send_map.rs | 2 | ||||
| -rw-r--r-- | src/libcore/stackwalk.rs | 2 | ||||
| -rw-r--r-- | src/libcore/str.rs | 42 | ||||
| -rw-r--r-- | src/libcore/sys.rs | 6 | ||||
| -rw-r--r-- | src/libcore/task.rs | 36 | ||||
| -rw-r--r-- | src/libcore/vec.rs | 38 |
22 files changed, 140 insertions, 140 deletions
diff --git a/src/libcore/at_vec.rs b/src/libcore/at_vec.rs index c05f0c3fc44..069bc625623 100644 --- a/src/libcore/at_vec.rs +++ b/src/libcore/at_vec.rs @@ -29,7 +29,7 @@ extern mod rusti { pure fn capacity<T>(&&v: @[const T]) -> uint { unsafe { let repr: **raw::VecRepr = - ::unsafe::reinterpret_cast(&addr_of(v)); + ::cast::reinterpret_cast(&addr_of(v)); (**repr).unboxed.alloc / sys::size_of::<T>() } } @@ -154,13 +154,13 @@ mod raw { */ #[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 = ::cast::reinterpret_cast(&addr_of(v)); (**repr).unboxed.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 = ::cast::reinterpret_cast(&addr_of(v)); let fill = (**repr).unboxed.fill; if (**repr).unboxed.alloc > fill { push_fast(v, move initval); @@ -172,7 +172,7 @@ mod raw { // 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 = ::cast::reinterpret_cast(&addr_of(v)); let fill = (**repr).unboxed.fill; (**repr).unboxed.fill += sys::size_of::<T>(); let p = ptr::addr_of((**repr).unboxed.data); diff --git a/src/libcore/unsafe.rs b/src/libcore/cast.rs index 601eeff6969..601eeff6969 100644 --- a/src/libcore/unsafe.rs +++ b/src/libcore/cast.rs diff --git a/src/libcore/cleanup.rs b/src/libcore/cleanup.rs index d5e474dd92b..35155e683dc 100644 --- a/src/libcore/cleanup.rs +++ b/src/libcore/cleanup.rs @@ -2,7 +2,7 @@ use libc::{c_char, c_void, intptr_t, uintptr_t}; use ptr::{mut_null, null, to_unsafe_ptr}; use repr::BoxRepr; use sys::TypeDesc; -use unsafe::transmute; +use cast::transmute; export annihilate; diff --git a/src/libcore/comm.rs b/src/libcore/comm.rs index 8da0131e585..c3ed8c8c82c 100644 --- a/src/libcore/comm.rs +++ b/src/libcore/comm.rs @@ -181,7 +181,7 @@ fn send<T: Send>(ch: Chan<T>, +data: T) { let res = rustrt::rust_port_id_send(p, data_ptr); if res != 0 unsafe { // Data sent successfully - unsafe::forget(move data); + cast::forget(move data); } task::yield(); } diff --git a/src/libcore/core.rc b/src/libcore/core.rc index 971f8b57170..e732bcdb2fb 100644 --- a/src/libcore/core.rc +++ b/src/libcore/core.rc @@ -41,7 +41,7 @@ export uint, u8, u16, u32, u64; export float, f32, f64; export box, char, str, ptr, vec, at_vec, bool; export either, option, result, iter; -export gc, io, libc, os, run, rand, sys, unsafe, logging; +export gc, io, libc, os, run, rand, sys, cast, logging; export comm, task, future, pipes; export extfmt; // The test harness links against core, so don't include runtime in tests. @@ -228,7 +228,7 @@ mod path; mod rand; mod run; mod sys; -mod unsafe; +mod cast; mod mutable; mod flate; mod repr; diff --git a/src/libcore/dvec.rs b/src/libcore/dvec.rs index 6f0f5c6bb06..32c40a3f66e 100644 --- a/src/libcore/dvec.rs +++ b/src/libcore/dvec.rs @@ -9,7 +9,7 @@ // // Note that recursive use is not permitted. -use unsafe::reinterpret_cast; +use cast::reinterpret_cast; use ptr::null; export DVec; @@ -81,7 +81,7 @@ fn unwrap<A>(+d: DVec<A>) -> ~[A] { priv impl<A> DVec<A> { pure fn check_not_borrowed() { unsafe { - let data: *() = unsafe::reinterpret_cast(&self.data); + let data: *() = cast::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(-~[A]) -> B) -> B { unsafe { - let mut data = unsafe::reinterpret_cast(&null::<()>()); + let mut data = cast::reinterpret_cast(&null::<()>()); data <-> self.data; - let data_ptr: *() = unsafe::reinterpret_cast(&data); + let data_ptr: *() = cast::reinterpret_cast(&data); if data_ptr.is_null() { fail ~"Recursive use of dvec"; } return f(move data); } @@ -168,9 +168,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 = cast::reinterpret_cast(&null::<()>()); data <-> self.data; - let data_ptr: *() = unsafe::reinterpret_cast(&data); + let data_ptr: *() = cast::reinterpret_cast(&data); if data_ptr.is_null() { fail ~"Recursive use of dvec"; } log(error, ~"a"); self.data <- ~[move t]; diff --git a/src/libcore/future.rs b/src/libcore/future.rs index 94f7aa8f3c5..5cd8dd237e0 100644 --- a/src/libcore/future.rs +++ b/src/libcore/future.rs @@ -17,7 +17,7 @@ use either::Either; use pipes::recv; -use unsafe::copy_lifetime; +use cast::copy_lifetime; export Future; export extensions; diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs index 94bf4808352..b1432bc39f5 100644 --- a/src/libcore/gc.rs +++ b/src/libcore/gc.rs @@ -55,14 +55,14 @@ extern mod rustrt { } unsafe fn bump<T, U>(ptr: *T, count: uint) -> *U { - return unsafe::reinterpret_cast(&ptr::offset(ptr, count)); + return cast::reinterpret_cast(&ptr::offset(ptr, count)); } unsafe fn align_to_pointer<T>(ptr: *T) -> *T { let align = sys::min_align_of::<*T>(); - let ptr: uint = unsafe::reinterpret_cast(&ptr); + let ptr: uint = cast::reinterpret_cast(&ptr); let ptr = (ptr + (align - 1)) & -align; - return unsafe::reinterpret_cast(&ptr); + return cast::reinterpret_cast(&ptr); } unsafe fn get_safe_point_count() -> uint { @@ -101,8 +101,8 @@ type Visitor = fn(root: **Word, tydesc: *Word) -> bool; // Walks the list of roots for the given safe point, and calls visitor // on each root. unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) { - let fp_bytes: *u8 = unsafe::reinterpret_cast(&fp); - let sp_meta: *u32 = unsafe::reinterpret_cast(&sp.sp_meta); + let fp_bytes: *u8 = cast::reinterpret_cast(&fp); + let sp_meta: *u32 = cast::reinterpret_cast(&sp.sp_meta); let num_stack_roots = *sp_meta as uint; let num_reg_roots = *ptr::offset(sp_meta, 1) as uint; @@ -143,9 +143,9 @@ unsafe fn walk_safe_point(fp: *Word, sp: SafePoint, visitor: Visitor) { // Is fp contained in segment? unsafe fn is_frame_in_segment(fp: *Word, segment: *StackSegment) -> bool { - let begin: Word = unsafe::reinterpret_cast(&segment); - let end: Word = unsafe::reinterpret_cast(&(*segment).end); - let frame: Word = unsafe::reinterpret_cast(&fp); + let begin: Word = cast::reinterpret_cast(&segment); + let end: Word = cast::reinterpret_cast(&(*segment).end); + let frame: Word = cast::reinterpret_cast(&fp); return begin <= frame && frame <= end; } @@ -315,7 +315,7 @@ fn cleanup_stack_for_failure() { // own stack roots on the stack anyway. let sentinel_box = ~0; let sentinel: **Word = if expect_sentinel() { - unsafe::reinterpret_cast(&ptr::addr_of(sentinel_box)) + cast::reinterpret_cast(&ptr::addr_of(sentinel_box)) } else { ptr::null() }; diff --git a/src/libcore/io.rs b/src/libcore/io.rs index ed87816a01b..54304658fd1 100644 --- a/src/libcore/io.rs +++ b/src/libcore/io.rs @@ -721,7 +721,7 @@ fn with_str_writer(f: fn(Writer)) -> ~str { vec::push(v, 0); assert str::is_utf8(v); - unsafe { move ::unsafe::transmute(v) } + unsafe { move ::cast::transmute(v) } } // Utility functions diff --git a/src/libcore/mutable.rs b/src/libcore/mutable.rs index 354bb686fef..506da9d3909 100644 --- a/src/libcore/mutable.rs +++ b/src/libcore/mutable.rs @@ -13,7 +13,7 @@ mutation when the data structure should be immutable. #[forbid(deprecated_pattern)]; use util::with; -use unsafe::transmute_immut; +use cast::transmute_immut; export Mut; diff --git a/src/libcore/os.rs b/src/libcore/os.rs index 27b8f65a133..3a15179e0c6 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -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>() == cast::reinterpret_cast(&s) { option::None::<~str> } else { - let s = unsafe::reinterpret_cast(&s); + let s = cast::reinterpret_cast(&s); option::Some::<~str>(str::raw::from_buf(s)) }; } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index e416bfced8f..3adb77873c2 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -77,7 +77,7 @@ bounded and unbounded protocols allows for less code duplication. #[forbid(deprecated_pattern)]; use cmp::Eq; -use unsafe::{forget, reinterpret_cast, transmute}; +use cast::{forget, reinterpret_cast, transmute}; use either::{Either, Left, Right}; use option::unwrap; diff --git a/src/libcore/private.rs b/src/libcore/private.rs index 06b380abac3..a5db84a9b06 100644 --- a/src/libcore/private.rs +++ b/src/libcore/private.rs @@ -89,8 +89,8 @@ unsafe fn chan_from_global_ptr<T: Send>( // Install the channel log(debug,~"BEFORE COMPARE AND SWAP"); let swapped = compare_and_swap( - unsafe::reinterpret_cast(&global), - 0u, unsafe::reinterpret_cast(&ch)); + cast::reinterpret_cast(&global), + 0u, cast::reinterpret_cast(&ch)); log(debug,fmt!("AFTER .. swapped? %?", swapped)); if swapped { @@ -100,11 +100,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) + cast::reinterpret_cast(&*global) } } else { log(debug, ~"global != 0"); - unsafe::reinterpret_cast(&*global) + cast::reinterpret_cast(&*global) } } @@ -211,7 +211,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(cast::reinterpret_cast(&ch)); } let _unweaken = Unweaken(ch); f(po); @@ -219,7 +219,7 @@ unsafe fn weaken_task(f: fn(comm::Port<()>)) { struct Unweaken { ch: comm::Chan<()>, drop unsafe { - rustrt::rust_task_unweaken(unsafe::reinterpret_cast(&self.ch)); + rustrt::rust_task_unweaken(cast::reinterpret_cast(&self.ch)); } } @@ -309,7 +309,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> = cast::reinterpret_cast(&self.data); let new_count = rustrt::rust_atomic_decrement(&mut data.count); assert new_count >= 0; if new_count == 0 { @@ -319,14 +319,14 @@ 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); + cast::reinterpret_cast(&data.unwrapper); let (message, response) = option::swap_unwrap(p); // Send 'ready' and wait for a response. pipes::send_one(move message, ()); // Unkillable wait. Message guaranteed to come. if pipes::recv_one(move response) { // Other task got the data. - unsafe::forget(move data); + cast::forget(move data); } else { // Other task was killed. drop glue takes over. } @@ -334,7 +334,7 @@ struct ArcDestruct<T> { // drop glue takes over. } } else { - unsafe::forget(move data); + cast::forget(move data); } } } @@ -359,7 +359,7 @@ unsafe fn unwrap_shared_mutable_state<T: Send>(+rc: SharedMutableState<T>) pipes::send_one(move response, false); // Either this swap_unwrap or the one below (at "Got here") // ought to run. - unsafe::forget(option::swap_unwrap(&mut self.ptr)); + cast::forget(option::swap_unwrap(&mut self.ptr)); } else { assert self.ptr.is_none(); pipes::send_one(move response, true); @@ -368,11 +368,11 @@ 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> = cast::reinterpret_cast(&rc.data); let (c1,p1) = pipes::oneshot(); // () let (c2,p2) = pipes::oneshot(); // bool let server: UnwrapProto = ~mut Some((move c1,move p2)); - let serverp: libc::uintptr_t = unsafe::transmute(move server); + let serverp: libc::uintptr_t = cast::transmute(move server); // Try to put our server end in the unwrapper slot. if rustrt::rust_compare_and_swap_ptr(&mut ptr.unwrapper, 0, serverp) { // Got in. Step 0: Tell destructor not to run. We are now it. @@ -383,7 +383,7 @@ unsafe fn unwrap_shared_mutable_state<T: Send>(+rc: SharedMutableState<T>) if new_count == 0 { // We were the last owner. Can unwrap immediately. // Also we have to free the server endpoints. - let _server: UnwrapProto = unsafe::transmute(move serverp); + let _server: UnwrapProto = cast::transmute(move serverp); option::swap_unwrap(&mut ptr.data) // drop glue takes over. } else { @@ -403,9 +403,9 @@ unsafe fn unwrap_shared_mutable_state<T: Send>(+rc: SharedMutableState<T>) } } else { // Somebody else was trying to unwrap. Avoid guaranteed deadlock. - unsafe::forget(move ptr); + cast::forget(move ptr); // Also we have to free the (rejected) server endpoints. - let _server: UnwrapProto = unsafe::transmute(move serverp); + let _server: UnwrapProto = cast::transmute(move serverp); fail ~"Another task is already unwrapping this ARC!"; } } @@ -422,7 +422,7 @@ type SharedMutableState<T: Send> = ArcDestruct<T>; unsafe fn shared_mutable_state<T: Send>(+data: T) -> SharedMutableState<T> { let data = ~ArcData { count: 1, unwrapper: 0, data: Some(move data) }; unsafe { - let ptr = unsafe::transmute(move data); + let ptr = cast::transmute(move data); ArcDestruct(ptr) } } @@ -431,23 +431,23 @@ 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> = cast::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)); - unsafe::forget(move ptr); - return unsafe::transmute_mut(r); + let r = cast::transmute_region(option::get_ref(&ptr.data)); + cast::forget(move ptr); + return cast::transmute_mut(r); } } #[inline(always)] 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> = cast::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)); - unsafe::forget(move ptr); + let r = cast::transmute_region(option::get_ref(&ptr.data)); + cast::forget(move ptr); return r; } } @@ -455,10 +455,10 @@ 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> = cast::reinterpret_cast(&(*rc).data); let new_count = rustrt::rust_atomic_increment(&mut ptr.count); assert new_count >= 2; - unsafe::forget(move ptr); + cast::forget(move ptr); } ArcDestruct((*rc).data) } @@ -543,7 +543,7 @@ impl<T: Send> Exclusive<T> { #[inline(always)] unsafe fn with_imm<U>(f: fn(x: &T) -> U) -> U { do self.with |x| { - f(unsafe::transmute_immut(x)) + f(cast::transmute_immut(x)) } } } diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 58ccc89e88f..31c52f0b407 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -53,7 +53,7 @@ pure fn addr_of<T>(val: T) -> *T { unsafe { rusti::addr_of(val) } } #[inline(always)] pure fn mut_addr_of<T>(val: T) -> *mut T { unsafe { - unsafe::reinterpret_cast(&rusti::addr_of(val)) + cast::reinterpret_cast(&rusti::addr_of(val)) } } @@ -97,11 +97,11 @@ 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 { cast::reinterpret_cast(&0u) } } /// Create an unsafe mutable null pointer #[inline(always)] -pure fn mut_null<T>() -> *mut T { unsafe { unsafe::reinterpret_cast(&0u) } } +pure fn mut_null<T>() -> *mut T { unsafe { cast::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() } @@ -147,7 +147,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 { cast::reinterpret_cast(&thing) } } /** @@ -157,7 +157,7 @@ fn to_unsafe_ptr<T>(thing: &T) -> *T { */ #[inline(always)] fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T { - unsafe { unsafe::reinterpret_cast(&thing) } + unsafe { cast::reinterpret_cast(&thing) } } /** @@ -167,7 +167,7 @@ fn to_const_unsafe_ptr<T>(thing: &const T) -> *const T { */ #[inline(always)] fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T { - unsafe { unsafe::reinterpret_cast(&thing) } + unsafe { cast::reinterpret_cast(&thing) } } /** @@ -179,7 +179,7 @@ fn to_mut_unsafe_ptr<T>(thing: &mut T) -> *mut T { */ #[inline(always)] fn to_uint<T>(thing: &T) -> uint unsafe { - unsafe::reinterpret_cast(&thing) + cast::reinterpret_cast(&thing) } /// Determine if two borrowed pointers point to the same thing. @@ -205,8 +205,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 = cast::reinterpret_cast(&self); + let b: uint = cast::reinterpret_cast(&other); return a == b; } pure fn ne(&&other: *const T) -> bool { !self.eq(other) } @@ -215,23 +215,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 = cast::reinterpret_cast(&self); + let b: uint = cast::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 = cast::reinterpret_cast(&self); + let b: uint = cast::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 = cast::reinterpret_cast(&self); + let b: uint = cast::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 = cast::reinterpret_cast(&self); + let b: uint = cast::reinterpret_cast(&other); return a > b; } } @@ -256,7 +256,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 = cast::reinterpret_cast(&pptr); assert (*iptr == 10);; *iptr = 30; assert (*iptr == 30); diff --git a/src/libcore/repr.rs b/src/libcore/repr.rs index c5eb8dc3140..55866cbdc52 100644 --- a/src/libcore/repr.rs +++ b/src/libcore/repr.rs @@ -3,7 +3,7 @@ use io::{Writer, WriterUtil}; use libc::c_void; use sys::TypeDesc; use to_str::ToStr; -use unsafe::transmute; +use cast::transmute; use intrinsic::{TyDesc, TyVisitor, visit_tydesc}; use reflect::{MovePtr, MovePtrAdaptor}; use vec::raw::{VecRepr, UnboxedVecRepr, SliceRepr}; @@ -981,7 +981,7 @@ pub fn write_repr<T>(writer: @Writer, object: &T) { unsafe { let ptr = ptr::to_unsafe_ptr(object) as *c_void; let tydesc = sys::get_type_desc::<T>(); - let tydesc = unsafe::transmute(tydesc); + let tydesc = cast::transmute(tydesc); let repr_printer = @ReprPrinter { ptr: ptr, diff --git a/src/libcore/run.rs b/src/libcore/run.rs index b99f3402ee5..cc93d30ecd6 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -113,7 +113,7 @@ fn with_envp<T>(env: &Option<~[(~str,~str)]>, } vec::push(ptrs, ptr::null()); vec::as_imm_buf(ptrs, |p, _len| - unsafe { cb(::unsafe::reinterpret_cast(&p)) } + unsafe { cb(::cast::reinterpret_cast(&p)) } ) } _ => cb(ptr::null()) diff --git a/src/libcore/send_map.rs b/src/libcore/send_map.rs index 4ddd16a52f5..28b36deb1d4 100644 --- a/src/libcore/send_map.rs +++ b/src/libcore/send_map.rs @@ -289,7 +289,7 @@ mod linear { // inference stupidly infers a // lifetime for `ref bkt` that is // shorter than it needs to be. - unsafe::copy_lifetime(self, &bkt.value) + cast::copy_lifetime(self, &bkt.value) }; Some(ptr) } diff --git a/src/libcore/stackwalk.rs b/src/libcore/stackwalk.rs index 6248fa46ff8..3a07186b011 100644 --- a/src/libcore/stackwalk.rs +++ b/src/libcore/stackwalk.rs @@ -1,6 +1,6 @@ // NB: Don't rely on other core mods here as this has to move into the rt -use unsafe::reinterpret_cast; +use cast::reinterpret_cast; use ptr::offset; use sys::size_of; diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 6a5f14f2c61..d785da3a462 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -149,7 +149,7 @@ pure fn from_slice(s: &str) -> ~str { */ pure fn from_byte(b: u8) -> ~str { assert b < 128u8; - unsafe { ::unsafe::transmute(~[b, 0u8]) } + unsafe { ::cast::transmute(~[b, 0u8]) } } /// Appends a character at the end of a string @@ -167,7 +167,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 = ::cast::reinterpret_cast(&buf); if nb == 1u { *ptr::mut_offset(buf, off) = code as u8; @@ -250,7 +250,7 @@ fn push_str_no_overallocate(&lhs: ~str, rhs: &str) { do as_buf(lhs) |lbuf, _llen| { do as_buf(rhs) |rbuf, _rlen| { let dst = ptr::offset(lbuf, llen); - let dst = ::unsafe::transmute_mut_unsafe(dst); + let dst = ::cast::transmute_mut_unsafe(dst); ptr::memcpy(dst, rbuf, rlen); } } @@ -267,7 +267,7 @@ fn push_str(&lhs: ~str, rhs: &str) { do as_buf(lhs) |lbuf, _llen| { do as_buf(rhs) |rbuf, _rlen| { let dst = ptr::offset(lbuf, llen); - let dst = ::unsafe::transmute_mut_unsafe(dst); + let dst = ::cast::transmute_mut_unsafe(dst); ptr::memcpy(dst, rbuf, rlen); } } @@ -438,7 +438,7 @@ Section: Transforming strings * The result vector is not null-terminated. */ pure fn to_bytes(s: &str) -> ~[u8] unsafe { - let mut v: ~[u8] = ::unsafe::transmute(from_slice(s)); + let mut v: ~[u8] = ::cast::transmute(from_slice(s)); vec::raw::set_len(v, len(s)); move v } @@ -1820,7 +1820,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] = ::cast::reinterpret_cast(&ptr::addr_of(s)); f(*v) } } @@ -1832,9 +1832,9 @@ pure fn as_bytes<T>(s: ~str, f: fn(~[u8]) -> T) -> T { */ pure fn as_bytes_slice(s: &a/str) -> &a/[u8] { unsafe { - let (ptr, len): (*u8, uint) = ::unsafe::reinterpret_cast(&s); + let (ptr, len): (*u8, uint) = ::cast::reinterpret_cast(&s); let outgoing_tuple: (*u8, uint) = (ptr, len - 1); - return ::unsafe::reinterpret_cast(&outgoing_tuple); + return ::cast::reinterpret_cast(&outgoing_tuple); } } @@ -1877,7 +1877,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) = ::cast::reinterpret_cast(&ptr::addr_of(s)); let (buf,len) = *v; f(buf, len) } @@ -1901,7 +1901,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] = ::cast::reinterpret_cast(&ptr::addr_of(s)); vec::reserve(*v, n + 1); } } @@ -1993,24 +1993,24 @@ mod raw { let mut v: ~[mut u8] = ~[mut]; vec::reserve(v, len + 1u); vec::as_imm_buf(v, |vbuf, _len| { - let vbuf = ::unsafe::transmute_mut_unsafe(vbuf); + let vbuf = ::cast::transmute_mut_unsafe(vbuf); ptr::memcpy(vbuf, buf as *u8, len) }); vec::raw::set_len(v, len); vec::push(v, 0u8); assert is_utf8(v); - return ::unsafe::transmute(move v); + return ::cast::transmute(move 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(::cast::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(::cast::reinterpret_cast(&c_str), len) } /// Converts a vector of bytes to a string. @@ -2026,8 +2026,8 @@ mod raw { /// Form a slice from a *u8 buffer of the given length without copying. unsafe fn buf_as_slice<T>(buf: *u8, len: uint, f: fn(&& &str) -> T) -> T { let v = (*buf, len + 1); - assert is_utf8(::unsafe::reinterpret_cast(&v)); - f(::unsafe::transmute(move v)) + assert is_utf8(::cast::reinterpret_cast(&v)); + f(::cast::transmute(move v)) } /** @@ -2049,13 +2049,13 @@ mod raw { vec::reserve(v, end - begin + 1u); unsafe { do vec::as_imm_buf(v) |vbuf, _vlen| { - let vbuf = ::unsafe::transmute_mut_unsafe(vbuf); + let vbuf = ::cast::transmute_mut_unsafe(vbuf); let src = ptr::offset(sbuf, begin); ptr::memcpy(vbuf, src, end - begin); } vec::raw::set_len(v, end - begin); vec::push(v, 0u8); - ::unsafe::transmute(move v) + ::cast::transmute(move v) } } } @@ -2077,7 +2077,7 @@ mod raw { assert (end <= n); let tuple = (ptr::offset(sbuf, begin), end - begin + 1); - ::unsafe::reinterpret_cast(&tuple) + ::cast::reinterpret_cast(&tuple) } } @@ -2085,7 +2085,7 @@ mod raw { 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 = ::cast::reinterpret_cast(&buf); *ptr::mut_offset(buf, len) = b; } set_len(s, s.len() + 1); @@ -2117,7 +2117,7 @@ mod raw { /// Sets the length of the string and adds the null terminator unsafe fn set_len(&v: ~str, new_len: uint) { - let repr: *vec::raw::VecRepr = ::unsafe::reinterpret_cast(&v); + let repr: *vec::raw::VecRepr = ::cast::reinterpret_cast(&v); (*repr).unboxed.fill = new_len + 1u; let null = ptr::mut_offset(ptr::mut_addr_of((*repr).unboxed.data), new_len); diff --git a/src/libcore/sys.rs b/src/libcore/sys.rs index ca3eef41996..35baa0e6a5a 100644 --- a/src/libcore/sys.rs +++ b/src/libcore/sys.rs @@ -92,7 +92,7 @@ pure fn pref_align_of<T>() -> uint { #[inline(always)] pure fn refcount<T>(+t: @T) -> uint { unsafe { - let ref_ptr: *uint = unsafe::reinterpret_cast(&t); + let ref_ptr: *uint = cast::reinterpret_cast(&t); *ref_ptr - 1 } } @@ -160,7 +160,7 @@ mod tests { assert f(20) == 30; - let original_closure: Closure = unsafe::transmute(f); + let original_closure: Closure = cast::transmute(f); let actual_function_pointer = original_closure.code; let environment = original_closure.env; @@ -170,7 +170,7 @@ mod tests { env: environment }; - let new_f: fn(int) -> int = unsafe::transmute(new_closure); + let new_f: fn(int) -> int = cast::transmute(new_closure); assert new_f(20) == 30; } } diff --git a/src/libcore/task.rs b/src/libcore/task.rs index 0ee5a89cb63..adeebcf344e 100644 --- a/src/libcore/task.rs +++ b/src/libcore/task.rs @@ -1206,7 +1206,7 @@ fn kill_taskgroup(state: TaskGroupInner, me: *rust_task, is_main: bool) { // a proper closure because the #[test]s won't understand. Have to fake it. macro_rules! taskgroup_key ( // Use a "code pointer" value that will never be a real code pointer. - () => (unsafe::transmute((-2 as uint, 0u))) + () => (cast::transmute((-2 as uint, 0u))) ) fn gen_child_taskgroup(linked: bool, supervised: bool) @@ -1313,13 +1313,13 @@ fn spawn_raw(+opts: TaskOpts, +f: fn~()) { let child_wrapper = make_child_wrapper(new_task, move child_tg, move ancestors, is_main, move notify_chan, move f); let fptr = ptr::addr_of(child_wrapper); - let closure: *rust_closure = unsafe::reinterpret_cast(&fptr); + let closure: *rust_closure = cast::reinterpret_cast(&fptr); // Getting killed between these two calls would free the child's // closure. (Reordering them wouldn't help - then getting killed // between them would leak.) rustrt::start_task(new_task, closure); - unsafe::forget(move child_wrapper); + cast::forget(move child_wrapper); } } @@ -1466,8 +1466,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) = cast::reinterpret_cast(&self); + let ptr_b: (uint, uint) = cast::reinterpret_cast(&other); return ptr_a == ptr_b; } pure fn ne(&&other: LocalData) -> bool { !self.eq(other) } @@ -1482,7 +1482,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 = cast::reinterpret_cast(&map_ptr); // All local_data will be destroyed along with the map. } @@ -1498,14 +1498,14 @@ unsafe fn get_task_local_map(task: *rust_task) -> TaskLocalMap { 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)); + task, cast::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); + cast::bump_box_refcount(map); map } else { - let map = unsafe::transmute(move map_ptr); - unsafe::bump_box_refcount(map); + let map = cast::transmute(move map_ptr); + cast::bump_box_refcount(map); map } } @@ -1515,7 +1515,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) = cast::reinterpret_cast(&key); pair.first() } @@ -1550,8 +1550,8 @@ unsafe fn local_get_helper<T: Owned>( // overwriting the local_data_box we need to give an extra reference. // We must also give an extra reference when not removing. let (index, data_ptr) = result; - let data: @T = unsafe::transmute(move data_ptr); - unsafe::bump_box_refcount(data); + let data: @T = cast::transmute(move data_ptr); + cast::bump_box_refcount(data); if do_pop { (*map).set_elt(index, None); } @@ -1584,7 +1584,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 = cast::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)); @@ -2232,12 +2232,12 @@ fn test_unkillable() { unsafe { do unkillable { let p = ~0; - let pp: *uint = unsafe::transmute(p); + let pp: *uint = cast::transmute(p); // If we are killed here then the box will leak po.recv(); - let _p: ~int = unsafe::transmute(pp); + let _p: ~int = cast::transmute(pp); } } @@ -2273,12 +2273,12 @@ fn test_unkillable_nested() { do unkillable { do unkillable {} // Here's the difference from the previous test. let p = ~0; - let pp: *uint = unsafe::transmute(p); + let pp: *uint = cast::transmute(p); // If we are killed here then the box will leak po.recv(); - let _p: ~int = unsafe::transmute(pp); + let _p: ~int = cast::transmute(pp); } } diff --git a/src/libcore/vec.rs b/src/libcore/vec.rs index 843ae07c4bc..6ee360e3e13 100644 --- a/src/libcore/vec.rs +++ b/src/libcore/vec.rs @@ -168,7 +168,7 @@ fn reserve_at_least<T>(&v: ~[const T], n: uint) { #[inline(always)] pure fn capacity<T>(&&v: ~[const T]) -> uint { unsafe { - let repr: **raw::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); + let repr: **raw::VecRepr = ::cast::reinterpret_cast(&addr_of(v)); (**repr).unboxed.alloc / sys::size_of::<T>() } } @@ -271,12 +271,12 @@ pure fn build_sized_opt<A>(size: Option<uint>, /// Produces a mut vector from an immutable vector. pure fn to_mut<T>(+v: ~[T]) -> ~[mut T] { - unsafe { ::unsafe::transmute(move v) } + unsafe { ::cast::transmute(move v) } } /// Produces an immutable vector from a mut vector. pure fn from_mut<T>(+v: ~[mut T]) -> ~[T] { - unsafe { ::unsafe::transmute(move v) } + unsafe { ::cast::transmute(move v) } } // Accessors @@ -335,7 +335,7 @@ pure fn view<T>(v: &[T], start: uint, end: uint) -> &[T] { assert (end <= len(v)); do as_imm_buf(v) |p, _len| { unsafe { - ::unsafe::reinterpret_cast( + ::cast::reinterpret_cast( &(ptr::offset(p, start), (end - start) * sys::size_of::<T>())) } @@ -348,7 +348,7 @@ pure fn mut_view<T>(v: &[mut T], start: uint, end: uint) -> &[mut T] { assert (end <= len(v)); do as_mut_buf(v) |p, _len| { unsafe { - ::unsafe::reinterpret_cast( + ::cast::reinterpret_cast( &(ptr::mut_offset(p, start), (end - start) * sys::size_of::<T>())) } @@ -361,7 +361,7 @@ pure fn const_view<T>(v: &[const T], start: uint, end: uint) -> &[const T] { assert (end <= len(v)); do as_const_buf(v) |p, _len| { unsafe { - ::unsafe::reinterpret_cast( + ::cast::reinterpret_cast( &(ptr::const_offset(p, start), (end - start) * sys::size_of::<T>())) } @@ -564,7 +564,7 @@ fn swap_remove<T>(&v: ~[const T], index: uint) -> T { #[inline(always)] fn push<T>(&v: ~[const T], +initval: T) { unsafe { - let repr: **raw::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); + let repr: **raw::VecRepr = ::cast::reinterpret_cast(&addr_of(v)); let fill = (**repr).unboxed.fill; if (**repr).unboxed.alloc > fill { push_fast(v, move initval); @@ -578,7 +578,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: **raw::VecRepr = ::unsafe::reinterpret_cast(&addr_of(v)); + let repr: **raw::VecRepr = ::cast::reinterpret_cast(&addr_of(v)); let fill = (**repr).unboxed.fill; (**repr).unboxed.fill += sys::size_of::<T>(); let p = ptr::addr_of((**repr).unboxed.data); @@ -1441,7 +1441,7 @@ pure fn as_imm_buf<T,U>(s: &[T], /* NB---this CANNOT be const, see below */ unsafe { let v : *(*T,uint) = - ::unsafe::reinterpret_cast(&ptr::addr_of(s)); + ::cast::reinterpret_cast(&ptr::addr_of(s)); let (buf,len) = *v; f(buf, len / sys::size_of::<T>()) } @@ -1454,7 +1454,7 @@ pure fn as_const_buf<T,U>(s: &[const T], unsafe { let v : *(*const T,uint) = - ::unsafe::reinterpret_cast(&ptr::addr_of(s)); + ::cast::reinterpret_cast(&ptr::addr_of(s)); let (buf,len) = *v; f(buf, len / sys::size_of::<T>()) } @@ -1467,7 +1467,7 @@ pure fn as_mut_buf<T,U>(s: &[mut T], unsafe { let v : *(*mut T,uint) = - ::unsafe::reinterpret_cast(&ptr::addr_of(s)); + ::cast::reinterpret_cast(&ptr::addr_of(s)); let (buf,len) = *v; f(buf, len / sys::size_of::<T>()) } @@ -1832,7 +1832,7 @@ mod raw { */ #[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 = ::cast::reinterpret_cast(&addr_of(v)); (**repr).unboxed.fill = new_len * sys::size_of::<T>(); } @@ -1847,22 +1847,22 @@ mod raw { */ #[inline(always)] unsafe fn to_ptr<T>(v: &[T]) -> *T { - let repr: **SliceRepr = ::unsafe::reinterpret_cast(&addr_of(v)); - return ::unsafe::reinterpret_cast(&addr_of((**repr).data)); + let repr: **SliceRepr = ::cast::reinterpret_cast(&addr_of(v)); + return ::cast::reinterpret_cast(&addr_of((**repr).data)); } /** see `to_ptr()` */ #[inline(always)] unsafe fn to_const_ptr<T>(v: &[const T]) -> *const T { - let repr: **SliceRepr = ::unsafe::reinterpret_cast(&addr_of(v)); - return ::unsafe::reinterpret_cast(&addr_of((**repr).data)); + let repr: **SliceRepr = ::cast::reinterpret_cast(&addr_of(v)); + return ::cast::reinterpret_cast(&addr_of((**repr).data)); } /** see `to_ptr()` */ #[inline(always)] unsafe fn to_mut_ptr<T>(v: &[mut T]) -> *mut T { - let repr: **SliceRepr = ::unsafe::reinterpret_cast(&addr_of(v)); - return ::unsafe::reinterpret_cast(&addr_of((**repr).data)); + let repr: **SliceRepr = ::cast::reinterpret_cast(&addr_of(v)); + return ::cast::reinterpret_cast(&addr_of((**repr).data)); } /** @@ -1873,7 +1873,7 @@ mod raw { 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)); + ::cast::reinterpret_cast(&ptr::addr_of(pair)); f(*v) } |
