From: Alex Crichton Date: Sat, 24 May 2014 03:53:56 +0000 (-0700) Subject: core: Finish stabilizing the `mem` module. X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=2fd484172406a25e11f0f83000daeef7a287aebb;p=rust.git core: Finish stabilizing the `mem` module. * 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] --- diff --git a/src/libcollections/lru_cache.rs b/src/libcollections/lru_cache.rs index 8fdc0e095bf..b9e2eccbb9a 100644 --- a/src/libcollections/lru_cache.rs +++ b/src/libcollections/lru_cache.rs @@ -92,7 +92,7 @@ pub fn new(capacity: uint) -> LruCache { let cache = LruCache { map: HashMap::new(), max_size: capacity, - head: unsafe{ mem::transmute(box mem::uninit::>()) }, + head: unsafe{ mem::transmute(box mem::uninitialized::>()) }, }; unsafe { (*cache.head).next = cache.head; diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index b72eebe85c5..dcec07ef24e 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -26,7 +26,7 @@ pub fn size_of() -> 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(_val: &T) -> uint { size_of::() } @@ -64,7 +64,7 @@ pub fn min_align_of() -> 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(_val: &T) -> uint { min_align_of::() } @@ -90,7 +90,7 @@ pub fn align_of() -> 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(_val: &T) -> uint { align_of::() } @@ -117,7 +117,7 @@ pub fn pref_align_of_val(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 { intrinsics::init() } @@ -136,7 +136,14 @@ pub unsafe fn init() -> 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 { + intrinsics::uninit() +} + +/// Deprecated, use `uninitialized` instead. +#[inline] +#[deprecated = "this function has been renamed to `uninitialized`"] pub unsafe fn uninit() -> T { intrinsics::uninit() } @@ -148,7 +155,7 @@ pub unsafe fn uninit() -> 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(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(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); diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index 90b5b0d8753..78f819089f3 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -201,7 +201,7 @@ pub unsafe fn copy_memory(dst: *mut T, src: *T, count: uint) { /// fn swap(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(dst: *mut T, count: uint) { #[inline] pub unsafe fn swap(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(dest: *mut T, mut src: T) -> T { /// Reads the value from `*src` and returns it. #[inline(always)] pub unsafe fn read(src: *T) -> T { - let mut tmp: T = mem::uninit(); + let mut tmp: T = mem::uninitialized(); copy_nonoverlapping_memory(&mut tmp, src, 1); tmp } diff --git a/src/libnative/io/file_unix.rs b/src/libnative/io/file_unix.rs index 5e357ec9cca..b10284a3b6c 100644 --- a/src/libnative/io/file_unix.rs +++ b/src/libnative/io/file_unix.rs @@ -164,7 +164,7 @@ fn truncate(&mut self, offset: i64) -> Result<(), IoError> { } fn fstat(&mut self) -> IoResult { - 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 { - 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 { } pub fn lstat(p: &CString) -> IoResult { - 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()), diff --git a/src/libnative/io/file_win32.rs b/src/libnative/io/file_win32.rs index f320aca2bfc..c9a48db6920 100644 --- a/src/libnative/io/file_win32.rs +++ b/src/libnative/io/file_win32.rs @@ -195,7 +195,7 @@ fn truncate(&mut self, offset: i64) -> Result<(), IoError> { } fn fstat(&mut self) -> IoResult { - 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 { - 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)), diff --git a/src/libregex_macros/lib.rs b/src/libregex_macros/lib.rs index 0b28ccbbd14..1c48faad9f8 100644 --- a/src/libregex_macros/lib.rs +++ b/src/libregex_macros/lib.rs @@ -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, } } diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index 4622c0934fe..fbb812d3fb3 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -377,7 +377,7 @@ unsafe fn with_c_str_unchecked(&self, f: |*libc::c_char| -> T) -> T { // Unsafe function that handles possibly copying the &[u8] into a stack array. unsafe fn with_c_str(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; diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 493dd86b276..21903f6b6b8 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -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 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; diff --git a/src/libstd/rt/thread.rs b/src/libstd/rt/thread.rs index e25fa4734d5..6cc9604dc59 100644 --- a/src/libstd/rt/thread.rs +++ b/src/libstd/rt/thread.rs @@ -227,8 +227,8 @@ mod imp { pub type rust_thread_return = *u8; pub unsafe fn create(stack: uint, p: Box) -> 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); diff --git a/src/test/run-pass/issue-10714.rs b/src/test/run-pass/issue-10714.rs index 3c389f49aa1..90e87f96f78 100644 --- a/src/test/run-pass/issue-10714.rs +++ b/src/test/run-pass/issue-10714.rs @@ -10,5 +10,5 @@ enum v {} pub fn main() { - let y: v = unsafe { ::std::mem::uninit() }; + let y: v = unsafe { ::std::mem::uninitialized() }; } diff --git a/src/test/run-pass/uninit-empty-types.rs b/src/test/run-pass/uninit-empty-types.rs index 54791ddd419..005205353fc 100644 --- a/src/test/run-pass/uninit-empty-types.rs +++ b/src/test/run-pass/uninit-empty-types.rs @@ -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(); } }