core: Rename 'unsafe' mod to 'cast'
This commit is contained in:
parent
77480e8e44
commit
2906f2de31
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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];
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
|
||||
use either::Either;
|
||||
use pipes::recv;
|
||||
use unsafe::copy_lifetime;
|
||||
use cast::copy_lifetime;
|
||||
|
||||
export Future;
|
||||
export extensions;
|
||||
|
|
|
@ -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()
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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))
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -359,7 +359,7 @@ impl<T: Const Send> &RWARC<T> {
|
|||
// Whatever region the input reference had, it will be safe to use
|
||||
// the same region for the output reference. (The only 'unsafe' part
|
||||
// of this cast is removing the mutability.)
|
||||
let new_data = unsafe { unsafe::transmute_immut(data) };
|
||||
let new_data = unsafe { cast::transmute_immut(data) };
|
||||
// Downgrade ensured the token belonged to us. Just a sanity check.
|
||||
assert ptr::ref_eq(&state.data, new_data);
|
||||
// Produce new token
|
||||
|
@ -390,7 +390,7 @@ fn unwrap_rw_arc<T: Const Send>(+arc: RWARC<T>) -> T {
|
|||
// field is never overwritten; only 'failed' and 'data'.
|
||||
#[doc(hidden)]
|
||||
fn borrow_rwlock<T: Const Send>(state: &r/mut RWARCInner<T>) -> &r/RWlock {
|
||||
unsafe { unsafe::transmute_immut(&mut state.lock) }
|
||||
unsafe { cast::transmute_immut(&mut state.lock) }
|
||||
}
|
||||
|
||||
// FIXME (#3154) ice with struct/&<T> prevents these from being structs.
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
export Arena, arena_with_size;
|
||||
|
||||
use list::{List, Cons, Nil};
|
||||
use unsafe::reinterpret_cast;
|
||||
use cast::reinterpret_cast;
|
||||
use sys::TypeDesc;
|
||||
use libc::size_t;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#[forbid(deprecated_pattern)];
|
||||
//! Unsafe debugging functions for inspecting values.
|
||||
|
||||
use unsafe::reinterpret_cast;
|
||||
use cast::reinterpret_cast;
|
||||
|
||||
export debug_tydesc;
|
||||
export debug_opaque;
|
||||
|
|
|
@ -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);
|
||||
cast::reinterpret_cast(&slice);
|
||||
log(info, fmt!("slice: %?",
|
||||
(base, vec::len(slice), end - base)));
|
||||
assert(vec::len(slice) == end - base);
|
||||
|
|
|
@ -807,18 +807,18 @@ mod node {
|
|||
option::Some(x) => {
|
||||
//FIXME (#2744): Replace with memcpy or something similar
|
||||
let mut local_buf: ~[u8] =
|
||||
unsafe::reinterpret_cast(&*x.content);
|
||||
cast::reinterpret_cast(&*x.content);
|
||||
let mut i = x.byte_offset;
|
||||
while i < x.byte_len {
|
||||
buf[offset] = local_buf[i];
|
||||
offset += 1u;
|
||||
i += 1u;
|
||||
}
|
||||
unsafe::forget(move local_buf);
|
||||
cast::forget(move local_buf);
|
||||
}
|
||||
}
|
||||
}
|
||||
return unsafe::transmute(move buf);
|
||||
return cast::transmute(move buf);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -779,7 +779,7 @@ mod tests {
|
|||
let ptr = ptr::addr_of(*sharedstate);
|
||||
do task::spawn {
|
||||
let sharedstate: &mut int =
|
||||
unsafe { unsafe::reinterpret_cast(&ptr) };
|
||||
unsafe { cast::reinterpret_cast(&ptr) };
|
||||
access_shared(sharedstate, m2, 10);
|
||||
c.send(());
|
||||
|
||||
|
@ -1051,7 +1051,7 @@ mod tests {
|
|||
let ptr = ptr::addr_of(*sharedstate);
|
||||
do task::spawn {
|
||||
let sharedstate: &mut int =
|
||||
unsafe { unsafe::reinterpret_cast(&ptr) };
|
||||
unsafe { cast::reinterpret_cast(&ptr) };
|
||||
access_shared(sharedstate, x2, mode1, 10);
|
||||
c.send(());
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ type spanned<T> = {node: T, span: span};
|
|||
/* can't import macros yet, so this is copied from token.rs. See its comment
|
||||
* there. */
|
||||
macro_rules! interner_key (
|
||||
() => (unsafe::transmute::<(uint, uint), &fn(+@@token::ident_interner)>(
|
||||
() => (cast::transmute::<(uint, uint), &fn(+@@token::ident_interner)>(
|
||||
(-3 as uint, 0u)))
|
||||
)
|
||||
|
||||
|
|
|
@ -330,7 +330,7 @@ type ident_interner = util::interner::interner<@~str>;
|
|||
* so we have to use a unique number. See taskgroup_key! in task.rs
|
||||
* for another case of this. */
|
||||
macro_rules! interner_key (
|
||||
() => (unsafe::transmute::<(uint, uint), &fn(+@@token::ident_interner)>(
|
||||
() => (cast::transmute::<(uint, uint), &fn(+@@token::ident_interner)>(
|
||||
(-3 as uint, 0u)))
|
||||
)
|
||||
|
||||
|
|
|
@ -96,7 +96,7 @@ mod jit {
|
|||
code: ptr,
|
||||
env: ptr::null()
|
||||
};
|
||||
let func: fn(~[~str]) = unsafe::transmute(move closure);
|
||||
let func: fn(~[~str]) = cast::transmute(move closure);
|
||||
|
||||
func(~[sess.opts.binary]);
|
||||
}
|
||||
|
|
|
@ -187,7 +187,7 @@ fn get_metadata_section(os: os,
|
|||
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
|
||||
let mut found = None;
|
||||
unsafe {
|
||||
let cvbuf: *u8 = unsafe::reinterpret_cast(&cbuf);
|
||||
let cvbuf: *u8 = cast::reinterpret_cast(&cbuf);
|
||||
let vlen = vec::len(encoder::metadata_encoding_version);
|
||||
debug!("checking %u bytes of metadata-version stamp",
|
||||
vlen);
|
||||
|
|
|
@ -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 cast::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 = cast::reinterpret_cast(&ptr::addr_of(val));
|
||||
let bbptr = cast::reinterpret_cast(&ptr::addr_of(bb));
|
||||
llvm::LLVMAddIncoming(phi, valptr, bbptr, 1 as c_uint);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1075,13 +1075,13 @@ fn C_array(ty: TypeRef, elts: ~[ValueRef]) -> ValueRef unsafe {
|
|||
|
||||
fn C_bytes(bytes: ~[u8]) -> ValueRef unsafe {
|
||||
return llvm::LLVMConstString(
|
||||
unsafe::reinterpret_cast(&vec::raw::to_ptr(bytes)),
|
||||
cast::reinterpret_cast(&vec::raw::to_ptr(bytes)),
|
||||
bytes.len() as c_uint, True);
|
||||
}
|
||||
|
||||
fn C_bytes_plus_null(bytes: ~[u8]) -> ValueRef unsafe {
|
||||
return llvm::LLVMConstString(
|
||||
unsafe::reinterpret_cast(&vec::raw::to_ptr(bytes)),
|
||||
cast::reinterpret_cast(&vec::raw::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>())
|
||||
cast::reinterpret_cast(&ptr::null::<ValueRef>())
|
||||
}
|
||||
|
||||
fn add_named_metadata(cx: @crate_ctxt, name: ~str, val: ValueRef) {
|
||||
|
@ -131,7 +131,7 @@ enum debug_metadata {
|
|||
|
||||
fn cast_safely<T: Copy, U>(val: T) -> U unsafe {
|
||||
let val2 = val;
|
||||
return unsafe::transmute(move val2);
|
||||
return cast::transmute(move val2);
|
||||
}
|
||||
|
||||
fn md_from_metadata<T>(val: debug_metadata) -> T unsafe {
|
||||
|
|
|
@ -382,9 +382,9 @@ 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 = cast::reinterpret_cast::<t, t_box>(&t);
|
||||
let t3 = t2;
|
||||
unsafe::forget(move t2);
|
||||
cast::forget(move t2);
|
||||
t3
|
||||
}
|
||||
|
||||
|
@ -886,7 +886,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 = {sty: st, o_def_id: o_def_id};
|
||||
match cx.interner.find(key) {
|
||||
Some(t) => unsafe { return unsafe::reinterpret_cast(&t); },
|
||||
Some(t) => unsafe { return cast::reinterpret_cast(&t); },
|
||||
_ => ()
|
||||
}
|
||||
let mut flags = 0u;
|
||||
|
@ -944,7 +944,7 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option<ast::def_id>) -> t {
|
|||
let t = @{sty: 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 { cast::reinterpret_cast(&t) }
|
||||
}
|
||||
|
||||
fn mk_nil(cx: ctxt) -> t { mk_t(cx, ty_nil) }
|
||||
|
|
|
@ -9,7 +9,7 @@ export from_srv, extract, to_str, interner;
|
|||
/* can't import macros yet, so this is copied from token.rs. See its comment
|
||||
* there. */
|
||||
macro_rules! interner_key (
|
||||
() => (unsafe::transmute::<(uint, uint),
|
||||
() => (cast::transmute::<(uint, uint),
|
||||
&fn(+@@syntax::parse::token::ident_interner)>((-3 as uint, 0u)))
|
||||
)
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ fn failfn() {
|
|||
struct r {
|
||||
v: *int,
|
||||
drop unsafe {
|
||||
let _v2: ~int = unsafe::reinterpret_cast(&self.v);
|
||||
let _v2: ~int = cast::reinterpret_cast(&self.v);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,8 @@ fn r(v: *int) -> r {
|
|||
|
||||
fn main() unsafe {
|
||||
let i1 = ~0;
|
||||
let i1p = unsafe::reinterpret_cast(&i1);
|
||||
unsafe::forget(i1);
|
||||
let i1p = cast::reinterpret_cast(&i1);
|
||||
cast::forget(i1);
|
||||
let x = @r(i1p);
|
||||
failfn();
|
||||
log(error, x);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Binop corner cases
|
||||
|
||||
extern mod std;
|
||||
use unsafe::reinterpret_cast;
|
||||
use cast::reinterpret_cast;
|
||||
|
||||
fn test_nil() {
|
||||
assert (() == ());
|
||||
|
@ -56,9 +56,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 = cast::reinterpret_cast(&0);
|
||||
let p2: *u8 = cast::reinterpret_cast(&0);
|
||||
let p3: *u8 = cast::reinterpret_cast(&1);
|
||||
|
||||
assert p1 == p2;
|
||||
assert p1 != p3;
|
||||
|
@ -102,8 +102,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))));
|
||||
(cast::reinterpret_cast::<*p, uint>(&ptr::addr_of(q))),
|
||||
(cast::reinterpret_cast::<*p, uint>(&ptr::addr_of(r))));
|
||||
}
|
||||
assert(q == r);
|
||||
r.y = 17;
|
||||
|
|
|
@ -5,7 +5,7 @@ extern mod rustrt {
|
|||
fn main() {
|
||||
unsafe {
|
||||
let x = @3;
|
||||
let p: *uint = unsafe::transmute(x);
|
||||
let p: *uint = cast::transmute(x);
|
||||
rustrt::rust_annihilate_box(p);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ extern mod rustrt {
|
|||
fn main() {
|
||||
unsafe {
|
||||
let x = ~[~"a", ~"b", ~"c"];
|
||||
let p: *uint = unsafe::transmute(x);
|
||||
let p: *uint = cast::transmute(x);
|
||||
rustrt::rust_annihilate_box(p);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ extern mod rustrt {
|
|||
fn main() {
|
||||
unsafe {
|
||||
let x = ~3;
|
||||
let p: *uint = unsafe::transmute(x);
|
||||
let p: *uint = cast::transmute(x);
|
||||
rustrt::rust_annihilate_box(p);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ use libc::{c_double, c_int};
|
|||
use f64::*;
|
||||
|
||||
fn to_c_int(v: &mut int) -> &mut c_int unsafe {
|
||||
unsafe::reinterpret_cast(&v)
|
||||
cast::reinterpret_cast(&v)
|
||||
}
|
||||
|
||||
fn lgamma(n: c_double, value: &mut int) -> c_double {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
mod pipes {
|
||||
use unsafe::{forget, transmute};
|
||||
use cast::{forget, transmute};
|
||||
|
||||
enum state {
|
||||
empty,
|
||||
|
@ -22,7 +22,7 @@ mod pipes {
|
|||
};
|
||||
|
||||
fn packet<T: Send>() -> *packet<T> unsafe {
|
||||
let p: *packet<T> = unsafe::transmute(~{
|
||||
let p: *packet<T> = cast::transmute(~{
|
||||
mut state: empty,
|
||||
mut blocked_task: None::<task::Task>,
|
||||
mut payload: None::<T>
|
||||
|
@ -40,7 +40,7 @@ mod pipes {
|
|||
// We should consider moving this to core::unsafe, although I
|
||||
// suspect graydon would want us to use void pointers instead.
|
||||
unsafe fn uniquify<T>(+x: *T) -> ~T {
|
||||
unsafe { unsafe::transmute(x) }
|
||||
unsafe { cast::transmute(x) }
|
||||
}
|
||||
|
||||
fn swap_state_acq(+dst: &mut state, src: state) -> state {
|
||||
|
@ -198,19 +198,19 @@ mod pingpong {
|
|||
|
||||
fn liberate_ping(-p: ping) -> pipes::send_packet<pong> unsafe {
|
||||
let addr : *pipes::send_packet<pong> = match p {
|
||||
ping(x) => { unsafe::transmute(ptr::addr_of(x)) }
|
||||
ping(x) => { cast::transmute(ptr::addr_of(x)) }
|
||||
};
|
||||
let liberated_value <- *addr;
|
||||
unsafe::forget(p);
|
||||
cast::forget(p);
|
||||
liberated_value
|
||||
}
|
||||
|
||||
fn liberate_pong(-p: pong) -> pipes::send_packet<ping> unsafe {
|
||||
let addr : *pipes::send_packet<ping> = match p {
|
||||
pong(x) => { unsafe::transmute(ptr::addr_of(x)) }
|
||||
pong(x) => { cast::transmute(ptr::addr_of(x)) }
|
||||
};
|
||||
let liberated_value <- *addr;
|
||||
unsafe::forget(p);
|
||||
cast::forget(p);
|
||||
liberated_value
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
extern mod std;
|
||||
use libc, sys, unsafe;
|
||||
use libc, sys, cast;
|
||||
use std::arena::Arena;
|
||||
|
||||
type bcx = {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
use libc, sys, unsafe;
|
||||
use libc, sys, cast;
|
||||
|
||||
enum arena = ();
|
||||
|
||||
|
@ -16,7 +16,7 @@ type ccx = {
|
|||
};
|
||||
|
||||
fn alloc(_bcx : &arena) -> &bcx unsafe {
|
||||
return unsafe::reinterpret_cast(
|
||||
return cast::reinterpret_cast(
|
||||
&libc::malloc(sys::size_of::<bcx/&blk>() as libc::size_t));
|
||||
}
|
||||
|
||||
|
@ -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(cast::reinterpret_cast(&bcx2));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -4,10 +4,10 @@ struct r {
|
|||
v: *int,
|
||||
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); }
|
||||
cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(self)),
|
||||
cast::reinterpret_cast::<**int, uint>(&ptr::addr_of(self.v)),
|
||||
cast::reinterpret_cast::<*int, uint>(&self.v));
|
||||
let v2: ~int = cast::reinterpret_cast(&self.v); }
|
||||
}
|
||||
|
||||
fn r(v: *int) -> r unsafe {
|
||||
|
@ -23,38 +23,38 @@ enum t = {
|
|||
|
||||
fn main() unsafe {
|
||||
let i1 = ~0;
|
||||
let i1p = unsafe::reinterpret_cast(&i1);
|
||||
unsafe::forget(i1);
|
||||
let i1p = cast::reinterpret_cast(&i1);
|
||||
cast::forget(i1);
|
||||
let i2 = ~0;
|
||||
let i2p = unsafe::reinterpret_cast(&i2);
|
||||
unsafe::forget(i2);
|
||||
let i2p = cast::reinterpret_cast(&i2);
|
||||
cast::forget(i2);
|
||||
|
||||
let x1 = @t({
|
||||
mut next: None,
|
||||
r: {
|
||||
let rs = r(i1p);
|
||||
debug!("r = %x",
|
||||
unsafe::reinterpret_cast::<*r, uint>(&ptr::addr_of(rs)));
|
||||
cast::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)));
|
||||
cast::reinterpret_cast::<@t, uint>(&x1),
|
||||
cast::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)));
|
||||
cast::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)));
|
||||
cast::reinterpret_cast::<@t, uint>(&x2),
|
||||
cast::reinterpret_cast::<*r, uint>(&ptr::addr_of(x2.r)));
|
||||
|
||||
x1.next = Some(x2);
|
||||
x2.next = Some(x1);
|
||||
|
|
|
@ -9,7 +9,7 @@ type u = {
|
|||
struct r {
|
||||
v: u,
|
||||
drop unsafe {
|
||||
let v2: ~int = unsafe::reinterpret_cast(&self.v.c);
|
||||
let v2: ~int = cast::reinterpret_cast(&self.v.c);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,11 +26,11 @@ enum t = {
|
|||
|
||||
fn main() unsafe {
|
||||
let i1 = ~0xA;
|
||||
let i1p = unsafe::reinterpret_cast(&i1);
|
||||
unsafe::forget(i1);
|
||||
let i1p = cast::reinterpret_cast(&i1);
|
||||
cast::forget(i1);
|
||||
let i2 = ~0xA;
|
||||
let i2p = unsafe::reinterpret_cast(&i2);
|
||||
unsafe::forget(i2);
|
||||
let i2p = cast::reinterpret_cast(&i2);
|
||||
cast::forget(i2);
|
||||
|
||||
let u1 = {a: 0xB, b: 0xC, c: i1p};
|
||||
let u2 = {a: 0xB, b: 0xC, c: i2p};
|
||||
|
|
|
@ -13,7 +13,7 @@ struct r {
|
|||
w: int,
|
||||
x: *int,
|
||||
drop unsafe {
|
||||
let _v2: ~int = unsafe::reinterpret_cast(&self.v.c);
|
||||
let _v2: ~int = cast::reinterpret_cast(&self.v.c);
|
||||
// let _v3: ~int = unsafe::reinterpret_cast(self.x);
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ fn r(v: u, w: int, _x: *int) -> r unsafe {
|
|||
r {
|
||||
v: v,
|
||||
w: w,
|
||||
x: unsafe::reinterpret_cast(&0)
|
||||
x: cast::reinterpret_cast(&0)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,11 +33,11 @@ enum t = {
|
|||
|
||||
fn main() unsafe {
|
||||
let i1 = ~0xA;
|
||||
let i1p = unsafe::reinterpret_cast(&i1);
|
||||
unsafe::forget(i1);
|
||||
let i1p = cast::reinterpret_cast(&i1);
|
||||
cast::forget(i1);
|
||||
let i2 = ~0xA;
|
||||
let i2p = unsafe::reinterpret_cast(&i2);
|
||||
unsafe::forget(i2);
|
||||
let i2p = cast::reinterpret_cast(&i2);
|
||||
cast::forget(i2);
|
||||
|
||||
let u1 = {a: 0xB, b: 0xC, c: i1p};
|
||||
let u2 = {a: 0xB, b: 0xC, c: i2p};
|
||||
|
|
|
@ -32,8 +32,8 @@ fn main() unsafe {
|
|||
assert child_sched_id == new_sched_id;
|
||||
comm::send(ch, ());
|
||||
};
|
||||
let fptr = unsafe::reinterpret_cast(&ptr::addr_of(f));
|
||||
let fptr = cast::reinterpret_cast(&ptr::addr_of(f));
|
||||
rustrt::start_task(new_task_id, fptr);
|
||||
unsafe::forget(f);
|
||||
cast::forget(f);
|
||||
comm::recv(po);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,6 @@
|
|||
// in that type gets resolved.
|
||||
extern mod std;
|
||||
|
||||
fn null<T>() -> *T unsafe { unsafe::reinterpret_cast(&0) }
|
||||
fn null<T>() -> *T unsafe { cast::reinterpret_cast(&0) }
|
||||
|
||||
fn main() { null::<int>(); }
|
||||
|
|
Loading…
Reference in New Issue