]> git.lizzy.rs Git - rust.git/commitdiff
std: Move size/align functions to std::mem. #2240
authorBrian Anderson <banderson@mozilla.com>
Thu, 17 Oct 2013 01:34:01 +0000 (18:34 -0700)
committerBrian Anderson <banderson@mozilla.com>
Fri, 18 Oct 2013 00:31:35 +0000 (17:31 -0700)
46 files changed:
doc/po/ja/rust.md.po
doc/po/ja/tutorial-ffi.md.po
doc/po/rust.md.pot
doc/po/tutorial-ffi.md.pot
doc/rust.md
doc/tutorial-ffi.md
src/libextra/arena.rs
src/libstd/at_vec.rs
src/libstd/cast.rs
src/libstd/cleanup.rs
src/libstd/mem.rs [new file with mode: 0644]
src/libstd/num/f32.rs
src/libstd/num/f64.rs
src/libstd/num/int_macros.rs
src/libstd/num/uint.rs
src/libstd/num/uint_macros.rs
src/libstd/rand/mod.rs
src/libstd/reflect.rs
src/libstd/rt/context.rs
src/libstd/rt/global_heap.rs
src/libstd/rt/io/native/process.rs
src/libstd/rt/sched.rs
src/libstd/rt/test.rs
src/libstd/std.rs
src/libstd/sys.rs
src/libstd/unstable/sync.rs
src/libstd/util.rs
src/libstd/vec.rs
src/test/run-fail/bounds-check-no-overflow.rs
src/test/run-fail/bug-2470-bounds-check-overflow.rs
src/test/run-pass/attr-no-drop-flag-size.rs
src/test/run-pass/enum-alignment.rs
src/test/run-pass/enum-discrim-width-stuff.rs
src/test/run-pass/fn-bare-size.rs
src/test/run-pass/issue-2895.rs
src/test/run-pass/nullable-pointer-size.rs
src/test/run-pass/packed-struct-generic-size.rs
src/test/run-pass/packed-struct-size-xc.rs
src/test/run-pass/packed-struct-size.rs
src/test/run-pass/packed-struct-vec.rs
src/test/run-pass/packed-tuple-struct-size.rs
src/test/run-pass/rec-align-u32.rs
src/test/run-pass/rec-align-u64.rs
src/test/run-pass/reflect-visit-data.rs
src/test/run-pass/regions-mock-trans.rs
src/test/run-pass/type-sizes.rs

index b21ddfe3e65d12333acf41a2bb6f4248fe9534e5..0313a3379b787b5cc8328aebad3d9dc5688b77c9 100644 (file)
@@ -1842,7 +1842,7 @@ msgid ""
 "The type parameters can also be explicitly supplied in a trailing [path]"
 "(#paths) component after the function name. This might be necessary if there "
 "is not sufficient context to determine the type parameters. For example, "
-"`sys::size_of::<u32>() == 4`."
+"`mem::size_of::<u32>() == 4`."
 msgstr ""
 
 #. type: Plain text
index a9bd3842558997953d039fcfac051c6d045eb151..ff28357cabf13456d3be08917b623ffe29dda0c0 100644 (file)
@@ -327,7 +327,7 @@ msgid ""
 "impl<T: Send> Unique<T> {\n"
 "    pub fn new(value: T) -> Unique<T> {\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"
 "            // `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it\n"
 "            intrinsics::move_val_init(&mut *ptr, value);\n"
index 942fd953ec0c804f48bc4f1cf4b1e4cccdae9666..31056378a48dca4426c26f49c807fd411887f77d 100644 (file)
@@ -1842,7 +1842,7 @@ msgid ""
 "The type parameters can also be explicitly supplied in a trailing [path]"
 "(#paths) component after the function name. This might be necessary if there "
 "is not sufficient context to determine the type parameters. For example, "
-"`sys::size_of::<u32>() == 4`."
+"`mem::size_of::<u32>() == 4`."
 msgstr ""
 
 #. type: Plain text
index 62bbd921cb8ad58cab604e0ccf0fb4342f6f5c18..c3116dea872749571c3e7ca66be705ee4bc6aa46 100644 (file)
@@ -327,7 +327,7 @@ msgid ""
 "impl<T: Send> Unique<T> {\n"
 "    pub fn new(value: T) -> Unique<T> {\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"
 "            // `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it\n"
 "            intrinsics::move_val_init(&mut *ptr, value);\n"
index f40a3e3a114c534f6d9351d2e99ea3b2ed958aef..621bf927e39fe33ad7bd184dc088c224969247d5 100644 (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
 [path](#paths) component after the function name. This might be necessary
 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
 operations that can be performed on it is limited. Values of parameter
index 38aea02f04082ab435eea446abd675a94775c58b..57dc926dfa9c6e6bf95c8044f09a08484c8382de 100644 (file)
@@ -300,7 +300,7 @@ impl<T: Send> Unique<T> {
         #[inline(never)];
 
         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));
             // `*ptr` is uninitialized, and `*ptr = value` would attempt to destroy it
             intrinsics::move_val_init(&mut *ptr, value);
index 520faad1afa0797775a7128c92fb0b07b2fdbb93..6c4e86d958e25ad494233a5a4d32c94a3e13283a 100644 (file)
@@ -42,7 +42,7 @@
 use std::cast;
 use std::num;
 use std::ptr;
-use std::sys;
+use std::mem;
 use std::uint;
 use std::vec;
 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 (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);
 
@@ -134,7 +134,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
         }
 
         // 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 @@ fn alloc_nonpod_inner(&mut self, n_bytes: uint, align: uint)
                 let head = transmute_mut_region(&mut self.head);
 
                 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);
                 end = start + n_bytes;
             }
@@ -230,7 +230,7 @@ fn alloc_nonpod_inner(&mut self, n_bytes: uint, align: uint)
             }
 
             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 = {}",
             //       start, n_bytes, align, head.fill);
index f6669893170ae211f66217b632a460679f4bdcc8..8607710edc396f5ccadba3c0b733027f79397dcc 100644 (file)
@@ -14,7 +14,7 @@
 use container::Container;
 use iter::Iterator;
 use option::{Option, Some, None};
-use sys;
+use mem;
 use unstable::raw::Repr;
 use vec::{ImmutableVector, OwnedVector};
 
@@ -26,7 +26,7 @@
 pub fn capacity<T>(v: @[T]) -> uint {
     unsafe {
         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 libc;
     use ptr;
-    use sys;
+    use mem;
     use uint;
     use unstable::intrinsics::{move_val_init, TyDesc};
     use unstable::intrinsics;
@@ -176,7 +176,7 @@ pub mod raw {
     #[inline]
     pub unsafe fn set_len<T>(v: &mut @[T], new_len: uint) {
         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 unsafe fn push<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 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;
         move_val_init(&mut(*p), initval);
     }
@@ -236,7 +236,7 @@ pub fn reserve_raw(ty: *TyDesc, ptr: *mut *mut Box<Vec<()>>, n: uint) {
         unsafe {
             if n > (**ptr).data.alloc / (*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 {
                     fail2!("vector size is too large: {}", n);
                 }
index e028bbeac68a122d26ca2c226166fb946283293b..a4f2ee0d09c78501cf7bd9bb2fc4835a77816ec1 100644 (file)
@@ -11,7 +11,7 @@
 //! Unsafe casting functions
 
 use ptr::RawPtr;
-use sys;
+use mem;
 use unstable::intrinsics;
 
 /// 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 dest_ptr: *mut u8 = transmute(&mut dest);
     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
 }
 
@@ -32,7 +32,7 @@ pub unsafe fn transmute_copy<T, U>(src: &T) -> U {
     let mut dest: U = intrinsics::uninit();
     let dest_ptr: *mut u8 = transmute(&mut dest);
     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
 }
 
index 38925621f1200c573bce52a6630689335eb80c0f..a8c4d9fdca3c20f1ff5091cb9eb9dae786045246 100644 (file)
@@ -68,7 +68,7 @@ fn debug_mem() -> bool {
 /// Destroys all managed memory (i.e. @ boxes) held by the current task.
 pub unsafe fn annihilate() {
     use rt::local_heap::local_free;
-    use sys;
+    use mem;
     use managed;
 
     let mut stats = AnnihilateStats {
@@ -115,7 +115,7 @@ pub unsafe fn annihilate() {
         if !uniq {
             stats.n_bytes_freed +=
                 (*((*box).type_desc)).size
-                + sys::size_of::<raw::Box<()>>();
+                + mem::size_of::<raw::Box<()>>();
             local_free(box as *i8);
         }
         true
diff --git a/src/libstd/mem.rs b/src/libstd/mem.rs
new file mode 100644 (file)
index 0000000..311bf5f
--- /dev/null
@@ -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);
+    }
+}
index 2b4a636e1ad94927c64397d39d68d7660cf5ae70..e99dcd6b2eb33b9e68231ea02d78f51bd055ebff 100644 (file)
@@ -928,7 +928,7 @@ mod tests {
 
     use num::*;
     use num;
-    use sys;
+    use mem;
 
     #[test]
     fn test_num() {
@@ -1198,8 +1198,8 @@ fn test_approx_eq() {
     #[test]
     fn test_primitive() {
         let none: Option<f32> = None;
-        assert_eq!(Primitive::bits(none), sys::size_of::<f32>() * 8);
-        assert_eq!(Primitive::bytes(none), sys::size_of::<f32>());
+        assert_eq!(Primitive::bits(none), mem::size_of::<f32>() * 8);
+        assert_eq!(Primitive::bytes(none), mem::size_of::<f32>());
     }
 
     #[test]
index d4442e5b34fabcdf671eadefc984941891495d00..f367de376d418fbf8d38a5cd1384ce88bf0c516d 100644 (file)
@@ -976,7 +976,7 @@ mod tests {
 
     use num::*;
     use num;
-    use sys;
+    use mem;
 
     #[test]
     fn test_num() {
@@ -1249,8 +1249,8 @@ fn test_approx_eq() {
     #[test]
     fn test_primitive() {
         let none: Option<f64> = None;
-        assert_eq!(Primitive::bits(none), sys::size_of::<f64>() * 8);
-        assert_eq!(Primitive::bytes(none), sys::size_of::<f64>());
+        assert_eq!(Primitive::bits(none), mem::size_of::<f64>() * 8);
+        assert_eq!(Primitive::bytes(none), mem::size_of::<f64>());
     }
 
     #[test]
index 7fae567809b012c2f315d0de8b67e6e7dc5c906d..694e5e7f6bfee28153aa4631d292396a6dc8706a 100644 (file)
@@ -456,7 +456,7 @@ mod tests {
     use int;
     use i32;
     use num;
-    use sys;
+    use mem;
 
     #[test]
     fn test_num() {
@@ -653,8 +653,8 @@ fn test_bitcount() {
     #[test]
     fn test_primitive() {
         let none: Option<$T> = None;
-        assert_eq!(Primitive::bits(none), sys::size_of::<$T>() * 8);
-        assert_eq!(Primitive::bytes(none), sys::size_of::<$T>());
+        assert_eq!(Primitive::bits(none), mem::size_of::<$T>() * 8);
+        assert_eq!(Primitive::bytes(none), mem::size_of::<$T>());
     }
 
     #[test]
index 38a4df270fc23cabfa2b56e1fa18d9b26917ea97..2ecbb79407e1bef98f451cea4eafb0c72fdc6b67 100644 (file)
@@ -14,7 +14,7 @@
 use num::{CheckedAdd, CheckedSub, CheckedMul};
 use option::{Option, Some, None};
 use unstable::intrinsics;
-use sys;
+use mem;
 
 pub use self::generated::*;
 
@@ -97,7 +97,7 @@ fn times(&self, it: &fn()) {
 /// Returns the smallest power of 2 greater than or equal to `n`
 #[inline]
 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 shift: uint = 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`
 #[inline]
 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 shift: uint = 1u;
     while shift <= halfbits { tmp |= tmp >> shift; shift <<= 1u; }
index f52feced67c77a91d7fee4d3388830016b6db05b..2974b402d4a7675af4424aafc7158bc7b254311a 100644 (file)
@@ -337,7 +337,7 @@ mod tests {
     use super::*;
 
     use num;
-    use sys;
+    use mem;
     use u16;
 
     #[test]
@@ -431,8 +431,8 @@ fn test_bitcount() {
     #[test]
     fn test_primitive() {
         let none: Option<$T> = None;
-        assert_eq!(Primitive::bits(none), sys::size_of::<$T>() * 8);
-        assert_eq!(Primitive::bytes(none), sys::size_of::<$T>());
+        assert_eq!(Primitive::bits(none), mem::size_of::<$T>() * 8);
+        assert_eq!(Primitive::bytes(none), mem::size_of::<$T>());
     }
 
     #[test]
index 1e76effd0d248987ce4669e077fd98cfd59d3c29..954db42c89be1f7329d48323818f8cb13bc9371e 100644 (file)
@@ -52,7 +52,7 @@ fn main () {
  ```
 */
 
-use sys::size_of;
+use mem::size_of;
 use unstable::raw::Slice;
 use cast;
 use container::Container;
@@ -952,7 +952,7 @@ fn test_std_rng_reseed() {
 mod bench {
     use extra::test::BenchHarness;
     use rand::*;
-    use sys::size_of;
+    use mem::size_of;
 
     #[bench]
     fn rand_xorshift(bh: &mut BenchHarness) {
index 292330de7b5138e78c376f6bf1b55bac50f78ba7..1cd7672771678a7cae63cde8122a21ee301f6730 100644 (file)
@@ -18,7 +18,7 @@
 
 use unstable::intrinsics::{Opaque, TyDesc, TyVisitor};
 use libc::c_void;
-use sys;
+use mem;
 use unstable::raw;
 
 /**
@@ -64,12 +64,12 @@ pub fn align(&mut self, a: uint) {
 
     #[inline]
     pub fn align_to<T>(&mut self) {
-        self.align(sys::min_align_of::<T>());
+        self.align(mem::min_align_of::<T>());
     }
 
     #[inline]
     pub fn bump_past<T>(&mut self) {
-        self.bump(sys::size_of::<T>());
+        self.bump(mem::size_of::<T>());
     }
 }
 
index 853cc08a0ba773d3d511709f1b894b79b4be3c1f..222f9a44b1745070dd13e49bf2c8530e230f0d1c 100644 (file)
@@ -233,6 +233,6 @@ fn align_down(sp: *mut uint) -> *mut uint {
 // ptr::mut_offset is positive ints only
 #[inline]
 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
 }
index 7d3f5f917748732982753722828c78349eaee010..446efbd9047102268271fb97cfe5305fbea7168d 100644 (file)
@@ -11,7 +11,7 @@
 use libc::{c_void, c_char, size_t, uintptr_t, free, malloc, realloc};
 use unstable::intrinsics::TyDesc;
 use unstable::raw;
-use sys::size_of;
+use mem::size_of;
 
 extern {
     #[rust_stack]
index d338192c664bca23cf57abfca8d7a8c0fb8da5ad..57367beacd833c19dfd09ff8aa109f30928fb2e5 100644 (file)
@@ -271,12 +271,12 @@ fn spawn_process_os(prog: &str, args: &[~str],
     };
     use libc::funcs::extra::msvcrt::get_osfhandle;
 
-    use sys;
+    use mem;
 
     unsafe {
 
         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;
 
         let cur_proc = GetCurrentProcess();
index 0a4622bc65eefefa65621ab3d28a5cb2ad385e6a..7724f58153ed67f89ee19bb4d4e4e9b45e4210f4 100644 (file)
@@ -857,7 +857,7 @@ fn new_sched_rng() -> XorShiftRng {
 #[fixed_stack_segment] #[inline(never)]
 fn new_sched_rng() -> XorShiftRng {
     use libc;
-    use sys;
+    use mem;
     use c_str::ToCStr;
     use vec::MutableVector;
     use iter::Iterator;
@@ -871,7 +871,7 @@ fn new_sched_rng() -> XorShiftRng {
     }
 
     let mut seeds = [0u32, .. 4];
-    let size = sys::size_of_val(&seeds);
+    let size = mem::size_of_val(&seeds);
     loop {
         let nbytes = do seeds.as_mut_buf |buf, _| {
             unsafe {
index 1178bfdaa80fc75e2824dff2bc8d92d1b604199c..9f4e6558ac598a19178bb6c22138198f3184a559 100644 (file)
@@ -103,7 +103,7 @@ pub unsafe fn raise_fd_limit() {
         // 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.
         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;
 
         // Fetch the kern.maxfilesperproc value
index 73cb6a5645de3317e7f817ef398b194b853f4e29..c446fe3d94f97658c1212135a58e5b51bdeac742 100644 (file)
@@ -189,6 +189,7 @@ pub mod linkhack {
 pub mod logging;
 pub mod util;
 pub mod routine;
+pub mod mem;
 
 /* Unsupported interfaces */
 
index 10c3fed1d54db73d5e3ae417e544e41be4d3f43d..0299ca0b49a775348f440d93cfa746f5c3367f27 100644 (file)
 use repr;
 use rt::task;
 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)
 #[inline]
@@ -131,84 +69,6 @@ mod tests {
     use cast;
     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]
     fn synthesize_closure() {
         use unstable::raw::Closure;
index f3945d8f3c9d4a0746652bf95c8a3f5e1fc7af74..0b28497e640f3844ba12370c5a9fe8d80cc92cdb 100644 (file)
@@ -425,7 +425,7 @@ mod tests {
     use super::{Exclusive, UnsafeArc, atomically};
     use task;
     use util;
-    use sys::size_of;
+    use mem::size_of;
 
     //#[unsafe_no_drop_flag] FIXME: #9758
     #[ignore]
index 44cfdb860576b27ea7b7673d1fa3e0aa774b3ad2..3e44a30e47b33adcbf9d16c2cf1d51a00f0ec6fe 100644 (file)
@@ -93,7 +93,7 @@ mod tests {
     use ops::Drop;
     use option::{None, Some};
     use either::{Either, Left, Right};
-    use sys::size_of;
+    use mem::size_of;
 
     #[test]
     fn identity_crisis() {
index 60c569e75d0caefba8cf2e066586ea9782498467..d298507aa8cb6e27a467c7d1e1afaa30fef84c7c 100644 (file)
 use ptr::RawPtr;
 use rt::global_heap::malloc_raw;
 use rt::global_heap::realloc_raw;
-use sys;
-use sys::size_of;
+use mem;
+use mem::size_of;
 use uint;
 use unstable::finally::Finally;
 use unstable::intrinsics;
@@ -185,8 +185,8 @@ pub fn with_capacity<T>(capacity: uint) -> ~[T] {
             vec.reserve(capacity);
             vec
         } else {
-            let alloc = capacity * sys::nonzero_size_of::<T>();
-            let ptr = malloc_raw(alloc + sys::size_of::<Vec<()>>()) as *mut Vec<()>;
+            let alloc = capacity * mem::nonzero_size_of::<T>();
+            let ptr = malloc_raw(alloc + mem::size_of::<Vec<()>>()) as *mut Vec<()>;
             (*ptr).alloc = alloc;
             (*ptr).fill = 0;
             cast::transmute(ptr)
@@ -1002,7 +1002,7 @@ fn slice_to(&self, end: uint) -> &'self [T] {
     fn iter(self) -> VecIterator<'self, T> {
         unsafe {
             let p = vec::raw::to_ptr(self);
-            if sys::size_of::<T>() == 0 {
+            if mem::size_of::<T>() == 0 {
                 VecIterator{ptr: p,
                             end: (p as uint + self.len()) as *T,
                             lifetime: None}
@@ -1406,9 +1406,9 @@ fn reserve(&mut self, n: uint) {
                     ::at_vec::raw::reserve_raw(td, ptr, n);
                 } else {
                     let ptr: *mut *mut Vec<()> = cast::transmute(self);
-                    let alloc = n * sys::nonzero_size_of::<T>();
-                    let size = alloc + sys::size_of::<Vec<()>>();
-                    if alloc / sys::nonzero_size_of::<T>() != n || size < alloc {
+                    let alloc = n * mem::nonzero_size_of::<T>();
+                    let size = alloc + mem::size_of::<Vec<()>>();
+                    if alloc / mem::nonzero_size_of::<T>() != n || size < alloc {
                         fail2!("vector size is too large: {}", n);
                     }
                     *ptr = realloc_raw(*ptr as *mut c_void, size)
@@ -1439,10 +1439,10 @@ fn capacity(&self) -> uint {
         unsafe {
             if contains_managed::<T>() {
                 let repr: **Box<Vec<()>> = cast::transmute(self);
-                (**repr).data.alloc / sys::nonzero_size_of::<T>()
+                (**repr).data.alloc / mem::nonzero_size_of::<T>()
             } else {
                 let repr: **Vec<()> = cast::transmute(self);
-                (**repr).alloc / sys::nonzero_size_of::<T>()
+                (**repr).alloc / mem::nonzero_size_of::<T>()
             }
         }
     }
@@ -1451,7 +1451,7 @@ fn shrink_to_fit(&mut self) {
         unsafe {
             let ptr: *mut *mut Vec<()> = cast::transmute(self);
             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).alloc = alloc;
         }
@@ -1485,14 +1485,14 @@ unsafe fn push_fast<T>(this: &mut ~[T], t: T) {
             if contains_managed::<T>() {
                 let repr: **mut Box<Vec<u8>> = cast::transmute(this);
                 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 = ptr::offset(p, fill as int) as *mut T;
                 intrinsics::move_val_init(&mut(*p), t);
             } else {
                 let repr: **mut Vec<u8> = cast::transmute(this);
                 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 = ptr::offset(p, fill as int) as *mut T;
                 intrinsics::move_val_init(&mut(*p), t);
@@ -1957,7 +1957,7 @@ fn mut_split(self, mid: uint) -> (&'self mut [T], &'self mut [T]) {
     fn mut_iter(self) -> VecMutIterator<'self, T> {
         unsafe {
             let p = vec::raw::to_mut_ptr(self);
-            if sys::size_of::<T>() == 0 {
+            if mem::size_of::<T>() == 0 {
                 VecMutIterator{ptr: p,
                                end: (p as uint + self.len()) as *mut T,
                                lifetime: None}
@@ -2054,7 +2054,7 @@ pub mod raw {
     use clone::Clone;
     use option::Some;
     use ptr;
-    use sys;
+    use mem;
     use unstable::intrinsics;
     use vec::{with_capacity, ImmutableVector, MutableVector};
     use unstable::intrinsics::contains_managed;
@@ -2071,10 +2071,10 @@ pub mod raw {
     pub unsafe fn set_len<T>(v: &mut ~[T], new_len: uint) {
         if contains_managed::<T>() {
             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 {
             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 @@ fn next(&mut self) -> Option<$elem> {
                         None
                     } else {
                         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
                             // vectors with 0-size elements this would return the
                             // same pointer.
@@ -2340,7 +2340,7 @@ fn next(&mut self) -> Option<$elem> {
             #[inline]
             fn size_hint(&self) -> (uint, Option<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))
             }
         }
@@ -2357,7 +2357,7 @@ fn next_back(&mut self) -> Option<$elem> {
                     if self.end == self.ptr {
                         None
                     } 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
                             cast::transmute(self.end as uint - 1)
                         } else {
@@ -2497,7 +2497,7 @@ fn extend<T: Iterator<A>>(&mut self, iterator: &mut T) {
 #[cfg(test)]
 mod tests {
     use option::{None, Option, Some};
-    use sys;
+    use mem;
     use vec::*;
     use cmp::*;
     use prelude::*;
@@ -2597,7 +2597,7 @@ fn test_len_divzero() {
         let v0 : &[Z] = &[];
         let v1 : &[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!(v1.len(), 1);
         assert_eq!(v2.len(), 2);
index 679f060a55d7c25cc54c7b9a62cb5a9d76f8d142..faced3531f582eb33550c38932546a4dded15868 100644 (file)
@@ -11,7 +11,7 @@
 // error-pattern:index out of bounds: the len is 3 but the index is
 
 use std::uint::max_value;
-use std::sys::size_of;
+use std::mem::size_of;
 
 fn main() {
     let xs = [1, 2, 3];
index 083ea5b8f190c028bbbb21ad70d16aaab912545a..17b4c83788ca8362181a379d5089a2bbb78c22bb 100644 (file)
@@ -10,7 +10,7 @@
 
 // error-pattern:index out of bounds
 
-use std::sys;
+use std::mem;
 
 fn main() {
 
@@ -23,12 +23,12 @@ fn main() {
     let x = ~[1u,2u,3u];
     do x.as_imm_buf |p, _len| {
         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 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}",
-               idx * sys::size_of::<uint>());
+               idx * mem::size_of::<uint>());
 
         // This should fail.
         error2!("ov1 0x{:x}",  x[idx]);
index bbc6501bc774cbdfe49ea933f2c4158909f0f300..48768a1c6fd27600f7c7707842d93a2bd3240162 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::sys::size_of;
+use std::mem::size_of;
 
 #[unsafe_no_drop_flag]
 struct Test<T> {
index a36aaaf936de9d2a5ee9a344b5d9a9fc74f971ba..4c60cfb73281651f57c3d1007d45fb16ddada1ea 100644 (file)
@@ -10,7 +10,7 @@
 
 use std::cast;
 use std::ptr;
-use std::sys;
+use std::mem;
 
 fn addr_of<T>(ptr: &T) -> uint {
     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 {
     unsafe {
         let addr: uint = cast::transmute(ptr);
-        (addr % sys::min_align_of::<T>()) == 0
+        (addr % mem::min_align_of::<T>()) == 0
     }
 }
 
index 71f0b0f9475a576e2d4d365d4d1a4adf3717cfb3..65f93b1c3c2e0f4a92a7d4e0612e7386b913cc3a 100644 (file)
@@ -8,12 +8,12 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::sys;
+use std::mem;
 
 pub fn main() {
     enum E { V = 0x1717171717171717 }
     static C: E = V;
-    let expected: u64 = if sys::size_of::<uint>() < 8 {
+    let expected: u64 = if mem::size_of::<uint>() < 8 {
         0x17171717
     } else {
         0x1717171717171717
index 144cc7c1e287a661592896068ec793d0cea5f19c..cdde98331e2d05859b27d3cf9511b89176ce3041 100644 (file)
@@ -8,9 +8,9 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::sys;
+use std::mem;
 
 pub fn main() {
     // 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>());
 }
index f325756d3687651261bfa18245797e54041636a0..1e1db3937801409a355fff44dd756f6f18415aa9 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::sys;
+use std::mem;
 
 struct Cat {
     x: int
@@ -24,13 +24,13 @@ fn drop(&mut self) {}
 
 #[cfg(target_arch = "x86_64")]
 pub fn main() {
-    assert_eq!(sys::size_of::<Cat>(), 8 as uint);
-    assert_eq!(sys::size_of::<Kitty>(), 16 as uint);
+    assert_eq!(mem::size_of::<Cat>(), 8 as uint);
+    assert_eq!(mem::size_of::<Kitty>(), 16 as uint);
 }
 
 #[cfg(target_arch = "x86")]
 #[cfg(target_arch = "arm")]
 pub fn main() {
-    assert_eq!(sys::size_of::<Cat>(), 4 as uint);
-    assert_eq!(sys::size_of::<Kitty>(), 8 as uint);
+    assert_eq!(mem::size_of::<Cat>(), 4 as uint);
+    assert_eq!(mem::size_of::<Kitty>(), 8 as uint);
 }
index 15cd508b655ffa008d6abfddd5bed7f7dd5b4463..228b91a4532cd939353cce92fd39632f43eebf84 100644 (file)
@@ -10,7 +10,7 @@
 
 #[feature(macro_rules)];
 
-use std::sys;
+use std::mem;
 
 enum E<T> { Thing(int, T), Nothing((), ((), ()), [i8, ..0]) }
 struct S<T>(int, T);
@@ -19,13 +19,13 @@ enum E<T> { Thing(int, T), Nothing((), ((), ()), [i8, ..0]) }
 
 macro_rules! check_option {
     ($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 {
     ($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>>());
     }
 }
 
index 798acc646be738de4666ed188bddf982a9b3c1fd..1d3d8cf736f4d27c66c1a77b00896d2d27d8ad18 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::sys;
+use std::mem;
 
 #[packed]
 struct S<T, S> {
@@ -18,10 +18,10 @@ struct S<T, S> {
 }
 
 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]>>(),
-               1 + sys::size_of::<~str>() + sys::size_of::<@mut [int]>());
+    assert_eq!(mem::size_of::<S<~str, @mut [int]>>(),
+               1 + mem::size_of::<~str>() + mem::size_of::<@mut [int]>());
 }
index 19f6046c7d69384459d28ec9058b481348a53c35..5b4426d314b5553481625a2d820b8ac1ae1f39a3 100644 (file)
@@ -3,8 +3,8 @@
 
 extern mod packed;
 
-use std::sys;
+use std::mem;
 
 fn main() {
-    assert_eq!(sys::size_of::<packed::S>(), 5);
+    assert_eq!(mem::size_of::<packed::S>(), 5);
 }
index b94b4db5f601de88848862b9c6f0d2814abc3c6c..cc4cb99e2f6610cb2d64c5b3a39bb3961d4d2dea 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::sys;
+use std::mem;
 
 #[packed]
 struct S4 {
@@ -57,9 +57,9 @@ struct S7_Option {
 
 
 pub fn main() {
-    assert_eq!(sys::size_of::<S4>(), 4);
-    assert_eq!(sys::size_of::<S5>(), 5);
-    assert_eq!(sys::size_of::<S13_str>(), 13 + sys::size_of::<~str>());
-    assert_eq!(sys::size_of::<S3_Foo>(), 3 + sys::size_of::<Foo>());
-    assert_eq!(sys::size_of::<S7_Option>(), 7 + sys::size_of::<Option<@mut f64>>());
+    assert_eq!(mem::size_of::<S4>(), 4);
+    assert_eq!(mem::size_of::<S5>(), 5);
+    assert_eq!(mem::size_of::<S13_str>(), 13 + mem::size_of::<~str>());
+    assert_eq!(mem::size_of::<S3_Foo>(), 3 + mem::size_of::<Foo>());
+    assert_eq!(mem::size_of::<S7_Option>(), 7 + mem::size_of::<Option<@mut f64>>());
 }
index 6cf519a387f1ee0d51c21b50b9e79ade11f22103..6007cc251c9d51afa52a36471bd15187346d6c66 100644 (file)
@@ -10,7 +10,7 @@
 
 // xfail-android: FIXME(#9116) Bus error
 
-use std::sys;
+use std::mem;
 
 #[packed]
 #[deriving(Eq)]
@@ -22,7 +22,7 @@ struct Foo {
 pub fn main() {
     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) {
         assert_eq!(foos[i], Foo { bar: 1, baz: 2});
index dd38a6b7d122a498624cd857d12c991b51d7bc9e..76362ffeaaf17cc0f6da18c3b7a4d39987b3f991 100644 (file)
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use std::sys;
+use std::mem;
 
 #[packed]
 struct S4(u8,[u8, .. 3]);
@@ -31,16 +31,16 @@ enum Foo {
 struct S7_Option(f32, u8, u16, Option<@mut f64>);
 
 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>>());
 }
index 804e6902002123cdcf967e8da119d336101aa6f8..43304b66176dcd8a194a7993b2e51b5f7ef6d26c 100644 (file)
@@ -12,7 +12,7 @@
 
 // Issue #2303
 
-use std::sys;
+use std::mem;
 
 mod rusti {
     extern "rust-intrinsic" {
@@ -55,7 +55,7 @@ pub fn main() {
         let y = format!("{:?}", x);
 
         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);
 
         // 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
         // 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}}");
     }
index 6ec2b63cfff8ecf7a13dd32e6d5088d87dde6314..5adb8cf951050b096fed1a39e0d1a11c6666a7ae 100644 (file)
@@ -12,7 +12,7 @@
 
 // Issue #2303
 
-use std::sys;
+use std::mem;
 
 mod rusti {
     extern "rust-intrinsic" {
@@ -77,7 +77,7 @@ pub fn main() {
         let y = format!("{:?}", x);
 
         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);
 
         // 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
         // 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}}");
     }
index 85cc8b224f6891d8f16fb4ec0ecc211f05540300..5a2243b19408836f7647a4ad0602d16a9b34a41f 100644 (file)
@@ -12,7 +12,7 @@
 
 use std::libc::c_void;
 use std::ptr;
-use std::sys;
+use std::mem;
 use std::unstable::intrinsics::{TyDesc, get_tydesc, visit_tydesc, TyVisitor, Opaque};
 use std::unstable::raw::Vec;
 
@@ -49,12 +49,12 @@ pub fn align(&mut self, a: uint) {
 
     #[inline(always)]
     pub fn align_to<T>(&mut self) {
-        self.align(sys::min_align_of::<T>());
+        self.align(mem::min_align_of::<T>());
     }
 
     #[inline(always)]
     pub fn bump_past<T>(&mut self) {
-        self.bump(sys::size_of::<T>());
+        self.bump(mem::size_of::<T>());
     }
 
 }
index 201584d48a58571231daf8ee855752e2a033359e..e66a34b47bce044aa8faaba445120a485107ff5d 100644 (file)
@@ -10,7 +10,7 @@
 
 use std::cast;
 use std::libc;
-use std::sys;
+use std::mem;
 
 struct arena(());
 
@@ -30,7 +30,7 @@ struct Ccx {
 #[fixed_stack_segment] #[inline(never)]
 fn alloc<'a>(_bcx : &'a arena) -> &'a Bcx<'a> {
     unsafe {
-        cast::transmute(libc::malloc(sys::size_of::<Bcx<'blk>>()
+        cast::transmute(libc::malloc(mem::size_of::<Bcx<'blk>>()
             as libc::size_t))
     }
 }
index 5695254cdbffbb5e15ed76c48c316b486c814224..2cdff23050db31ed859acc8e08ccc361df8c2c65 100644 (file)
@@ -9,7 +9,7 @@
 // except according to those terms.
 
 extern mod std;
-use std::sys::size_of;
+use std::mem::size_of;
 
 struct t {a: u8, b: i8}
 struct u {a: u8, b: i8, c: u8}