std: Move size/align functions to std::mem. #2240

This commit is contained in:
Brian Anderson 2013-10-16 18:34:01 -07:00
parent 3fd0e3a77b
commit 34d376f3cf
46 changed files with 288 additions and 269 deletions

View File

@ -1842,7 +1842,7 @@ msgid ""
"The type parameters can also be explicitly supplied in a trailing [path]" "The type parameters can also be explicitly supplied in a trailing [path]"
"(#paths) component after the function name. This might be necessary if there " "(#paths) component after the function name. This might be necessary if there "
"is not sufficient context to determine the type parameters. For example, " "is not sufficient context to determine the type parameters. For example, "
"`sys::size_of::<u32>() == 4`." "`mem::size_of::<u32>() == 4`."
msgstr "" msgstr ""
#. type: Plain text #. type: Plain text

View File

@ -327,7 +327,7 @@ msgid ""
"impl<T: Send> Unique<T> {\n" "impl<T: Send> Unique<T> {\n"
" pub fn new(value: T) -> Unique<T> {\n" " pub fn new(value: T) -> Unique<T> {\n"
" unsafe {\n" " unsafe {\n"
" let ptr = malloc(std::sys::size_of::<T>() as size_t) as *mut T;\n" " let ptr = malloc(std::mem::size_of::<T>() as size_t) as *mut T;\n"
" assert!(!ptr::is_null(ptr));\n" " assert!(!ptr::is_null(ptr));\n"
" // `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it\n" " // `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it\n"
" intrinsics::move_val_init(&mut *ptr, value);\n" " intrinsics::move_val_init(&mut *ptr, value);\n"

View File

@ -1842,7 +1842,7 @@ msgid ""
"The type parameters can also be explicitly supplied in a trailing [path]" "The type parameters can also be explicitly supplied in a trailing [path]"
"(#paths) component after the function name. This might be necessary if there " "(#paths) component after the function name. This might be necessary if there "
"is not sufficient context to determine the type parameters. For example, " "is not sufficient context to determine the type parameters. For example, "
"`sys::size_of::<u32>() == 4`." "`mem::size_of::<u32>() == 4`."
msgstr "" msgstr ""
#. type: Plain text #. type: Plain text

View File

@ -327,7 +327,7 @@ msgid ""
"impl<T: Send> Unique<T> {\n" "impl<T: Send> Unique<T> {\n"
" pub fn new(value: T) -> Unique<T> {\n" " pub fn new(value: T) -> Unique<T> {\n"
" unsafe {\n" " unsafe {\n"
" let ptr = malloc(std::sys::size_of::<T>() as size_t) as *mut T;\n" " let ptr = malloc(std::mem::size_of::<T>() as size_t) as *mut T;\n"
" assert!(!ptr::is_null(ptr));\n" " assert!(!ptr::is_null(ptr));\n"
" // `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it\n" " // `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it\n"
" intrinsics::move_val_init(&mut *ptr, value);\n" " intrinsics::move_val_init(&mut *ptr, value);\n"

View File

@ -975,7 +975,7 @@ with `int`, and require the closure parameter to have type
The type parameters can also be explicitly supplied in a trailing The type parameters can also be explicitly supplied in a trailing
[path](#paths) component after the function name. This might be necessary [path](#paths) component after the function name. This might be necessary
if there is not sufficient context to determine the type parameters. For if there is not sufficient context to determine the type parameters. For
example, `sys::size_of::<u32>() == 4`. example, `mem::size_of::<u32>() == 4`.
Since a parameter type is opaque to the generic function, the set of Since a parameter type is opaque to the generic function, the set of
operations that can be performed on it is limited. Values of parameter operations that can be performed on it is limited. Values of parameter

View File

@ -300,7 +300,7 @@ impl<T: Send> Unique<T> {
#[inline(never)]; #[inline(never)];
unsafe { unsafe {
let ptr = malloc(std::sys::size_of::<T>() as size_t) as *mut T; let ptr = malloc(std::mem::size_of::<T>() as size_t) as *mut T;
assert!(!ptr::is_null(ptr)); assert!(!ptr::is_null(ptr));
// `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it // `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it
intrinsics::move_val_init(&mut *ptr, value); intrinsics::move_val_init(&mut *ptr, value);

View File

@ -42,7 +42,7 @@ use std::cast::{transmute, transmute_mut, transmute_mut_region};
use std::cast; use std::cast;
use std::num; use std::num;
use std::ptr; use std::ptr;
use std::sys; use std::mem;
use std::uint; use std::uint;
use std::vec; use std::vec;
use std::unstable::intrinsics; use std::unstable::intrinsics;
@ -123,7 +123,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data); let (tydesc, is_done) = un_bitpack_tydesc_ptr(*tydesc_data);
let (size, align) = ((*tydesc).size, (*tydesc).align); let (size, align) = ((*tydesc).size, (*tydesc).align);
let after_tydesc = idx + sys::size_of::<*TyDesc>(); let after_tydesc = idx + mem::size_of::<*TyDesc>();
let start = round_up_to(after_tydesc, align); let start = round_up_to(after_tydesc, align);
@ -134,7 +134,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
} }
// Find where the next tydesc lives // Find where the next tydesc lives
idx = round_up_to(start + size, sys::pref_align_of::<*TyDesc>()); idx = round_up_to(start + size, mem::pref_align_of::<*TyDesc>());
} }
} }
@ -220,7 +220,7 @@ impl Arena {
let head = transmute_mut_region(&mut self.head); let head = transmute_mut_region(&mut self.head);
tydesc_start = head.fill; tydesc_start = head.fill;
after_tydesc = head.fill + sys::size_of::<*TyDesc>(); after_tydesc = head.fill + mem::size_of::<*TyDesc>();
start = round_up_to(after_tydesc, align); start = round_up_to(after_tydesc, align);
end = start + n_bytes; end = start + n_bytes;
} }
@ -230,7 +230,7 @@ impl Arena {
} }
let head = transmute_mut_region(&mut self.head); let head = transmute_mut_region(&mut self.head);
head.fill = round_up_to(end, sys::pref_align_of::<*TyDesc>()); head.fill = round_up_to(end, mem::pref_align_of::<*TyDesc>());
//debug2!("idx = {}, size = {}, align = {}, fill = {}", //debug2!("idx = {}, size = {}, align = {}, fill = {}",
// start, n_bytes, align, head.fill); // start, n_bytes, align, head.fill);

View File

@ -14,7 +14,7 @@ use clone::Clone;
use container::Container; use container::Container;
use iter::Iterator; use iter::Iterator;
use option::{Option, Some, None}; use option::{Option, Some, None};
use sys; use mem;
use unstable::raw::Repr; use unstable::raw::Repr;
use vec::{ImmutableVector, OwnedVector}; use vec::{ImmutableVector, OwnedVector};
@ -26,7 +26,7 @@ use vec::{ImmutableVector, OwnedVector};
pub fn capacity<T>(v: @[T]) -> uint { pub fn capacity<T>(v: @[T]) -> uint {
unsafe { unsafe {
let box = v.repr(); let box = v.repr();
(*box).data.alloc / sys::size_of::<T>() (*box).data.alloc / mem::size_of::<T>()
} }
} }
@ -160,7 +160,7 @@ pub mod raw {
use cast::{transmute, transmute_copy}; use cast::{transmute, transmute_copy};
use libc; use libc;
use ptr; use ptr;
use sys; use mem;
use uint; use uint;
use unstable::intrinsics::{move_val_init, TyDesc}; use unstable::intrinsics::{move_val_init, TyDesc};
use unstable::intrinsics; use unstable::intrinsics;
@ -176,7 +176,7 @@ pub mod raw {
#[inline] #[inline]
pub unsafe fn set_len<T>(v: &mut @[T], new_len: uint) { pub unsafe fn set_len<T>(v: &mut @[T], new_len: uint) {
let repr: *mut Box<Vec<T>> = cast::transmute_copy(v); let repr: *mut Box<Vec<T>> = cast::transmute_copy(v);
(*repr).data.fill = new_len * sys::size_of::<T>(); (*repr).data.fill = new_len * mem::size_of::<T>();
} }
/** /**
@ -199,7 +199,7 @@ pub mod raw {
unsafe fn push_fast<T>(v: &mut @[T], initval: T) { unsafe fn push_fast<T>(v: &mut @[T], initval: T) {
let repr: *mut Box<Vec<T>> = cast::transmute_copy(v); let repr: *mut Box<Vec<T>> = cast::transmute_copy(v);
let amt = v.len(); let amt = v.len();
(*repr).data.fill += sys::size_of::<T>(); (*repr).data.fill += mem::size_of::<T>();
let p = ptr::offset(&(*repr).data.data as *T, amt as int) as *mut T; let p = ptr::offset(&(*repr).data.data as *T, amt as int) as *mut T;
move_val_init(&mut(*p), initval); move_val_init(&mut(*p), initval);
} }
@ -236,7 +236,7 @@ pub mod raw {
unsafe { unsafe {
if n > (**ptr).data.alloc / (*ty).size { if n > (**ptr).data.alloc / (*ty).size {
let alloc = n * (*ty).size; let alloc = n * (*ty).size;
let total_size = alloc + sys::size_of::<Vec<()>>(); let total_size = alloc + mem::size_of::<Vec<()>>();
if alloc / (*ty).size != n || total_size < alloc { if alloc / (*ty).size != n || total_size < alloc {
fail2!("vector size is too large: {}", n); fail2!("vector size is too large: {}", n);
} }

View File

@ -11,7 +11,7 @@
//! Unsafe casting functions //! Unsafe casting functions
use ptr::RawPtr; use ptr::RawPtr;
use sys; use mem;
use unstable::intrinsics; use unstable::intrinsics;
/// Casts the value at `src` to U. The two types must have the same length. /// Casts the value at `src` to U. The two types must have the same length.
@ -21,7 +21,7 @@ pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
let mut dest: U = intrinsics::uninit(); let mut dest: U = intrinsics::uninit();
let dest_ptr: *mut u8 = transmute(&mut dest); let dest_ptr: *mut u8 = transmute(&mut dest);
let src_ptr: *u8 = transmute(src); let src_ptr: *u8 = transmute(src);
intrinsics::memcpy32(dest_ptr, src_ptr, sys::size_of::<U>() as u32); intrinsics::memcpy32(dest_ptr, src_ptr, mem::size_of::<U>() as u32);
dest dest
} }
@ -32,7 +32,7 @@ pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
let mut dest: U = intrinsics::uninit(); let mut dest: U = intrinsics::uninit();
let dest_ptr: *mut u8 = transmute(&mut dest); let dest_ptr: *mut u8 = transmute(&mut dest);
let src_ptr: *u8 = transmute(src); let src_ptr: *u8 = transmute(src);
intrinsics::memcpy64(dest_ptr, src_ptr, sys::size_of::<U>() as u64); intrinsics::memcpy64(dest_ptr, src_ptr, mem::size_of::<U>() as u64);
dest dest
} }

View File

@ -68,7 +68,7 @@ fn debug_mem() -> bool {
/// Destroys all managed memory (i.e. @ boxes) held by the current task. /// Destroys all managed memory (i.e. @ boxes) held by the current task.
pub unsafe fn annihilate() { pub unsafe fn annihilate() {
use rt::local_heap::local_free; use rt::local_heap::local_free;
use sys; use mem;
use managed; use managed;
let mut stats = AnnihilateStats { let mut stats = AnnihilateStats {
@ -115,7 +115,7 @@ pub unsafe fn annihilate() {
if !uniq { if !uniq {
stats.n_bytes_freed += stats.n_bytes_freed +=
(*((*box).type_desc)).size (*((*box).type_desc)).size
+ sys::size_of::<raw::Box<()>>(); + mem::size_of::<raw::Box<()>>();
local_free(box as *i8); local_free(box as *i8);
} }
true true

158
src/libstd/mem.rs Normal file
View File

@ -0,0 +1,158 @@
// Copyright 2012 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.
//! Functions relating to memory layout
use unstable::intrinsics;
/// Returns the size of a type
#[inline]
pub fn size_of<T>() -> uint {
unsafe { intrinsics::size_of::<T>() }
}
/// Returns the size of the type that `_val` points to
#[inline]
pub fn size_of_val<T>(_val: &T) -> uint {
size_of::<T>()
}
/**
* Returns the size of a type, or 1 if the actual size is zero.
*
* Useful for building structures containing variable-length arrays.
*/
#[inline]
pub fn nonzero_size_of<T>() -> uint {
let s = size_of::<T>();
if s == 0 { 1 } else { s }
}
/// Returns the size of the type of the value that `_val` points to
#[inline]
pub fn nonzero_size_of_val<T>(_val: &T) -> uint {
nonzero_size_of::<T>()
}
/**
* Returns the ABI-required minimum alignment of a type
*
* This is the alignment used for struct fields. It may be smaller
* than the preferred alignment.
*/
#[inline]
pub fn min_align_of<T>() -> uint {
unsafe { intrinsics::min_align_of::<T>() }
}
/// Returns the ABI-required minimum alignment of the type of the value that
/// `_val` points to
#[inline]
pub fn min_align_of_val<T>(_val: &T) -> uint {
min_align_of::<T>()
}
/// Returns the preferred alignment of a type
#[inline]
pub fn pref_align_of<T>() -> uint {
unsafe { intrinsics::pref_align_of::<T>() }
}
/// Returns the preferred alignment of the type of the value that
/// `_val` points to
#[inline]
pub fn pref_align_of_val<T>(_val: &T) -> uint {
pref_align_of::<T>()
}
#[cfg(test)]
mod tests {
use cast;
use mem::*;
#[test]
fn size_of_basic() {
assert_eq!(size_of::<u8>(), 1u);
assert_eq!(size_of::<u16>(), 2u);
assert_eq!(size_of::<u32>(), 4u);
assert_eq!(size_of::<u64>(), 8u);
}
#[test]
#[cfg(target_arch = "x86")]
#[cfg(target_arch = "arm")]
#[cfg(target_arch = "mips")]
fn size_of_32() {
assert_eq!(size_of::<uint>(), 4u);
assert_eq!(size_of::<*uint>(), 4u);
}
#[test]
#[cfg(target_arch = "x86_64")]
fn size_of_64() {
assert_eq!(size_of::<uint>(), 8u);
assert_eq!(size_of::<*uint>(), 8u);
}
#[test]
fn size_of_val_basic() {
assert_eq!(size_of_val(&1u8), 1);
assert_eq!(size_of_val(&1u16), 2);
assert_eq!(size_of_val(&1u32), 4);
assert_eq!(size_of_val(&1u64), 8);
}
#[test]
fn nonzero_size_of_basic() {
type Z = [i8, ..0];
assert_eq!(size_of::<Z>(), 0u);
assert_eq!(nonzero_size_of::<Z>(), 1u);
assert_eq!(nonzero_size_of::<uint>(), size_of::<uint>());
}
#[test]
fn nonzero_size_of_val_basic() {
let z = [0u8, ..0];
assert_eq!(size_of_val(&z), 0u);
assert_eq!(nonzero_size_of_val(&z), 1u);
assert_eq!(nonzero_size_of_val(&1u), size_of_val(&1u));
}
#[test]
fn align_of_basic() {
assert_eq!(pref_align_of::<u8>(), 1u);
assert_eq!(pref_align_of::<u16>(), 2u);
assert_eq!(pref_align_of::<u32>(), 4u);
}
#[test]
#[cfg(target_arch = "x86")]
#[cfg(target_arch = "arm")]
#[cfg(target_arch = "mips")]
fn align_of_32() {
assert_eq!(pref_align_of::<uint>(), 4u);
assert_eq!(pref_align_of::<*uint>(), 4u);
}
#[test]
#[cfg(target_arch = "x86_64")]
fn align_of_64() {
assert_eq!(pref_align_of::<uint>(), 8u);
assert_eq!(pref_align_of::<*uint>(), 8u);
}
#[test]
fn align_of_val_basic() {
assert_eq!(pref_align_of_val(&1u8), 1u);
assert_eq!(pref_align_of_val(&1u16), 2u);
assert_eq!(pref_align_of_val(&1u32), 4u);
}
}

View File

@ -928,7 +928,7 @@ mod tests {
use num::*; use num::*;
use num; use num;
use sys; use mem;
#[test] #[test]
fn test_num() { fn test_num() {
@ -1198,8 +1198,8 @@ mod tests {
#[test] #[test]
fn test_primitive() { fn test_primitive() {
let none: Option<f32> = None; let none: Option<f32> = None;
assert_eq!(Primitive::bits(none), sys::size_of::<f32>() * 8); assert_eq!(Primitive::bits(none), mem::size_of::<f32>() * 8);
assert_eq!(Primitive::bytes(none), sys::size_of::<f32>()); assert_eq!(Primitive::bytes(none), mem::size_of::<f32>());
} }
#[test] #[test]

View File

@ -976,7 +976,7 @@ mod tests {
use num::*; use num::*;
use num; use num;
use sys; use mem;
#[test] #[test]
fn test_num() { fn test_num() {
@ -1249,8 +1249,8 @@ mod tests {
#[test] #[test]
fn test_primitive() { fn test_primitive() {
let none: Option<f64> = None; let none: Option<f64> = None;
assert_eq!(Primitive::bits(none), sys::size_of::<f64>() * 8); assert_eq!(Primitive::bits(none), mem::size_of::<f64>() * 8);
assert_eq!(Primitive::bytes(none), sys::size_of::<f64>()); assert_eq!(Primitive::bytes(none), mem::size_of::<f64>());
} }
#[test] #[test]

View File

@ -456,7 +456,7 @@ mod tests {
use int; use int;
use i32; use i32;
use num; use num;
use sys; use mem;
#[test] #[test]
fn test_num() { fn test_num() {
@ -653,8 +653,8 @@ mod tests {
#[test] #[test]
fn test_primitive() { fn test_primitive() {
let none: Option<$T> = None; let none: Option<$T> = None;
assert_eq!(Primitive::bits(none), sys::size_of::<$T>() * 8); assert_eq!(Primitive::bits(none), mem::size_of::<$T>() * 8);
assert_eq!(Primitive::bytes(none), sys::size_of::<$T>()); assert_eq!(Primitive::bytes(none), mem::size_of::<$T>());
} }
#[test] #[test]

View File

@ -14,7 +14,7 @@ use num;
use num::{CheckedAdd, CheckedSub, CheckedMul}; use num::{CheckedAdd, CheckedSub, CheckedMul};
use option::{Option, Some, None}; use option::{Option, Some, None};
use unstable::intrinsics; use unstable::intrinsics;
use sys; use mem;
pub use self::generated::*; pub use self::generated::*;
@ -97,7 +97,7 @@ impl num::Times for uint {
/// Returns the smallest power of 2 greater than or equal to `n` /// Returns the smallest power of 2 greater than or equal to `n`
#[inline] #[inline]
pub fn next_power_of_two(n: uint) -> uint { pub fn next_power_of_two(n: uint) -> uint {
let halfbits: uint = sys::size_of::<uint>() * 4u; let halfbits: uint = mem::size_of::<uint>() * 4u;
let mut tmp: uint = n - 1u; let mut tmp: uint = n - 1u;
let mut shift: uint = 1u; let mut shift: uint = 1u;
while shift <= halfbits { tmp |= tmp >> shift; shift <<= 1u; } while shift <= halfbits { tmp |= tmp >> shift; shift <<= 1u; }
@ -107,7 +107,7 @@ pub fn next_power_of_two(n: uint) -> uint {
/// Returns the smallest power of 2 greater than or equal to `n` /// Returns the smallest power of 2 greater than or equal to `n`
#[inline] #[inline]
pub fn next_power_of_two_opt(n: uint) -> Option<uint> { pub fn next_power_of_two_opt(n: uint) -> Option<uint> {
let halfbits: uint = sys::size_of::<uint>() * 4u; let halfbits: uint = mem::size_of::<uint>() * 4u;
let mut tmp: uint = n - 1u; let mut tmp: uint = n - 1u;
let mut shift: uint = 1u; let mut shift: uint = 1u;
while shift <= halfbits { tmp |= tmp >> shift; shift <<= 1u; } while shift <= halfbits { tmp |= tmp >> shift; shift <<= 1u; }

View File

@ -337,7 +337,7 @@ mod tests {
use super::*; use super::*;
use num; use num;
use sys; use mem;
use u16; use u16;
#[test] #[test]
@ -431,8 +431,8 @@ mod tests {
#[test] #[test]
fn test_primitive() { fn test_primitive() {
let none: Option<$T> = None; let none: Option<$T> = None;
assert_eq!(Primitive::bits(none), sys::size_of::<$T>() * 8); assert_eq!(Primitive::bits(none), mem::size_of::<$T>() * 8);
assert_eq!(Primitive::bytes(none), sys::size_of::<$T>()); assert_eq!(Primitive::bytes(none), mem::size_of::<$T>());
} }
#[test] #[test]

View File

@ -52,7 +52,7 @@ fn main () {
``` ```
*/ */
use sys::size_of; use mem::size_of;
use unstable::raw::Slice; use unstable::raw::Slice;
use cast; use cast;
use container::Container; use container::Container;
@ -952,7 +952,7 @@ mod test {
mod bench { mod bench {
use extra::test::BenchHarness; use extra::test::BenchHarness;
use rand::*; use rand::*;
use sys::size_of; use mem::size_of;
#[bench] #[bench]
fn rand_xorshift(bh: &mut BenchHarness) { fn rand_xorshift(bh: &mut BenchHarness) {

View File

@ -18,7 +18,7 @@ Runtime type reflection
use unstable::intrinsics::{Opaque, TyDesc, TyVisitor}; use unstable::intrinsics::{Opaque, TyDesc, TyVisitor};
use libc::c_void; use libc::c_void;
use sys; use mem;
use unstable::raw; use unstable::raw;
/** /**
@ -64,12 +64,12 @@ impl<V:TyVisitor + MovePtr> MovePtrAdaptor<V> {
#[inline] #[inline]
pub fn align_to<T>(&mut self) { pub fn align_to<T>(&mut self) {
self.align(sys::min_align_of::<T>()); self.align(mem::min_align_of::<T>());
} }
#[inline] #[inline]
pub fn bump_past<T>(&mut self) { pub fn bump_past<T>(&mut self) {
self.bump(sys::size_of::<T>()); self.bump(mem::size_of::<T>());
} }
} }

View File

@ -233,6 +233,6 @@ fn align_down(sp: *mut uint) -> *mut uint {
// ptr::mut_offset is positive ints only // ptr::mut_offset is positive ints only
#[inline] #[inline]
pub fn mut_offset<T>(ptr: *mut T, count: int) -> *mut T { pub fn mut_offset<T>(ptr: *mut T, count: int) -> *mut T {
use std::sys::size_of; use mem::size_of;
(ptr as int + count * (size_of::<T>() as int)) as *mut T (ptr as int + count * (size_of::<T>() as int)) as *mut T
} }

View File

@ -11,7 +11,7 @@
use libc::{c_void, c_char, size_t, uintptr_t, free, malloc, realloc}; use libc::{c_void, c_char, size_t, uintptr_t, free, malloc, realloc};
use unstable::intrinsics::TyDesc; use unstable::intrinsics::TyDesc;
use unstable::raw; use unstable::raw;
use sys::size_of; use mem::size_of;
extern { extern {
#[rust_stack] #[rust_stack]

View File

@ -271,12 +271,12 @@ fn spawn_process_os(prog: &str, args: &[~str],
}; };
use libc::funcs::extra::msvcrt::get_osfhandle; use libc::funcs::extra::msvcrt::get_osfhandle;
use sys; use mem;
unsafe { unsafe {
let mut si = zeroed_startupinfo(); let mut si = zeroed_startupinfo();
si.cb = sys::size_of::<STARTUPINFO>() as DWORD; si.cb = mem::size_of::<STARTUPINFO>() as DWORD;
si.dwFlags = STARTF_USESTDHANDLES; si.dwFlags = STARTF_USESTDHANDLES;
let cur_proc = GetCurrentProcess(); let cur_proc = GetCurrentProcess();

View File

@ -857,7 +857,7 @@ fn new_sched_rng() -> XorShiftRng {
#[fixed_stack_segment] #[inline(never)] #[fixed_stack_segment] #[inline(never)]
fn new_sched_rng() -> XorShiftRng { fn new_sched_rng() -> XorShiftRng {
use libc; use libc;
use sys; use mem;
use c_str::ToCStr; use c_str::ToCStr;
use vec::MutableVector; use vec::MutableVector;
use iter::Iterator; use iter::Iterator;
@ -871,7 +871,7 @@ fn new_sched_rng() -> XorShiftRng {
} }
let mut seeds = [0u32, .. 4]; let mut seeds = [0u32, .. 4];
let size = sys::size_of_val(&seeds); let size = mem::size_of_val(&seeds);
loop { loop {
let nbytes = do seeds.as_mut_buf |buf, _| { let nbytes = do seeds.as_mut_buf |buf, _| {
unsafe { unsafe {

View File

@ -103,7 +103,7 @@ mod darwin_fd_limit {
// The strategy here is to fetch the current resource limits, read the kern.maxfilesperproc // The strategy here is to fetch the current resource limits, read the kern.maxfilesperproc
// sysctl value, and bump the soft resource limit for maxfiles up to the sysctl value. // sysctl value, and bump the soft resource limit for maxfiles up to the sysctl value.
use ptr::{to_unsafe_ptr, to_mut_unsafe_ptr, mut_null}; use ptr::{to_unsafe_ptr, to_mut_unsafe_ptr, mut_null};
use sys::size_of_val; use mem::size_of_val;
use os::last_os_error; use os::last_os_error;
// Fetch the kern.maxfilesperproc value // Fetch the kern.maxfilesperproc value

View File

@ -189,6 +189,7 @@ pub mod condition;
pub mod logging; pub mod logging;
pub mod util; pub mod util;
pub mod routine; pub mod routine;
pub mod mem;
/* Unsupported interfaces */ /* Unsupported interfaces */

View File

@ -19,68 +19,6 @@ use libc;
use repr; use repr;
use rt::task; use rt::task;
use str; use str;
use unstable::intrinsics;
/// Returns the size of a type
#[inline]
pub fn size_of<T>() -> uint {
unsafe { intrinsics::size_of::<T>() }
}
/// Returns the size of the type that `_val` points to
#[inline]
pub fn size_of_val<T>(_val: &T) -> uint {
size_of::<T>()
}
/**
* Returns the size of a type, or 1 if the actual size is zero.
*
* Useful for building structures containing variable-length arrays.
*/
#[inline]
pub fn nonzero_size_of<T>() -> uint {
let s = size_of::<T>();
if s == 0 { 1 } else { s }
}
/// Returns the size of the type of the value that `_val` points to
#[inline]
pub fn nonzero_size_of_val<T>(_val: &T) -> uint {
nonzero_size_of::<T>()
}
/**
* Returns the ABI-required minimum alignment of a type
*
* This is the alignment used for struct fields. It may be smaller
* than the preferred alignment.
*/
#[inline]
pub fn min_align_of<T>() -> uint {
unsafe { intrinsics::min_align_of::<T>() }
}
/// Returns the ABI-required minimum alignment of the type of the value that
/// `_val` points to
#[inline]
pub fn min_align_of_val<T>(_val: &T) -> uint {
min_align_of::<T>()
}
/// Returns the preferred alignment of a type
#[inline]
pub fn pref_align_of<T>() -> uint {
unsafe { intrinsics::pref_align_of::<T>() }
}
/// Returns the preferred alignment of the type of the value that
/// `_val` points to
#[inline]
pub fn pref_align_of_val<T>(_val: &T) -> uint {
pref_align_of::<T>()
}
/// Returns the refcount of a shared box (as just before calling this) /// Returns the refcount of a shared box (as just before calling this)
#[inline] #[inline]
@ -131,84 +69,6 @@ mod tests {
use cast; use cast;
use sys::*; use sys::*;
#[test]
fn size_of_basic() {
assert_eq!(size_of::<u8>(), 1u);
assert_eq!(size_of::<u16>(), 2u);
assert_eq!(size_of::<u32>(), 4u);
assert_eq!(size_of::<u64>(), 8u);
}
#[test]
#[cfg(target_arch = "x86")]
#[cfg(target_arch = "arm")]
#[cfg(target_arch = "mips")]
fn size_of_32() {
assert_eq!(size_of::<uint>(), 4u);
assert_eq!(size_of::<*uint>(), 4u);
}
#[test]
#[cfg(target_arch = "x86_64")]
fn size_of_64() {
assert_eq!(size_of::<uint>(), 8u);
assert_eq!(size_of::<*uint>(), 8u);
}
#[test]
fn size_of_val_basic() {
assert_eq!(size_of_val(&1u8), 1);
assert_eq!(size_of_val(&1u16), 2);
assert_eq!(size_of_val(&1u32), 4);
assert_eq!(size_of_val(&1u64), 8);
}
#[test]
fn nonzero_size_of_basic() {
type Z = [i8, ..0];
assert_eq!(size_of::<Z>(), 0u);
assert_eq!(nonzero_size_of::<Z>(), 1u);
assert_eq!(nonzero_size_of::<uint>(), size_of::<uint>());
}
#[test]
fn nonzero_size_of_val_basic() {
let z = [0u8, ..0];
assert_eq!(size_of_val(&z), 0u);
assert_eq!(nonzero_size_of_val(&z), 1u);
assert_eq!(nonzero_size_of_val(&1u), size_of_val(&1u));
}
#[test]
fn align_of_basic() {
assert_eq!(pref_align_of::<u8>(), 1u);
assert_eq!(pref_align_of::<u16>(), 2u);
assert_eq!(pref_align_of::<u32>(), 4u);
}
#[test]
#[cfg(target_arch = "x86")]
#[cfg(target_arch = "arm")]
#[cfg(target_arch = "mips")]
fn align_of_32() {
assert_eq!(pref_align_of::<uint>(), 4u);
assert_eq!(pref_align_of::<*uint>(), 4u);
}
#[test]
#[cfg(target_arch = "x86_64")]
fn align_of_64() {
assert_eq!(pref_align_of::<uint>(), 8u);
assert_eq!(pref_align_of::<*uint>(), 8u);
}
#[test]
fn align_of_val_basic() {
assert_eq!(pref_align_of_val(&1u8), 1u);
assert_eq!(pref_align_of_val(&1u16), 2u);
assert_eq!(pref_align_of_val(&1u32), 4u);
}
#[test] #[test]
fn synthesize_closure() { fn synthesize_closure() {
use unstable::raw::Closure; use unstable::raw::Closure;

View File

@ -425,7 +425,7 @@ mod tests {
use super::{Exclusive, UnsafeArc, atomically}; use super::{Exclusive, UnsafeArc, atomically};
use task; use task;
use util; use util;
use sys::size_of; use mem::size_of;
//#[unsafe_no_drop_flag] FIXME: #9758 //#[unsafe_no_drop_flag] FIXME: #9758
#[ignore] #[ignore]

View File

@ -93,7 +93,7 @@ mod tests {
use ops::Drop; use ops::Drop;
use option::{None, Some}; use option::{None, Some};
use either::{Either, Left, Right}; use either::{Either, Left, Right};
use sys::size_of; use mem::size_of;
#[test] #[test]
fn identity_crisis() { fn identity_crisis() {

View File

@ -116,8 +116,8 @@ use ptr;
use ptr::RawPtr; use ptr::RawPtr;
use rt::global_heap::malloc_raw; use rt::global_heap::malloc_raw;
use rt::global_heap::realloc_raw; use rt::global_heap::realloc_raw;
use sys; use mem;
use sys::size_of; use mem::size_of;
use uint; use uint;
use unstable::finally::Finally; use unstable::finally::Finally;
use unstable::intrinsics; use unstable::intrinsics;
@ -185,8 +185,8 @@ pub fn with_capacity<T>(capacity: uint) -> ~[T] {
vec.reserve(capacity); vec.reserve(capacity);
vec vec
} else { } else {
let alloc = capacity * sys::nonzero_size_of::<T>(); let alloc = capacity * mem::nonzero_size_of::<T>();
let ptr = malloc_raw(alloc + sys::size_of::<Vec<()>>()) as *mut Vec<()>; let ptr = malloc_raw(alloc + mem::size_of::<Vec<()>>()) as *mut Vec<()>;
(*ptr).alloc = alloc; (*ptr).alloc = alloc;
(*ptr).fill = 0; (*ptr).fill = 0;
cast::transmute(ptr) cast::transmute(ptr)
@ -1002,7 +1002,7 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
fn iter(self) -> VecIterator<'self, T> { fn iter(self) -> VecIterator<'self, T> {
unsafe { unsafe {
let p = vec::raw::to_ptr(self); let p = vec::raw::to_ptr(self);
if sys::size_of::<T>() == 0 { if mem::size_of::<T>() == 0 {
VecIterator{ptr: p, VecIterator{ptr: p,
end: (p as uint + self.len()) as *T, end: (p as uint + self.len()) as *T,
lifetime: None} lifetime: None}
@ -1406,9 +1406,9 @@ impl<T> OwnedVector<T> for ~[T] {
::at_vec::raw::reserve_raw(td, ptr, n); ::at_vec::raw::reserve_raw(td, ptr, n);
} else { } else {
let ptr: *mut *mut Vec<()> = cast::transmute(self); let ptr: *mut *mut Vec<()> = cast::transmute(self);
let alloc = n * sys::nonzero_size_of::<T>(); let alloc = n * mem::nonzero_size_of::<T>();
let size = alloc + sys::size_of::<Vec<()>>(); let size = alloc + mem::size_of::<Vec<()>>();
if alloc / sys::nonzero_size_of::<T>() != n || size < alloc { if alloc / mem::nonzero_size_of::<T>() != n || size < alloc {
fail2!("vector size is too large: {}", n); fail2!("vector size is too large: {}", n);
} }
*ptr = realloc_raw(*ptr as *mut c_void, size) *ptr = realloc_raw(*ptr as *mut c_void, size)
@ -1439,10 +1439,10 @@ impl<T> OwnedVector<T> for ~[T] {
unsafe { unsafe {
if contains_managed::<T>() { if contains_managed::<T>() {
let repr: **Box<Vec<()>> = cast::transmute(self); let repr: **Box<Vec<()>> = cast::transmute(self);
(**repr).data.alloc / sys::nonzero_size_of::<T>() (**repr).data.alloc / mem::nonzero_size_of::<T>()
} else { } else {
let repr: **Vec<()> = cast::transmute(self); let repr: **Vec<()> = cast::transmute(self);
(**repr).alloc / sys::nonzero_size_of::<T>() (**repr).alloc / mem::nonzero_size_of::<T>()
} }
} }
} }
@ -1451,7 +1451,7 @@ impl<T> OwnedVector<T> for ~[T] {
unsafe { unsafe {
let ptr: *mut *mut Vec<()> = cast::transmute(self); let ptr: *mut *mut Vec<()> = cast::transmute(self);
let alloc = (**ptr).fill; let alloc = (**ptr).fill;
let size = alloc + sys::size_of::<Vec<()>>(); let size = alloc + mem::size_of::<Vec<()>>();
*ptr = realloc_raw(*ptr as *mut c_void, size) as *mut Vec<()>; *ptr = realloc_raw(*ptr as *mut c_void, size) as *mut Vec<()>;
(**ptr).alloc = alloc; (**ptr).alloc = alloc;
} }
@ -1485,14 +1485,14 @@ impl<T> OwnedVector<T> for ~[T] {
if contains_managed::<T>() { if contains_managed::<T>() {
let repr: **mut Box<Vec<u8>> = cast::transmute(this); let repr: **mut Box<Vec<u8>> = cast::transmute(this);
let fill = (**repr).data.fill; let fill = (**repr).data.fill;
(**repr).data.fill += sys::nonzero_size_of::<T>(); (**repr).data.fill += mem::nonzero_size_of::<T>();
let p = to_unsafe_ptr(&((**repr).data.data)); let p = to_unsafe_ptr(&((**repr).data.data));
let p = ptr::offset(p, fill as int) as *mut T; let p = ptr::offset(p, fill as int) as *mut T;
intrinsics::move_val_init(&mut(*p), t); intrinsics::move_val_init(&mut(*p), t);
} else { } else {
let repr: **mut Vec<u8> = cast::transmute(this); let repr: **mut Vec<u8> = cast::transmute(this);
let fill = (**repr).fill; let fill = (**repr).fill;
(**repr).fill += sys::nonzero_size_of::<T>(); (**repr).fill += mem::nonzero_size_of::<T>();
let p = to_unsafe_ptr(&((**repr).data)); let p = to_unsafe_ptr(&((**repr).data));
let p = ptr::offset(p, fill as int) as *mut T; let p = ptr::offset(p, fill as int) as *mut T;
intrinsics::move_val_init(&mut(*p), t); intrinsics::move_val_init(&mut(*p), t);
@ -1957,7 +1957,7 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
fn mut_iter(self) -> VecMutIterator<'self, T> { fn mut_iter(self) -> VecMutIterator<'self, T> {
unsafe { unsafe {
let p = vec::raw::to_mut_ptr(self); let p = vec::raw::to_mut_ptr(self);
if sys::size_of::<T>() == 0 { if mem::size_of::<T>() == 0 {
VecMutIterator{ptr: p, VecMutIterator{ptr: p,
end: (p as uint + self.len()) as *mut T, end: (p as uint + self.len()) as *mut T,
lifetime: None} lifetime: None}
@ -2054,7 +2054,7 @@ pub mod raw {
use clone::Clone; use clone::Clone;
use option::Some; use option::Some;
use ptr; use ptr;
use sys; use mem;
use unstable::intrinsics; use unstable::intrinsics;
use vec::{with_capacity, ImmutableVector, MutableVector}; use vec::{with_capacity, ImmutableVector, MutableVector};
use unstable::intrinsics::contains_managed; use unstable::intrinsics::contains_managed;
@ -2071,10 +2071,10 @@ pub mod raw {
pub unsafe fn set_len<T>(v: &mut ~[T], new_len: uint) { pub unsafe fn set_len<T>(v: &mut ~[T], new_len: uint) {
if contains_managed::<T>() { if contains_managed::<T>() {
let repr: **mut Box<Vec<()>> = cast::transmute(v); let repr: **mut Box<Vec<()>> = cast::transmute(v);
(**repr).data.fill = new_len * sys::nonzero_size_of::<T>(); (**repr).data.fill = new_len * mem::nonzero_size_of::<T>();
} else { } else {
let repr: **mut Vec<()> = cast::transmute(v); let repr: **mut Vec<()> = cast::transmute(v);
(**repr).fill = new_len * sys::nonzero_size_of::<T>(); (**repr).fill = new_len * mem::nonzero_size_of::<T>();
} }
} }
@ -2323,7 +2323,7 @@ macro_rules! iterator {
None None
} else { } else {
let old = self.ptr; let old = self.ptr;
self.ptr = if sys::size_of::<T>() == 0 { self.ptr = if mem::size_of::<T>() == 0 {
// purposefully don't use 'ptr.offset' because for // purposefully don't use 'ptr.offset' because for
// vectors with 0-size elements this would return the // vectors with 0-size elements this would return the
// same pointer. // same pointer.
@ -2340,7 +2340,7 @@ macro_rules! iterator {
#[inline] #[inline]
fn size_hint(&self) -> (uint, Option<uint>) { fn size_hint(&self) -> (uint, Option<uint>) {
let diff = (self.end as uint) - (self.ptr as uint); let diff = (self.end as uint) - (self.ptr as uint);
let exact = diff / sys::nonzero_size_of::<T>(); let exact = diff / mem::nonzero_size_of::<T>();
(exact, Some(exact)) (exact, Some(exact))
} }
} }
@ -2357,7 +2357,7 @@ macro_rules! double_ended_iterator {
if self.end == self.ptr { if self.end == self.ptr {
None None
} else { } else {
self.end = if sys::size_of::<T>() == 0 { self.end = if mem::size_of::<T>() == 0 {
// See above for why 'ptr.offset' isn't used // See above for why 'ptr.offset' isn't used
cast::transmute(self.end as uint - 1) cast::transmute(self.end as uint - 1)
} else { } else {
@ -2497,7 +2497,7 @@ impl<A> Extendable<A> for ~[A] {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use option::{None, Option, Some}; use option::{None, Option, Some};
use sys; use mem;
use vec::*; use vec::*;
use cmp::*; use cmp::*;
use prelude::*; use prelude::*;
@ -2597,7 +2597,7 @@ mod tests {
let v0 : &[Z] = &[]; let v0 : &[Z] = &[];
let v1 : &[Z] = &[[]]; let v1 : &[Z] = &[[]];
let v2 : &[Z] = &[[], []]; let v2 : &[Z] = &[[], []];
assert_eq!(sys::size_of::<Z>(), 0); assert_eq!(mem::size_of::<Z>(), 0);
assert_eq!(v0.len(), 0); assert_eq!(v0.len(), 0);
assert_eq!(v1.len(), 1); assert_eq!(v1.len(), 1);
assert_eq!(v2.len(), 2); assert_eq!(v2.len(), 2);

View File

@ -11,7 +11,7 @@
// error-pattern:index out of bounds: the len is 3 but the index is // error-pattern:index out of bounds: the len is 3 but the index is
use std::uint::max_value; use std::uint::max_value;
use std::sys::size_of; use std::mem::size_of;
fn main() { fn main() {
let xs = [1, 2, 3]; let xs = [1, 2, 3];

View File

@ -10,7 +10,7 @@
// error-pattern:index out of bounds // error-pattern:index out of bounds
use std::sys; use std::mem;
fn main() { fn main() {
@ -23,12 +23,12 @@ fn main() {
let x = ~[1u,2u,3u]; let x = ~[1u,2u,3u];
do x.as_imm_buf |p, _len| { do x.as_imm_buf |p, _len| {
let base = p as uint; let base = p as uint;
let idx = base / sys::size_of::<uint>(); let idx = base / mem::size_of::<uint>();
error2!("ov1 base = 0x{:x}", base); error2!("ov1 base = 0x{:x}", base);
error2!("ov1 idx = 0x{:x}", idx); error2!("ov1 idx = 0x{:x}", idx);
error2!("ov1 sizeof::<uint>() = 0x{:x}", sys::size_of::<uint>()); error2!("ov1 sizeof::<uint>() = 0x{:x}", mem::size_of::<uint>());
error2!("ov1 idx * sizeof::<uint>() = 0x{:x}", error2!("ov1 idx * sizeof::<uint>() = 0x{:x}",
idx * sys::size_of::<uint>()); idx * mem::size_of::<uint>());
// This should fail. // This should fail.
error2!("ov1 0x{:x}", x[idx]); error2!("ov1 0x{:x}", x[idx]);

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::sys::size_of; use std::mem::size_of;
#[unsafe_no_drop_flag] #[unsafe_no_drop_flag]
struct Test<T> { struct Test<T> {

View File

@ -10,7 +10,7 @@
use std::cast; use std::cast;
use std::ptr; use std::ptr;
use std::sys; use std::mem;
fn addr_of<T>(ptr: &T) -> uint { fn addr_of<T>(ptr: &T) -> uint {
let ptr = ptr::to_unsafe_ptr(ptr); let ptr = ptr::to_unsafe_ptr(ptr);
@ -20,7 +20,7 @@ fn addr_of<T>(ptr: &T) -> uint {
fn is_aligned<T>(ptr: &T) -> bool { fn is_aligned<T>(ptr: &T) -> bool {
unsafe { unsafe {
let addr: uint = cast::transmute(ptr); let addr: uint = cast::transmute(ptr);
(addr % sys::min_align_of::<T>()) == 0 (addr % mem::min_align_of::<T>()) == 0
} }
} }

View File

@ -8,12 +8,12 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::sys; use std::mem;
pub fn main() { pub fn main() {
enum E { V = 0x1717171717171717 } enum E { V = 0x1717171717171717 }
static C: E = V; static C: E = V;
let expected: u64 = if sys::size_of::<uint>() < 8 { let expected: u64 = if mem::size_of::<uint>() < 8 {
0x17171717 0x17171717
} else { } else {
0x1717171717171717 0x1717171717171717

View File

@ -8,9 +8,9 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::sys; use std::mem;
pub fn main() { pub fn main() {
// Bare functions should just be a pointer // Bare functions should just be a pointer
assert_eq!(sys::size_of::<extern "Rust" fn()>(), sys::size_of::<int>()); assert_eq!(mem::size_of::<extern "Rust" fn()>(), mem::size_of::<int>());
} }

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::sys; use std::mem;
struct Cat { struct Cat {
x: int x: int
@ -24,13 +24,13 @@ impl Drop for Kitty {
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
pub fn main() { pub fn main() {
assert_eq!(sys::size_of::<Cat>(), 8 as uint); assert_eq!(mem::size_of::<Cat>(), 8 as uint);
assert_eq!(sys::size_of::<Kitty>(), 16 as uint); assert_eq!(mem::size_of::<Kitty>(), 16 as uint);
} }
#[cfg(target_arch = "x86")] #[cfg(target_arch = "x86")]
#[cfg(target_arch = "arm")] #[cfg(target_arch = "arm")]
pub fn main() { pub fn main() {
assert_eq!(sys::size_of::<Cat>(), 4 as uint); assert_eq!(mem::size_of::<Cat>(), 4 as uint);
assert_eq!(sys::size_of::<Kitty>(), 8 as uint); assert_eq!(mem::size_of::<Kitty>(), 8 as uint);
} }

View File

@ -10,7 +10,7 @@
#[feature(macro_rules)]; #[feature(macro_rules)];
use std::sys; use std::mem;
enum E<T> { Thing(int, T), Nothing((), ((), ()), [i8, ..0]) } enum E<T> { Thing(int, T), Nothing((), ((), ()), [i8, ..0]) }
struct S<T>(int, T); struct S<T>(int, T);
@ -19,13 +19,13 @@ struct S<T>(int, T);
macro_rules! check_option { macro_rules! check_option {
($T:ty) => { ($T:ty) => {
assert_eq!(sys::size_of::<Option<$T>>(), sys::size_of::<$T>()); assert_eq!(mem::size_of::<Option<$T>>(), mem::size_of::<$T>());
} }
} }
macro_rules! check_fancy { macro_rules! check_fancy {
($T:ty) => { ($T:ty) => {
assert_eq!(sys::size_of::<E<$T>>(), sys::size_of::<S<$T>>()); assert_eq!(mem::size_of::<E<$T>>(), mem::size_of::<S<$T>>());
} }
} }

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::sys; use std::mem;
#[packed] #[packed]
struct S<T, S> { struct S<T, S> {
@ -18,10 +18,10 @@ struct S<T, S> {
} }
pub fn main() { pub fn main() {
assert_eq!(sys::size_of::<S<u8, u8>>(), 3); assert_eq!(mem::size_of::<S<u8, u8>>(), 3);
assert_eq!(sys::size_of::<S<u64, u16>>(), 11); assert_eq!(mem::size_of::<S<u64, u16>>(), 11);
assert_eq!(sys::size_of::<S<~str, @mut [int]>>(), assert_eq!(mem::size_of::<S<~str, @mut [int]>>(),
1 + sys::size_of::<~str>() + sys::size_of::<@mut [int]>()); 1 + mem::size_of::<~str>() + mem::size_of::<@mut [int]>());
} }

View File

@ -3,8 +3,8 @@
extern mod packed; extern mod packed;
use std::sys; use std::mem;
fn main() { fn main() {
assert_eq!(sys::size_of::<packed::S>(), 5); assert_eq!(mem::size_of::<packed::S>(), 5);
} }

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::sys; use std::mem;
#[packed] #[packed]
struct S4 { struct S4 {
@ -57,9 +57,9 @@ static TEST_S3_Foo: S3_Foo = S3_Foo { a: 1, b: 2, c: Baz };
pub fn main() { pub fn main() {
assert_eq!(sys::size_of::<S4>(), 4); assert_eq!(mem::size_of::<S4>(), 4);
assert_eq!(sys::size_of::<S5>(), 5); assert_eq!(mem::size_of::<S5>(), 5);
assert_eq!(sys::size_of::<S13_str>(), 13 + sys::size_of::<~str>()); assert_eq!(mem::size_of::<S13_str>(), 13 + mem::size_of::<~str>());
assert_eq!(sys::size_of::<S3_Foo>(), 3 + sys::size_of::<Foo>()); assert_eq!(mem::size_of::<S3_Foo>(), 3 + mem::size_of::<Foo>());
assert_eq!(sys::size_of::<S7_Option>(), 7 + sys::size_of::<Option<@mut f64>>()); assert_eq!(mem::size_of::<S7_Option>(), 7 + mem::size_of::<Option<@mut f64>>());
} }

View File

@ -10,7 +10,7 @@
// xfail-android: FIXME(#9116) Bus error // xfail-android: FIXME(#9116) Bus error
use std::sys; use std::mem;
#[packed] #[packed]
#[deriving(Eq)] #[deriving(Eq)]
@ -22,7 +22,7 @@ struct Foo {
pub fn main() { pub fn main() {
let foos = [Foo { bar: 1, baz: 2 }, .. 10]; let foos = [Foo { bar: 1, baz: 2 }, .. 10];
assert_eq!(sys::size_of::<[Foo, .. 10]>(), 90); assert_eq!(mem::size_of::<[Foo, .. 10]>(), 90);
for i in range(0u, 10) { for i in range(0u, 10) {
assert_eq!(foos[i], Foo { bar: 1, baz: 2}); assert_eq!(foos[i], Foo { bar: 1, baz: 2});

View File

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed // option. This file may not be copied, modified, or distributed
// except according to those terms. // except according to those terms.
use std::sys; use std::mem;
#[packed] #[packed]
struct S4(u8,[u8, .. 3]); struct S4(u8,[u8, .. 3]);
@ -31,16 +31,16 @@ struct S3_Foo(u8, u16, Foo);
struct S7_Option(f32, u8, u16, Option<@mut f64>); struct S7_Option(f32, u8, u16, Option<@mut f64>);
pub fn main() { pub fn main() {
assert_eq!(sys::size_of::<S4>(), 4); assert_eq!(mem::size_of::<S4>(), 4);
assert_eq!(sys::size_of::<S5>(), 5); assert_eq!(mem::size_of::<S5>(), 5);
assert_eq!(sys::size_of::<S13_str>(), assert_eq!(mem::size_of::<S13_str>(),
13 + sys::size_of::<~str>()); 13 + mem::size_of::<~str>());
assert_eq!(sys::size_of::<S3_Foo>(), assert_eq!(mem::size_of::<S3_Foo>(),
3 + sys::size_of::<Foo>()); 3 + mem::size_of::<Foo>());
assert_eq!(sys::size_of::<S7_Option>(), assert_eq!(mem::size_of::<S7_Option>(),
7 + sys::size_of::<Option<@mut f64>>()); 7 + mem::size_of::<Option<@mut f64>>());
} }

View File

@ -12,7 +12,7 @@
// Issue #2303 // Issue #2303
use std::sys; use std::mem;
mod rusti { mod rusti {
extern "rust-intrinsic" { extern "rust-intrinsic" {
@ -55,7 +55,7 @@ pub fn main() {
let y = format!("{:?}", x); let y = format!("{:?}", x);
info2!("align inner = {:?}", rusti::min_align_of::<Inner>()); info2!("align inner = {:?}", rusti::min_align_of::<Inner>());
info2!("size outer = {:?}", sys::size_of::<Outer>()); info2!("size outer = {:?}", mem::size_of::<Outer>());
info2!("y = {}", y); info2!("y = {}", y);
// per clang/gcc the alignment of `inner` is 4 on x86. // per clang/gcc the alignment of `inner` is 4 on x86.
@ -63,7 +63,7 @@ pub fn main() {
// per clang/gcc the size of `outer` should be 12 // per clang/gcc the size of `outer` should be 12
// because `inner`s alignment was 4. // because `inner`s alignment was 4.
assert_eq!(sys::size_of::<Outer>(), m::size()); assert_eq!(mem::size_of::<Outer>(), m::size());
assert_eq!(y, ~"Outer{c8: 22u8, t: Inner{c64: 44u32}}"); assert_eq!(y, ~"Outer{c8: 22u8, t: Inner{c64: 44u32}}");
} }

View File

@ -12,7 +12,7 @@
// Issue #2303 // Issue #2303
use std::sys; use std::mem;
mod rusti { mod rusti {
extern "rust-intrinsic" { extern "rust-intrinsic" {
@ -77,7 +77,7 @@ pub fn main() {
let y = format!("{:?}", x); let y = format!("{:?}", x);
info2!("align inner = {}", rusti::min_align_of::<Inner>()); info2!("align inner = {}", rusti::min_align_of::<Inner>());
info2!("size outer = {}", sys::size_of::<Outer>()); info2!("size outer = {}", mem::size_of::<Outer>());
info2!("y = {}", y); info2!("y = {}", y);
// per clang/gcc the alignment of `Inner` is 4 on x86. // per clang/gcc the alignment of `Inner` is 4 on x86.
@ -85,7 +85,7 @@ pub fn main() {
// per clang/gcc the size of `Outer` should be 12 // per clang/gcc the size of `Outer` should be 12
// because `Inner`s alignment was 4. // because `Inner`s alignment was 4.
assert_eq!(sys::size_of::<Outer>(), m::m::size()); assert_eq!(mem::size_of::<Outer>(), m::m::size());
assert_eq!(y, ~"Outer{c8: 22u8, t: Inner{c64: 44u64}}"); assert_eq!(y, ~"Outer{c8: 22u8, t: Inner{c64: 44u64}}");
} }

View File

@ -12,7 +12,7 @@
use std::libc::c_void; use std::libc::c_void;
use std::ptr; use std::ptr;
use std::sys; use std::mem;
use std::unstable::intrinsics::{TyDesc, get_tydesc, visit_tydesc, TyVisitor, Opaque}; use std::unstable::intrinsics::{TyDesc, get_tydesc, visit_tydesc, TyVisitor, Opaque};
use std::unstable::raw::Vec; use std::unstable::raw::Vec;
@ -49,12 +49,12 @@ impl<V:TyVisitor + movable_ptr> ptr_visit_adaptor<V> {
#[inline(always)] #[inline(always)]
pub fn align_to<T>(&mut self) { pub fn align_to<T>(&mut self) {
self.align(sys::min_align_of::<T>()); self.align(mem::min_align_of::<T>());
} }
#[inline(always)] #[inline(always)]
pub fn bump_past<T>(&mut self) { pub fn bump_past<T>(&mut self) {
self.bump(sys::size_of::<T>()); self.bump(mem::size_of::<T>());
} }
} }

View File

@ -10,7 +10,7 @@
use std::cast; use std::cast;
use std::libc; use std::libc;
use std::sys; use std::mem;
struct arena(()); struct arena(());
@ -30,7 +30,7 @@ struct Ccx {
#[fixed_stack_segment] #[inline(never)] #[fixed_stack_segment] #[inline(never)]
fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> { fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> {
unsafe { unsafe {
cast::transmute(libc::malloc(sys::size_of::<Bcx<'blk>>() cast::transmute(libc::malloc(mem::size_of::<Bcx<'blk>>()
as libc::size_t)) as libc::size_t))
} }
} }

View File

@ -9,7 +9,7 @@
// except according to those terms. // except according to those terms.
extern mod std; extern mod std;
use std::sys::size_of; use std::mem::size_of;
struct t {a: u8, b: i8} struct t {a: u8, b: i8}
struct u {a: u8, b: i8, c: u8} struct u {a: u8, b: i8, c: u8}