]> git.lizzy.rs Git - rust.git/commitdiff
core: Finish stabilizing the `mem` module.
authorAlex Crichton <alex@alexcrichton.com>
Sat, 24 May 2014 03:53:56 +0000 (20:53 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sat, 24 May 2014 03:55:57 +0000 (20:55 -0700)
* All of the *_val functions have gone from #[unstable] to #[stable]
* The overwrite and zeroed functions have gone from #[unstable] to #[stable]
* The uninit function is now deprecated, replaced by its stable counterpart,
  uninitialized

[breaking-change]

src/libcollections/lru_cache.rs
src/libcore/mem.rs
src/libcore/ptr.rs
src/libnative/io/file_unix.rs
src/libnative/io/file_win32.rs
src/libregex_macros/lib.rs
src/libstd/c_str.rs
src/libstd/os.rs
src/libstd/rt/thread.rs
src/test/run-pass/issue-10714.rs
src/test/run-pass/uninit-empty-types.rs

index 8fdc0e095bf411096cb4caa6bc162fb4182d2e65..b9e2eccbb9a2963b73096c9425ca966363a84725 100644 (file)
@@ -92,7 +92,7 @@ pub fn new(capacity: uint) -> LruCache<K, V> {
         let cache = LruCache {
             map: HashMap::new(),
             max_size: capacity,
-            head: unsafe{ mem::transmute(box mem::uninit::<LruEntry<K, V>>()) },
+            head: unsafe{ mem::transmute(box mem::uninitialized::<LruEntry<K, V>>()) },
         };
         unsafe {
             (*cache.head).next = cache.head;
index b72eebe85c587441ea81bf07b21a9e405b3037f1..dcec07ef24e3279beb8b44d89fd7f00b36a10483 100644 (file)
@@ -26,7 +26,7 @@ pub fn size_of<T>() -> uint {
 
 /// Returns the size of the type that `_val` points to in bytes.
 #[inline]
-#[unstable = "the name of this function may change slightly before stabilizing"]
+#[stable]
 pub fn size_of_val<T>(_val: &T) -> uint {
     size_of::<T>()
 }
@@ -64,7 +64,7 @@ pub fn min_align_of<T>() -> uint {
 /// Returns the ABI-required minimum alignment of the type of the value that
 /// `_val` points to
 #[inline]
-#[unstable = "the name of this function may change slightly before stabilizing"]
+#[stable]
 pub fn min_align_of_val<T>(_val: &T) -> uint {
     min_align_of::<T>()
 }
@@ -90,7 +90,7 @@ pub fn align_of<T>() -> uint {
 /// as trait objects (in the future), returning the alignment for an arbitrary
 /// value at runtime.
 #[inline]
-#[unstable = "the name of this function may change slightly before stabilizing"]
+#[stable]
 pub fn align_of_val<T>(_val: &T) -> uint {
     align_of::<T>()
 }
@@ -117,7 +117,7 @@ pub fn pref_align_of_val<T>(val: &T) -> uint { align_of_val(val) }
 ///
 /// This is useful for FFI functions sometimes, but should generally be avoided.
 #[inline]
-#[unstable = "the name of this function is subject to change"]
+#[stable]
 pub unsafe fn zeroed<T>() -> T {
     intrinsics::init()
 }
@@ -136,7 +136,14 @@ pub unsafe fn init<T>() -> T { zeroed() }
 ///
 /// This is useful for FFI functions sometimes, but should generally be avoided.
 #[inline]
-#[unstable = "the name of this function is subject to change"]
+#[stable]
+pub unsafe fn uninitialized<T>() -> T {
+    intrinsics::uninit()
+}
+
+/// Deprecated, use `uninitialized` instead.
+#[inline]
+#[deprecated = "this function has been renamed to `uninitialized`"]
 pub unsafe fn uninit<T>() -> T {
     intrinsics::uninit()
 }
@@ -148,7 +155,7 @@ pub unsafe fn uninit<T>() -> T {
 /// contained at the location `dst`. This could leak allocations or resources,
 /// so care must be taken to previously deallocate the value at `dst`.
 #[inline]
-#[unstable = "the name of this function is subject to change"]
+#[stable]
 pub unsafe fn overwrite<T>(dst: *mut T, src: T) {
     intrinsics::move_val_init(&mut *dst, src)
 }
@@ -315,7 +322,7 @@ pub fn from_be64(x: u64) -> u64 { x }
 pub fn swap<T>(x: &mut T, y: &mut T) {
     unsafe {
         // Give ourselves some scratch space to work with
-        let mut t: T = uninit();
+        let mut t: T = uninitialized();
 
         // Perform the swap, `&mut` pointers never alias
         ptr::copy_nonoverlapping_memory(&mut t, &*x, 1);
index 90b5b0d8753e432af7d80df6f21da82231681f97..78f819089f32ca212dc69f396529c96d38c8f348 100644 (file)
@@ -201,7 +201,7 @@ pub unsafe fn copy_memory<T>(dst: *mut T, src: *T, count: uint) {
 /// fn swap<T>(x: &mut T, y: &mut T) {
 ///     unsafe {
 ///         // Give ourselves some scratch space to work with
-///         let mut t: T = mem::uninit();
+///         let mut t: T = mem::uninitialized();
 ///
 ///         // Perform the swap, `&mut` pointers never alias
 ///         ptr::copy_nonoverlapping_memory(&mut t, &*x, 1);
@@ -244,7 +244,7 @@ pub unsafe fn zero_memory<T>(dst: *mut T, count: uint) {
 #[inline]
 pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
     // Give ourselves some scratch space to work with
-    let mut tmp: T = mem::uninit();
+    let mut tmp: T = mem::uninitialized();
     let t: *mut T = &mut tmp;
 
     // Perform the swap
@@ -268,7 +268,7 @@ pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
 /// Reads the value from `*src` and returns it.
 #[inline(always)]
 pub unsafe fn read<T>(src: *T) -> T {
-    let mut tmp: T = mem::uninit();
+    let mut tmp: T = mem::uninitialized();
     copy_nonoverlapping_memory(&mut tmp, src, 1);
     tmp
 }
index 5e357ec9cca0fac9478e280e1b8b999888c382cf..b10284a3b6c3f0da7b269c186667bf6cb803ac02 100644 (file)
@@ -164,7 +164,7 @@ fn truncate(&mut self, offset: i64) -> Result<(), IoError> {
     }
 
     fn fstat(&mut self) -> IoResult<io::FileStat> {
-        let mut stat: libc::stat = unsafe { mem::uninit() };
+        let mut stat: libc::stat = unsafe { mem::zeroed() };
         match retry(|| unsafe { libc::fstat(self.fd(), &mut stat) }) {
             0 => Ok(mkstat(&stat)),
             _ => Err(super::last_error()),
@@ -509,7 +509,7 @@ fn gen(_stat: &libc::stat) -> u64 { 0 }
 }
 
 pub fn stat(p: &CString) -> IoResult<io::FileStat> {
-    let mut stat: libc::stat = unsafe { mem::uninit() };
+    let mut stat: libc::stat = unsafe { mem::zeroed() };
     match retry(|| unsafe { libc::stat(p.with_ref(|p| p), &mut stat) }) {
         0 => Ok(mkstat(&stat)),
         _ => Err(super::last_error()),
@@ -517,7 +517,7 @@ pub fn stat(p: &CString) -> IoResult<io::FileStat> {
 }
 
 pub fn lstat(p: &CString) -> IoResult<io::FileStat> {
-    let mut stat: libc::stat = unsafe { mem::uninit() };
+    let mut stat: libc::stat = unsafe { mem::zeroed() };
     match retry(|| unsafe { libc::lstat(p.with_ref(|p| p), &mut stat) }) {
         0 => Ok(mkstat(&stat)),
         _ => Err(super::last_error()),
index f320aca2bfcbf54d1f26a5c81f694cb513b592b8..c9a48db69207a23d01585850d9c7784eff4a6cd1 100644 (file)
@@ -195,7 +195,7 @@ fn truncate(&mut self, offset: i64) -> Result<(), IoError> {
     }
 
     fn fstat(&mut self) -> IoResult<io::FileStat> {
-        let mut stat: libc::stat = unsafe { mem::uninit() };
+        let mut stat: libc::stat = unsafe { mem::zeroed() };
         match unsafe { libc::fstat(self.fd(), &mut stat) } {
             0 => Ok(mkstat(&stat)),
             _ => Err(super::last_error()),
@@ -510,7 +510,7 @@ fn mkstat(stat: &libc::stat) -> io::FileStat {
 }
 
 pub fn stat(p: &CString) -> IoResult<io::FileStat> {
-    let mut stat: libc::stat = unsafe { mem::uninit() };
+    let mut stat: libc::stat = unsafe { mem::zeroed() };
     as_utf16_p(p.as_str().unwrap(), |up| {
         match unsafe { libc::wstat(up, &mut stat) } {
             0 => Ok(mkstat(&stat)),
index 0b28ccbbd14387e3cfec5ca1881f9084c8e2c19b..1c48faad9f8472ab956e299aaec37c8f225e1769 100644 (file)
@@ -254,8 +254,8 @@ fn new(which: MatchKind) -> Threads {
                 // The idea here is to avoid initializing threads that never
                 // need to be initialized, particularly for larger regexs with
                 // a lot of instructions.
-                queue: unsafe { ::std::mem::uninit() },
-                sparse: unsafe { ::std::mem::uninit() },
+                queue: unsafe { ::std::mem::uninitialized() },
+                sparse: unsafe { ::std::mem::uninitialized() },
                 size: 0,
             }
         }
index 4622c0934fe44b06a6abad43d50770ab1fd6e16e..fbb812d3fb3b0608b1532b969c8c33afbb0c935d 100644 (file)
@@ -377,7 +377,7 @@ unsafe fn with_c_str_unchecked<T>(&self, f: |*libc::c_char| -> T) -> T {
 // Unsafe function that handles possibly copying the &[u8] into a stack array.
 unsafe fn with_c_str<T>(v: &[u8], checked: bool, f: |*libc::c_char| -> T) -> T {
     if v.len() < BUF_LEN {
-        let mut buf: [u8, .. BUF_LEN] = mem::uninit();
+        let mut buf: [u8, .. BUF_LEN] = mem::uninitialized();
         slice::bytes::copy_memory(buf, v);
         buf[v.len()] = 0;
 
index 493dd86b2763a1a0605e158eee757ba1bd3a6e09..21903f6b6b88feef24bf36e81c70420f544cae2e 100644 (file)
@@ -969,7 +969,7 @@ pub fn page_size() -> uint {
 pub fn page_size() -> uint {
     use mem;
     unsafe {
-        let mut info = mem::uninit();
+        let mut info = mem::zeroed();
         libc::GetSystemInfo(&mut info);
 
         return info.dwPageSize as uint;
@@ -1288,7 +1288,7 @@ pub fn new(min_len: uint, options: &[MapOption]) -> Result<MemoryMap, MapError>
     pub fn granularity() -> uint {
         use mem;
         unsafe {
-            let mut info = mem::uninit();
+            let mut info = mem::zeroed();
             libc::GetSystemInfo(&mut info);
 
             return info.dwAllocationGranularity as uint;
index e25fa4734d5cb0e06161e8daae2a6e8607264503..6cc9604dc59a5deef5137ee3549916739431d63b 100644 (file)
@@ -227,8 +227,8 @@ mod imp {
     pub type rust_thread_return = *u8;
 
     pub unsafe fn create(stack: uint, p: Box<proc():Send>) -> rust_thread {
-        let mut native: libc::pthread_t = mem::uninit();
-        let mut attr: libc::pthread_attr_t = mem::uninit();
+        let mut native: libc::pthread_t = mem::zeroed();
+        let mut attr: libc::pthread_attr_t = mem::zeroed();
         assert_eq!(pthread_attr_init(&mut attr), 0);
         assert_eq!(pthread_attr_setdetachstate(&mut attr,
                                                PTHREAD_CREATE_JOINABLE), 0);
index 3c389f49aa14af6c5456d3ff1aad18262de92415..90e87f96f7899e54edec7a9dad75b6d9fa140c65 100644 (file)
@@ -10,5 +10,5 @@
 
 enum v {}
 pub fn main() {
-    let y: v = unsafe { ::std::mem::uninit() };
+    let y: v = unsafe { ::std::mem::uninitialized() };
 }
index 54791ddd4192e7a774fa456409f290f71d9f5151..005205353fce6a4d15a02de5a086f073f5b8f21d 100644 (file)
@@ -17,7 +17,7 @@
 
 pub fn main() {
     unsafe {
-        let _x: Foo = mem::uninit();
-        let _x: [Foo, ..2] = mem::uninit();
+        let _x: Foo = mem::uninitialized();
+        let _x: [Foo, ..2] = mem::uninitialized();
     }
 }