auto merge of #14069 : alexcrichton/rust/cast-module, r=brson
This commit revisits the `cast` module in libcore and libstd, and scrutinizes all functions inside of it. The result was to remove the `cast` module entirely, folding all functionality into the `mem` module. Specifically, this is the fate of each function in the `cast` module. * transmute - This function was moved to `mem`, but it is now marked as #[unstable]. This is due to planned changes to the `transmute` function and how it can be invoked (see the #[unstable] comment). For more information, see RFC 5 and #12898 * transmute_copy - This function was moved to `mem`, with clarification that is is not an error to invoke it with T/U that are different sizes, but rather that it is strongly discouraged. This function is now #[stable] * forget - This function was moved to `mem` and marked #[stable] * bump_box_refcount - This function was removed due to the deprecation of managed boxes as well as its questionable utility. * transmute_mut - This function was previously deprecated, and removed as part of this commit. * transmute_mut_unsafe - This function doesn't serve much of a purpose when it can be achieved with an `as` in safe code, so it was removed. * transmute_lifetime - This function was removed because it is likely a strong indication that code is incorrect in the first place. * transmute_mut_lifetime - This function was removed for the same reasons as `transmute_lifetime` * copy_lifetime - This function was moved to `mem`, but it is marked `#[unstable]` now due to the likelihood of being removed in the future if it is found to not be very useful. * copy_mut_lifetime - This function was also moved to `mem`, but had the same treatment as `copy_lifetime`. * copy_lifetime_vec - This function was removed because it is not used today, and its existence is not necessary with DST (copy_lifetime will suffice). In summary, the cast module was stripped down to these functions, and then the functions were moved to the `mem` module. transmute - #[unstable] transmute_copy - #[stable] forget - #[stable] copy_lifetime - #[unstable] copy_mut_lifetime - #[unstable]
This commit is contained in:
commit
fb569fd398
@ -66,11 +66,11 @@ restrictions is undefined behaviour. For example, the following
|
||||
creates two aliasing `&mut` pointers, and is invalid.
|
||||
|
||||
```
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
let mut x: u8 = 1;
|
||||
|
||||
let ref_1: &mut u8 = &mut x;
|
||||
let ref_2: &mut u8 = unsafe { cast::transmute_mut_lifetime(ref_1) };
|
||||
let ref_2: &mut u8 = unsafe { mem::transmute(&mut *ref_1) };
|
||||
|
||||
// oops, ref_1 and ref_2 point to the same piece of data (x) and are
|
||||
// both usable
|
||||
|
@ -26,8 +26,6 @@
|
||||
|
||||
extern crate collections;
|
||||
|
||||
use std::cast::{transmute, transmute_mut_lifetime};
|
||||
use std::cast;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::cmp;
|
||||
use std::intrinsics::{TyDesc, get_tydesc};
|
||||
@ -137,7 +135,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
|
||||
let fill = chunk.fill.get();
|
||||
|
||||
while idx < fill {
|
||||
let tydesc_data: *uint = transmute(buf.offset(idx as int));
|
||||
let tydesc_data: *uint = mem::transmute(buf.offset(idx as int));
|
||||
let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data);
|
||||
let (size, align) = ((*tydesc).size, (*tydesc).align);
|
||||
|
||||
@ -187,18 +185,17 @@ impl Arena {
|
||||
#[inline]
|
||||
fn alloc_copy_inner(&mut self, n_bytes: uint, align: uint) -> *u8 {
|
||||
unsafe {
|
||||
let this = transmute_mut_lifetime(self);
|
||||
let start = round_up(this.copy_head.fill.get(), align);
|
||||
let start = round_up(self.copy_head.fill.get(), align);
|
||||
let end = start + n_bytes;
|
||||
if end > self.chunk_size() {
|
||||
return this.alloc_copy_grow(n_bytes, align);
|
||||
return self.alloc_copy_grow(n_bytes, align);
|
||||
}
|
||||
this.copy_head.fill.set(end);
|
||||
self.copy_head.fill.set(end);
|
||||
|
||||
//debug!("idx = {}, size = {}, align = {}, fill = {}",
|
||||
// start, n_bytes, align, head.fill.get());
|
||||
|
||||
this.copy_head.as_ptr().offset(start as int)
|
||||
self.copy_head.as_ptr().offset(start as int)
|
||||
}
|
||||
}
|
||||
|
||||
@ -206,9 +203,9 @@ impl Arena {
|
||||
fn alloc_copy<'a, T>(&'a mut self, op: || -> T) -> &'a T {
|
||||
unsafe {
|
||||
let ptr = self.alloc_copy_inner(mem::size_of::<T>(), min_align_of::<T>());
|
||||
let ptr: *mut T = transmute(ptr);
|
||||
let ptr = ptr as *mut T;
|
||||
mem::move_val_init(&mut (*ptr), op());
|
||||
return transmute(ptr);
|
||||
return &*ptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -228,26 +225,16 @@ impl Arena {
|
||||
fn alloc_noncopy_inner(&mut self, n_bytes: uint, align: uint)
|
||||
-> (*u8, *u8) {
|
||||
unsafe {
|
||||
let start;
|
||||
let end;
|
||||
let tydesc_start;
|
||||
let after_tydesc;
|
||||
|
||||
{
|
||||
let head = transmute_mut_lifetime(&mut self.head);
|
||||
|
||||
tydesc_start = head.fill.get();
|
||||
after_tydesc = head.fill.get() + mem::size_of::<*TyDesc>();
|
||||
start = round_up(after_tydesc, align);
|
||||
end = start + n_bytes;
|
||||
}
|
||||
let tydesc_start = self.head.fill.get();
|
||||
let after_tydesc = self.head.fill.get() + mem::size_of::<*TyDesc>();
|
||||
let start = round_up(after_tydesc, align);
|
||||
let end = start + n_bytes;
|
||||
|
||||
if end > self.head.capacity() {
|
||||
return self.alloc_noncopy_grow(n_bytes, align);
|
||||
}
|
||||
|
||||
let head = transmute_mut_lifetime(&mut self.head);
|
||||
head.fill.set(round_up(end, mem::pref_align_of::<*TyDesc>()));
|
||||
self.head.fill.set(round_up(end, mem::pref_align_of::<*TyDesc>()));
|
||||
|
||||
//debug!("idx = {}, size = {}, align = {}, fill = {}",
|
||||
// start, n_bytes, align, head.fill);
|
||||
@ -263,18 +250,18 @@ impl Arena {
|
||||
let tydesc = get_tydesc::<T>();
|
||||
let (ty_ptr, ptr) =
|
||||
self.alloc_noncopy_inner(mem::size_of::<T>(), min_align_of::<T>());
|
||||
let ty_ptr: *mut uint = transmute(ty_ptr);
|
||||
let ptr: *mut T = transmute(ptr);
|
||||
let ty_ptr = ty_ptr as *mut uint;
|
||||
let ptr = ptr as *mut T;
|
||||
// Write in our tydesc along with a bit indicating that it
|
||||
// has *not* been initialized yet.
|
||||
*ty_ptr = transmute(tydesc);
|
||||
*ty_ptr = mem::transmute(tydesc);
|
||||
// Actually initialize it
|
||||
mem::move_val_init(&mut(*ptr), op());
|
||||
// Now that we are done, update the tydesc to indicate that
|
||||
// the object is there.
|
||||
*ty_ptr = bitpack_tydesc_ptr(tydesc, true);
|
||||
|
||||
return transmute(ptr);
|
||||
return &*ptr;
|
||||
}
|
||||
}
|
||||
|
||||
@ -283,7 +270,7 @@ impl Arena {
|
||||
pub fn alloc<'a, T>(&'a self, op: || -> T) -> &'a T {
|
||||
unsafe {
|
||||
// FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes
|
||||
let this: &mut Arena = transmute::<&_, &mut _>(self);
|
||||
let this: &mut Arena = mem::transmute::<&_, &mut _>(self);
|
||||
if intrinsics::needs_drop::<T>() {
|
||||
this.alloc_noncopy(op)
|
||||
} else {
|
||||
@ -366,7 +353,7 @@ impl<T> TypedArenaChunk<T> {
|
||||
|
||||
let mut chunk = unsafe {
|
||||
let chunk = exchange_malloc(size);
|
||||
let mut chunk: Box<TypedArenaChunk<T>> = cast::transmute(chunk);
|
||||
let mut chunk: Box<TypedArenaChunk<T>> = mem::transmute(chunk);
|
||||
mem::move_val_init(&mut chunk.next, next);
|
||||
chunk
|
||||
};
|
||||
@ -387,7 +374,7 @@ impl<T> TypedArenaChunk<T> {
|
||||
|
||||
let mut chunk = unsafe {
|
||||
let chunk = exchange_malloc(size, min_align_of::<TypedArenaChunk<T>>());
|
||||
let mut chunk: Box<TypedArenaChunk<T>> = cast::transmute(chunk);
|
||||
let mut chunk: Box<TypedArenaChunk<T>> = mem::transmute(chunk);
|
||||
mem::move_val_init(&mut chunk.next, next);
|
||||
chunk
|
||||
};
|
||||
@ -425,7 +412,7 @@ impl<T> TypedArenaChunk<T> {
|
||||
fn start(&self) -> *u8 {
|
||||
let this: *TypedArenaChunk<T> = self;
|
||||
unsafe {
|
||||
cast::transmute(round_up(this.offset(1) as uint, min_align_of::<T>()))
|
||||
mem::transmute(round_up(this.offset(1) as uint, min_align_of::<T>()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -463,12 +450,12 @@ impl<T> TypedArena<T> {
|
||||
pub fn alloc<'a>(&'a self, object: T) -> &'a T {
|
||||
unsafe {
|
||||
// FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes
|
||||
let this: &mut TypedArena<T> = cast::transmute::<&_, &mut _>(self);
|
||||
let this: &mut TypedArena<T> = mem::transmute::<&_, &mut _>(self);
|
||||
if this.ptr == this.end {
|
||||
this.grow()
|
||||
}
|
||||
|
||||
let ptr: &'a mut T = cast::transmute(this.ptr);
|
||||
let ptr: &'a mut T = mem::transmute(this.ptr);
|
||||
mem::move_val_init(ptr, object);
|
||||
this.ptr = this.ptr.offset(1);
|
||||
let ptr: &'a T = ptr;
|
||||
|
@ -21,10 +21,9 @@
|
||||
// Backlinks over DList::prev are raw pointers that form a full chain in
|
||||
// the reverse direction.
|
||||
|
||||
use std::cast;
|
||||
use std::iter::Rev;
|
||||
use std::iter;
|
||||
use std::mem::{replace, swap};
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
|
||||
use deque::Deque;
|
||||
@ -93,13 +92,13 @@ impl<T> Rawlink<T> {
|
||||
if self.p.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(unsafe { cast::transmute(self.p) })
|
||||
Some(unsafe { mem::transmute(self.p) })
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the `Rawlink` and replace with `Rawlink::none()`
|
||||
fn take(&mut self) -> Rawlink<T> {
|
||||
replace(self, Rawlink::none())
|
||||
mem::replace(self, Rawlink::none())
|
||||
}
|
||||
}
|
||||
|
||||
@ -159,7 +158,7 @@ impl<T> DList<T> {
|
||||
Some(ref mut head) => {
|
||||
new_head.prev = Rawlink::none();
|
||||
head.prev = Rawlink::some(new_head);
|
||||
swap(head, &mut new_head);
|
||||
mem::swap(head, &mut new_head);
|
||||
head.next = Some(new_head);
|
||||
}
|
||||
}
|
||||
@ -317,7 +316,7 @@ impl<T> DList<T> {
|
||||
/// O(1)
|
||||
#[inline]
|
||||
pub fn prepend(&mut self, mut other: DList<T>) {
|
||||
swap(self, &mut other);
|
||||
mem::swap(self, &mut other);
|
||||
self.append(other);
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ impl<E:CLike> Iterator<E> for Items<E> {
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
|
||||
use enum_set::{EnumSet, CLike};
|
||||
|
||||
@ -153,7 +153,7 @@ mod test {
|
||||
}
|
||||
|
||||
fn from_uint(v: uint) -> Foo {
|
||||
unsafe { cast::transmute(v) }
|
||||
unsafe { mem::transmute(v) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -37,7 +37,6 @@
|
||||
//! assert!(cache.get(&2).is_none());
|
||||
//! ```
|
||||
|
||||
use std::cast;
|
||||
use std::container::Container;
|
||||
use std::hash::Hash;
|
||||
use std::fmt;
|
||||
@ -93,7 +92,7 @@ impl<K: Hash + TotalEq, V> LruCache<K, V> {
|
||||
let cache = LruCache {
|
||||
map: HashMap::new(),
|
||||
max_size: capacity,
|
||||
head: unsafe{ cast::transmute(box mem::uninit::<LruEntry<K, V>>()) },
|
||||
head: unsafe{ mem::transmute(box mem::uninit::<LruEntry<K, V>>()) },
|
||||
};
|
||||
unsafe {
|
||||
(*cache.head).next = cache.head;
|
||||
@ -241,11 +240,11 @@ impl<K: Hash + TotalEq, V> Mutable for LruCache<K, V> {
|
||||
impl<K, V> Drop for LruCache<K, V> {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
let node: Box<LruEntry<K, V>> = cast::transmute(self.head);
|
||||
let node: Box<LruEntry<K, V>> = mem::transmute(self.head);
|
||||
// Prevent compiler from trying to drop the un-initialized field in the sigil node.
|
||||
let box LruEntry { key: k, value: v, .. } = node;
|
||||
cast::forget(k);
|
||||
cast::forget(v);
|
||||
mem::forget(k);
|
||||
mem::forget(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
//! value. `Box<Any>` adds the `move` method, which will unwrap a `Box<T>` from the object. See
|
||||
//! the extension traits (`*Ext`) for the full details.
|
||||
|
||||
use cast::{transmute, transmute_copy};
|
||||
use mem::{transmute, transmute_copy};
|
||||
use option::{Option, Some, None};
|
||||
use owned::Box;
|
||||
use raw::TraitObject;
|
||||
|
@ -1,127 +0,0 @@
|
||||
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
//! Unsafe casting functions
|
||||
|
||||
use mem;
|
||||
use intrinsics;
|
||||
use ptr::copy_nonoverlapping_memory;
|
||||
|
||||
/**
|
||||
* Transform a value of one type into a value of another type.
|
||||
* Both types must have the same size and alignment.
|
||||
*
|
||||
* # Example
|
||||
*
|
||||
* ```rust
|
||||
* use std::cast;
|
||||
*
|
||||
* let v: &[u8] = unsafe { cast::transmute("L") };
|
||||
* assert!(v == [76u8]);
|
||||
* ```
|
||||
*/
|
||||
#[inline]
|
||||
pub unsafe fn transmute<T, U>(thing: T) -> U {
|
||||
intrinsics::transmute(thing)
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a thing into the void
|
||||
*
|
||||
* The forget function will take ownership of the provided value but neglect
|
||||
* to run any required cleanup or memory-management operations on it.
|
||||
*/
|
||||
#[inline]
|
||||
pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing); }
|
||||
|
||||
/// Casts the value at `src` to U. The two types must have the same length.
|
||||
#[inline]
|
||||
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
|
||||
let mut dest: U = mem::uninit();
|
||||
let dest_ptr: *mut u8 = transmute(&mut dest);
|
||||
let src_ptr: *u8 = transmute(src);
|
||||
copy_nonoverlapping_memory(dest_ptr, src_ptr, mem::size_of::<U>());
|
||||
dest
|
||||
}
|
||||
|
||||
/// Coerce an immutable reference to be mutable.
|
||||
#[inline]
|
||||
#[deprecated="casting &T to &mut T is undefined behaviour: use Cell<T>, RefCell<T> or Unsafe<T>"]
|
||||
pub unsafe fn transmute_mut<'a,T>(ptr: &'a T) -> &'a mut T { transmute(ptr) }
|
||||
|
||||
/// Coerce a reference to have an arbitrary associated lifetime.
|
||||
#[inline]
|
||||
pub unsafe fn transmute_lifetime<'a,'b,T>(ptr: &'a T) -> &'b T {
|
||||
transmute(ptr)
|
||||
}
|
||||
|
||||
/// Coerce an immutable reference to be mutable.
|
||||
#[inline]
|
||||
pub unsafe fn transmute_mut_unsafe<T>(ptr: *T) -> *mut T {
|
||||
transmute(ptr)
|
||||
}
|
||||
|
||||
/// Coerce a mutable reference to have an arbitrary associated lifetime.
|
||||
#[inline]
|
||||
pub unsafe fn transmute_mut_lifetime<'a,'b,T>(ptr: &'a mut T) -> &'b mut T {
|
||||
transmute(ptr)
|
||||
}
|
||||
|
||||
/// Transforms lifetime of the second pointer to match the first.
|
||||
#[inline]
|
||||
pub unsafe fn copy_lifetime<'a,S,T>(_ptr: &'a S, ptr: &T) -> &'a T {
|
||||
transmute_lifetime(ptr)
|
||||
}
|
||||
|
||||
/// Transforms lifetime of the second pointer to match the first.
|
||||
#[inline]
|
||||
pub unsafe fn copy_mut_lifetime<'a,S,T>(_ptr: &'a mut S, ptr: &mut T) -> &'a mut T {
|
||||
transmute_mut_lifetime(ptr)
|
||||
}
|
||||
|
||||
/// Transforms lifetime of the second pointer to match the first.
|
||||
#[inline]
|
||||
pub unsafe fn copy_lifetime_vec<'a,S,T>(_ptr: &'a [S], ptr: &T) -> &'a T {
|
||||
transmute_lifetime(ptr)
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************
|
||||
* Tests
|
||||
****************************************************************************/
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use cast::transmute;
|
||||
use raw;
|
||||
use realstd::str::StrAllocating;
|
||||
|
||||
#[test]
|
||||
fn test_transmute_copy() {
|
||||
assert_eq!(1u, unsafe { ::cast::transmute_copy(&1) });
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transmute() {
|
||||
unsafe {
|
||||
let x = @100u8;
|
||||
let x: *raw::Box<u8> = transmute(x);
|
||||
assert!((*x).data == 100);
|
||||
let _x: @int = transmute(x);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transmute2() {
|
||||
unsafe {
|
||||
assert_eq!(box [76u8], transmute("L".to_owned()));
|
||||
}
|
||||
}
|
||||
}
|
@ -24,7 +24,7 @@
|
||||
//! and, as such, should be performed via the `from_u32` function..
|
||||
|
||||
|
||||
use cast::transmute;
|
||||
use mem::transmute;
|
||||
use option::{None, Option, Some};
|
||||
use iter::{Iterator, range_step};
|
||||
use unicode::{derived_property, property, general_category, decompose, conversions};
|
||||
|
@ -112,12 +112,12 @@ pub mod marker {
|
||||
/// but does not actually *reference* that type parameter:
|
||||
///
|
||||
/// ```ignore
|
||||
/// use std::cast;
|
||||
/// use std::mem;
|
||||
///
|
||||
/// struct S<T> { x: *() }
|
||||
/// fn get<T>(s: &S<T>) -> T {
|
||||
/// unsafe {
|
||||
/// let x: *T = cast::transmute(s.x);
|
||||
/// let x: *T = mem::transmute(s.x);
|
||||
/// *x
|
||||
/// }
|
||||
/// }
|
||||
@ -153,12 +153,12 @@ pub mod marker {
|
||||
/// but does not actually *reference* that type parameter:
|
||||
///
|
||||
/// ```
|
||||
/// use std::cast;
|
||||
/// use std::mem;
|
||||
///
|
||||
/// struct S<T> { x: *() }
|
||||
/// fn get<T>(s: &S<T>, v: T) {
|
||||
/// unsafe {
|
||||
/// let x: fn(T) = cast::transmute(s.x);
|
||||
/// let x: fn(T) = mem::transmute(s.x);
|
||||
/// x(v)
|
||||
/// }
|
||||
/// }
|
||||
|
@ -63,7 +63,6 @@ pub mod prelude;
|
||||
|
||||
/* Core modules for ownership management */
|
||||
|
||||
pub mod cast;
|
||||
pub mod intrinsics;
|
||||
pub mod mem;
|
||||
pub mod ptr;
|
||||
|
@ -13,7 +13,6 @@
|
||||
//! This module contains functions for querying the size and alignment of
|
||||
//! types, initializing and manipulating memory.
|
||||
|
||||
use cast;
|
||||
use ptr;
|
||||
use intrinsics;
|
||||
use intrinsics::{bswap16, bswap32, bswap64};
|
||||
@ -239,7 +238,7 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
|
||||
|
||||
// y and t now point to the same thing, but we need to completely forget `t`
|
||||
// because it's no longer relevant.
|
||||
cast::forget(t);
|
||||
forget(t);
|
||||
}
|
||||
}
|
||||
|
||||
@ -286,14 +285,103 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
|
||||
}
|
||||
|
||||
/// Disposes of a value.
|
||||
///
|
||||
/// This function can be used to destroy any value by allowing `drop` to take
|
||||
/// ownership of its argument.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```
|
||||
/// use std::cell::RefCell;
|
||||
///
|
||||
/// let x = RefCell::new(1);
|
||||
///
|
||||
/// let mut mutable_borrow = x.borrow_mut();
|
||||
/// *mutable_borrow = 1;
|
||||
/// drop(mutable_borrow); // relinquish the mutable borrow on this slot
|
||||
///
|
||||
/// let borrow = x.borrow();
|
||||
/// println!("{}", *borrow);
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn drop<T>(_x: T) { }
|
||||
|
||||
/// Moves a thing into the void.
|
||||
///
|
||||
/// The forget function will take ownership of the provided value but neglect
|
||||
/// to run any required cleanup or memory management operations on it.
|
||||
///
|
||||
/// This function is the unsafe version of the `drop` function because it does
|
||||
/// not run any destructors.
|
||||
#[inline]
|
||||
#[stable]
|
||||
pub unsafe fn forget<T>(thing: T) { intrinsics::forget(thing) }
|
||||
|
||||
/// Unsafely transforms a value of one type into a value of another type.
|
||||
///
|
||||
/// Both types must have the same size and alignment, and this guarantee is
|
||||
/// enforced at compile-time.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// use std::mem;
|
||||
///
|
||||
/// let v: &[u8] = unsafe { mem::transmute("L") };
|
||||
/// assert!(v == [76u8]);
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable = "this function will be modified to reject invocations of it which \
|
||||
cannot statically prove that T and U are the same size. For \
|
||||
example, this function, as written today, will be rejected in \
|
||||
the future because the size of T and U cannot be statically \
|
||||
known to be the same"]
|
||||
pub unsafe fn transmute<T, U>(thing: T) -> U {
|
||||
intrinsics::transmute(thing)
|
||||
}
|
||||
|
||||
/// Interprets `src` as `&U`, and then reads `src` without moving the contained
|
||||
/// value.
|
||||
///
|
||||
/// This function will unsafely assume the pointer `src` is valid for
|
||||
/// `sizeof(U)` bytes by transmuting `&T` to `&U` and then reading the `&U`. It
|
||||
/// will also unsafely create a copy of the contained value instead of moving
|
||||
/// out of `src`.
|
||||
///
|
||||
/// It is not a compile-time error if `T` and `U` have different sizes, but it
|
||||
/// is highly encouraged to only invoke this function where `T` and `U` have the
|
||||
/// same size. This function triggers undefined behavior if `U` is larger than
|
||||
/// `T`.
|
||||
#[inline]
|
||||
#[stable]
|
||||
pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
|
||||
ptr::read(src as *T as *U)
|
||||
}
|
||||
|
||||
/// Transforms lifetime of the second pointer to match the first.
|
||||
#[inline]
|
||||
#[unstable = "this function may be removed in the future due to its \
|
||||
questionable utility"]
|
||||
pub unsafe fn copy_lifetime<'a, S, T>(_ptr: &'a S, ptr: &T) -> &'a T {
|
||||
transmute(ptr)
|
||||
}
|
||||
|
||||
/// Transforms lifetime of the second mutable pointer to match the first.
|
||||
#[inline]
|
||||
#[unstable = "this function may be removed in the future due to its \
|
||||
questionable utility"]
|
||||
pub unsafe fn copy_mut_lifetime<'a, S, T>(_ptr: &'a mut S,
|
||||
ptr: &mut T) -> &'a mut T {
|
||||
transmute(ptr)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use mem::*;
|
||||
use option::{Some,None};
|
||||
use realstd::str::StrAllocating;
|
||||
use owned::Box;
|
||||
use raw;
|
||||
|
||||
#[test]
|
||||
fn size_of_basic() {
|
||||
@ -389,6 +477,28 @@ mod tests {
|
||||
assert!(x.is_none());
|
||||
assert!(y.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transmute_copy() {
|
||||
assert_eq!(1u, unsafe { ::mem::transmute_copy(&1) });
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_transmute() {
|
||||
trait Foo {}
|
||||
impl Foo for int {}
|
||||
|
||||
let a = box 100 as Box<Foo>;
|
||||
unsafe {
|
||||
let x: raw::TraitObject = transmute(a);
|
||||
assert!(*(x.data as *int) == 100);
|
||||
let _x: Box<Foo> = transmute(x);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
assert_eq!(box [76u8], transmute("L".to_owned()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME #13642 (these benchmarks should be in another place)
|
||||
|
@ -604,10 +604,10 @@ mod tests {
|
||||
fn test_get_ptr() {
|
||||
unsafe {
|
||||
let x = box 0;
|
||||
let addr_x: *int = ::cast::transmute(&*x);
|
||||
let addr_x: *int = ::mem::transmute(&*x);
|
||||
let opt = Some(x);
|
||||
let y = opt.unwrap();
|
||||
let addr_y: *int = ::cast::transmute(&*y);
|
||||
let addr_y: *int = ::mem::transmute(&*y);
|
||||
assert_eq!(addr_x, addr_y);
|
||||
}
|
||||
}
|
||||
|
@ -52,18 +52,18 @@
|
||||
//! though unsafely, transformed from one type to the other.
|
||||
//!
|
||||
//! ```
|
||||
//! use std::cast;
|
||||
//! use std::mem;
|
||||
//!
|
||||
//! unsafe {
|
||||
//! let my_num: Box<int> = box 10;
|
||||
//! let my_num: *int = cast::transmute(my_num);
|
||||
//! let my_num: *int = mem::transmute(my_num);
|
||||
//! let my_speed: Box<int> = box 88;
|
||||
//! let my_speed: *mut int = cast::transmute(my_speed);
|
||||
//! let my_speed: *mut int = mem::transmute(my_speed);
|
||||
//!
|
||||
//! // By taking ownership of the original `Box<T>` though
|
||||
//! // we are obligated to transmute it back later to be destroyed.
|
||||
//! drop(cast::transmute::<_, Box<int>>(my_speed));
|
||||
//! drop(cast::transmute::<_, Box<int>>(my_num));
|
||||
//! drop(mem::transmute::<_, Box<int>>(my_speed));
|
||||
//! drop(mem::transmute::<_, Box<int>>(my_num));
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
@ -92,11 +92,10 @@
|
||||
//! but C APIs hand out a lot of pointers generally, so are a common source
|
||||
//! of unsafe pointers in Rust.
|
||||
|
||||
use cast;
|
||||
use mem;
|
||||
use clone::Clone;
|
||||
use intrinsics;
|
||||
use iter::{range, Iterator};
|
||||
use mem;
|
||||
use option::{Some, None, Option};
|
||||
|
||||
#[cfg(not(test))] use cmp::{Eq, TotalEq, Ord, Equiv};
|
||||
@ -196,7 +195,6 @@ pub unsafe fn copy_memory<T>(dst: *mut T, src: *T, count: uint) {
|
||||
/// A safe swap function:
|
||||
///
|
||||
/// ```
|
||||
/// use std::cast;
|
||||
/// use std::mem;
|
||||
/// use std::ptr;
|
||||
///
|
||||
@ -212,7 +210,7 @@ pub unsafe fn copy_memory<T>(dst: *mut T, src: *T, count: uint) {
|
||||
///
|
||||
/// // y and t now point to the same thing, but we need to completely forget `tmp`
|
||||
/// // because it's no longer relevant.
|
||||
/// cast::forget(t);
|
||||
/// mem::forget(t);
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
@ -256,14 +254,14 @@ pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
|
||||
|
||||
// y and t now point to the same thing, but we need to completely forget `tmp`
|
||||
// because it's no longer relevant.
|
||||
cast::forget(tmp);
|
||||
mem::forget(tmp);
|
||||
}
|
||||
|
||||
/// Replace the value at a mutable location with a new one, returning the old
|
||||
/// value, without deinitialising either.
|
||||
#[inline]
|
||||
pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
|
||||
mem::swap(cast::transmute(dest), &mut src); // cannot overlap
|
||||
mem::swap(mem::transmute(dest), &mut src); // cannot overlap
|
||||
src
|
||||
}
|
||||
|
||||
@ -361,7 +359,7 @@ impl<T> RawPtr<T> for *T {
|
||||
if self.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(cast::transmute(*self))
|
||||
Some(mem::transmute(*self))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -386,7 +384,7 @@ impl<T> RawPtr<T> for *mut T {
|
||||
if self.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(cast::transmute(*self))
|
||||
Some(mem::transmute(*self))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -436,14 +434,14 @@ impl<T> Equiv<*T> for *mut T {
|
||||
// Equality for extern "C" fn pointers
|
||||
#[cfg(not(test))]
|
||||
mod externfnpointers {
|
||||
use cast;
|
||||
use mem;
|
||||
use cmp::Eq;
|
||||
|
||||
impl<_R> Eq for extern "C" fn() -> _R {
|
||||
#[inline]
|
||||
fn eq(&self, other: &extern "C" fn() -> _R) -> bool {
|
||||
let self_: *() = unsafe { cast::transmute(*self) };
|
||||
let other_: *() = unsafe { cast::transmute(*other) };
|
||||
let self_: *() = unsafe { mem::transmute(*self) };
|
||||
let other_: *() = unsafe { mem::transmute(*other) };
|
||||
self_ == other_
|
||||
}
|
||||
}
|
||||
@ -452,8 +450,8 @@ mod externfnpointers {
|
||||
impl<_R,$($p),*> Eq for extern "C" fn($($p),*) -> _R {
|
||||
#[inline]
|
||||
fn eq(&self, other: &extern "C" fn($($p),*) -> _R) -> bool {
|
||||
let self_: *() = unsafe { cast::transmute(*self) };
|
||||
let other_: *() = unsafe { cast::transmute(*other) };
|
||||
let self_: *() = unsafe { mem::transmute(*self) };
|
||||
let other_: *() = unsafe { mem::transmute(*other) };
|
||||
self_ == other_
|
||||
}
|
||||
}
|
||||
@ -485,7 +483,7 @@ pub mod ptr_tests {
|
||||
use realstd::prelude::*;
|
||||
|
||||
use realstd::c_str::ToCStr;
|
||||
use cast;
|
||||
use mem;
|
||||
use libc;
|
||||
use realstd::str;
|
||||
use slice::{ImmutableVector, MutableVector};
|
||||
@ -499,7 +497,7 @@ pub mod ptr_tests {
|
||||
};
|
||||
let mut p = Pair {fst: 10, snd: 20};
|
||||
let pptr: *mut Pair = &mut p;
|
||||
let iptr: *mut int = cast::transmute(pptr);
|
||||
let iptr: *mut int = mem::transmute(pptr);
|
||||
assert_eq!(*iptr, 10);
|
||||
*iptr = 30;
|
||||
assert_eq!(*iptr, 30);
|
||||
|
@ -18,7 +18,7 @@
|
||||
//!
|
||||
//! Their definition should always match the ABI defined in `rustc::back::abi`.
|
||||
|
||||
use cast;
|
||||
use mem;
|
||||
|
||||
/// The representation of a Rust managed box
|
||||
pub struct Box<T> {
|
||||
@ -74,7 +74,7 @@ pub trait Repr<T> {
|
||||
/// for the struct. This is a safe method because by default it does not
|
||||
/// enable write-access to the fields of the return value in safe code.
|
||||
#[inline]
|
||||
fn repr(&self) -> T { unsafe { cast::transmute_copy(self) } }
|
||||
fn repr(&self) -> T { unsafe { mem::transmute_copy(self) } }
|
||||
}
|
||||
|
||||
impl<'a, T> Repr<Slice<T>> for &'a [T] {}
|
||||
@ -87,7 +87,7 @@ impl Repr<*String> for ~str {}
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use cast;
|
||||
use mem;
|
||||
|
||||
#[test]
|
||||
fn synthesize_closure() {
|
||||
@ -97,7 +97,7 @@ mod tests {
|
||||
|
||||
assert_eq!(f(20), 30);
|
||||
|
||||
let original_closure: Closure = cast::transmute(f);
|
||||
let original_closure: Closure = mem::transmute(f);
|
||||
|
||||
let actual_function_pointer = original_closure.code;
|
||||
let environment = original_closure.env;
|
||||
@ -107,7 +107,7 @@ mod tests {
|
||||
env: environment
|
||||
};
|
||||
|
||||
let new_f: |int| -> int = cast::transmute(new_closure);
|
||||
let new_f: |int| -> int = mem::transmute(new_closure);
|
||||
assert_eq!(new_f(20), 30);
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use cast;
|
||||
use char::Char;
|
||||
use clone::Clone;
|
||||
use container::Container;
|
||||
@ -73,7 +72,7 @@ impl Default for ~str {
|
||||
(*ptr).fill = 0;
|
||||
(*ptr).alloc = 0;
|
||||
|
||||
cast::transmute(ptr)
|
||||
mem::transmute(ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -91,7 +90,7 @@ impl Clone for ~str {
|
||||
(*ptr).fill = len;
|
||||
(*ptr).alloc = len;
|
||||
|
||||
cast::transmute(ptr)
|
||||
mem::transmute(ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,7 +105,7 @@ impl FromIterator<char> for ~str {
|
||||
|
||||
unsafe {
|
||||
let mut ptr = alloc(cap) as *mut Vec<u8>;
|
||||
let mut ret = cast::transmute(ptr);
|
||||
let mut ret = mem::transmute(ptr);
|
||||
for ch in iterator {
|
||||
let amt = ch.encode_utf8(tmp);
|
||||
|
||||
@ -121,8 +120,8 @@ impl FromIterator<char> for ~str {
|
||||
len);
|
||||
// FIXME: #13994: port to the sized deallocation API when available
|
||||
rust_free(ptr as *u8, 0, 8);
|
||||
cast::forget(ret);
|
||||
ret = cast::transmute(ptr2);
|
||||
mem::forget(ret);
|
||||
ret = mem::transmute(ptr2);
|
||||
ptr = ptr2;
|
||||
}
|
||||
|
||||
@ -155,7 +154,7 @@ impl<'a> Add<&'a str,~str> for &'a str {
|
||||
rhs.len());
|
||||
(*ptr).fill = amt;
|
||||
(*ptr).alloc = amt;
|
||||
cast::transmute(ptr)
|
||||
mem::transmute(ptr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -192,7 +191,7 @@ impl<A: Clone> Clone for ~[A] {
|
||||
}
|
||||
rust_free(ret as *u8, 0, 8);
|
||||
});
|
||||
cast::transmute(ret)
|
||||
mem::transmute(ret)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,8 +12,7 @@
|
||||
//!
|
||||
//! For more details `std::slice`.
|
||||
|
||||
use cast;
|
||||
use cast::transmute;
|
||||
use mem::transmute;
|
||||
use clone::Clone;
|
||||
use container::Container;
|
||||
use cmp::{Eq, TotalOrd, Ordering, Less, Equal, Greater};
|
||||
@ -1012,7 +1011,7 @@ impl<'a,T> MutableVector<'a, T> for &'a mut [T] {
|
||||
fn mut_split_at(self, mid: uint) -> (&'a mut [T], &'a mut [T]) {
|
||||
unsafe {
|
||||
let len = self.len();
|
||||
let self2: &'a mut [T] = cast::transmute_copy(&self);
|
||||
let self2: &'a mut [T] = mem::transmute_copy(&self);
|
||||
(self.mut_slice(0, mid), self2.mut_slice(mid, len))
|
||||
}
|
||||
}
|
||||
@ -1162,7 +1161,7 @@ impl<'a, T:Clone> MutableCloneableVector<T> for &'a mut [T] {
|
||||
|
||||
/// Unsafe operations
|
||||
pub mod raw {
|
||||
use cast::transmute;
|
||||
use mem::transmute;
|
||||
use iter::Iterator;
|
||||
use ptr::RawPtr;
|
||||
use raw::Slice;
|
||||
|
@ -12,8 +12,7 @@
|
||||
//!
|
||||
//! For more details, see std::str
|
||||
|
||||
use cast::transmute;
|
||||
use cast;
|
||||
use mem;
|
||||
use char;
|
||||
use clone::Clone;
|
||||
use cmp::{Eq, TotalEq};
|
||||
@ -572,7 +571,7 @@ impl<'a> Iterator<UTF16Item> for UTF16Items<'a> {
|
||||
|
||||
if u < 0xD800 || 0xDFFF < u {
|
||||
// not a surrogate
|
||||
Some(ScalarValue(unsafe {cast::transmute(u as u32)}))
|
||||
Some(ScalarValue(unsafe {mem::transmute(u as u32)}))
|
||||
} else if u >= 0xDC00 {
|
||||
// a trailing surrogate
|
||||
Some(LoneSurrogate(u))
|
||||
@ -594,7 +593,7 @@ impl<'a> Iterator<UTF16Item> for UTF16Items<'a> {
|
||||
|
||||
// all ok, so lets decode it.
|
||||
let c = ((u - 0xD800) as u32 << 10 | (u2 - 0xDC00) as u32) + 0x1_0000;
|
||||
Some(ScalarValue(unsafe {cast::transmute(c)}))
|
||||
Some(ScalarValue(unsafe {mem::transmute(c)}))
|
||||
}
|
||||
}
|
||||
|
||||
@ -710,7 +709,7 @@ static TAG_CONT_U8: u8 = 128u8;
|
||||
|
||||
/// Unsafe operations
|
||||
pub mod raw {
|
||||
use cast;
|
||||
use mem;
|
||||
use container::Container;
|
||||
use iter::Iterator;
|
||||
use ptr::RawPtr;
|
||||
@ -721,7 +720,7 @@ pub mod raw {
|
||||
/// Converts a slice of bytes to a string slice without checking
|
||||
/// that the string contains valid UTF-8.
|
||||
pub unsafe fn from_utf8<'a>(v: &'a [u8]) -> &'a str {
|
||||
cast::transmute(v)
|
||||
mem::transmute(v)
|
||||
}
|
||||
|
||||
/// Form a slice from a C string. Unsafe because the caller must ensure the
|
||||
@ -736,8 +735,8 @@ pub mod raw {
|
||||
curr = s.offset(len as int);
|
||||
}
|
||||
let v = Slice { data: s, len: len };
|
||||
assert!(is_utf8(::cast::transmute(v)));
|
||||
::cast::transmute(v)
|
||||
assert!(is_utf8(::mem::transmute(v)));
|
||||
::mem::transmute(v)
|
||||
}
|
||||
|
||||
/// Takes a bytewise (not UTF-8) slice from a string.
|
||||
@ -762,7 +761,7 @@ pub mod raw {
|
||||
/// Caller must check slice boundaries!
|
||||
#[inline]
|
||||
pub unsafe fn slice_unchecked<'a>(s: &'a str, begin: uint, end: uint) -> &'a str {
|
||||
cast::transmute(Slice {
|
||||
mem::transmute(Slice {
|
||||
data: s.as_ptr().offset(begin as int),
|
||||
len: end - begin,
|
||||
})
|
||||
@ -1747,7 +1746,7 @@ impl<'a> StrSlice<'a> for &'a str {
|
||||
if w > 2 { val = utf8_acc_cont_byte!(val, s[i + 2]); }
|
||||
if w > 3 { val = utf8_acc_cont_byte!(val, s[i + 3]); }
|
||||
|
||||
return CharRange {ch: unsafe { transmute(val) }, next: i + w};
|
||||
return CharRange {ch: unsafe { mem::transmute(val) }, next: i + w};
|
||||
}
|
||||
|
||||
return multibyte_char_range_at(*self, i);
|
||||
@ -1776,7 +1775,7 @@ impl<'a> StrSlice<'a> for &'a str {
|
||||
if w > 2 { val = utf8_acc_cont_byte!(val, s[i + 2]); }
|
||||
if w > 3 { val = utf8_acc_cont_byte!(val, s[i + 3]); }
|
||||
|
||||
return CharRange {ch: unsafe { transmute(val) }, next: i};
|
||||
return CharRange {ch: unsafe { mem::transmute(val) }, next: i};
|
||||
}
|
||||
|
||||
return multibyte_char_range_at_reverse(*self, prev);
|
||||
@ -1794,7 +1793,7 @@ impl<'a> StrSlice<'a> for &'a str {
|
||||
|
||||
#[inline]
|
||||
fn as_bytes(&self) -> &'a [u8] {
|
||||
unsafe { cast::transmute(*self) }
|
||||
unsafe { mem::transmute(*self) }
|
||||
}
|
||||
|
||||
fn find<C: CharEq>(&self, mut search: C) -> Option<uint> {
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
//! Types dealing with unsafe actions.
|
||||
|
||||
use cast;
|
||||
use kinds::marker;
|
||||
|
||||
/// Unsafe type that wraps a type T and indicates unsafe interior operations on the
|
||||
@ -63,7 +62,7 @@ impl<T> Unsafe<T> {
|
||||
|
||||
/// Gets a mutable pointer to the wrapped value
|
||||
#[inline]
|
||||
pub unsafe fn get(&self) -> *mut T { cast::transmute_mut_unsafe(&self.value) }
|
||||
pub unsafe fn get(&self) -> *mut T { &self.value as *T as *mut T }
|
||||
|
||||
/// Unwraps the value
|
||||
#[inline]
|
||||
|
@ -15,8 +15,7 @@
|
||||
//! This implementation is also used as the fallback implementation of an event
|
||||
//! loop if no other one is provided (and M:N scheduling is desired).
|
||||
|
||||
use std::cast;
|
||||
use std::mem::replace;
|
||||
use std::mem;
|
||||
use std::rt::rtio::{EventLoop, IoFactory, RemoteCallback};
|
||||
use std::rt::rtio::{PausableIdleCallback, Callback};
|
||||
use std::unstable::sync::Exclusive;
|
||||
@ -50,7 +49,7 @@ impl BasicLoop {
|
||||
/// Process everything in the work queue (continually)
|
||||
fn work(&mut self) {
|
||||
while self.work.len() > 0 {
|
||||
for work in replace(&mut self.work, vec![]).move_iter() {
|
||||
for work in mem::replace(&mut self.work, vec![]).move_iter() {
|
||||
work();
|
||||
}
|
||||
}
|
||||
@ -60,7 +59,7 @@ impl BasicLoop {
|
||||
let messages = unsafe {
|
||||
self.messages.with(|messages| {
|
||||
if messages.len() > 0 {
|
||||
Some(replace(messages, vec![]))
|
||||
Some(mem::replace(messages, vec![]))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@ -145,7 +144,7 @@ impl EventLoop for BasicLoop {
|
||||
let callback = box BasicPausable::new(self, cb);
|
||||
rtassert!(self.idle.is_none());
|
||||
unsafe {
|
||||
let cb_ptr: &*mut BasicPausable = cast::transmute(&callback);
|
||||
let cb_ptr: &*mut BasicPausable = mem::transmute(&callback);
|
||||
self.idle = Some(*cb_ptr);
|
||||
}
|
||||
callback as Box<PausableIdleCallback:Send>
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
use stack::Stack;
|
||||
use std::uint;
|
||||
use std::cast::{transmute, transmute_mut_unsafe};
|
||||
use std::mem::transmute;
|
||||
use std::rt::stack;
|
||||
use std::raw;
|
||||
|
||||
@ -50,7 +50,7 @@ impl Context {
|
||||
stack: &mut Stack) -> Context {
|
||||
|
||||
let sp: *uint = stack.end();
|
||||
let sp: *mut uint = unsafe { transmute_mut_unsafe(sp) };
|
||||
let sp: *mut uint = sp as *mut uint;
|
||||
// Save and then immediately load the current context,
|
||||
// which we will then modify to call the given function when restored
|
||||
let mut regs = new_regs();
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::rt::local::Local;
|
||||
use std::rt::rtio::{RemoteCallback, PausableIdleCallback, Callback, EventLoop};
|
||||
use std::rt::task::BlockedTask;
|
||||
@ -633,7 +633,7 @@ impl Scheduler {
|
||||
unsafe {
|
||||
|
||||
let sched: &mut Scheduler =
|
||||
cast::transmute_mut_lifetime(*next_task.sched.get_mut_ref());
|
||||
mem::transmute(&**next_task.sched.get_mut_ref());
|
||||
|
||||
let current_task: &mut GreenTask = match sched.cleanup_job {
|
||||
Some(CleanupJob { task: ref mut task, .. }) => &mut **task,
|
||||
@ -647,7 +647,7 @@ impl Scheduler {
|
||||
// works because due to transmute the borrow checker
|
||||
// believes that we have no internal pointers to
|
||||
// next_task.
|
||||
cast::forget(next_task);
|
||||
mem::forget(next_task);
|
||||
|
||||
// The raw context swap operation. The next action taken
|
||||
// will be running the cleanup job from the context of the
|
||||
@ -659,7 +659,7 @@ impl Scheduler {
|
||||
// run the cleanup job, as expected by the previously called
|
||||
// swap_contexts function.
|
||||
let mut current_task: Box<GreenTask> = unsafe {
|
||||
cast::transmute(current_task_dupe)
|
||||
mem::transmute(current_task_dupe)
|
||||
};
|
||||
current_task.sched.get_mut_ref().run_cleanup_job();
|
||||
|
||||
@ -677,15 +677,17 @@ impl Scheduler {
|
||||
// references to keep even when we don't own the tasks. It looks
|
||||
// kinda safe because we are doing transmutes before passing in
|
||||
// the arguments.
|
||||
pub fn get_contexts<'a>(current_task: &mut GreenTask, next_task: &mut GreenTask) ->
|
||||
(&'a mut Context, &'a mut Context) {
|
||||
pub fn get_contexts<'a>(current_task: &mut GreenTask,
|
||||
next_task: &mut GreenTask)
|
||||
-> (&'a mut Context, &'a mut Context)
|
||||
{
|
||||
let current_task_context =
|
||||
&mut current_task.coroutine.get_mut_ref().saved_context;
|
||||
let next_task_context =
|
||||
&mut next_task.coroutine.get_mut_ref().saved_context;
|
||||
unsafe {
|
||||
(cast::transmute_mut_lifetime(current_task_context),
|
||||
cast::transmute_mut_lifetime(next_task_context))
|
||||
(mem::transmute(current_task_context),
|
||||
mem::transmute(next_task_context))
|
||||
}
|
||||
}
|
||||
|
||||
@ -961,10 +963,10 @@ trait ClosureConverter {
|
||||
}
|
||||
impl ClosureConverter for UnsafeTaskReceiver {
|
||||
fn from_fn(f: |&mut Scheduler, Box<GreenTask>|) -> UnsafeTaskReceiver {
|
||||
unsafe { cast::transmute(f) }
|
||||
unsafe { mem::transmute(f) }
|
||||
}
|
||||
fn to_fn(self) -> |&mut Scheduler, Box<GreenTask>| {
|
||||
unsafe { cast::transmute(self) }
|
||||
unsafe { mem::transmute(self) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@
|
||||
//! scheduler pool and then interacting with it.
|
||||
|
||||
use std::any::Any;
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::rt::Runtime;
|
||||
use std::rt::local::Local;
|
||||
use std::rt::rtio;
|
||||
@ -48,10 +48,10 @@ impl Runtime for SimpleTask {
|
||||
guard.wait();
|
||||
}
|
||||
}
|
||||
Err(task) => { cast::forget(task.wake()); }
|
||||
Err(task) => { mem::forget(task.wake()); }
|
||||
}
|
||||
drop(guard);
|
||||
cur_task = cast::transmute(cur_dupe);
|
||||
cur_task = mem::transmute(cur_dupe);
|
||||
}
|
||||
Local::put(cur_task);
|
||||
}
|
||||
@ -59,7 +59,7 @@ impl Runtime for SimpleTask {
|
||||
let me = &mut *self as *mut SimpleTask;
|
||||
to_wake.put_runtime(self);
|
||||
unsafe {
|
||||
cast::forget(to_wake);
|
||||
mem::forget(to_wake);
|
||||
let guard = (*me).lock.lock();
|
||||
(*me).awoken = true;
|
||||
guard.signal();
|
||||
|
@ -19,7 +19,7 @@
|
||||
//! values.
|
||||
|
||||
use std::any::Any;
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::raw;
|
||||
use std::rt::Runtime;
|
||||
use std::rt::env;
|
||||
@ -93,11 +93,11 @@ pub enum Home {
|
||||
extern fn bootstrap_green_task(task: uint, code: *(), env: *()) -> ! {
|
||||
// Acquire ownership of the `proc()`
|
||||
let start: proc() = unsafe {
|
||||
cast::transmute(raw::Procedure { code: code, env: env })
|
||||
mem::transmute(raw::Procedure { code: code, env: env })
|
||||
};
|
||||
|
||||
// Acquire ownership of the `Box<GreenTask>`
|
||||
let mut task: Box<GreenTask> = unsafe { cast::transmute(task) };
|
||||
let mut task: Box<GreenTask> = unsafe { mem::transmute(task) };
|
||||
|
||||
// First code after swap to this new context. Run our cleanup job
|
||||
task.pool_id = {
|
||||
@ -271,7 +271,7 @@ impl GreenTask {
|
||||
}
|
||||
|
||||
pub unsafe fn from_uint(val: uint) -> Box<GreenTask> {
|
||||
cast::transmute(val)
|
||||
mem::transmute(val)
|
||||
}
|
||||
|
||||
// Runtime glue functions and helpers
|
||||
|
@ -118,10 +118,10 @@ if logging is disabled, none of the components of the log will be executed.
|
||||
|
||||
extern crate sync;
|
||||
|
||||
use std::cast;
|
||||
use std::fmt;
|
||||
use std::io::LineBufferedWriter;
|
||||
use std::io;
|
||||
use std::mem;
|
||||
use std::os;
|
||||
use std::rt;
|
||||
use std::slice;
|
||||
@ -343,13 +343,13 @@ fn init() {
|
||||
LOG_LEVEL = max_level;
|
||||
|
||||
assert!(DIRECTIVES.is_null());
|
||||
DIRECTIVES = cast::transmute(box directives);
|
||||
DIRECTIVES = mem::transmute(box directives);
|
||||
|
||||
// Schedule the cleanup for this global for when the runtime exits.
|
||||
rt::at_exit(proc() {
|
||||
assert!(!DIRECTIVES.is_null());
|
||||
let _directives: Box<Vec<directive::LogDirective>> =
|
||||
cast::transmute(DIRECTIVES);
|
||||
mem::transmute(DIRECTIVES);
|
||||
DIRECTIVES = 0 as *Vec<directive::LogDirective>;
|
||||
});
|
||||
}
|
||||
|
@ -9,11 +9,11 @@
|
||||
// except according to those terms.
|
||||
|
||||
use ai = std::io::net::addrinfo;
|
||||
use std::c_str::CString;
|
||||
use std::cast;
|
||||
use std::io::IoError;
|
||||
use libc;
|
||||
use libc::{c_char, c_int};
|
||||
use libc;
|
||||
use std::c_str::CString;
|
||||
use std::io::IoError;
|
||||
use std::mem;
|
||||
use std::ptr::{null, mut_null};
|
||||
|
||||
use super::net::sockaddr_to_addr;
|
||||
@ -61,7 +61,7 @@ impl GetAddrInfoRequest {
|
||||
let mut rp = res;
|
||||
while rp.is_not_null() {
|
||||
unsafe {
|
||||
let addr = match sockaddr_to_addr(cast::transmute((*rp).ai_addr),
|
||||
let addr = match sockaddr_to_addr(mem::transmute((*rp).ai_addr),
|
||||
(*rp).ai_addrlen as uint) {
|
||||
Ok(a) => a,
|
||||
Err(e) => return Err(e)
|
||||
|
@ -11,7 +11,6 @@
|
||||
//! Blocking win32-based file I/O
|
||||
|
||||
use std::c_str::CString;
|
||||
use std::cast;
|
||||
use std::io::IoError;
|
||||
use std::io;
|
||||
use libc::{c_int, c_void};
|
||||
@ -175,7 +174,7 @@ impl rtio::RtioFileStream for FileDesc {
|
||||
// This transmute is fine because our seek implementation doesn't
|
||||
// actually use the mutable self at all.
|
||||
// FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes
|
||||
unsafe { cast::transmute::<&_, &mut FileDesc>(self).seek(0, io::SeekCur) }
|
||||
unsafe { mem::transmute::<&_, &mut FileDesc>(self).seek(0, io::SeekCur) }
|
||||
}
|
||||
|
||||
fn fsync(&mut self) -> Result<(), IoError> {
|
||||
|
@ -9,7 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
use libc;
|
||||
use std::cast;
|
||||
use std::io::net::ip;
|
||||
use std::io;
|
||||
use std::mem;
|
||||
@ -72,14 +71,14 @@ fn addr_to_sockaddr(addr: ip::SocketAddr) -> (libc::sockaddr_storage, uint) {
|
||||
let storage: libc::sockaddr_storage = mem::init();
|
||||
let len = match ip_to_inaddr(addr.ip) {
|
||||
InAddr(inaddr) => {
|
||||
let storage: *mut libc::sockaddr_in = cast::transmute(&storage);
|
||||
let storage: *mut libc::sockaddr_in = mem::transmute(&storage);
|
||||
(*storage).sin_family = libc::AF_INET as libc::sa_family_t;
|
||||
(*storage).sin_port = htons(addr.port);
|
||||
(*storage).sin_addr = inaddr;
|
||||
mem::size_of::<libc::sockaddr_in>()
|
||||
}
|
||||
In6Addr(inaddr) => {
|
||||
let storage: *mut libc::sockaddr_in6 = cast::transmute(&storage);
|
||||
let storage: *mut libc::sockaddr_in6 = mem::transmute(&storage);
|
||||
(*storage).sin6_family = libc::AF_INET6 as libc::sa_family_t;
|
||||
(*storage).sin6_port = htons(addr.port);
|
||||
(*storage).sin6_addr = inaddr;
|
||||
@ -173,7 +172,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
|
||||
libc::AF_INET => {
|
||||
assert!(len as uint >= mem::size_of::<libc::sockaddr_in>());
|
||||
let storage: &libc::sockaddr_in = unsafe {
|
||||
cast::transmute(storage)
|
||||
mem::transmute(storage)
|
||||
};
|
||||
let addr = storage.sin_addr.s_addr as u32;
|
||||
let a = (addr >> 0) as u8;
|
||||
@ -188,7 +187,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
|
||||
libc::AF_INET6 => {
|
||||
assert!(len as uint >= mem::size_of::<libc::sockaddr_in6>());
|
||||
let storage: &libc::sockaddr_in6 = unsafe {
|
||||
cast::transmute(storage)
|
||||
mem::transmute(storage)
|
||||
};
|
||||
let a = ntohs(storage.sin6_addr.s6_addr[0]);
|
||||
let b = ntohs(storage.sin6_addr.s6_addr[1]);
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
use libc;
|
||||
use std::c_str::CString;
|
||||
use std::cast;
|
||||
use std::intrinsics;
|
||||
use std::io;
|
||||
use std::mem;
|
||||
@ -36,7 +35,7 @@ fn addr_to_sockaddr_un(addr: &CString) -> IoResult<(libc::sockaddr_storage, uint
|
||||
assert!(mem::size_of::<libc::sockaddr_storage>() >=
|
||||
mem::size_of::<libc::sockaddr_un>());
|
||||
let mut storage: libc::sockaddr_storage = unsafe { intrinsics::init() };
|
||||
let s: &mut libc::sockaddr_un = unsafe { cast::transmute(&mut storage) };
|
||||
let s: &mut libc::sockaddr_un = unsafe { mem::transmute(&mut storage) };
|
||||
|
||||
let len = addr.len();
|
||||
if len > s.sun_path.len() - 1 {
|
||||
|
@ -19,7 +19,7 @@ use p = std::io::process;
|
||||
use super::IoResult;
|
||||
use super::file;
|
||||
|
||||
#[cfg(windows)] use std::cast;
|
||||
#[cfg(windows)] use std::mem;
|
||||
#[cfg(windows)] use std::strbuf::StrBuf;
|
||||
#[cfg(not(windows))] use super::retry;
|
||||
|
||||
@ -326,7 +326,7 @@ fn spawn_process_os(config: p::ProcessConfig,
|
||||
with_envp(env, |envp| {
|
||||
with_dirp(dir, |dirp| {
|
||||
cmd.with_c_str(|cmdp| {
|
||||
let created = CreateProcessA(ptr::null(), cast::transmute(cmdp),
|
||||
let created = CreateProcessA(ptr::null(), mem::transmute(cmdp),
|
||||
ptr::mut_null(), ptr::mut_null(), TRUE,
|
||||
flags, envp, dirp, &mut si,
|
||||
&mut pi);
|
||||
@ -714,7 +714,7 @@ fn with_dirp<T>(d: Option<&Path>, cb: |*libc::c_char| -> T) -> T {
|
||||
#[cfg(windows)]
|
||||
fn free_handle(handle: *()) {
|
||||
assert!(unsafe {
|
||||
libc::CloseHandle(cast::transmute(handle)) != 0
|
||||
libc::CloseHandle(mem::transmute(handle)) != 0
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
//! can be created in the future and there must be no active timers at that
|
||||
//! time.
|
||||
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::rt::bookkeeping;
|
||||
use std::rt;
|
||||
use std::unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
|
||||
@ -48,7 +48,7 @@ pub fn boot(helper: fn(imp::signal, Receiver<Req>)) {
|
||||
let (tx, rx) = channel();
|
||||
// promote this to a shared channel
|
||||
drop(tx.clone());
|
||||
HELPER_CHAN = cast::transmute(box tx);
|
||||
HELPER_CHAN = mem::transmute(box tx);
|
||||
let (receive, send) = imp::new();
|
||||
HELPER_SIGNAL = send;
|
||||
|
||||
@ -86,7 +86,7 @@ fn shutdown() {
|
||||
// Clean up after ther helper thread
|
||||
unsafe {
|
||||
imp::close(HELPER_SIGNAL);
|
||||
let _chan: Box<Sender<Req>> = cast::transmute(HELPER_CHAN);
|
||||
let _chan: Box<Sender<Req>> = mem::transmute(HELPER_CHAN);
|
||||
HELPER_CHAN = 0 as *mut Sender<Req>;
|
||||
HELPER_SIGNAL = 0 as imp::signal;
|
||||
}
|
||||
|
@ -73,9 +73,9 @@ static OS_DEFAULT_STACK_ESTIMATE: uint = 2 * (1 << 20);
|
||||
#[lang = "start"]
|
||||
#[cfg(not(test))]
|
||||
pub fn lang_start(main: *u8, argc: int, argv: **u8) -> int {
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
start(argc, argv, proc() {
|
||||
let main: extern "Rust" fn() = unsafe { cast::transmute(main) };
|
||||
let main: extern "Rust" fn() = unsafe { mem::transmute(main) };
|
||||
main();
|
||||
})
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
//! in order to spawn new tasks and deschedule the current task.
|
||||
|
||||
use std::any::Any;
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::rt::bookkeeping;
|
||||
use std::rt::env;
|
||||
use std::rt::local::Local;
|
||||
@ -169,7 +169,7 @@ impl rt::Runtime for Ops {
|
||||
// for both tasks because these operations are all done inside of a mutex.
|
||||
//
|
||||
// You'll also find that if blocking fails (the `f` function hands the
|
||||
// BlockedTask back to us), we will `cast::forget` the handles. The
|
||||
// BlockedTask back to us), we will `mem::forget` the handles. The
|
||||
// reasoning for this is the same logic as above in that the task silently
|
||||
// transfers ownership via the `uint`, not through normal compiler
|
||||
// semantics.
|
||||
@ -198,7 +198,7 @@ impl rt::Runtime for Ops {
|
||||
guard.wait();
|
||||
}
|
||||
}
|
||||
Err(task) => { cast::forget(task.wake()); }
|
||||
Err(task) => { mem::forget(task.wake()); }
|
||||
}
|
||||
} else {
|
||||
let iter = task.make_selectable(times);
|
||||
@ -217,7 +217,7 @@ impl rt::Runtime for Ops {
|
||||
Some(task) => {
|
||||
match task.wake() {
|
||||
Some(task) => {
|
||||
cast::forget(task);
|
||||
mem::forget(task);
|
||||
(*me).awoken = true;
|
||||
}
|
||||
None => {}
|
||||
@ -229,7 +229,7 @@ impl rt::Runtime for Ops {
|
||||
}
|
||||
}
|
||||
// re-acquire ownership of the task
|
||||
cur_task = cast::transmute(cur_task_dupe);
|
||||
cur_task = mem::transmute(cur_task_dupe);
|
||||
}
|
||||
|
||||
// put the task back in TLS, and everything is as it once was.
|
||||
@ -242,7 +242,7 @@ impl rt::Runtime for Ops {
|
||||
unsafe {
|
||||
let me = &mut *self as *mut Ops;
|
||||
to_wake.put_runtime(self);
|
||||
cast::forget(to_wake);
|
||||
mem::forget(to_wake);
|
||||
let guard = (*me).lock.lock();
|
||||
(*me).awoken = true;
|
||||
guard.signal();
|
||||
|
@ -18,7 +18,7 @@ use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
|
||||
///
|
||||
/// See `Exp` for the general exponential distribution.Note that this
|
||||
// has to be unwrapped before use as an `f64` (using either
|
||||
/// `*` or `cast::transmute` is safe).
|
||||
/// `*` or `mem::transmute` is safe).
|
||||
///
|
||||
/// Implemented via the ZIGNOR variant[1] of the Ziggurat method. The
|
||||
/// exact description in the paper was adjusted to use tables for the
|
||||
|
@ -19,7 +19,7 @@ use distributions::{ziggurat, ziggurat_tables, Sample, IndependentSample};
|
||||
///
|
||||
/// See `Normal` for the general normal distribution. That this has to
|
||||
/// be unwrapped before use as an `f64` (using either `*` or
|
||||
/// `cast::transmute` is safe).
|
||||
/// `mem::transmute` is safe).
|
||||
///
|
||||
/// Implemented via the ZIGNOR variant[1] of the Ziggurat method.
|
||||
///
|
||||
|
@ -76,9 +76,9 @@ println!("{:?}", tuple_ptr)
|
||||
#[cfg(test)]
|
||||
#[phase(syntax, link)] extern crate log;
|
||||
|
||||
use std::cast;
|
||||
use std::io::IoResult;
|
||||
use std::kinds::marker;
|
||||
use std::mem;
|
||||
use std::strbuf::StrBuf;
|
||||
|
||||
pub use isaac::{IsaacRng, Isaac64Rng};
|
||||
@ -454,11 +454,11 @@ impl<'a> SeedableRng<&'a [uint]> for StdRng {
|
||||
fn reseed(&mut self, seed: &'a [uint]) {
|
||||
// the internal RNG can just be seeded from the above
|
||||
// randomness.
|
||||
self.rng.reseed(unsafe {cast::transmute(seed)})
|
||||
self.rng.reseed(unsafe {mem::transmute(seed)})
|
||||
}
|
||||
|
||||
fn from_seed(seed: &'a [uint]) -> StdRng {
|
||||
StdRng { rng: SeedableRng::from_seed(unsafe {cast::transmute(seed)}) }
|
||||
StdRng { rng: SeedableRng::from_seed(unsafe {mem::transmute(seed)}) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -547,7 +547,7 @@ impl XorShiftRng {
|
||||
break;
|
||||
}
|
||||
}
|
||||
let s: [u32, ..4] = unsafe { cast::transmute(s) };
|
||||
let s: [u32, ..4] = unsafe { mem::transmute(s) };
|
||||
Ok(SeedableRng::from_seed(s))
|
||||
}
|
||||
}
|
||||
|
@ -61,8 +61,8 @@ mod imp {
|
||||
extern crate libc;
|
||||
|
||||
use Rng;
|
||||
use std::cast;
|
||||
use std::io::{IoResult, IoError};
|
||||
use std::mem;
|
||||
use std::os;
|
||||
use std::rt::stack;
|
||||
use self::libc::{c_ulong, DWORD, BYTE, LPCSTR, BOOL};
|
||||
@ -156,12 +156,12 @@ mod imp {
|
||||
fn next_u32(&mut self) -> u32 {
|
||||
let mut v = [0u8, .. 4];
|
||||
self.fill_bytes(v);
|
||||
unsafe { cast::transmute(v) }
|
||||
unsafe { mem::transmute(v) }
|
||||
}
|
||||
fn next_u64(&mut self) -> u64 {
|
||||
let mut v = [0u8, .. 8];
|
||||
self.fill_bytes(v);
|
||||
unsafe { cast::transmute(v) }
|
||||
unsafe { mem::transmute(v) }
|
||||
}
|
||||
fn fill_bytes(&mut self, v: &mut [u8]) {
|
||||
let ret = unsafe {
|
||||
|
@ -72,14 +72,14 @@ impl<R: Reader> Rng for ReaderRng<R> {
|
||||
mod test {
|
||||
use super::ReaderRng;
|
||||
use std::io::MemReader;
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use Rng;
|
||||
|
||||
#[test]
|
||||
fn test_reader_rng_u64() {
|
||||
// transmute from the target to avoid endianness concerns.
|
||||
let v = box [1u64, 2u64, 3u64];
|
||||
let bytes: ~[u8] = unsafe {cast::transmute(v)};
|
||||
let bytes: ~[u8] = unsafe {mem::transmute(v)};
|
||||
let mut rng = ReaderRng::new(MemReader::new(bytes.move_iter().collect()));
|
||||
|
||||
assert_eq!(rng.next_u64(), 1);
|
||||
@ -90,7 +90,7 @@ mod test {
|
||||
fn test_reader_rng_u32() {
|
||||
// transmute from the target to avoid endianness concerns.
|
||||
let v = box [1u32, 2u32, 3u32];
|
||||
let bytes: ~[u8] = unsafe {cast::transmute(v)};
|
||||
let bytes: ~[u8] = unsafe {mem::transmute(v)};
|
||||
let mut rng = ReaderRng::new(MemReader::new(bytes.move_iter().collect()));
|
||||
|
||||
assert_eq!(rng.next_u32(), 1);
|
||||
|
@ -15,14 +15,14 @@ use driver::session::Session;
|
||||
use metadata::filesearch;
|
||||
use lib::llvm::{ArchiveRef, llvm};
|
||||
|
||||
use std::cast;
|
||||
use std::io;
|
||||
use std::io::{fs, TempDir};
|
||||
use libc;
|
||||
use std::os;
|
||||
use std::io::process::{ProcessConfig, Process, ProcessOutput};
|
||||
use std::str;
|
||||
use std::io::{fs, TempDir};
|
||||
use std::io;
|
||||
use std::mem;
|
||||
use std::os;
|
||||
use std::raw;
|
||||
use std::str;
|
||||
use syntax::abi;
|
||||
|
||||
pub static METADATA_FILENAME: &'static str = "rust.metadata.bin";
|
||||
@ -230,7 +230,7 @@ impl ArchiveRO {
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(cast::transmute(raw::Slice {
|
||||
Some(mem::transmute(raw::Slice {
|
||||
data: ptr,
|
||||
len: size as uint,
|
||||
}))
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use syntax::crateid::CrateId;
|
||||
use back::svh::Svh;
|
||||
|
||||
@ -147,7 +147,7 @@ impl astencode_tag {
|
||||
pub fn from_uint(value : uint) -> Option<astencode_tag> {
|
||||
let is_a_tag = first_astencode_tag <= value && value <= last_astencode_tag;
|
||||
if !is_a_tag { None } else {
|
||||
Some(unsafe { cast::transmute(value) })
|
||||
Some(unsafe { mem::transmute(value) })
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ use middle;
|
||||
use util::nodemap::{NodeMap, NodeSet};
|
||||
|
||||
use serialize::Encodable;
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::cell::RefCell;
|
||||
use std::hash;
|
||||
use std::hash::Hash;
|
||||
@ -1247,7 +1247,7 @@ fn my_visit_item(i: &Item,
|
||||
index: &mut Vec<entry<i64>>) {
|
||||
let mut ebml_w = unsafe { ebml_w.unsafe_clone() };
|
||||
// See above
|
||||
let ecx: &EncodeContext = unsafe { cast::transmute(ecx_ptr) };
|
||||
let ecx: &EncodeContext = unsafe { mem::transmute(ecx_ptr) };
|
||||
ecx.tcx.map.with_path(i.id, |path| {
|
||||
encode_info_for_item(ecx, &mut ebml_w, i, index, path, i.vis);
|
||||
});
|
||||
@ -1258,7 +1258,7 @@ fn my_visit_foreign_item(ni: &ForeignItem,
|
||||
ecx_ptr:*int,
|
||||
index: &mut Vec<entry<i64>>) {
|
||||
// See above
|
||||
let ecx: &EncodeContext = unsafe { cast::transmute(ecx_ptr) };
|
||||
let ecx: &EncodeContext = unsafe { mem::transmute(ecx_ptr) };
|
||||
debug!("writing foreign item {}::{}",
|
||||
ecx.tcx.map.path_to_str(ni.id),
|
||||
token::get_ident(ni.ident));
|
||||
@ -1320,7 +1320,7 @@ fn encode_info_for_items(ecx: &EncodeContext,
|
||||
Public);
|
||||
|
||||
// See comment in `encode_side_tables_for_ii` in astencode
|
||||
let ecx_ptr: *int = unsafe { cast::transmute(ecx) };
|
||||
let ecx_ptr: *int = unsafe { mem::transmute(ecx) };
|
||||
visit::walk_crate(&mut EncodeVisitor {
|
||||
index: &mut index,
|
||||
ecx_ptr: ecx_ptr,
|
||||
|
@ -25,9 +25,9 @@ use syntax::attr::AttrMetaMethods;
|
||||
use util::fs;
|
||||
|
||||
use std::c_str::ToCStr;
|
||||
use std::cast;
|
||||
use std::cmp;
|
||||
use std::io;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::slice;
|
||||
use std::str;
|
||||
@ -469,7 +469,7 @@ impl ArchiveMetadata {
|
||||
// Hence, we're guaranteed that the buffer will never be used after
|
||||
// this object is dead, so this is a safe operation to transmute and
|
||||
// store the data as a static buffer.
|
||||
unsafe { cast::transmute(data) }
|
||||
unsafe { mem::transmute(data) }
|
||||
};
|
||||
Some(ArchiveMetadata {
|
||||
archive: ar,
|
||||
@ -532,7 +532,7 @@ fn get_metadata_section_imp(os: Os, filename: &Path) -> Result<MetadataBlob, ~st
|
||||
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
|
||||
let csz = llvm::LLVMGetSectionSize(si.llsi) as uint;
|
||||
let mut found = Err(format!("metadata not found: '{}'", filename.display()));
|
||||
let cvbuf: *u8 = cast::transmute(cbuf);
|
||||
let cvbuf: *u8 = mem::transmute(cbuf);
|
||||
let vlen = encoder::metadata_encoding_version.len();
|
||||
debug!("checking {} bytes of metadata-version stamp",
|
||||
vlen);
|
||||
|
@ -34,9 +34,9 @@ use syntax::parse::token;
|
||||
use syntax;
|
||||
|
||||
use libc;
|
||||
use std::cast;
|
||||
use std::io::Seek;
|
||||
use std::io::MemWriter;
|
||||
use std::mem;
|
||||
use std::rc::Rc;
|
||||
use std::strbuf::StrBuf;
|
||||
|
||||
@ -913,7 +913,7 @@ impl<'a,'b> ast_util::IdVisitingOperation for
|
||||
};
|
||||
// See above
|
||||
let ecx: &e::EncodeContext = unsafe {
|
||||
cast::transmute(self.ecx_ptr)
|
||||
mem::transmute(self.ecx_ptr)
|
||||
};
|
||||
encode_side_tables_for_id(ecx, &mut new_ebml_w, id)
|
||||
}
|
||||
@ -932,7 +932,7 @@ fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
|
||||
// tied to the CrateContext that lives throughout this entire section.
|
||||
ast_util::visit_ids_for_inlined_item(ii, &SideTableEncodingIdVisitor {
|
||||
ecx_ptr: unsafe {
|
||||
cast::transmute(ecx)
|
||||
mem::transmute(ecx)
|
||||
},
|
||||
new_ebml_w: &mut new_ebml_w,
|
||||
});
|
||||
|
@ -109,7 +109,7 @@ use middle::pat_util;
|
||||
use middle::ty;
|
||||
use util::nodemap::NodeMap;
|
||||
|
||||
use std::cast::transmute;
|
||||
use std::mem::transmute;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
use std::rc::Rc;
|
||||
|
@ -19,7 +19,7 @@ use syntax::ast;
|
||||
use syntax::abi::{X86, X86_64, Arm, Mips};
|
||||
|
||||
use std::c_str::ToCStr;
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
|
||||
use libc::{c_uint};
|
||||
|
||||
@ -140,19 +140,19 @@ impl Type {
|
||||
}
|
||||
|
||||
pub fn func(args: &[Type], ret: &Type) -> Type {
|
||||
let vec : &[TypeRef] = unsafe { cast::transmute(args) };
|
||||
let vec : &[TypeRef] = unsafe { mem::transmute(args) };
|
||||
ty!(llvm::LLVMFunctionType(ret.to_ref(), vec.as_ptr(),
|
||||
args.len() as c_uint, False))
|
||||
}
|
||||
|
||||
pub fn variadic_func(args: &[Type], ret: &Type) -> Type {
|
||||
let vec : &[TypeRef] = unsafe { cast::transmute(args) };
|
||||
let vec : &[TypeRef] = unsafe { mem::transmute(args) };
|
||||
ty!(llvm::LLVMFunctionType(ret.to_ref(), vec.as_ptr(),
|
||||
args.len() as c_uint, True))
|
||||
}
|
||||
|
||||
pub fn struct_(ccx: &CrateContext, els: &[Type], packed: bool) -> Type {
|
||||
let els : &[TypeRef] = unsafe { cast::transmute(els) };
|
||||
let els : &[TypeRef] = unsafe { mem::transmute(els) };
|
||||
ty!(llvm::LLVMStructTypeInContext(ccx.llcx, els.as_ptr(),
|
||||
els.len() as c_uint,
|
||||
packed as Bool))
|
||||
@ -245,7 +245,7 @@ impl Type {
|
||||
|
||||
pub fn set_struct_body(&mut self, els: &[Type], packed: bool) {
|
||||
unsafe {
|
||||
let vec : &[TypeRef] = cast::transmute(els);
|
||||
let vec : &[TypeRef] = mem::transmute(els);
|
||||
llvm::LLVMStructSetBody(self.to_ref(), vec.as_ptr(),
|
||||
els.len() as c_uint, packed as Bool)
|
||||
}
|
||||
@ -281,7 +281,7 @@ impl Type {
|
||||
}
|
||||
let mut elts = Vec::from_elem(n_elts, 0 as TypeRef);
|
||||
llvm::LLVMGetStructElementTypes(self.to_ref(), elts.get_mut(0));
|
||||
cast::transmute(elts)
|
||||
mem::transmute(elts)
|
||||
}
|
||||
}
|
||||
|
||||
@ -294,7 +294,7 @@ impl Type {
|
||||
let n_args = llvm::LLVMCountParamTypes(self.to_ref()) as uint;
|
||||
let args = Vec::from_elem(n_args, 0 as TypeRef);
|
||||
llvm::LLVMGetParamTypes(self.to_ref(), args.as_ptr());
|
||||
cast::transmute(args)
|
||||
mem::transmute(args)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -34,13 +34,13 @@ use util::ppaux::{Repr, UserString};
|
||||
use util::common::{indenter};
|
||||
use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet, FnvHashMap};
|
||||
|
||||
use std::cast;
|
||||
use std::cell::{Cell, RefCell};
|
||||
use std::cmp;
|
||||
use std::fmt::Show;
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, sip};
|
||||
use std::iter::AdditiveIterator;
|
||||
use std::mem;
|
||||
use std::ops;
|
||||
use std::rc::Rc;
|
||||
use collections::{HashMap, HashSet};
|
||||
@ -394,7 +394,7 @@ impl fmt::Show for t {
|
||||
|
||||
pub fn get(t: t) -> t_box {
|
||||
unsafe {
|
||||
let t2: t_box = cast::transmute(t);
|
||||
let t2: t_box = mem::transmute(t);
|
||||
t2
|
||||
}
|
||||
}
|
||||
@ -854,7 +854,7 @@ impl CLike for BuiltinBound {
|
||||
*self as uint
|
||||
}
|
||||
fn from_uint(v: uint) -> BuiltinBound {
|
||||
unsafe { cast::transmute(v) }
|
||||
unsafe { mem::transmute(v) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1158,7 +1158,7 @@ pub fn mk_t(cx: &ctxt, st: sty) -> t {
|
||||
let key = intern_key { sty: &st };
|
||||
|
||||
match cx.interner.borrow().find(&key) {
|
||||
Some(t) => unsafe { return cast::transmute(&t.sty); },
|
||||
Some(t) => unsafe { return mem::transmute(&t.sty); },
|
||||
_ => ()
|
||||
}
|
||||
|
||||
@ -1259,14 +1259,14 @@ pub fn mk_t(cx: &ctxt, st: sty) -> t {
|
||||
cx.next_id.set(cx.next_id.get() + 1);
|
||||
|
||||
unsafe {
|
||||
cast::transmute::<*sty, t>(sty_ptr)
|
||||
mem::transmute::<*sty, t>(sty_ptr)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn mk_prim_t(primitive: &'static t_box_) -> t {
|
||||
unsafe {
|
||||
cast::transmute::<&'static t_box_, t>(primitive)
|
||||
mem::transmute::<&'static t_box_, t>(primitive)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -14,7 +14,7 @@
|
||||
/// It is assumed that all invocations of this struct happen on the same thread
|
||||
/// (the uv event loop).
|
||||
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::rt::local::Local;
|
||||
use std::rt::task::{BlockedTask, Task};
|
||||
use std::sync::arc::UnsafeArc;
|
||||
@ -110,7 +110,7 @@ impl<'a> Drop for Guard<'a> {
|
||||
// on the same I/O event loop, so this unsafety should be ok.
|
||||
assert!(self.missile.is_some());
|
||||
let inner: &mut Inner = unsafe {
|
||||
cast::transmute(self.access.inner.get())
|
||||
mem::transmute(self.access.inner.get())
|
||||
};
|
||||
|
||||
match inner.queue.shift() {
|
||||
|
@ -9,9 +9,9 @@
|
||||
// except according to those terms.
|
||||
|
||||
use ai = std::io::net::addrinfo;
|
||||
use std::cast;
|
||||
use libc;
|
||||
use libc::c_int;
|
||||
use libc;
|
||||
use std::mem;
|
||||
use std::ptr::null;
|
||||
use std::rt::task::BlockedTask;
|
||||
|
||||
@ -140,7 +140,7 @@ pub fn accum_addrinfo(addr: &Addrinfo) -> Vec<ai::Info> {
|
||||
|
||||
let mut addrs = Vec::new();
|
||||
loop {
|
||||
let rustaddr = net::sockaddr_to_addr(cast::transmute((*addr).ai_addr),
|
||||
let rustaddr = net::sockaddr_to_addr(mem::transmute((*addr).ai_addr),
|
||||
(*addr).ai_addrlen as uint);
|
||||
|
||||
let mut flags = 0;
|
||||
|
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::rt::rtio::{Callback, RemoteCallback};
|
||||
use std::unstable::sync::Exclusive;
|
||||
|
||||
@ -39,7 +39,7 @@ impl AsyncWatcher {
|
||||
let flag = Exclusive::new(false);
|
||||
let payload = box Payload { callback: cb, exit_flag: flag.clone() };
|
||||
unsafe {
|
||||
let payload: *u8 = cast::transmute(payload);
|
||||
let payload: *u8 = mem::transmute(payload);
|
||||
uvll::set_data_for_uv_handle(handle, payload);
|
||||
}
|
||||
return AsyncWatcher { handle: handle, exit_flag: flag, };
|
||||
@ -55,7 +55,7 @@ impl UvHandle<uvll::uv_async_t> for AsyncWatcher {
|
||||
|
||||
extern fn async_cb(handle: *uvll::uv_async_t) {
|
||||
let payload: &mut Payload = unsafe {
|
||||
cast::transmute(uvll::get_data_for_uv_handle(handle))
|
||||
mem::transmute(uvll::get_data_for_uv_handle(handle))
|
||||
};
|
||||
|
||||
// The synchronization logic here is subtle. To review,
|
||||
@ -94,7 +94,7 @@ extern fn async_cb(handle: *uvll::uv_async_t) {
|
||||
extern fn close_cb(handle: *uvll::uv_handle_t) {
|
||||
// drop the payload
|
||||
let _payload: Box<Payload> = unsafe {
|
||||
cast::transmute(uvll::get_data_for_uv_handle(handle))
|
||||
mem::transmute(uvll::get_data_for_uv_handle(handle))
|
||||
};
|
||||
// and then free the handle
|
||||
unsafe { uvll::free_handle(handle) }
|
||||
|
@ -8,16 +8,15 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::c_str::CString;
|
||||
use std::c_str;
|
||||
use std::cast::transmute;
|
||||
use std::cast;
|
||||
use libc::{c_int, c_char, c_void, ssize_t};
|
||||
use libc;
|
||||
use std::rt::task::BlockedTask;
|
||||
use std::c_str::CString;
|
||||
use std::c_str;
|
||||
use std::io::{FileStat, IoError};
|
||||
use std::io;
|
||||
use std::mem;
|
||||
use std::rt::rtio;
|
||||
use std::rt::task::BlockedTask;
|
||||
|
||||
use homing::{HomingIO, HomeHandle};
|
||||
use super::{Loop, UvError, uv_error_to_io_error, wait_until_woken_after, wakeup};
|
||||
@ -341,7 +340,7 @@ fn execute(f: |*uvll::uv_fs_t, uvll::uv_fs_cb| -> c_int)
|
||||
|
||||
extern fn fs_cb(req: *uvll::uv_fs_t) {
|
||||
let slot: &mut Option<BlockedTask> = unsafe {
|
||||
cast::transmute(uvll::get_data_for_req(req))
|
||||
mem::transmute(uvll::get_data_for_req(req))
|
||||
};
|
||||
wakeup(slot);
|
||||
}
|
||||
@ -448,7 +447,7 @@ impl rtio::RtioFileStream for FileWatcher {
|
||||
use libc::SEEK_CUR;
|
||||
// this is temporary
|
||||
// FIXME #13933: Remove/justify all `&T` to `&mut T` transmutes
|
||||
let self_ = unsafe { cast::transmute::<&_, &mut FileWatcher>(self) };
|
||||
let self_ = unsafe { mem::transmute::<&_, &mut FileWatcher>(self) };
|
||||
self_.seek_common(0, SEEK_CUR)
|
||||
}
|
||||
fn fsync(&mut self) -> Result<(), IoError> {
|
||||
|
@ -33,7 +33,7 @@
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::rt::local::Local;
|
||||
use std::rt::rtio::LocalIo;
|
||||
use std::rt::task::{Task, BlockedTask};
|
||||
@ -77,7 +77,7 @@ pub fn local_id() -> uint {
|
||||
};
|
||||
let io = io.get();
|
||||
unsafe {
|
||||
let (_vtable, ptr): (uint, uint) = cast::transmute(io);
|
||||
let (_vtable, ptr): (uint, uint) = mem::transmute(io);
|
||||
return ptr;
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,8 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::cast;
|
||||
use libc::c_void;
|
||||
use std::mem;
|
||||
|
||||
use uvll;
|
||||
use super::{Loop, UvHandle};
|
||||
@ -41,7 +41,7 @@ impl IdleWatcher {
|
||||
let handle = UvHandle::alloc(None::<IdleWatcher>, uvll::UV_IDLE);
|
||||
unsafe {
|
||||
assert_eq!(uvll::uv_idle_init(loop_.handle, handle), 0);
|
||||
let data: *c_void = cast::transmute(box f);
|
||||
let data: *c_void = mem::transmute(box f);
|
||||
uvll::set_data_for_uv_handle(handle, data);
|
||||
assert_eq!(uvll::uv_idle_start(handle, onetime_cb), 0)
|
||||
}
|
||||
@ -49,7 +49,7 @@ impl IdleWatcher {
|
||||
extern fn onetime_cb(handle: *uvll::uv_idle_t) {
|
||||
unsafe {
|
||||
let data = uvll::get_data_for_uv_handle(handle);
|
||||
let f: Box<proc()> = cast::transmute(data);
|
||||
let f: Box<proc()> = mem::transmute(data);
|
||||
(*f)();
|
||||
assert_eq!(uvll::uv_idle_stop(handle), 0);
|
||||
uvll::uv_close(handle, close_cb);
|
||||
@ -95,7 +95,7 @@ impl Drop for IdleWatcher {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use std::rt::rtio::{Callback, PausableIdleCallback};
|
||||
@ -130,7 +130,7 @@ mod test {
|
||||
let rc = Rc::new(RefCell::new((None, 0)));
|
||||
let cb = box MyCallback(rc.clone(), v);
|
||||
let cb = cb as Box<Callback:>;
|
||||
let cb = unsafe { cast::transmute(cb) };
|
||||
let cb = unsafe { mem::transmute(cb) };
|
||||
(IdleWatcher::new(&mut local_loop().loop_, cb), rc)
|
||||
}
|
||||
|
||||
|
@ -48,10 +48,10 @@ via `close` and `delete` methods.
|
||||
extern crate libc;
|
||||
|
||||
use libc::{c_int, c_void};
|
||||
use std::cast;
|
||||
use std::fmt;
|
||||
use std::io::IoError;
|
||||
use std::io;
|
||||
use std::mem;
|
||||
use std::ptr::null;
|
||||
use std::ptr;
|
||||
use std::rt::local::Local;
|
||||
@ -147,12 +147,12 @@ pub trait UvHandle<T> {
|
||||
}
|
||||
|
||||
unsafe fn from_uv_handle<'a>(h: &'a *T) -> &'a mut Self {
|
||||
cast::transmute(uvll::get_data_for_uv_handle(*h))
|
||||
mem::transmute(uvll::get_data_for_uv_handle(*h))
|
||||
}
|
||||
|
||||
fn install(~self) -> Box<Self> {
|
||||
unsafe {
|
||||
let myptr = cast::transmute::<&Box<Self>, &*u8>(&self);
|
||||
let myptr = mem::transmute::<&Box<Self>, &*u8>(&self);
|
||||
uvll::set_data_for_uv_handle(self.uv_handle(), *myptr);
|
||||
}
|
||||
self
|
||||
@ -188,7 +188,7 @@ pub trait UvHandle<T> {
|
||||
let data = uvll::get_data_for_uv_handle(handle);
|
||||
uvll::free_handle(handle);
|
||||
if data == ptr::null() { return }
|
||||
let slot: &mut Option<BlockedTask> = cast::transmute(data);
|
||||
let slot: &mut Option<BlockedTask> = mem::transmute(data);
|
||||
wakeup(slot);
|
||||
}
|
||||
}
|
||||
@ -284,7 +284,7 @@ impl Request {
|
||||
pub unsafe fn get_data<T>(&self) -> &'static mut T {
|
||||
let data = uvll::get_data_for_req(self.handle);
|
||||
assert!(data != null());
|
||||
cast::transmute(data)
|
||||
mem::transmute(data)
|
||||
}
|
||||
|
||||
// This function should be used when the request handle has been given to an
|
||||
@ -459,11 +459,11 @@ pub fn slice_to_uv_buf(v: &[u8]) -> Buf {
|
||||
#[cfg(test)]
|
||||
fn local_loop() -> &'static mut uvio::UvIoFactory {
|
||||
unsafe {
|
||||
cast::transmute({
|
||||
mem::transmute({
|
||||
let mut task = Local::borrow(None::<Task>);
|
||||
let mut io = task.local_io().unwrap();
|
||||
let (_vtable, uvio): (uint, &'static mut uvio::UvIoFactory) =
|
||||
cast::transmute(io.get());
|
||||
mem::transmute(io.get());
|
||||
uvio
|
||||
})
|
||||
}
|
||||
@ -471,7 +471,7 @@ fn local_loop() -> &'static mut uvio::UvIoFactory {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::cast::transmute;
|
||||
use std::mem::transmute;
|
||||
use std::unstable::run_in_bare_thread;
|
||||
|
||||
use super::{slice_to_uv_buf, Loop};
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
use libc::{size_t, ssize_t, c_int, c_void, c_uint};
|
||||
use libc;
|
||||
use std::cast;
|
||||
use std::io;
|
||||
use std::io::IoError;
|
||||
use std::io::net::ip;
|
||||
@ -42,7 +41,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
|
||||
libc::AF_INET => {
|
||||
assert!(len as uint >= mem::size_of::<libc::sockaddr_in>());
|
||||
let storage: &libc::sockaddr_in = unsafe {
|
||||
cast::transmute(storage)
|
||||
mem::transmute(storage)
|
||||
};
|
||||
let addr = storage.sin_addr.s_addr as u32;
|
||||
let a = (addr >> 0) as u8;
|
||||
@ -57,7 +56,7 @@ pub fn sockaddr_to_addr(storage: &libc::sockaddr_storage,
|
||||
libc::AF_INET6 => {
|
||||
assert!(len as uint >= mem::size_of::<libc::sockaddr_in6>());
|
||||
let storage: &libc::sockaddr_in6 = unsafe {
|
||||
cast::transmute(storage)
|
||||
mem::transmute(storage)
|
||||
};
|
||||
let a = ntohs(storage.sin6_addr.s6_addr[0]);
|
||||
let b = ntohs(storage.sin6_addr.s6_addr[1]);
|
||||
@ -84,7 +83,7 @@ fn addr_to_sockaddr(addr: ip::SocketAddr) -> (libc::sockaddr_storage, uint) {
|
||||
let len = match addr.ip {
|
||||
ip::Ipv4Addr(a, b, c, d) => {
|
||||
let storage: &mut libc::sockaddr_in =
|
||||
cast::transmute(&mut storage);
|
||||
mem::transmute(&mut storage);
|
||||
(*storage).sin_family = libc::AF_INET as libc::sa_family_t;
|
||||
(*storage).sin_port = htons(addr.port);
|
||||
(*storage).sin_addr = libc::in_addr {
|
||||
@ -97,7 +96,7 @@ fn addr_to_sockaddr(addr: ip::SocketAddr) -> (libc::sockaddr_storage, uint) {
|
||||
}
|
||||
ip::Ipv6Addr(a, b, c, d, e, f, g, h) => {
|
||||
let storage: &mut libc::sockaddr_in6 =
|
||||
cast::transmute(&mut storage);
|
||||
mem::transmute(&mut storage);
|
||||
storage.sin6_family = libc::AF_INET6 as libc::sa_family_t;
|
||||
storage.sin6_port = htons(addr.port);
|
||||
storage.sin6_addr = libc::in6_addr {
|
||||
@ -316,7 +315,7 @@ impl rtio::RtioTcpStream for TcpWatcher {
|
||||
&self.stream as *_ as uint);
|
||||
|
||||
fn cancel_read(stream: uint) -> Option<BlockedTask> {
|
||||
let stream: &mut StreamWatcher = unsafe { cast::transmute(stream) };
|
||||
let stream: &mut StreamWatcher = unsafe { mem::transmute(stream) };
|
||||
stream.cancel_read(uvll::ECANCELED as ssize_t)
|
||||
}
|
||||
}
|
||||
@ -328,7 +327,7 @@ impl rtio::RtioTcpStream for TcpWatcher {
|
||||
&self.stream as *_ as uint);
|
||||
|
||||
fn cancel_write(stream: uint) -> Option<BlockedTask> {
|
||||
let stream: &mut StreamWatcher = unsafe { cast::transmute(stream) };
|
||||
let stream: &mut StreamWatcher = unsafe { mem::transmute(stream) };
|
||||
stream.cancel_write()
|
||||
}
|
||||
}
|
||||
@ -602,7 +601,7 @@ impl rtio::RtioUdpSocket for UdpWatcher {
|
||||
None
|
||||
} else {
|
||||
let len = mem::size_of::<libc::sockaddr_storage>();
|
||||
Some(sockaddr_to_addr(unsafe { cast::transmute(addr) }, len))
|
||||
Some(sockaddr_to_addr(unsafe { mem::transmute(addr) }, len))
|
||||
};
|
||||
cx.result = Some((nread, addr));
|
||||
wakeup(&mut cx.task);
|
||||
@ -652,7 +651,7 @@ impl rtio::RtioUdpSocket for UdpWatcher {
|
||||
};
|
||||
unsafe {
|
||||
req.set_data(&*new_cx);
|
||||
cast::forget(new_cx);
|
||||
mem::forget(new_cx);
|
||||
}
|
||||
Err(uv_error_to_io_error(UvError(cx.result)))
|
||||
}
|
||||
@ -670,7 +669,7 @@ impl rtio::RtioUdpSocket for UdpWatcher {
|
||||
let udp: &mut UdpWatcher = unsafe { &mut *cx.udp };
|
||||
wakeup(&mut udp.blocked_sender);
|
||||
} else {
|
||||
let _cx: Box<UdpSendCtx> = unsafe { cast::transmute(cx) };
|
||||
let _cx: Box<UdpSendCtx> = unsafe { mem::transmute(cx) };
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -789,7 +788,7 @@ impl rtio::RtioUdpSocket for UdpWatcher {
|
||||
self as *mut _ as uint);
|
||||
|
||||
fn cancel_write(stream: uint) -> Option<BlockedTask> {
|
||||
let stream: &mut UdpWatcher = unsafe { cast::transmute(stream) };
|
||||
let stream: &mut UdpWatcher = unsafe { mem::transmute(stream) };
|
||||
stream.blocked_sender.take()
|
||||
}
|
||||
}
|
||||
|
@ -10,9 +10,9 @@
|
||||
|
||||
use libc;
|
||||
use std::c_str::CString;
|
||||
use std::cast;
|
||||
use std::io::IoError;
|
||||
use std::io;
|
||||
use std::mem;
|
||||
use std::rt::rtio::{RtioPipe, RtioUnixListener, RtioUnixAcceptor};
|
||||
use std::rt::task::BlockedTask;
|
||||
|
||||
@ -185,7 +185,7 @@ impl RtioPipe for PipeWatcher {
|
||||
&self.stream as *_ as uint);
|
||||
|
||||
fn cancel_read(stream: uint) -> Option<BlockedTask> {
|
||||
let stream: &mut StreamWatcher = unsafe { cast::transmute(stream) };
|
||||
let stream: &mut StreamWatcher = unsafe { mem::transmute(stream) };
|
||||
stream.cancel_read(uvll::ECANCELED as libc::ssize_t)
|
||||
}
|
||||
}
|
||||
@ -197,7 +197,7 @@ impl RtioPipe for PipeWatcher {
|
||||
&self.stream as *_ as uint);
|
||||
|
||||
fn cancel_write(stream: uint) -> Option<BlockedTask> {
|
||||
let stream: &mut StreamWatcher = unsafe { cast::transmute(stream) };
|
||||
let stream: &mut StreamWatcher = unsafe { mem::transmute(stream) };
|
||||
stream.cancel_write()
|
||||
}
|
||||
}
|
||||
|
@ -21,10 +21,10 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use libc::c_void;
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::rt::task::BlockedTask;
|
||||
use std::unstable::mutex::NativeMutex;
|
||||
use std::sync::arc::UnsafeArc;
|
||||
use std::unstable::mutex::NativeMutex;
|
||||
use mpsc = std::sync::mpsc_queue;
|
||||
|
||||
use async::AsyncWatcher;
|
||||
@ -57,9 +57,9 @@ pub struct Queue {
|
||||
|
||||
extern fn async_cb(handle: *uvll::uv_async_t) {
|
||||
let pool: &mut QueuePool = unsafe {
|
||||
cast::transmute(uvll::get_data_for_uv_handle(handle))
|
||||
mem::transmute(uvll::get_data_for_uv_handle(handle))
|
||||
};
|
||||
let state: &mut State = unsafe { cast::transmute(pool.queue.get()) };
|
||||
let state: &mut State = unsafe { mem::transmute(pool.queue.get()) };
|
||||
|
||||
// Remember that there is no guarantee about how many times an async
|
||||
// callback is called with relation to the number of sends, so process the
|
||||
@ -183,7 +183,7 @@ impl Drop for Queue {
|
||||
impl Drop for State {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
uvll::uv_close(self.handle, cast::transmute(0));
|
||||
uvll::uv_close(self.handle, mem::transmute(0));
|
||||
// Note that this does *not* free the handle, that is the
|
||||
// responsibility of the caller because the uv loop must be closed
|
||||
// before we deallocate this uv handle.
|
||||
|
@ -8,8 +8,8 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use std::cast;
|
||||
use libc::{c_int, size_t, ssize_t};
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::rt::task::BlockedTask;
|
||||
|
||||
@ -212,7 +212,7 @@ impl StreamWatcher {
|
||||
};
|
||||
unsafe {
|
||||
req.set_data(&*new_wcx);
|
||||
cast::forget(new_wcx);
|
||||
mem::forget(new_wcx);
|
||||
}
|
||||
Err(UvError(wcx.result))
|
||||
}
|
||||
@ -232,7 +232,7 @@ extern fn alloc_cb(stream: *uvll::uv_stream_t, _hint: size_t, buf: *mut Buf) {
|
||||
uvdebug!("alloc_cb");
|
||||
unsafe {
|
||||
let rcx: &mut ReadContext =
|
||||
cast::transmute(uvll::get_data_for_uv_handle(stream));
|
||||
mem::transmute(uvll::get_data_for_uv_handle(stream));
|
||||
*buf = rcx.buf.take().expect("stream alloc_cb called more than once");
|
||||
}
|
||||
}
|
||||
@ -243,7 +243,7 @@ extern fn read_cb(handle: *uvll::uv_stream_t, nread: ssize_t, _buf: *Buf) {
|
||||
uvdebug!("read_cb {}", nread);
|
||||
assert!(nread != uvll::ECANCELED as ssize_t);
|
||||
let rcx: &mut ReadContext = unsafe {
|
||||
cast::transmute(uvll::get_data_for_uv_handle(handle))
|
||||
mem::transmute(uvll::get_data_for_uv_handle(handle))
|
||||
};
|
||||
// Stop reading so that no read callbacks are
|
||||
// triggered before the user calls `read` again.
|
||||
@ -272,6 +272,6 @@ extern fn write_cb(req: *uvll::uv_write_t, status: c_int) {
|
||||
let stream: &mut StreamWatcher = unsafe { &mut *wcx.stream };
|
||||
wakeup(&mut stream.blocked_writer);
|
||||
} else {
|
||||
let _wcx: Box<WriteContext> = unsafe { cast::transmute(wcx) };
|
||||
let _wcx: Box<WriteContext> = unsafe { mem::transmute(wcx) };
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@
|
||||
// except according to those terms.
|
||||
|
||||
use libc::c_int;
|
||||
use std::cast;
|
||||
use std::io::IoResult;
|
||||
use std::mem;
|
||||
use std::rt::task::BlockedTask;
|
||||
@ -127,7 +126,7 @@ impl AccessTimeout {
|
||||
};
|
||||
unsafe {
|
||||
timer.set_data(&*cx);
|
||||
cast::forget(cx);
|
||||
mem::forget(cx);
|
||||
}
|
||||
self.timer = Some(timer);
|
||||
}
|
||||
@ -199,7 +198,7 @@ impl Drop for AccessTimeout {
|
||||
match self.timer {
|
||||
Some(ref timer) => unsafe {
|
||||
let data = uvll::get_data_for_uv_handle(timer.handle);
|
||||
let _data: Box<TimerContext> = cast::transmute(data);
|
||||
let _data: Box<TimerContext> = mem::transmute(data);
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
|
@ -11,7 +11,6 @@
|
||||
//! The implementation of `rtio` for libuv
|
||||
|
||||
use std::c_str::CString;
|
||||
use std::cast;
|
||||
use std::io::IoError;
|
||||
use std::io::net::ip::SocketAddr;
|
||||
use std::io::process::ProcessConfig;
|
||||
@ -19,6 +18,7 @@ use std::io::signal::Signum;
|
||||
use std::io::{FileMode, FileAccess, Open, Append, Truncate, Read, Write,
|
||||
ReadWrite, FileStat};
|
||||
use std::io;
|
||||
use std::mem;
|
||||
use libc::c_int;
|
||||
use libc::{O_CREAT, O_APPEND, O_TRUNC, O_RDWR, O_RDONLY, O_WRONLY, S_IRUSR,
|
||||
S_IWUSR};
|
||||
@ -140,7 +140,7 @@ impl UvIoFactory {
|
||||
pub fn make_handle(&mut self) -> HomeHandle {
|
||||
// It's understood by the homing code that the "local id" is just the
|
||||
// pointer of the local I/O factory cast to a uint.
|
||||
let id: uint = unsafe { cast::transmute_copy(&self) };
|
||||
let id: uint = unsafe { mem::transmute_copy(&self) };
|
||||
HomeHandle::new(id, &mut **self.handle_pool.get_mut_ref())
|
||||
}
|
||||
}
|
||||
|
@ -88,7 +88,7 @@ pub enum Error {
|
||||
pub mod reader {
|
||||
use std::char;
|
||||
|
||||
use std::cast::transmute;
|
||||
use std::mem::transmute;
|
||||
use std::int;
|
||||
use std::option::{None, Option, Some};
|
||||
use std::io::extensions::u64_from_be_bytes;
|
||||
@ -617,11 +617,11 @@ pub mod reader {
|
||||
}
|
||||
|
||||
pub mod writer {
|
||||
use std::cast;
|
||||
use std::clone::Clone;
|
||||
use std::io;
|
||||
use std::io::{Writer, Seek};
|
||||
use std::io::extensions::u64_to_be_bytes;
|
||||
use std::io::{Writer, Seek};
|
||||
use std::io;
|
||||
use std::mem;
|
||||
|
||||
use super::{ EsVec, EsMap, EsEnum, EsVecLen, EsVecElt, EsMapLen, EsMapKey,
|
||||
EsEnumVid, EsU64, EsU32, EsU16, EsU8, EsInt, EsI64, EsI32, EsI16, EsI8,
|
||||
@ -679,7 +679,7 @@ pub mod writer {
|
||||
/// FIXME(pcwalton): Workaround for badness in trans. DO NOT USE ME.
|
||||
pub unsafe fn unsafe_clone(&self) -> Encoder<'a, W> {
|
||||
Encoder {
|
||||
writer: cast::transmute_copy(&self.writer),
|
||||
writer: mem::transmute_copy(&self.writer),
|
||||
size_positions: self.size_positions.clone(),
|
||||
}
|
||||
}
|
||||
@ -853,11 +853,11 @@ pub mod writer {
|
||||
}
|
||||
|
||||
fn emit_f64(&mut self, v: f64) -> EncodeResult {
|
||||
let bits = unsafe { cast::transmute(v) };
|
||||
let bits = unsafe { mem::transmute(v) };
|
||||
self.wr_tagged_u64(EsF64 as uint, bits)
|
||||
}
|
||||
fn emit_f32(&mut self, v: f32) -> EncodeResult {
|
||||
let bits = unsafe { cast::transmute(v) };
|
||||
let bits = unsafe { mem::transmute(v) };
|
||||
self.wr_tagged_u32(EsF32 as uint, bits)
|
||||
}
|
||||
fn emit_char(&mut self, v: char) -> EncodeResult {
|
||||
|
@ -10,18 +10,18 @@
|
||||
|
||||
//! Operations on ASCII strings and characters
|
||||
|
||||
use to_str::{IntoStr};
|
||||
use str;
|
||||
use str::Str;
|
||||
use str::{StrAllocating, StrSlice};
|
||||
use str::OwnedStr;
|
||||
use container::Container;
|
||||
use cast;
|
||||
use fmt;
|
||||
use iter::Iterator;
|
||||
use slice::{ImmutableVector, MutableVector, Vector};
|
||||
use vec::Vec;
|
||||
use mem;
|
||||
use option::{Option, Some, None};
|
||||
use slice::{ImmutableVector, MutableVector, Vector};
|
||||
use str::OwnedStr;
|
||||
use str::Str;
|
||||
use str::{StrAllocating, StrSlice};
|
||||
use str;
|
||||
use to_str::{IntoStr};
|
||||
use vec::Vec;
|
||||
|
||||
/// Datatype to hold one ascii character. It wraps a `u8`, with the highest bit always zero.
|
||||
#[deriving(Clone, Eq, Ord, TotalOrd, TotalEq, Hash)]
|
||||
@ -162,7 +162,7 @@ pub trait AsciiCast<T> {
|
||||
impl<'a> AsciiCast<&'a[Ascii]> for &'a [u8] {
|
||||
#[inline]
|
||||
unsafe fn to_ascii_nocheck(&self) -> &'a[Ascii] {
|
||||
cast::transmute(*self)
|
||||
mem::transmute(*self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -177,7 +177,7 @@ impl<'a> AsciiCast<&'a[Ascii]> for &'a [u8] {
|
||||
impl<'a> AsciiCast<&'a [Ascii]> for &'a str {
|
||||
#[inline]
|
||||
unsafe fn to_ascii_nocheck(&self) -> &'a [Ascii] {
|
||||
cast::transmute(*self)
|
||||
mem::transmute(*self)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -245,7 +245,7 @@ impl OwnedAsciiCast for ~[u8] {
|
||||
|
||||
#[inline]
|
||||
unsafe fn into_ascii_nocheck(self) -> Vec<Ascii> {
|
||||
cast::transmute(Vec::from_slice(self.as_slice()))
|
||||
mem::transmute(Vec::from_slice(self.as_slice()))
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,7 +257,7 @@ impl OwnedAsciiCast for ~str {
|
||||
|
||||
#[inline]
|
||||
unsafe fn into_ascii_nocheck(self) -> Vec<Ascii> {
|
||||
let v: ~[u8] = cast::transmute(self);
|
||||
let v: ~[u8] = mem::transmute(self);
|
||||
v.into_ascii_nocheck()
|
||||
}
|
||||
}
|
||||
@ -270,7 +270,7 @@ impl OwnedAsciiCast for Vec<u8> {
|
||||
|
||||
#[inline]
|
||||
unsafe fn into_ascii_nocheck(self) -> Vec<Ascii> {
|
||||
cast::transmute(self)
|
||||
mem::transmute(self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ pub trait AsciiStr {
|
||||
impl<'a> AsciiStr for &'a [Ascii] {
|
||||
#[inline]
|
||||
fn as_str_ascii<'a>(&'a self) -> &'a str {
|
||||
unsafe { cast::transmute(*self) }
|
||||
unsafe { mem::transmute(*self) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -315,7 +315,7 @@ impl<'a> AsciiStr for &'a [Ascii] {
|
||||
impl IntoStr for ~[Ascii] {
|
||||
#[inline]
|
||||
fn into_str(self) -> ~str {
|
||||
unsafe { cast::transmute(self) }
|
||||
unsafe { mem::transmute(self) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,7 +323,7 @@ impl IntoStr for Vec<Ascii> {
|
||||
#[inline]
|
||||
fn into_str(self) -> ~str {
|
||||
unsafe {
|
||||
let s: &str = cast::transmute(self.as_slice());
|
||||
let s: &str = mem::transmute(self.as_slice());
|
||||
s.to_owned()
|
||||
}
|
||||
}
|
||||
@ -337,7 +337,7 @@ pub trait IntoBytes {
|
||||
|
||||
impl IntoBytes for Vec<Ascii> {
|
||||
fn into_bytes(self) -> Vec<u8> {
|
||||
unsafe { cast::transmute(self) }
|
||||
unsafe { mem::transmute(self) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,24 +65,23 @@ fn main() {
|
||||
|
||||
*/
|
||||
|
||||
use cast;
|
||||
use clone::Clone;
|
||||
use cmp::Eq;
|
||||
use container::Container;
|
||||
use iter::{Iterator, range};
|
||||
use libc;
|
||||
use kinds::marker;
|
||||
use ops::Drop;
|
||||
use cmp::Eq;
|
||||
use clone::Clone;
|
||||
use libc;
|
||||
use mem;
|
||||
use ops::Drop;
|
||||
use option::{Option, Some, None};
|
||||
use ptr::RawPtr;
|
||||
use ptr;
|
||||
use str::StrSlice;
|
||||
use str;
|
||||
use raw::Slice;
|
||||
use rt::libc_heap::malloc_raw;
|
||||
use slice::{ImmutableVector, MutableVector};
|
||||
use slice;
|
||||
use rt::libc_heap::malloc_raw;
|
||||
use raw::Slice;
|
||||
use str::StrSlice;
|
||||
use str;
|
||||
|
||||
/// The representation of a C String.
|
||||
///
|
||||
@ -154,7 +153,7 @@ impl CString {
|
||||
/// Fails if the CString is null.
|
||||
pub fn with_mut_ref<T>(&mut self, f: |*mut libc::c_char| -> T) -> T {
|
||||
if self.buf.is_null() { fail!("CString is null!"); }
|
||||
f(unsafe { cast::transmute_mut_unsafe(self.buf) })
|
||||
f(self.buf as *mut libc::c_char)
|
||||
}
|
||||
|
||||
/// Returns true if the CString is a null.
|
||||
@ -182,7 +181,7 @@ impl CString {
|
||||
pub fn as_bytes<'a>(&'a self) -> &'a [u8] {
|
||||
if self.buf.is_null() { fail!("CString is null!"); }
|
||||
unsafe {
|
||||
cast::transmute(Slice { data: self.buf, len: self.len() + 1 })
|
||||
mem::transmute(Slice { data: self.buf, len: self.len() + 1 })
|
||||
}
|
||||
}
|
||||
|
||||
@ -196,7 +195,7 @@ impl CString {
|
||||
pub fn as_bytes_no_nul<'a>(&'a self) -> &'a [u8] {
|
||||
if self.buf.is_null() { fail!("CString is null!"); }
|
||||
unsafe {
|
||||
cast::transmute(Slice { data: self.buf, len: self.len() })
|
||||
mem::transmute(Slice { data: self.buf, len: self.len() })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,9 +33,9 @@
|
||||
//! handled correctly, i.e. that allocated memory is eventually freed
|
||||
//! if necessary.
|
||||
|
||||
use cast;
|
||||
use container::Container;
|
||||
use kinds::Send;
|
||||
use mem;
|
||||
use ops::Drop;
|
||||
use option::{Option, Some, None};
|
||||
use ptr::RawPtr;
|
||||
@ -102,14 +102,14 @@ impl<T> CVec<T> {
|
||||
/// View the stored data as a slice.
|
||||
pub fn as_slice<'a>(&'a self) -> &'a [T] {
|
||||
unsafe {
|
||||
cast::transmute(raw::Slice { data: self.base as *T, len: self.len })
|
||||
mem::transmute(raw::Slice { data: self.base as *T, len: self.len })
|
||||
}
|
||||
}
|
||||
|
||||
/// View the stored data as a mutable slice.
|
||||
pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
|
||||
unsafe {
|
||||
cast::transmute(raw::Slice { data: self.base as *T, len: self.len })
|
||||
mem::transmute(raw::Slice { data: self.base as *T, len: self.len })
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,11 +45,11 @@
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
use cast;
|
||||
use cell::Cell;
|
||||
use iter::Iterator;
|
||||
use kinds::marker;
|
||||
use kinds::Send;
|
||||
use kinds::marker;
|
||||
use mem;
|
||||
use ops::Drop;
|
||||
use option::{Some, None, Option};
|
||||
use owned::Box;
|
||||
@ -247,8 +247,8 @@ impl<'rx, T: Send> Handle<'rx, T> {
|
||||
/// while it is added to the `Select` set.
|
||||
pub unsafe fn add(&mut self) {
|
||||
if self.added { return }
|
||||
let selector: &mut Select = cast::transmute(&*self.selector);
|
||||
let me: *mut Handle<'static, ()> = cast::transmute(&*self);
|
||||
let selector: &mut Select = mem::transmute(&*self.selector);
|
||||
let me: *mut Handle<'static, ()> = mem::transmute(&*self);
|
||||
|
||||
if selector.head.is_null() {
|
||||
selector.head = me;
|
||||
@ -268,8 +268,8 @@ impl<'rx, T: Send> Handle<'rx, T> {
|
||||
pub unsafe fn remove(&mut self) {
|
||||
if !self.added { return }
|
||||
|
||||
let selector: &mut Select = cast::transmute(&*self.selector);
|
||||
let me: *mut Handle<'static, ()> = cast::transmute(&*self);
|
||||
let selector: &mut Select = mem::transmute(&*self.selector);
|
||||
let me: *mut Handle<'static, ()> = mem::transmute(&*self);
|
||||
|
||||
if self.prev.is_null() {
|
||||
assert_eq!(selector.head, me);
|
||||
|
@ -33,7 +33,6 @@
|
||||
/// of a synchronous channel. There are a few branches for the unbuffered case,
|
||||
/// but they're mostly just relevant to blocking senders.
|
||||
|
||||
use cast;
|
||||
use container::Container;
|
||||
use iter::Iterator;
|
||||
use kinds::Send;
|
||||
@ -187,7 +186,7 @@ impl<T: Send> Packet<T> {
|
||||
NoneBlocked if state.cap == 0 => {
|
||||
let mut canceled = false;
|
||||
assert!(state.canceled.is_none());
|
||||
state.canceled = Some(unsafe { cast::transmute(&mut canceled) });
|
||||
state.canceled = Some(unsafe { mem::transmute(&mut canceled) });
|
||||
wait(&mut state.blocker, BlockedSender, &self.lock);
|
||||
if canceled {Err(state.buf.dequeue())} else {Ok(())}
|
||||
}
|
||||
|
@ -484,26 +484,26 @@ will look like `"\\{"`.
|
||||
*/
|
||||
|
||||
use any;
|
||||
use cast;
|
||||
use cell::Cell;
|
||||
use char::Char;
|
||||
use cmp;
|
||||
use container::Container;
|
||||
use intrinsics::TypeId;
|
||||
use io::MemWriter;
|
||||
use io;
|
||||
use iter;
|
||||
use iter::{Iterator, range};
|
||||
use iter;
|
||||
use kinds::Copy;
|
||||
use mem;
|
||||
use num::Signed;
|
||||
use option::{Option, Some, None};
|
||||
use owned::Box;
|
||||
use repr;
|
||||
use result::{Ok, Err, ResultUnwrap};
|
||||
use str::{StrSlice, StrAllocating, UTF16Item, ScalarValue, LoneSurrogate};
|
||||
use str;
|
||||
use slice::{Vector, ImmutableVector};
|
||||
use slice;
|
||||
use intrinsics::TypeId;
|
||||
use str::{StrSlice, StrAllocating, UTF16Item, ScalarValue, LoneSurrogate};
|
||||
use str;
|
||||
|
||||
pub use self::num::radix;
|
||||
pub use self::num::Radix;
|
||||
@ -552,7 +552,7 @@ impl<'a> Arguments<'a> {
|
||||
#[doc(hidden)] #[inline]
|
||||
pub unsafe fn new<'a>(fmt: &'static [rt::Piece<'static>],
|
||||
args: &'a [Argument<'a>]) -> Arguments<'a> {
|
||||
Arguments{ fmt: cast::transmute(fmt), args: args }
|
||||
Arguments{ fmt: mem::transmute(fmt), args: args }
|
||||
}
|
||||
}
|
||||
|
||||
@ -870,7 +870,7 @@ impl<'a> Formatter<'a> {
|
||||
rt::Plural(offset, ref selectors, ref default) => {
|
||||
// This is validated at compile-time to be a pointer to a
|
||||
// '&uint' value.
|
||||
let value: &uint = unsafe { cast::transmute(arg.value) };
|
||||
let value: &uint = unsafe { mem::transmute(arg.value) };
|
||||
let value = *value;
|
||||
|
||||
// First, attempt to match against explicit values without the
|
||||
@ -913,7 +913,7 @@ impl<'a> Formatter<'a> {
|
||||
rt::Select(ref selectors, ref default) => {
|
||||
// This is validated at compile-time to be a pointer to a
|
||||
// string slice,
|
||||
let value: & &str = unsafe { cast::transmute(arg.value) };
|
||||
let value: & &str = unsafe { mem::transmute(arg.value) };
|
||||
let value = *value;
|
||||
|
||||
for s in selectors.iter() {
|
||||
@ -1093,8 +1093,8 @@ pub fn argument<'a, T>(f: extern "Rust" fn(&T, &mut Formatter) -> Result,
|
||||
t: &'a T) -> Argument<'a> {
|
||||
unsafe {
|
||||
Argument {
|
||||
formatter: cast::transmute(f),
|
||||
value: cast::transmute(t)
|
||||
formatter: mem::transmute(f),
|
||||
value: mem::transmute(t)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1141,7 +1141,7 @@ impl Char for char {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result {
|
||||
let mut utf8 = [0u8, ..4];
|
||||
let amt = self.encode_utf8(utf8);
|
||||
let s: &str = unsafe { cast::transmute(utf8.slice_to(amt)) };
|
||||
let s: &str = unsafe { mem::transmute(utf8.slice_to(amt)) };
|
||||
secret_string(&s, f)
|
||||
}
|
||||
}
|
||||
|
@ -307,7 +307,7 @@ impl<S: Writer, T: Hash<S>, U: Hash<S>> Hash<S> for Result<T, U> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use cast;
|
||||
use mem;
|
||||
use io::{IoResult, Writer};
|
||||
use iter::{Iterator};
|
||||
use option::{Some, None};
|
||||
@ -367,12 +367,12 @@ mod tests {
|
||||
assert_eq!(hasher.hash(& &[1u8, 2u8, 3u8]), 9);
|
||||
|
||||
unsafe {
|
||||
let ptr: *int = cast::transmute(5);
|
||||
let ptr: *int = mem::transmute(5);
|
||||
assert_eq!(hasher.hash(&ptr), 5);
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let ptr: *mut int = cast::transmute(5);
|
||||
let ptr: *mut int = mem::transmute(5);
|
||||
assert_eq!(hasher.hash(&ptr), 5);
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ impl<'r, R: Reader> Iterator<IoResult<u8>> for Bytes<'r, R> {
|
||||
/// This function returns the value returned by the callback, for convenience.
|
||||
pub fn u64_to_le_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
|
||||
use mem::{to_le16, to_le32, to_le64};
|
||||
use cast::transmute;
|
||||
use mem::transmute;
|
||||
|
||||
// LLVM fails to properly optimize this when using shifts instead of the to_le* intrinsics
|
||||
assert!(size <= 8u);
|
||||
@ -117,7 +117,7 @@ pub fn u64_to_le_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
|
||||
/// This function returns the value returned by the callback, for convenience.
|
||||
pub fn u64_to_be_bytes<T>(n: u64, size: uint, f: |v: &[u8]| -> T) -> T {
|
||||
use mem::{to_be16, to_be32, to_be64};
|
||||
use cast::transmute;
|
||||
use mem::transmute;
|
||||
|
||||
// LLVM fails to properly optimize this when using shifts instead of the to_be* intrinsics
|
||||
assert!(size <= 8u);
|
||||
|
@ -217,24 +217,24 @@ responding to errors that may occur while attempting to read the numbers.
|
||||
|
||||
#![deny(unused_must_use)]
|
||||
|
||||
use cast;
|
||||
use char::Char;
|
||||
use container::Container;
|
||||
use fmt;
|
||||
use int;
|
||||
use iter::Iterator;
|
||||
use libc;
|
||||
use mem::transmute;
|
||||
use ops::{BitOr, BitAnd, Sub};
|
||||
use os;
|
||||
use option::{Option, Some, None};
|
||||
use os;
|
||||
use owned::Box;
|
||||
use path::Path;
|
||||
use result::{Ok, Err, Result};
|
||||
use slice::{Vector, MutableVector, ImmutableVector};
|
||||
use str::{StrSlice, StrAllocating};
|
||||
use str;
|
||||
use uint;
|
||||
use unstable::finally::try_finally;
|
||||
use slice::{Vector, MutableVector, ImmutableVector};
|
||||
use vec::Vec;
|
||||
|
||||
// Reexports
|
||||
@ -729,7 +729,7 @@ pub trait Reader {
|
||||
/// `f64`s are 8 byte, IEEE754 double-precision floating point numbers.
|
||||
fn read_be_f64(&mut self) -> IoResult<f64> {
|
||||
self.read_be_u64().map(|i| unsafe {
|
||||
cast::transmute::<u64, f64>(i)
|
||||
transmute::<u64, f64>(i)
|
||||
})
|
||||
}
|
||||
|
||||
@ -738,7 +738,7 @@ pub trait Reader {
|
||||
/// `f32`s are 4 byte, IEEE754 single-precision floating point numbers.
|
||||
fn read_be_f32(&mut self) -> IoResult<f32> {
|
||||
self.read_be_u32().map(|i| unsafe {
|
||||
cast::transmute::<u32, f32>(i)
|
||||
transmute::<u32, f32>(i)
|
||||
})
|
||||
}
|
||||
|
||||
@ -789,7 +789,7 @@ pub trait Reader {
|
||||
/// `f64`s are 8 byte, IEEE754 double-precision floating point numbers.
|
||||
fn read_le_f64(&mut self) -> IoResult<f64> {
|
||||
self.read_le_u64().map(|i| unsafe {
|
||||
cast::transmute::<u64, f64>(i)
|
||||
transmute::<u64, f64>(i)
|
||||
})
|
||||
}
|
||||
|
||||
@ -798,7 +798,7 @@ pub trait Reader {
|
||||
/// `f32`s are 4 byte, IEEE754 single-precision floating point numbers.
|
||||
fn read_le_f32(&mut self) -> IoResult<f32> {
|
||||
self.read_le_u32().map(|i| unsafe {
|
||||
cast::transmute::<u32, f32>(i)
|
||||
transmute::<u32, f32>(i)
|
||||
})
|
||||
}
|
||||
|
||||
@ -995,14 +995,14 @@ pub trait Writer {
|
||||
/// Write a big-endian IEEE754 double-precision floating-point (8 bytes).
|
||||
fn write_be_f64(&mut self, f: f64) -> IoResult<()> {
|
||||
unsafe {
|
||||
self.write_be_u64(cast::transmute(f))
|
||||
self.write_be_u64(transmute(f))
|
||||
}
|
||||
}
|
||||
|
||||
/// Write a big-endian IEEE754 single-precision floating-point (4 bytes).
|
||||
fn write_be_f32(&mut self, f: f32) -> IoResult<()> {
|
||||
unsafe {
|
||||
self.write_be_u32(cast::transmute(f))
|
||||
self.write_be_u32(transmute(f))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1040,7 +1040,7 @@ pub trait Writer {
|
||||
/// (8 bytes).
|
||||
fn write_le_f64(&mut self, f: f64) -> IoResult<()> {
|
||||
unsafe {
|
||||
self.write_le_u64(cast::transmute(f))
|
||||
self.write_le_u64(transmute(f))
|
||||
}
|
||||
}
|
||||
|
||||
@ -1048,7 +1048,7 @@ pub trait Writer {
|
||||
/// (4 bytes).
|
||||
fn write_le_f32(&mut self, f: f32) -> IoResult<()> {
|
||||
unsafe {
|
||||
self.write_le_u32(cast::transmute(f))
|
||||
self.write_le_u32(transmute(f))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -226,6 +226,7 @@ impl Writer for UdpStream {
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[allow(experimental)]
|
||||
mod test {
|
||||
use super::*;
|
||||
use io::net::ip::{SocketAddr};
|
||||
|
@ -143,7 +143,6 @@ extern crate core;
|
||||
|
||||
pub use core::any;
|
||||
pub use core::bool;
|
||||
pub use core::cast;
|
||||
pub use core::cell;
|
||||
pub use core::char;
|
||||
pub use core::clone;
|
||||
|
@ -38,11 +38,11 @@ assert_eq!(*key_vector.get().unwrap(), ~[4]);
|
||||
// Casting 'Arcane Sight' reveals an overwhelming aura of Transmutation
|
||||
// magic.
|
||||
|
||||
use cast;
|
||||
use iter::{Iterator};
|
||||
use kinds::Send;
|
||||
use kinds::marker;
|
||||
use mem::replace;
|
||||
use mem;
|
||||
use ops::{Drop, Deref};
|
||||
use option::{None, Option, Some};
|
||||
use owned::Box;
|
||||
@ -172,7 +172,7 @@ impl<T: 'static> KeyValue<T> {
|
||||
// anything.
|
||||
let newval = data.map(|d| {
|
||||
let d = box d as Box<LocalData>;
|
||||
let d: Box<LocalData:Send> = unsafe { cast::transmute(d) };
|
||||
let d: Box<LocalData:Send> = unsafe { mem::transmute(d) };
|
||||
(keyval, d, 0)
|
||||
});
|
||||
|
||||
@ -188,8 +188,8 @@ impl<T: 'static> KeyValue<T> {
|
||||
replace(map.get_mut(i), newval).map(|(_, data, _)| {
|
||||
// Move `data` into transmute to get out the memory that it
|
||||
// owns, we must free it manually later.
|
||||
let t: raw::TraitObject = unsafe { cast::transmute(data) };
|
||||
let alloc: Box<T> = unsafe { cast::transmute(t.data) };
|
||||
let t: raw::TraitObject = unsafe { mem::transmute(data) };
|
||||
let alloc: Box<T> = unsafe { mem::transmute(t.data) };
|
||||
|
||||
// Now that we own `alloc`, we can just move out of it as we
|
||||
// would with any other data.
|
||||
|
@ -15,13 +15,13 @@
|
||||
|
||||
use prelude::*;
|
||||
|
||||
use cast;
|
||||
use from_str::FromStr;
|
||||
use libc::c_int;
|
||||
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
|
||||
use num::strconv;
|
||||
use num;
|
||||
use intrinsics;
|
||||
use libc::c_int;
|
||||
use mem;
|
||||
use num::strconv;
|
||||
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
|
||||
use num;
|
||||
|
||||
pub use core::f32::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON, MIN_VALUE};
|
||||
pub use core::f32::{MIN_POS_VALUE, MAX_VALUE, MIN_EXP, MAX_EXP, MIN_10_EXP};
|
||||
@ -111,7 +111,7 @@ impl Float for f32 {
|
||||
static EXP_MASK: u32 = 0x7f800000;
|
||||
static MAN_MASK: u32 = 0x007fffff;
|
||||
|
||||
let bits: u32 = unsafe { cast::transmute(self) };
|
||||
let bits: u32 = unsafe { mem::transmute(self) };
|
||||
match (bits & MAN_MASK, bits & EXP_MASK) {
|
||||
(0, 0) => FPZero,
|
||||
(_, 0) => FPSubnormal,
|
||||
@ -168,7 +168,7 @@ impl Float for f32 {
|
||||
|
||||
/// Returns the mantissa, exponent and sign as integers.
|
||||
fn integer_decode(self) -> (u64, i16, i8) {
|
||||
let bits: u32 = unsafe { cast::transmute(self) };
|
||||
let bits: u32 = unsafe { mem::transmute(self) };
|
||||
let sign: i8 = if bits >> 31 == 0 { 1 } else { -1 };
|
||||
let mut exponent: i16 = ((bits >> 23) & 0xff) as i16;
|
||||
let mantissa = if exponent == 0 {
|
||||
|
@ -14,13 +14,13 @@
|
||||
|
||||
use prelude::*;
|
||||
|
||||
use cast;
|
||||
use from_str::FromStr;
|
||||
use intrinsics;
|
||||
use libc::{c_int};
|
||||
use mem;
|
||||
use num::{FPCategory, FPNaN, FPInfinite , FPZero, FPSubnormal, FPNormal};
|
||||
use num::{strconv};
|
||||
use num;
|
||||
use intrinsics;
|
||||
|
||||
pub use core::f64::{RADIX, MANTISSA_DIGITS, DIGITS, EPSILON, MIN_VALUE};
|
||||
pub use core::f64::{MIN_POS_VALUE, MAX_VALUE, MIN_EXP, MAX_EXP, MIN_10_EXP};
|
||||
@ -119,7 +119,7 @@ impl Float for f64 {
|
||||
static EXP_MASK: u64 = 0x7ff0000000000000;
|
||||
static MAN_MASK: u64 = 0x000fffffffffffff;
|
||||
|
||||
let bits: u64 = unsafe { cast::transmute(self) };
|
||||
let bits: u64 = unsafe { mem::transmute(self) };
|
||||
match (bits & MAN_MASK, bits & EXP_MASK) {
|
||||
(0, 0) => FPZero,
|
||||
(_, 0) => FPSubnormal,
|
||||
@ -176,7 +176,7 @@ impl Float for f64 {
|
||||
|
||||
/// Returns the mantissa, exponent and sign as integers.
|
||||
fn integer_decode(self) -> (u64, i16, i8) {
|
||||
let bits: u64 = unsafe { cast::transmute(self) };
|
||||
let bits: u64 = unsafe { mem::transmute(self) };
|
||||
let sign: i8 = if bits >> 63 == 0 { 1 } else { -1 };
|
||||
let mut exponent: i16 = ((bits >> 52) & 0x7ff) as i16;
|
||||
let mantissa = if exponent == 0 {
|
||||
|
@ -12,13 +12,13 @@
|
||||
|
||||
use ascii::AsciiCast;
|
||||
use c_str::{CString, ToCStr};
|
||||
use cast;
|
||||
use clone::Clone;
|
||||
use container::Container;
|
||||
use cmp::{Eq, TotalEq};
|
||||
use container::Container;
|
||||
use from_str::FromStr;
|
||||
use io::Writer;
|
||||
use iter::{AdditiveIterator, DoubleEndedIterator, Extendable, Rev, Iterator, Map};
|
||||
use mem;
|
||||
use option::{Option, Some, None};
|
||||
use slice::{Vector, OwnedVector, ImmutableVector};
|
||||
use str::{CharSplits, Str, StrAllocating, StrVector, StrSlice};
|
||||
@ -389,13 +389,13 @@ impl GenericPath for Path {
|
||||
#[inline]
|
||||
fn filestem_str<'a>(&'a self) -> Option<&'a str> {
|
||||
// filestem() returns a byte vector that's guaranteed valid UTF-8
|
||||
self.filestem().map(|t| unsafe { cast::transmute(t) })
|
||||
self.filestem().map(|t| unsafe { mem::transmute(t) })
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn extension_str<'a>(&'a self) -> Option<&'a str> {
|
||||
// extension() returns a byte vector that's guaranteed valid UTF-8
|
||||
self.extension().map(|t| unsafe { cast::transmute(t) })
|
||||
self.extension().map(|t| unsafe { mem::transmute(t) })
|
||||
}
|
||||
|
||||
fn dir_path(&self) -> Path {
|
||||
|
@ -23,7 +23,7 @@ pointers, and then storing the parent pointers as `Weak` pointers.
|
||||
|
||||
*/
|
||||
|
||||
use cast::transmute;
|
||||
use mem::transmute;
|
||||
use cell::Cell;
|
||||
use clone::Clone;
|
||||
use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering};
|
||||
|
@ -16,7 +16,7 @@ More runtime type reflection
|
||||
|
||||
#![allow(missing_doc)]
|
||||
|
||||
use cast::transmute;
|
||||
use mem::transmute;
|
||||
use char;
|
||||
use container::Container;
|
||||
use io;
|
||||
@ -157,7 +157,7 @@ impl<'a> ReprVisitor<'a> {
|
||||
ptr: ptr,
|
||||
ptr_stk: vec!(),
|
||||
var_stk: vec!(),
|
||||
writer: ::cast::transmute_copy(&self.writer),
|
||||
writer: ::mem::transmute_copy(&self.writer),
|
||||
last_err: None,
|
||||
};
|
||||
let mut v = reflect::MovePtrAdaptor(u);
|
||||
|
@ -40,7 +40,7 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) }
|
||||
#[cfg(not(test))] pub fn take() -> Option<Vec<~[u8]>> { imp::take() }
|
||||
#[cfg(test)] pub fn take() -> Option<Vec<~[u8]>> {
|
||||
match realargs::take() {
|
||||
realstd::option::Some(v) => Some(unsafe{ ::cast::transmute(v) }),
|
||||
realstd::option::Some(v) => Some(unsafe{ ::mem::transmute(v) }),
|
||||
realstd::option::None => None,
|
||||
}
|
||||
}
|
||||
@ -49,13 +49,13 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) }
|
||||
///
|
||||
/// It is an error if the arguments already exist.
|
||||
#[cfg(not(test))] pub fn put(args: Vec<~[u8]>) { imp::put(args) }
|
||||
#[cfg(test)] pub fn put(args: Vec<~[u8]>) { realargs::put(unsafe { ::cast::transmute(args) }) }
|
||||
#[cfg(test)] pub fn put(args: Vec<~[u8]>) { realargs::put(unsafe { ::mem::transmute(args) }) }
|
||||
|
||||
/// Make a clone of the global arguments.
|
||||
#[cfg(not(test))] pub fn clone() -> Option<Vec<~[u8]>> { imp::clone() }
|
||||
#[cfg(test)] pub fn clone() -> Option<Vec<~[u8]>> {
|
||||
match realargs::clone() {
|
||||
realstd::option::Some(v) => Some(unsafe { ::cast::transmute(v) }),
|
||||
realstd::option::Some(v) => Some(unsafe { ::mem::transmute(v) }),
|
||||
realstd::option::None => None,
|
||||
}
|
||||
}
|
||||
@ -64,10 +64,9 @@ pub unsafe fn init(argc: int, argv: **u8) { realargs::init(argc, argv) }
|
||||
#[cfg(target_os = "android")]
|
||||
#[cfg(target_os = "freebsd")]
|
||||
mod imp {
|
||||
use cast;
|
||||
use clone::Clone;
|
||||
use option::{Option, Some, None};
|
||||
use iter::Iterator;
|
||||
use option::{Option, Some, None};
|
||||
use owned::Box;
|
||||
use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
|
||||
use mem;
|
||||
@ -120,7 +119,7 @@ mod imp {
|
||||
}
|
||||
|
||||
fn get_global_ptr() -> *mut Option<Box<Vec<~[u8]>>> {
|
||||
unsafe { cast::transmute(&global_args_ptr) }
|
||||
unsafe { mem::transmute(&global_args_ptr) }
|
||||
}
|
||||
|
||||
// Copied from `os`.
|
||||
|
@ -12,15 +12,14 @@
|
||||
//!
|
||||
//! Documentation can be found on the `rt::at_exit` function.
|
||||
|
||||
use cast;
|
||||
use iter::Iterator;
|
||||
use kinds::Send;
|
||||
use mem;
|
||||
use option::{Some, None};
|
||||
use owned::Box;
|
||||
use ptr::RawPtr;
|
||||
use unstable::sync::Exclusive;
|
||||
use slice::OwnedVector;
|
||||
use unstable::sync::Exclusive;
|
||||
use vec::Vec;
|
||||
|
||||
type Queue = Exclusive<Vec<proc():Send>>;
|
||||
@ -38,7 +37,7 @@ pub fn init() {
|
||||
rtassert!(!RUNNING);
|
||||
rtassert!(QUEUE.is_null());
|
||||
let state: Box<Queue> = box Exclusive::new(vec!());
|
||||
QUEUE = cast::transmute(state);
|
||||
QUEUE = mem::transmute(state);
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,7 +45,7 @@ pub fn push(f: proc():Send) {
|
||||
unsafe {
|
||||
rtassert!(!RUNNING);
|
||||
rtassert!(!QUEUE.is_null());
|
||||
let state: &mut Queue = cast::transmute(QUEUE);
|
||||
let state: &mut Queue = mem::transmute(QUEUE);
|
||||
let mut f = Some(f);
|
||||
state.with(|arr| {
|
||||
arr.push(f.take_unwrap());
|
||||
@ -59,7 +58,7 @@ pub fn run() {
|
||||
rtassert!(!RUNNING);
|
||||
rtassert!(!QUEUE.is_null());
|
||||
RUNNING = true;
|
||||
let state: Box<Queue> = cast::transmute(QUEUE);
|
||||
let state: Box<Queue> = mem::transmute(QUEUE);
|
||||
QUEUE = 0 as *mut Queue;
|
||||
let mut vec = None;
|
||||
state.with(|arr| {
|
||||
|
@ -237,9 +237,9 @@ fn demangle(writer: &mut Writer, s: &str) -> IoResult<()> {
|
||||
#[cfg(unix)]
|
||||
mod imp {
|
||||
use c_str::CString;
|
||||
use cast;
|
||||
use io::{IoResult, IoError, Writer};
|
||||
use libc;
|
||||
use mem;
|
||||
use option::{Some, None, Option};
|
||||
use result::{Ok, Err};
|
||||
use unstable::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
|
||||
@ -280,7 +280,7 @@ mod imp {
|
||||
|
||||
extern fn trace_fn(ctx: *uw::_Unwind_Context,
|
||||
arg: *libc::c_void) -> uw::_Unwind_Reason_Code {
|
||||
let cx: &mut Context = unsafe { cast::transmute(arg) };
|
||||
let cx: &mut Context = unsafe { mem::transmute(arg) };
|
||||
let ip = unsafe { uw::_Unwind_GetIP(ctx) as *libc::c_void };
|
||||
// dladdr() on osx gets whiny when we use FindEnclosingFunction, and
|
||||
// it appears to work fine without it, so we only use
|
||||
|
@ -10,18 +10,17 @@
|
||||
|
||||
//! The local, garbage collected heap
|
||||
|
||||
use cast;
|
||||
use iter::Iterator;
|
||||
use libc::{c_void, free};
|
||||
use mem;
|
||||
use ops::Drop;
|
||||
use option::{Option, None, Some};
|
||||
use ptr;
|
||||
use ptr::RawPtr;
|
||||
use ptr;
|
||||
use raw;
|
||||
use rt::libc_heap;
|
||||
use rt::local::Local;
|
||||
use rt::task::Task;
|
||||
use raw;
|
||||
use slice::{ImmutableVector, Vector};
|
||||
use vec::Vec;
|
||||
|
||||
@ -63,7 +62,7 @@ impl LocalHeap {
|
||||
let alloc = self.memory_region.malloc(total_size);
|
||||
{
|
||||
// Make sure that we can't use `mybox` outside of this scope
|
||||
let mybox: &mut Box = unsafe { cast::transmute(alloc) };
|
||||
let mybox: &mut Box = unsafe { mem::transmute(alloc) };
|
||||
// Clear out this box, and move it to the front of the live
|
||||
// allocations list
|
||||
mybox.drop_glue = drop_glue;
|
||||
@ -85,7 +84,7 @@ impl LocalHeap {
|
||||
let new_box = self.memory_region.realloc(ptr, total_size);
|
||||
{
|
||||
// Fix links because we could have moved around
|
||||
let mybox: &mut Box = unsafe { cast::transmute(new_box) };
|
||||
let mybox: &mut Box = unsafe { mem::transmute(new_box) };
|
||||
if !mybox.prev.is_null() {
|
||||
unsafe { (*mybox.prev).next = new_box; }
|
||||
}
|
||||
@ -103,7 +102,7 @@ impl LocalHeap {
|
||||
pub fn free(&mut self, alloc: *mut Box) {
|
||||
{
|
||||
// Make sure that we can't use `mybox` outside of this scope
|
||||
let mybox: &mut Box = unsafe { cast::transmute(alloc) };
|
||||
let mybox: &mut Box = unsafe { mem::transmute(alloc) };
|
||||
|
||||
// Unlink it from the linked list
|
||||
if !mybox.prev.is_null() {
|
||||
@ -167,7 +166,7 @@ impl AllocHeader {
|
||||
fn update_size(&mut self, _size: u32) {}
|
||||
|
||||
fn as_box(&mut self) -> *mut Box {
|
||||
let myaddr: uint = unsafe { cast::transmute(self) };
|
||||
let myaddr: uint = unsafe { mem::transmute(self) };
|
||||
(myaddr + AllocHeader::size()) as *mut Box
|
||||
}
|
||||
|
||||
@ -191,7 +190,7 @@ impl MemoryRegion {
|
||||
libc_heap::malloc_raw(total_size) as *AllocHeader
|
||||
};
|
||||
|
||||
let alloc: &mut AllocHeader = unsafe { cast::transmute(alloc) };
|
||||
let alloc: &mut AllocHeader = unsafe { mem::transmute(alloc) };
|
||||
alloc.init(size as u32);
|
||||
self.claim(alloc);
|
||||
self.live_allocations += 1;
|
||||
@ -210,7 +209,7 @@ impl MemoryRegion {
|
||||
libc_heap::realloc_raw(orig_alloc as *mut u8, total_size) as *AllocHeader
|
||||
};
|
||||
|
||||
let alloc: &mut AllocHeader = unsafe { cast::transmute(alloc) };
|
||||
let alloc: &mut AllocHeader = unsafe { mem::transmute(alloc) };
|
||||
alloc.assert_sane();
|
||||
alloc.update_size(size as u32);
|
||||
self.update(alloc, orig_alloc as *AllocHeader);
|
||||
@ -223,7 +222,7 @@ impl MemoryRegion {
|
||||
let alloc = AllocHeader::from(alloc);
|
||||
unsafe {
|
||||
(*alloc).assert_sane();
|
||||
self.release(cast::transmute(alloc));
|
||||
self.release(mem::transmute(alloc));
|
||||
rtassert!(self.live_allocations > 0);
|
||||
self.live_allocations -= 1;
|
||||
free(alloc as *mut c_void)
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
use cast;
|
||||
use mem;
|
||||
use ops::{Drop, Deref, DerefMut};
|
||||
use owned::Box;
|
||||
use ptr::RawPtr;
|
||||
@ -44,7 +44,7 @@ impl<T> Drop for Borrowed<T> {
|
||||
if self.val.is_null() {
|
||||
rtabort!("Aiee, returning null borrowed object!");
|
||||
}
|
||||
let val: Box<T> = cast::transmute(self.val);
|
||||
let val: Box<T> = mem::transmute(self.val);
|
||||
put::<T>(val);
|
||||
rtassert!(exists());
|
||||
}
|
||||
@ -71,7 +71,7 @@ impl<T> DerefMut<T> for Borrowed<T> {
|
||||
/// Does not validate the pointer type.
|
||||
#[inline]
|
||||
pub unsafe fn borrow<T>() -> Borrowed<T> {
|
||||
let val: *() = cast::transmute(take::<T>());
|
||||
let val: *() = mem::transmute(take::<T>());
|
||||
Borrowed {
|
||||
val: val,
|
||||
}
|
||||
@ -83,7 +83,7 @@ pub unsafe fn borrow<T>() -> Borrowed<T> {
|
||||
/// it wherever possible.
|
||||
#[cfg(not(windows), not(target_os = "android"))]
|
||||
pub mod compiled {
|
||||
use cast;
|
||||
use mem;
|
||||
use option::{Option, Some, None};
|
||||
use owned::Box;
|
||||
use ptr::RawPtr;
|
||||
@ -157,7 +157,7 @@ pub mod compiled {
|
||||
/// Does not validate the pointer type.
|
||||
#[inline(never)] // see comments above
|
||||
pub unsafe fn put<T>(sched: Box<T>) {
|
||||
RT_TLS_PTR = cast::transmute(sched)
|
||||
RT_TLS_PTR = mem::transmute(sched)
|
||||
}
|
||||
|
||||
/// Take ownership of a pointer from thread-local storage.
|
||||
@ -169,9 +169,9 @@ pub mod compiled {
|
||||
pub unsafe fn take<T>() -> Box<T> {
|
||||
let ptr = RT_TLS_PTR;
|
||||
rtassert!(!ptr.is_null());
|
||||
let ptr: Box<T> = cast::transmute(ptr);
|
||||
let ptr: Box<T> = mem::transmute(ptr);
|
||||
// can't use `as`, due to type not matching with `cfg(test)`
|
||||
RT_TLS_PTR = cast::transmute(0);
|
||||
RT_TLS_PTR = mem::transmute(0);
|
||||
ptr
|
||||
}
|
||||
|
||||
@ -186,9 +186,9 @@ pub mod compiled {
|
||||
if ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
let ptr: Box<T> = cast::transmute(ptr);
|
||||
let ptr: Box<T> = mem::transmute(ptr);
|
||||
// can't use `as`, due to type not matching with `cfg(test)`
|
||||
RT_TLS_PTR = cast::transmute(0);
|
||||
RT_TLS_PTR = mem::transmute(0);
|
||||
Some(ptr)
|
||||
}
|
||||
}
|
||||
@ -201,7 +201,7 @@ pub mod compiled {
|
||||
/// Leaves the old pointer in TLS for speed.
|
||||
#[inline(never)] // see comments above
|
||||
pub unsafe fn unsafe_take<T>() -> Box<T> {
|
||||
cast::transmute(RT_TLS_PTR)
|
||||
mem::transmute(RT_TLS_PTR)
|
||||
}
|
||||
|
||||
/// Check whether there is a thread-local pointer installed.
|
||||
@ -234,11 +234,11 @@ pub mod compiled {
|
||||
/// implementation uses the `thread_local_storage` module to provide a
|
||||
/// thread-local value.
|
||||
pub mod native {
|
||||
use cast;
|
||||
use mem;
|
||||
use option::{Option, Some, None};
|
||||
use owned::Box;
|
||||
use ptr;
|
||||
use ptr::RawPtr;
|
||||
use ptr;
|
||||
use tls = rt::thread_local_storage;
|
||||
|
||||
static mut RT_TLS_KEY: tls::Key = -1;
|
||||
@ -264,7 +264,7 @@ pub mod native {
|
||||
#[inline]
|
||||
pub unsafe fn put<T>(sched: Box<T>) {
|
||||
let key = tls_key();
|
||||
let void_ptr: *mut u8 = cast::transmute(sched);
|
||||
let void_ptr: *mut u8 = mem::transmute(sched);
|
||||
tls::set(key, void_ptr);
|
||||
}
|
||||
|
||||
@ -280,7 +280,7 @@ pub mod native {
|
||||
if void_ptr.is_null() {
|
||||
rtabort!("thread-local pointer is null. bogus!");
|
||||
}
|
||||
let ptr: Box<T> = cast::transmute(void_ptr);
|
||||
let ptr: Box<T> = mem::transmute(void_ptr);
|
||||
tls::set(key, ptr::mut_null());
|
||||
return ptr;
|
||||
}
|
||||
@ -298,7 +298,7 @@ pub mod native {
|
||||
if void_ptr.is_null() {
|
||||
None
|
||||
} else {
|
||||
let ptr: Box<T> = cast::transmute(void_ptr);
|
||||
let ptr: Box<T> = mem::transmute(void_ptr);
|
||||
tls::set(key, ptr::mut_null());
|
||||
Some(ptr)
|
||||
}
|
||||
@ -320,7 +320,7 @@ pub mod native {
|
||||
if void_ptr.is_null() {
|
||||
rtabort!("thread-local pointer is null. bogus!");
|
||||
}
|
||||
let ptr: Box<T> = cast::transmute(void_ptr);
|
||||
let ptr: Box<T> = mem::transmute(void_ptr);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@ -398,7 +398,7 @@ pub mod native {
|
||||
pub fn maybe_tls_key() -> Option<tls::Key> {
|
||||
use realstd;
|
||||
unsafe {
|
||||
cast::transmute(realstd::rt::shouldnt_be_public::maybe_tls_key())
|
||||
mem::transmute(realstd::rt::shouldnt_be_public::maybe_tls_key())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,11 +11,11 @@
|
||||
//! The EventLoop and internal synchronous I/O interface.
|
||||
|
||||
use c_str::CString;
|
||||
use cast;
|
||||
use comm::{Sender, Receiver};
|
||||
use kinds::Send;
|
||||
use libc::c_int;
|
||||
use libc;
|
||||
use kinds::Send;
|
||||
use mem;
|
||||
use ops::Drop;
|
||||
use option::{Option, Some, None};
|
||||
use owned::Box;
|
||||
@ -118,7 +118,7 @@ impl<'a> LocalIo<'a> {
|
||||
// in order to have what is likely a static lifetime (bad).
|
||||
let mut t: Box<Task> = Local::take();
|
||||
let ret = t.local_io().map(|t| {
|
||||
unsafe { cast::transmute_copy(&t) }
|
||||
unsafe { mem::transmute_copy(&t) }
|
||||
});
|
||||
Local::put(t);
|
||||
return ret;
|
||||
@ -143,7 +143,7 @@ impl<'a> LocalIo<'a> {
|
||||
// FIXME(pcwalton): I think this is actually sound? Could borrow check
|
||||
// allow this safely?
|
||||
unsafe {
|
||||
cast::transmute_copy(&self.factory)
|
||||
mem::transmute_copy(&self.factory)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,6 @@
|
||||
//! to implement this.
|
||||
|
||||
use any::AnyOwnExt;
|
||||
use cast;
|
||||
use cleanup;
|
||||
use clone::Clone;
|
||||
use comm::Sender;
|
||||
@ -22,6 +21,7 @@ use io::Writer;
|
||||
use iter::{Iterator, Take};
|
||||
use kinds::Send;
|
||||
use local_data;
|
||||
use mem;
|
||||
use ops::Drop;
|
||||
use option::{Option, Some, None};
|
||||
use owned::Box;
|
||||
@ -116,7 +116,7 @@ impl Task {
|
||||
// Unsafely get a handle to the task so we can continue to use it after
|
||||
// putting it in tls (so we can invoke the unwinder).
|
||||
let handle: *mut Task = unsafe {
|
||||
*cast::transmute::<&Box<Task>, &*mut Task>(&self)
|
||||
*mem::transmute::<&Box<Task>, &*mut Task>(&self)
|
||||
};
|
||||
Local::put(self);
|
||||
|
||||
@ -222,13 +222,13 @@ impl Task {
|
||||
// crops up.
|
||||
unsafe {
|
||||
let imp = self.imp.take_unwrap();
|
||||
let &(vtable, _): &(uint, uint) = cast::transmute(&imp);
|
||||
let &(vtable, _): &(uint, uint) = mem::transmute(&imp);
|
||||
match imp.wrap().move::<T>() {
|
||||
Ok(t) => Some(t),
|
||||
Err(t) => {
|
||||
let (_, obj): (uint, uint) = cast::transmute(t);
|
||||
let (_, obj): (uint, uint) = mem::transmute(t);
|
||||
let obj: Box<Runtime:Send> =
|
||||
cast::transmute((vtable, obj));
|
||||
mem::transmute((vtable, obj));
|
||||
self.put_runtime(obj);
|
||||
None
|
||||
}
|
||||
@ -317,7 +317,7 @@ impl BlockedTask {
|
||||
Shared(arc) => unsafe {
|
||||
match (*arc.get()).swap(0, SeqCst) {
|
||||
0 => None,
|
||||
n => Some(cast::transmute(n)),
|
||||
n => Some(mem::transmute(n)),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -343,7 +343,7 @@ impl BlockedTask {
|
||||
pub fn make_selectable(self, num_handles: uint) -> Take<BlockedTasks> {
|
||||
let arc = match self {
|
||||
Owned(task) => {
|
||||
let flag = unsafe { AtomicUint::new(cast::transmute(task)) };
|
||||
let flag = unsafe { AtomicUint::new(mem::transmute(task)) };
|
||||
UnsafeArc::new(flag)
|
||||
}
|
||||
Shared(arc) => arc.clone(),
|
||||
@ -357,12 +357,12 @@ impl BlockedTask {
|
||||
pub unsafe fn cast_to_uint(self) -> uint {
|
||||
match self {
|
||||
Owned(task) => {
|
||||
let blocked_task_ptr: uint = cast::transmute(task);
|
||||
let blocked_task_ptr: uint = mem::transmute(task);
|
||||
rtassert!(blocked_task_ptr & 0x1 == 0);
|
||||
blocked_task_ptr
|
||||
}
|
||||
Shared(arc) => {
|
||||
let blocked_task_ptr: uint = cast::transmute(box arc);
|
||||
let blocked_task_ptr: uint = mem::transmute(box arc);
|
||||
rtassert!(blocked_task_ptr & 0x1 == 0);
|
||||
blocked_task_ptr | 0x1
|
||||
}
|
||||
@ -374,10 +374,10 @@ impl BlockedTask {
|
||||
#[inline]
|
||||
pub unsafe fn cast_from_uint(blocked_task_ptr: uint) -> BlockedTask {
|
||||
if blocked_task_ptr & 0x1 == 0 {
|
||||
Owned(cast::transmute(blocked_task_ptr))
|
||||
Owned(mem::transmute(blocked_task_ptr))
|
||||
} else {
|
||||
let ptr: Box<UnsafeArc<AtomicUint>> =
|
||||
cast::transmute(blocked_task_ptr & !1);
|
||||
mem::transmute(blocked_task_ptr & !1);
|
||||
Shared(*ptr)
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,9 @@
|
||||
#![allow(non_camel_case_types)]
|
||||
#![allow(unsigned_negate)]
|
||||
|
||||
use cast;
|
||||
use kinds::Send;
|
||||
use libc;
|
||||
use mem;
|
||||
use ops::Drop;
|
||||
use option::{Option, Some, None};
|
||||
use owned::Box;
|
||||
@ -46,9 +46,9 @@ extern fn thread_start(main: *libc::c_void) -> imp::rust_thread_return {
|
||||
use rt::stack;
|
||||
unsafe {
|
||||
stack::record_stack_bounds(0, uint::MAX);
|
||||
let f: Box<proc()> = cast::transmute(main);
|
||||
let f: Box<proc()> = mem::transmute(main);
|
||||
(*f)();
|
||||
cast::transmute(0 as imp::rust_thread_return)
|
||||
mem::transmute(0 as imp::rust_thread_return)
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,7 +83,7 @@ impl Thread<()> {
|
||||
// so.
|
||||
let packet = box None;
|
||||
let packet2: *mut Option<T> = unsafe {
|
||||
*cast::transmute::<&Box<Option<T>>, **mut Option<T>>(&packet)
|
||||
*mem::transmute::<&Box<Option<T>>, **mut Option<T>>(&packet)
|
||||
};
|
||||
let main = proc() unsafe { *packet2 = Some(main()); };
|
||||
let native = unsafe { imp::create(stack, box main) };
|
||||
@ -146,7 +146,7 @@ impl<T: Send> Drop for Thread<T> {
|
||||
|
||||
#[cfg(windows)]
|
||||
mod imp {
|
||||
use cast;
|
||||
use mem;
|
||||
use cmp;
|
||||
use kinds::Send;
|
||||
use libc;
|
||||
@ -161,7 +161,7 @@ mod imp {
|
||||
pub type rust_thread_return = DWORD;
|
||||
|
||||
pub unsafe fn create(stack: uint, p: Box<proc():Send>) -> rust_thread {
|
||||
let arg: *mut libc::c_void = cast::transmute(p);
|
||||
let arg: *mut libc::c_void = mem::transmute(p);
|
||||
// FIXME On UNIX, we guard against stack sizes that are too small but
|
||||
// that's because pthreads enforces that stacks are at least
|
||||
// PTHREAD_STACK_MIN bytes big. Windows has no such lower limit, it's
|
||||
@ -177,7 +177,7 @@ mod imp {
|
||||
|
||||
if ret as uint == 0 {
|
||||
// be sure to not leak the closure
|
||||
let _p: Box<proc():Send> = cast::transmute(arg);
|
||||
let _p: Box<proc():Send> = mem::transmute(arg);
|
||||
fail!("failed to spawn native thread: {}", os::last_os_error());
|
||||
}
|
||||
return ret;
|
||||
@ -213,7 +213,6 @@ mod imp {
|
||||
|
||||
#[cfg(unix)]
|
||||
mod imp {
|
||||
use cast;
|
||||
use cmp;
|
||||
use kinds::Send;
|
||||
use libc::consts::os::posix01::{PTHREAD_CREATE_JOINABLE, PTHREAD_STACK_MIN};
|
||||
@ -254,13 +253,13 @@ mod imp {
|
||||
},
|
||||
};
|
||||
|
||||
let arg: *libc::c_void = cast::transmute(p);
|
||||
let arg: *libc::c_void = mem::transmute(p);
|
||||
let ret = pthread_create(&mut native, &attr, super::thread_start, arg);
|
||||
assert_eq!(pthread_attr_destroy(&mut attr), 0);
|
||||
|
||||
if ret != 0 {
|
||||
// be sure to not leak the closure
|
||||
let _p: Box<proc():Send> = cast::transmute(arg);
|
||||
let _p: Box<proc():Send> = mem::transmute(arg);
|
||||
fail!("failed to spawn native thread: {}", os::last_os_error());
|
||||
}
|
||||
native
|
||||
@ -302,7 +301,7 @@ mod imp {
|
||||
if __pthread_get_minstack.is_null() {
|
||||
PTHREAD_STACK_MIN
|
||||
} else {
|
||||
unsafe { cast::transmute::<*(), F>(__pthread_get_minstack)(attr) }
|
||||
unsafe { mem::transmute::<*(), F>(__pthread_get_minstack)(attr) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ extern "system" {
|
||||
|
||||
#[test]
|
||||
fn tls_smoke_test() {
|
||||
use cast::transmute;
|
||||
use mem::transmute;
|
||||
unsafe {
|
||||
let mut key = 0;
|
||||
let value = box 20;
|
||||
|
@ -58,8 +58,8 @@
|
||||
// Currently Rust uses unwind runtime provided by libgcc.
|
||||
|
||||
use any::{Any, AnyRefExt};
|
||||
use cast;
|
||||
use fmt;
|
||||
use intrinsics;
|
||||
use kinds::Send;
|
||||
use mem;
|
||||
use option::{Some, None, Option};
|
||||
@ -72,7 +72,6 @@ use rt::local::Local;
|
||||
use rt::task::Task;
|
||||
use str::Str;
|
||||
use task::TaskResult;
|
||||
use intrinsics;
|
||||
|
||||
use uw = rt::libunwind;
|
||||
|
||||
@ -98,7 +97,7 @@ impl Unwinder {
|
||||
use libc::{c_void};
|
||||
|
||||
unsafe {
|
||||
let closure: Closure = cast::transmute(f);
|
||||
let closure: Closure = mem::transmute(f);
|
||||
let ep = rust_try(try_fn, closure.code as *c_void,
|
||||
closure.env as *c_void);
|
||||
if !ep.is_null() {
|
||||
@ -109,7 +108,7 @@ impl Unwinder {
|
||||
|
||||
extern fn try_fn(code: *c_void, env: *c_void) {
|
||||
unsafe {
|
||||
let closure: || = cast::transmute(Closure {
|
||||
let closure: || = mem::transmute(Closure {
|
||||
code: code as *(),
|
||||
env: env as *(),
|
||||
});
|
||||
@ -146,7 +145,7 @@ impl Unwinder {
|
||||
exception_cleanup: exception_cleanup,
|
||||
private: [0, ..uw::unwinder_private_data_size],
|
||||
};
|
||||
let error = uw::_Unwind_RaiseException(cast::transmute(exception));
|
||||
let error = uw::_Unwind_RaiseException(mem::transmute(exception));
|
||||
rtabort!("Could not unwind stack, error = {}", error as int)
|
||||
}
|
||||
|
||||
@ -155,7 +154,7 @@ impl Unwinder {
|
||||
rtdebug!("exception_cleanup()");
|
||||
unsafe {
|
||||
let _: Box<uw::_Unwind_Exception> =
|
||||
cast::transmute(exception);
|
||||
mem::transmute(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -97,8 +97,7 @@ There are a number of free functions that create or take vectors, for example:
|
||||
|
||||
*/
|
||||
|
||||
use cast::transmute;
|
||||
use cast;
|
||||
use mem::transmute;
|
||||
use clone::Clone;
|
||||
use cmp::{TotalOrd, Ordering, Less, Greater};
|
||||
use cmp;
|
||||
@ -333,7 +332,7 @@ impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
|
||||
// FIXME: #13994 (should pass align and size here)
|
||||
exchange_free(ret as *mut u8, 0, 8);
|
||||
});
|
||||
cast::transmute(ret)
|
||||
mem::transmute(ret)
|
||||
}
|
||||
}
|
||||
|
||||
@ -380,7 +379,7 @@ impl<'a, T: Clone> CloneableVector<T> for &'a [T] {
|
||||
// FIXME: #13994 (should pass align and size here)
|
||||
exchange_free(ret as *mut u8, 0, 8);
|
||||
});
|
||||
cast::transmute(ret)
|
||||
mem::transmute(ret)
|
||||
}
|
||||
}
|
||||
|
||||
@ -531,7 +530,7 @@ fn insertion_sort<T>(v: &mut [T], compare: |&T, &T| -> Ordering) {
|
||||
ptr::copy_nonoverlapping_memory(buf_v.offset(j),
|
||||
&tmp as *T,
|
||||
1);
|
||||
cast::forget(tmp);
|
||||
mem::forget(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,23 +74,23 @@ The actual representation of strings have direct mappings to vectors:
|
||||
|
||||
*/
|
||||
|
||||
use cast;
|
||||
use cast::transmute;
|
||||
use char;
|
||||
use char::Char;
|
||||
use char;
|
||||
use clone::Clone;
|
||||
use cmp::{Eq, TotalEq, Ord, TotalOrd, Equiv, Ordering};
|
||||
use container::Container;
|
||||
use default::Default;
|
||||
use fmt;
|
||||
use from_str::FromStr;
|
||||
use io::Writer;
|
||||
use iter::{Iterator, range, AdditiveIterator};
|
||||
use mem::transmute;
|
||||
use mem;
|
||||
use option::{None, Option, Some};
|
||||
use from_str::FromStr;
|
||||
use slice::{ImmutableVector, MutableVector, CloneableVector};
|
||||
use slice::Vector;
|
||||
use vec::Vec;
|
||||
use default::Default;
|
||||
use slice::{ImmutableVector, MutableVector, CloneableVector};
|
||||
use strbuf::StrBuf;
|
||||
use vec::Vec;
|
||||
|
||||
pub use core::str::{from_utf8, CharEq, Chars, CharOffsets, RevChars};
|
||||
pub use core::str::{RevCharOffsets, Bytes, RevBytes, CharSplits, RevCharSplits};
|
||||
@ -126,7 +126,7 @@ impl FromStr for ~str {
|
||||
/// Fails if invalid UTF-8
|
||||
pub fn from_byte(b: u8) -> ~str {
|
||||
assert!(b < 128u8);
|
||||
unsafe { ::cast::transmute(box [b]) }
|
||||
unsafe { ::mem::transmute(box [b]) }
|
||||
}
|
||||
|
||||
/// Convert a char to a string
|
||||
@ -403,7 +403,7 @@ static TAG_CONT_U8: u8 = 128u8;
|
||||
/// ```
|
||||
pub fn from_utf8_lossy<'a>(v: &'a [u8]) -> MaybeOwned<'a> {
|
||||
if is_utf8(v) {
|
||||
return Slice(unsafe { cast::transmute(v) })
|
||||
return Slice(unsafe { mem::transmute(v) })
|
||||
}
|
||||
|
||||
static REPLACEMENT: &'static [u8] = bytes!(0xEF, 0xBF, 0xBD); // U+FFFD in UTF-8
|
||||
@ -666,8 +666,8 @@ impl<'a> fmt::Show for MaybeOwned<'a> {
|
||||
|
||||
/// Unsafe operations
|
||||
pub mod raw {
|
||||
use cast;
|
||||
use libc;
|
||||
use mem;
|
||||
use ptr::RawPtr;
|
||||
use raw::Slice;
|
||||
use slice::CloneableVector;
|
||||
@ -679,9 +679,9 @@ pub mod raw {
|
||||
/// Create a Rust string from a *u8 buffer of the given length
|
||||
pub unsafe fn from_buf_len(buf: *u8, len: uint) -> ~str {
|
||||
let v = Slice { data: buf, len: len };
|
||||
let bytes: &[u8] = ::cast::transmute(v);
|
||||
let bytes: &[u8] = ::mem::transmute(v);
|
||||
assert!(is_utf8(bytes));
|
||||
let s: &str = ::cast::transmute(bytes);
|
||||
let s: &str = ::mem::transmute(bytes);
|
||||
s.to_owned()
|
||||
}
|
||||
|
||||
@ -707,7 +707,7 @@ pub mod raw {
|
||||
/// that the utf-8-ness of the vector has already been validated
|
||||
#[inline]
|
||||
pub unsafe fn from_utf8_owned(v: ~[u8]) -> ~str {
|
||||
cast::transmute(v)
|
||||
mem::transmute(v)
|
||||
}
|
||||
|
||||
/// Converts a byte to a string.
|
||||
@ -717,7 +717,7 @@ pub mod raw {
|
||||
/// The caller must preserve the valid UTF-8 property when modifying.
|
||||
#[inline]
|
||||
pub unsafe fn as_owned_vec<'a>(s: &'a mut ~str) -> &'a mut ~[u8] {
|
||||
cast::transmute(s)
|
||||
mem::transmute(s)
|
||||
}
|
||||
|
||||
/// Sets the length of a string
|
||||
@ -823,7 +823,7 @@ pub trait StrAllocating: Str {
|
||||
use slice::Vector;
|
||||
|
||||
unsafe {
|
||||
::cast::transmute(self.as_slice().as_bytes().to_owned())
|
||||
::mem::transmute(self.as_slice().as_bytes().to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
@ -933,7 +933,7 @@ pub trait OwnedStr {
|
||||
impl OwnedStr for ~str {
|
||||
#[inline]
|
||||
fn into_bytes(self) -> ~[u8] {
|
||||
unsafe { cast::transmute(self) }
|
||||
unsafe { mem::transmute(self) }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
@ -11,12 +11,12 @@
|
||||
//! An owned, growable string that enforces that its contents are valid UTF-8.
|
||||
|
||||
use c_vec::CVec;
|
||||
use cast;
|
||||
use char::Char;
|
||||
use container::Container;
|
||||
use fmt;
|
||||
use io::Writer;
|
||||
use iter::{Extendable, FromIterator, Iterator, range};
|
||||
use mem;
|
||||
use option::{None, Option, Some};
|
||||
use ptr::RawPtr;
|
||||
use slice::{OwnedVector, Vector, CloneableVector};
|
||||
@ -265,7 +265,7 @@ impl Str for StrBuf {
|
||||
#[inline]
|
||||
fn as_slice<'a>(&'a self) -> &'a str {
|
||||
unsafe {
|
||||
cast::transmute(self.vec.as_slice())
|
||||
mem::transmute(self.vec.as_slice())
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -274,7 +274,7 @@ impl StrAllocating for StrBuf {
|
||||
#[inline]
|
||||
fn into_owned(self) -> ~str {
|
||||
unsafe {
|
||||
cast::transmute(self.vec.as_slice().to_owned())
|
||||
mem::transmute(self.vec.as_slice().to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,10 @@
|
||||
//! the underlying data will remain valid (not free'd) so long as the reference
|
||||
//! count is greater than one.
|
||||
|
||||
use cast;
|
||||
use clone::Clone;
|
||||
use iter::Iterator;
|
||||
use kinds::Send;
|
||||
use mem;
|
||||
use ops::Drop;
|
||||
use owned::Box;
|
||||
use ptr::RawPtr;
|
||||
@ -50,7 +50,7 @@ unsafe fn new_inner<T: Send>(data: T, refcount: uint) -> *mut ArcData<T> {
|
||||
count: AtomicUint::new(refcount),
|
||||
data: Unsafe::new(data)
|
||||
};
|
||||
cast::transmute(data)
|
||||
mem::transmute(data)
|
||||
}
|
||||
|
||||
impl<T: Send> UnsafeArc<T> {
|
||||
@ -158,7 +158,7 @@ impl<T> Drop for UnsafeArc<T>{
|
||||
// happened before), and an "acquire" operation before deleting the object.
|
||||
// [1]: (www.boost.org/doc/libs/1_55_0/doc/html/atomic/usage_examples.html)
|
||||
fence(Acquire);
|
||||
let _: Box<ArcData<T>> = cast::transmute(self.data);
|
||||
let _: Box<ArcData<T>> = mem::transmute(self.data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -108,11 +108,11 @@
|
||||
#![allow(missing_doc)]
|
||||
|
||||
use intrinsics;
|
||||
use cast;
|
||||
use std::kinds::marker;
|
||||
use option::{Option,Some,None};
|
||||
use mem;
|
||||
use ops::Drop;
|
||||
use option::{Option,Some,None};
|
||||
use owned::Box;
|
||||
use std::kinds::marker;
|
||||
use ty::Unsafe;
|
||||
|
||||
/// An atomic boolean type.
|
||||
@ -665,7 +665,7 @@ impl<T> AtomicPtr<T> {
|
||||
impl<T> AtomicOption<T> {
|
||||
/// Create a new `AtomicOption`
|
||||
pub fn new(p: Box<T>) -> AtomicOption<T> {
|
||||
unsafe { AtomicOption { p: Unsafe::new(cast::transmute(p)) } }
|
||||
unsafe { AtomicOption { p: Unsafe::new(mem::transmute(p)) } }
|
||||
}
|
||||
|
||||
/// Create a new `AtomicOption` that doesn't contain a value
|
||||
@ -675,13 +675,13 @@ impl<T> AtomicOption<T> {
|
||||
#[inline]
|
||||
pub fn swap(&self, val: Box<T>, order: Ordering) -> Option<Box<T>> {
|
||||
unsafe {
|
||||
let val = cast::transmute(val);
|
||||
let val = mem::transmute(val);
|
||||
|
||||
let p = atomic_swap(self.p.get(), val, order);
|
||||
if p as uint == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(cast::transmute(p))
|
||||
Some(mem::transmute(p))
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -689,7 +689,7 @@ impl<T> AtomicOption<T> {
|
||||
/// Remove the value, leaving the `AtomicOption` empty.
|
||||
#[inline]
|
||||
pub fn take(&self, order: Ordering) -> Option<Box<T>> {
|
||||
unsafe { self.swap(cast::transmute(0), order) }
|
||||
unsafe { self.swap(mem::transmute(0), order) }
|
||||
}
|
||||
|
||||
/// Replace an empty value with a non-empty value.
|
||||
@ -700,13 +700,13 @@ impl<T> AtomicOption<T> {
|
||||
#[inline]
|
||||
pub fn fill(&self, val: Box<T>, order: Ordering) -> Option<Box<T>> {
|
||||
unsafe {
|
||||
let val = cast::transmute(val);
|
||||
let expected = cast::transmute(0);
|
||||
let val = mem::transmute(val);
|
||||
let expected = mem::transmute(0);
|
||||
let oldval = atomic_compare_and_swap(self.p.get(), expected, val, order);
|
||||
if oldval == expected {
|
||||
None
|
||||
} else {
|
||||
Some(cast::transmute(val))
|
||||
Some(mem::transmute(val))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,6 @@
|
||||
// FIXME: all atomic operations in this module use a SeqCst ordering. That is
|
||||
// probably overkill
|
||||
|
||||
use cast;
|
||||
use clone::Clone;
|
||||
use iter::{range, Iterator};
|
||||
use kinds::Send;
|
||||
@ -57,12 +56,12 @@ use mem;
|
||||
use ops::Drop;
|
||||
use option::{Option, Some, None};
|
||||
use owned::Box;
|
||||
use ptr;
|
||||
use ptr::RawPtr;
|
||||
use ptr;
|
||||
use slice::ImmutableVector;
|
||||
use sync::arc::UnsafeArc;
|
||||
use sync::atomics::{AtomicInt, AtomicPtr, SeqCst};
|
||||
use unstable::sync::Exclusive;
|
||||
use slice::ImmutableVector;
|
||||
use vec::Vec;
|
||||
|
||||
// Once the queue is less than 1/K full, then it will be downsized. Note that
|
||||
@ -230,7 +229,7 @@ impl<T: Send> Deque<T> {
|
||||
Deque {
|
||||
bottom: AtomicInt::new(0),
|
||||
top: AtomicInt::new(0),
|
||||
array: AtomicPtr::new(unsafe { cast::transmute(buf) }),
|
||||
array: AtomicPtr::new(unsafe { mem::transmute(buf) }),
|
||||
pool: pool,
|
||||
}
|
||||
}
|
||||
@ -272,7 +271,7 @@ impl<T: Send> Deque<T> {
|
||||
return Some(data);
|
||||
} else {
|
||||
self.bottom.store(t + 1, SeqCst);
|
||||
cast::forget(data); // someone else stole this value
|
||||
mem::forget(data); // someone else stole this value
|
||||
return None;
|
||||
}
|
||||
}
|
||||
@ -294,7 +293,7 @@ impl<T: Send> Deque<T> {
|
||||
if self.top.compare_and_swap(t, t + 1, SeqCst) == t {
|
||||
Data(data)
|
||||
} else {
|
||||
cast::forget(data); // someone else stole this value
|
||||
mem::forget(data); // someone else stole this value
|
||||
Abort
|
||||
}
|
||||
}
|
||||
@ -315,7 +314,7 @@ impl<T: Send> Deque<T> {
|
||||
// continue to be read after we flag this buffer for reclamation.
|
||||
unsafe fn swap_buffer(&mut self, b: int, old: *mut Buffer<T>,
|
||||
buf: Buffer<T>) -> *mut Buffer<T> {
|
||||
let newbuf: *mut Buffer<T> = cast::transmute(box buf);
|
||||
let newbuf: *mut Buffer<T> = mem::transmute(box buf);
|
||||
self.array.store(newbuf, SeqCst);
|
||||
let ss = (*newbuf).size();
|
||||
self.bottom.store(b + ss, SeqCst);
|
||||
@ -323,7 +322,7 @@ impl<T: Send> Deque<T> {
|
||||
if self.top.compare_and_swap(t, t + ss, SeqCst) != t {
|
||||
self.bottom.store(b, SeqCst);
|
||||
}
|
||||
self.pool.free(cast::transmute(old));
|
||||
self.pool.free(mem::transmute(old));
|
||||
return newbuf;
|
||||
}
|
||||
}
|
||||
@ -340,7 +339,7 @@ impl<T: Send> Drop for Deque<T> {
|
||||
for i in range(t, b) {
|
||||
let _: T = unsafe { (*a).get(i) };
|
||||
}
|
||||
self.pool.free(unsafe { cast::transmute(a) });
|
||||
self.pool.free(unsafe { mem::transmute(a) });
|
||||
}
|
||||
}
|
||||
|
||||
@ -373,7 +372,7 @@ impl<T: Send> Buffer<T> {
|
||||
unsafe fn put(&mut self, i: int, t: T) {
|
||||
let ptr = self.storage.offset(i & self.mask());
|
||||
ptr::copy_nonoverlapping_memory(ptr as *mut T, &t as *T, 1);
|
||||
cast::forget(t);
|
||||
mem::forget(t);
|
||||
}
|
||||
|
||||
// Again, unsafe because this has incredibly dubious ownership violations.
|
||||
@ -400,7 +399,7 @@ mod tests {
|
||||
use prelude::*;
|
||||
use super::{Data, BufferPool, Abort, Empty, Worker, Stealer};
|
||||
|
||||
use cast;
|
||||
use mem;
|
||||
use owned::Box;
|
||||
use rt::thread::Thread;
|
||||
use rand;
|
||||
@ -607,7 +606,7 @@ mod tests {
|
||||
let s = s.clone();
|
||||
let unique_box = box AtomicUint::new(0);
|
||||
let thread_box = unsafe {
|
||||
*cast::transmute::<&Box<AtomicUint>,
|
||||
*mem::transmute::<&Box<AtomicUint>,
|
||||
**mut AtomicUint>(&unique_box)
|
||||
};
|
||||
(Thread::start(proc() {
|
||||
|
@ -38,8 +38,8 @@
|
||||
// http://www.1024cores.net/home/lock-free-algorithms
|
||||
// /queues/non-intrusive-mpsc-node-based-queue
|
||||
|
||||
use cast;
|
||||
use kinds::Send;
|
||||
use mem;
|
||||
use ops::Drop;
|
||||
use option::{Option, None, Some};
|
||||
use owned::Box;
|
||||
@ -74,7 +74,7 @@ pub struct Queue<T> {
|
||||
|
||||
impl<T> Node<T> {
|
||||
unsafe fn new(v: Option<T>) -> *mut Node<T> {
|
||||
cast::transmute(box Node {
|
||||
mem::transmute(box Node {
|
||||
next: AtomicPtr::new(0 as *mut Node<T>),
|
||||
value: v,
|
||||
})
|
||||
@ -121,7 +121,7 @@ impl<T: Send> Queue<T> {
|
||||
assert!((*tail).value.is_none());
|
||||
assert!((*next).value.is_some());
|
||||
let ret = (*next).value.take_unwrap();
|
||||
let _: Box<Node<T>> = cast::transmute(tail);
|
||||
let _: Box<Node<T>> = mem::transmute(tail);
|
||||
return Data(ret);
|
||||
}
|
||||
|
||||
@ -146,7 +146,7 @@ impl<T: Send> Drop for Queue<T> {
|
||||
let mut cur = self.tail;
|
||||
while !cur.is_null() {
|
||||
let next = (*cur).next.load(Relaxed);
|
||||
let _: Box<Node<T>> = cast::transmute(cur);
|
||||
let _: Box<Node<T>> = mem::transmute(cur);
|
||||
cur = next;
|
||||
}
|
||||
}
|
||||
|
@ -33,8 +33,8 @@
|
||||
//! concurrently between two tasks. This data structure is safe to use and
|
||||
//! enforces the semantics that there is one pusher and one popper.
|
||||
|
||||
use cast;
|
||||
use kinds::Send;
|
||||
use mem;
|
||||
use ops::Drop;
|
||||
use option::{Some, None, Option};
|
||||
use owned::Box;
|
||||
@ -74,7 +74,7 @@ pub struct Queue<T> {
|
||||
impl<T: Send> Node<T> {
|
||||
fn new() -> *mut Node<T> {
|
||||
unsafe {
|
||||
cast::transmute(box Node {
|
||||
mem::transmute(box Node {
|
||||
value: None,
|
||||
next: AtomicPtr::new(0 as *mut Node<T>),
|
||||
})
|
||||
@ -188,7 +188,7 @@ impl<T: Send> Queue<T> {
|
||||
(*self.tail_prev.load(Relaxed)).next.store(next, Relaxed);
|
||||
// We have successfully erased all references to 'tail', so
|
||||
// now we can safely drop it.
|
||||
let _: Box<Node<T>> = cast::transmute(tail);
|
||||
let _: Box<Node<T>> = mem::transmute(tail);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
@ -216,7 +216,7 @@ impl<T: Send> Drop for Queue<T> {
|
||||
let mut cur = self.first;
|
||||
while !cur.is_null() {
|
||||
let next = (*cur).next.load(Relaxed);
|
||||
let _n: Box<Node<T>> = cast::transmute(cur);
|
||||
let _n: Box<Node<T>> = mem::transmute(cur);
|
||||
cur = next;
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ A simple wrapper over the platform's dynamic library facilities
|
||||
*/
|
||||
|
||||
use c_str::ToCStr;
|
||||
use cast;
|
||||
use iter::Iterator;
|
||||
use mem;
|
||||
use ops::*;
|
||||
use option::*;
|
||||
use os;
|
||||
@ -97,7 +97,7 @@ impl DynamicLibrary {
|
||||
// the destructor does not run.
|
||||
match maybe_symbol_value {
|
||||
Err(err) => Err(err),
|
||||
Ok(symbol_value) => Ok(cast::transmute(symbol_value))
|
||||
Ok(symbol_value) => Ok(mem::transmute(symbol_value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,23 +10,21 @@
|
||||
|
||||
//! An owned, growable vector.
|
||||
|
||||
use cast::{forget, transmute};
|
||||
use RawVec = raw::Vec;
|
||||
use clone::Clone;
|
||||
use cmp::{Ord, Eq, Ordering, TotalEq, TotalOrd, max};
|
||||
use container::{Container, Mutable};
|
||||
use default::Default;
|
||||
use fmt;
|
||||
use iter::{DoubleEndedIterator, FromIterator, Extendable, Iterator, range};
|
||||
use mem::{min_align_of, move_val_init, size_of};
|
||||
use mem;
|
||||
use num;
|
||||
use num::{CheckedMul, CheckedAdd};
|
||||
use num;
|
||||
use ops::{Add, Drop};
|
||||
use option::{None, Option, Some, Expect};
|
||||
use ptr::RawPtr;
|
||||
use ptr;
|
||||
use raw::Slice;
|
||||
use RawVec = raw::Vec;
|
||||
use rt::heap::{allocate, reallocate, deallocate};
|
||||
use slice::{ImmutableEqVector, ImmutableVector, Items, MutItems, MutableVector};
|
||||
use slice::{MutableTotalOrdVector, OwnedVector, Vector};
|
||||
@ -91,12 +89,14 @@ impl<T> Vec<T> {
|
||||
/// let vec: Vec<int> = Vec::with_capacity(10);
|
||||
/// ```
|
||||
pub fn with_capacity(capacity: uint) -> Vec<T> {
|
||||
if size_of::<T>() == 0 { return Vec { len: 0, cap: ::uint::MAX, ptr: 0 as *mut T } }
|
||||
if capacity == 0 {
|
||||
if mem::size_of::<T>() == 0 {
|
||||
Vec { len: 0, cap: ::uint::MAX, ptr: 0 as *mut T }
|
||||
} else if capacity == 0 {
|
||||
Vec::new()
|
||||
} else {
|
||||
let size = capacity.checked_mul(&size_of::<T>()).expect("capacity overflow");
|
||||
let ptr = unsafe { allocate(size, min_align_of::<T>()) };
|
||||
let size = capacity.checked_mul(&mem::size_of::<T>())
|
||||
.expect("capacity overflow");
|
||||
let ptr = unsafe { allocate(size, mem::min_align_of::<T>()) };
|
||||
Vec { len: 0, cap: capacity, ptr: ptr as *mut T }
|
||||
}
|
||||
}
|
||||
@ -117,7 +117,8 @@ impl<T> Vec<T> {
|
||||
unsafe {
|
||||
let mut xs = Vec::with_capacity(length);
|
||||
while xs.len < length {
|
||||
move_val_init(xs.as_mut_slice().unsafe_mut_ref(xs.len), op(xs.len));
|
||||
mem::move_val_init(xs.as_mut_slice().unsafe_mut_ref(xs.len),
|
||||
op(xs.len));
|
||||
xs.len += 1;
|
||||
}
|
||||
xs
|
||||
@ -133,7 +134,8 @@ impl<T> Vec<T> {
|
||||
/// - there must be `length` valid instances of type `T` at the
|
||||
/// beginning of that allocation
|
||||
/// - `ptr` must be allocated by the default `Vec` allocator
|
||||
pub unsafe fn from_raw_parts(length: uint, capacity: uint, ptr: *mut T) -> Vec<T> {
|
||||
pub unsafe fn from_raw_parts(length: uint, capacity: uint,
|
||||
ptr: *mut T) -> Vec<T> {
|
||||
Vec { len: length, cap: capacity, ptr: ptr }
|
||||
}
|
||||
|
||||
@ -212,7 +214,8 @@ impl<T: Clone> Vec<T> {
|
||||
unsafe {
|
||||
let mut xs = Vec::with_capacity(length);
|
||||
while xs.len < length {
|
||||
move_val_init(xs.as_mut_slice().unsafe_mut_ref(xs.len), value.clone());
|
||||
mem::move_val_init(xs.as_mut_slice().unsafe_mut_ref(xs.len),
|
||||
value.clone());
|
||||
xs.len += 1;
|
||||
}
|
||||
xs
|
||||
@ -405,16 +408,19 @@ impl<T> Container for Vec<T> {
|
||||
#[inline(never)]
|
||||
unsafe fn alloc_or_realloc<T>(ptr: *mut T, size: uint, old_size: uint) -> *mut T {
|
||||
if old_size == 0 {
|
||||
allocate(size, min_align_of::<T>()) as *mut T
|
||||
allocate(size, mem::min_align_of::<T>()) as *mut T
|
||||
} else {
|
||||
reallocate(ptr as *mut u8, size, min_align_of::<T>(), old_size) as *mut T
|
||||
reallocate(ptr as *mut u8, size,
|
||||
mem::min_align_of::<T>(), old_size) as *mut T
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
unsafe fn dealloc<T>(ptr: *mut T, len: uint) {
|
||||
if size_of::<T>() != 0 {
|
||||
deallocate(ptr as *mut u8, len * size_of::<T>(), min_align_of::<T>())
|
||||
if mem::size_of::<T>() != 0 {
|
||||
deallocate(ptr as *mut u8,
|
||||
len * mem::size_of::<T>(),
|
||||
mem::min_align_of::<T>())
|
||||
}
|
||||
}
|
||||
|
||||
@ -494,11 +500,14 @@ impl<T> Vec<T> {
|
||||
/// assert_eq!(vec.capacity(), 11);
|
||||
/// ```
|
||||
pub fn reserve_exact(&mut self, capacity: uint) {
|
||||
if size_of::<T>() == 0 { return }
|
||||
if mem::size_of::<T>() == 0 { return }
|
||||
|
||||
if capacity > self.cap {
|
||||
let size = capacity.checked_mul(&size_of::<T>()).expect("capacity overflow");
|
||||
let size = capacity.checked_mul(&mem::size_of::<T>())
|
||||
.expect("capacity overflow");
|
||||
unsafe {
|
||||
self.ptr = alloc_or_realloc(self.ptr, size, self.cap * size_of::<T>());
|
||||
self.ptr = alloc_or_realloc(self.ptr, size,
|
||||
self.cap * mem::size_of::<T>());
|
||||
}
|
||||
self.cap = capacity;
|
||||
}
|
||||
@ -513,7 +522,8 @@ impl<T> Vec<T> {
|
||||
/// vec.shrink_to_fit();
|
||||
/// ```
|
||||
pub fn shrink_to_fit(&mut self) {
|
||||
if size_of::<T>() == 0 { return }
|
||||
if mem::size_of::<T>() == 0 { return }
|
||||
|
||||
if self.len == 0 {
|
||||
if self.cap != 0 {
|
||||
unsafe {
|
||||
@ -523,9 +533,12 @@ impl<T> Vec<T> {
|
||||
}
|
||||
} else {
|
||||
unsafe {
|
||||
// Overflow check is unnecessary as the vector is already at least this large.
|
||||
self.ptr = reallocate(self.ptr as *mut u8, self.len * size_of::<T>(),
|
||||
min_align_of::<T>(), self.cap * size_of::<T>()) as *mut T;
|
||||
// Overflow check is unnecessary as the vector is already at
|
||||
// least this large.
|
||||
self.ptr = reallocate(self.ptr as *mut u8,
|
||||
self.len * mem::size_of::<T>(),
|
||||
mem::min_align_of::<T>(),
|
||||
self.cap * mem::size_of::<T>()) as *mut T;
|
||||
}
|
||||
self.cap = self.len;
|
||||
}
|
||||
@ -568,25 +581,26 @@ impl<T> Vec<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
pub fn push(&mut self, value: T) {
|
||||
if size_of::<T>() == 0 {
|
||||
if mem::size_of::<T>() == 0 {
|
||||
// zero-size types consume no memory, so we can't rely on the address space running out
|
||||
self.len = self.len.checked_add(&1).expect("length overflow");
|
||||
unsafe { forget(value); }
|
||||
unsafe { mem::forget(value); }
|
||||
return
|
||||
}
|
||||
if self.len == self.cap {
|
||||
let old_size = self.cap * size_of::<T>();
|
||||
let size = max(old_size, 2 * size_of::<T>()) * 2;
|
||||
let old_size = self.cap * mem::size_of::<T>();
|
||||
let size = max(old_size, 2 * mem::size_of::<T>()) * 2;
|
||||
if old_size > size { fail!("capacity overflow") }
|
||||
unsafe {
|
||||
self.ptr = alloc_or_realloc(self.ptr, size, self.cap * size_of::<T>());
|
||||
self.ptr = alloc_or_realloc(self.ptr, size,
|
||||
self.cap * mem::size_of::<T>());
|
||||
}
|
||||
self.cap = max(self.cap, 2) * 2;
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let end = (self.ptr as *T).offset(self.len as int) as *mut T;
|
||||
move_val_init(&mut *end, value);
|
||||
mem::move_val_init(&mut *end, value);
|
||||
self.len += 1;
|
||||
}
|
||||
}
|
||||
@ -644,7 +658,7 @@ impl<T> Vec<T> {
|
||||
#[inline]
|
||||
pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
|
||||
unsafe {
|
||||
transmute(Slice { data: self.as_mut_ptr() as *T, len: self.len })
|
||||
mem::transmute(Slice { data: self.as_mut_ptr() as *T, len: self.len })
|
||||
}
|
||||
}
|
||||
|
||||
@ -664,10 +678,10 @@ impl<T> Vec<T> {
|
||||
#[inline]
|
||||
pub fn move_iter(self) -> MoveItems<T> {
|
||||
unsafe {
|
||||
let iter = transmute(self.as_slice().iter());
|
||||
let iter = mem::transmute(self.as_slice().iter());
|
||||
let ptr = self.ptr;
|
||||
let cap = self.cap;
|
||||
forget(self);
|
||||
mem::forget(self);
|
||||
MoveItems { allocation: ptr, cap: cap, iter: iter }
|
||||
}
|
||||
}
|
||||
@ -949,7 +963,7 @@ impl<T> Vec<T> {
|
||||
ptr::copy_memory(p.offset(1), &*p, len - index);
|
||||
// Write it in, overwriting the first copy of the `index`th
|
||||
// element.
|
||||
move_val_init(&mut *p, element);
|
||||
mem::move_val_init(&mut *p, element);
|
||||
}
|
||||
self.set_len(len + 1);
|
||||
}
|
||||
@ -1395,7 +1409,7 @@ impl<T> Vector<T> for Vec<T> {
|
||||
/// ```
|
||||
#[inline]
|
||||
fn as_slice<'a>(&'a self) -> &'a [T] {
|
||||
unsafe { transmute(Slice { data: self.as_ptr(), len: self.len }) }
|
||||
unsafe { mem::transmute(Slice { data: self.as_ptr(), len: self.len }) }
|
||||
}
|
||||
}
|
||||
|
||||
@ -1538,7 +1552,7 @@ impl<T> FromVec<T> for ~[T] {
|
||||
// as it still needs to free its own allocation.
|
||||
v.set_len(0);
|
||||
|
||||
transmute(ret)
|
||||
mem::transmute(ret)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
* between tasks.
|
||||
*/
|
||||
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use std::rt::heap::exchange_free;
|
||||
use std::sync::atomics;
|
||||
@ -76,7 +76,7 @@ impl<T: Share + Send> Arc<T> {
|
||||
weak: atomics::AtomicUint::new(1),
|
||||
data: data,
|
||||
};
|
||||
Arc { x: unsafe { cast::transmute(x) } }
|
||||
Arc { x: unsafe { mem::transmute(x) } }
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -149,7 +149,7 @@ impl<T: Send + Share + Clone> Arc<T> {
|
||||
// reference count is guaranteed to be 1 at this point, and we required
|
||||
// the Arc itself to be `mut`, so we're returning the only possible
|
||||
// reference to the inner data.
|
||||
unsafe { cast::transmute::<&_, &mut _>(self.deref()) }
|
||||
unsafe { mem::transmute::<&_, &mut _>(self.deref()) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,7 @@
|
||||
// http://www.1024cores.net/home/lock-free-algorithms
|
||||
// /queues/intrusive-mpsc-node-based-queue
|
||||
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::sync::atomics;
|
||||
use std::ty::Unsafe;
|
||||
|
||||
@ -97,7 +97,7 @@ impl<T: Send> Queue<T> {
|
||||
pub unsafe fn pop(&self) -> Option<*mut Node<T>> {
|
||||
let tail = *self.tail.get();
|
||||
let mut tail = if !tail.is_null() {tail} else {
|
||||
cast::transmute(&self.stub)
|
||||
mem::transmute(&self.stub)
|
||||
};
|
||||
let mut next = (*tail).next(atomics::Relaxed);
|
||||
if tail as uint == &self.stub as *DummyNode as uint {
|
||||
@ -116,7 +116,7 @@ impl<T: Send> Queue<T> {
|
||||
if tail != head {
|
||||
return None;
|
||||
}
|
||||
let stub = cast::transmute(&self.stub);
|
||||
let stub = mem::transmute(&self.stub);
|
||||
self.push(stub);
|
||||
next = (*tail).next(atomics::Relaxed);
|
||||
if !next.is_null() {
|
||||
@ -135,6 +135,6 @@ impl<T: Send> Node<T> {
|
||||
}
|
||||
}
|
||||
pub unsafe fn next(&self, ord: atomics::Ordering) -> *mut Node<T> {
|
||||
cast::transmute::<uint, *mut Node<T>>(self.next.load(ord))
|
||||
mem::transmute::<uint, *mut Node<T>>(self.next.load(ord))
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,8 @@
|
||||
//! `sync` crate which wrap values directly and provide safer abstractions for
|
||||
//! containing data.
|
||||
|
||||
use std::cast;
|
||||
use std::kinds::marker;
|
||||
use std::mem::replace;
|
||||
use std::mem;
|
||||
use std::sync::atomics;
|
||||
use std::unstable::finally::Finally;
|
||||
|
||||
@ -109,7 +108,7 @@ struct SemGuard<'a, Q> {
|
||||
impl<Q: Send> Sem<Q> {
|
||||
fn new(count: int, q: Q) -> Sem<Q> {
|
||||
let inner = unsafe {
|
||||
cast::transmute(box SemInner {
|
||||
mem::transmute(box SemInner {
|
||||
waiters: WaitQueue::new(),
|
||||
count: count,
|
||||
blocked: q,
|
||||
@ -168,7 +167,7 @@ impl<Q: Send> Sem<Q> {
|
||||
impl<Q: Send> Drop for Sem<Q> {
|
||||
fn drop(&mut self) {
|
||||
let _waiters: Box<SemInner<Q>> = unsafe {
|
||||
cast::transmute(self.inner)
|
||||
mem::transmute(self.inner)
|
||||
};
|
||||
self.inner = 0 as *();
|
||||
}
|
||||
@ -317,8 +316,8 @@ impl<'a> Condvar<'a> {
|
||||
// To avoid :broadcast_heavy, we make a new waitqueue,
|
||||
// swap it out with the old one, and broadcast on the
|
||||
// old one outside of the little-lock.
|
||||
queue = Some(replace(state.blocked.get_mut(condvar_id),
|
||||
WaitQueue::new()));
|
||||
queue = Some(mem::replace(state.blocked.get_mut(condvar_id),
|
||||
WaitQueue::new()));
|
||||
} else {
|
||||
out_of_bounds = Some(state.blocked.len());
|
||||
}
|
||||
@ -578,7 +577,7 @@ impl<'a> RWLockWriteGuard<'a> {
|
||||
let lock = self.lock;
|
||||
// Don't run the destructor of the write guard, we're in charge of
|
||||
// things from now on
|
||||
unsafe { cast::forget(self) }
|
||||
unsafe { mem::forget(self) }
|
||||
|
||||
let old_count = lock.read_count.fetch_add(1, atomics::Release);
|
||||
// If another reader was already blocking, we need to hand-off
|
||||
@ -626,7 +625,7 @@ mod tests {
|
||||
use arc::Arc;
|
||||
use super::{Semaphore, Mutex, RWLock, Condvar};
|
||||
|
||||
use std::cast;
|
||||
use std::mem;
|
||||
use std::result;
|
||||
use std::task;
|
||||
|
||||
@ -902,7 +901,7 @@ mod tests {
|
||||
let ptr: *int = &*sharedstate;
|
||||
task::spawn(proc() {
|
||||
let sharedstate: &mut int =
|
||||
unsafe { cast::transmute(ptr) };
|
||||
unsafe { mem::transmute(ptr) };
|
||||
access_shared(sharedstate, &x2, mode1, 10);
|
||||
tx.send(());
|
||||
});
|
||||
|
@ -29,9 +29,9 @@ use visit;
|
||||
use visit::Visitor;
|
||||
use util::small_vector::SmallVector;
|
||||
|
||||
use std::cast;
|
||||
use std::unstable::dynamic_lib::DynamicLibrary;
|
||||
use std::mem;
|
||||
use std::os;
|
||||
use std::unstable::dynamic_lib::DynamicLibrary;
|
||||
|
||||
pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
|
||||
match e.node {
|
||||
@ -544,7 +544,7 @@ fn load_extern_macros(krate: &ast::ViewItem, fld: &mut MacroExpander) {
|
||||
// Intentionally leak the dynamic library. We can't ever unload it
|
||||
// since the library can do things that will outlive the expansion
|
||||
// phase (e.g. make an @-box cycle or launch a task).
|
||||
cast::forget(lib);
|
||||
mem::forget(lib);
|
||||
}
|
||||
}
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user