Skip to content

Commit 2fd4841

Browse files
committed
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]
1 parent ad775be commit 2fd4841

File tree

11 files changed

+33
-26
lines changed

11 files changed

+33
-26
lines changed

src/libcollections/lru_cache.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<K: Hash + TotalEq, V> LruCache<K, V> {
9292
let cache = LruCache {
9393
map: HashMap::new(),
9494
max_size: capacity,
95-
head: unsafe{ mem::transmute(box mem::uninit::<LruEntry<K, V>>()) },
95+
head: unsafe{ mem::transmute(box mem::uninitialized::<LruEntry<K, V>>()) },
9696
};
9797
unsafe {
9898
(*cache.head).next = cache.head;

src/libcore/mem.rs

+14-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn size_of<T>() -> uint {
2626

2727
/// Returns the size of the type that `_val` points to in bytes.
2828
#[inline]
29-
#[unstable = "the name of this function may change slightly before stabilizing"]
29+
#[stable]
3030
pub fn size_of_val<T>(_val: &T) -> uint {
3131
size_of::<T>()
3232
}
@@ -64,7 +64,7 @@ pub fn min_align_of<T>() -> uint {
6464
/// Returns the ABI-required minimum alignment of the type of the value that
6565
/// `_val` points to
6666
#[inline]
67-
#[unstable = "the name of this function may change slightly before stabilizing"]
67+
#[stable]
6868
pub fn min_align_of_val<T>(_val: &T) -> uint {
6969
min_align_of::<T>()
7070
}
@@ -90,7 +90,7 @@ pub fn align_of<T>() -> uint {
9090
/// as trait objects (in the future), returning the alignment for an arbitrary
9191
/// value at runtime.
9292
#[inline]
93-
#[unstable = "the name of this function may change slightly before stabilizing"]
93+
#[stable]
9494
pub fn align_of_val<T>(_val: &T) -> uint {
9595
align_of::<T>()
9696
}
@@ -117,7 +117,7 @@ pub fn pref_align_of_val<T>(val: &T) -> uint { align_of_val(val) }
117117
///
118118
/// This is useful for FFI functions sometimes, but should generally be avoided.
119119
#[inline]
120-
#[unstable = "the name of this function is subject to change"]
120+
#[stable]
121121
pub unsafe fn zeroed<T>() -> T {
122122
intrinsics::init()
123123
}
@@ -136,7 +136,14 @@ pub unsafe fn init<T>() -> T { zeroed() }
136136
///
137137
/// This is useful for FFI functions sometimes, but should generally be avoided.
138138
#[inline]
139-
#[unstable = "the name of this function is subject to change"]
139+
#[stable]
140+
pub unsafe fn uninitialized<T>() -> T {
141+
intrinsics::uninit()
142+
}
143+
144+
/// Deprecated, use `uninitialized` instead.
145+
#[inline]
146+
#[deprecated = "this function has been renamed to `uninitialized`"]
140147
pub unsafe fn uninit<T>() -> T {
141148
intrinsics::uninit()
142149
}
@@ -148,7 +155,7 @@ pub unsafe fn uninit<T>() -> T {
148155
/// contained at the location `dst`. This could leak allocations or resources,
149156
/// so care must be taken to previously deallocate the value at `dst`.
150157
#[inline]
151-
#[unstable = "the name of this function is subject to change"]
158+
#[stable]
152159
pub unsafe fn overwrite<T>(dst: *mut T, src: T) {
153160
intrinsics::move_val_init(&mut *dst, src)
154161
}
@@ -315,7 +322,7 @@ pub fn from_be64(x: u64) -> u64 { x }
315322
pub fn swap<T>(x: &mut T, y: &mut T) {
316323
unsafe {
317324
// Give ourselves some scratch space to work with
318-
let mut t: T = uninit();
325+
let mut t: T = uninitialized();
319326

320327
// Perform the swap, `&mut` pointers never alias
321328
ptr::copy_nonoverlapping_memory(&mut t, &*x, 1);

src/libcore/ptr.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ pub unsafe fn copy_memory<T>(dst: *mut T, src: *T, count: uint) {
201201
/// fn swap<T>(x: &mut T, y: &mut T) {
202202
/// unsafe {
203203
/// // Give ourselves some scratch space to work with
204-
/// let mut t: T = mem::uninit();
204+
/// let mut t: T = mem::uninitialized();
205205
///
206206
/// // Perform the swap, `&mut` pointers never alias
207207
/// ptr::copy_nonoverlapping_memory(&mut t, &*x, 1);
@@ -244,7 +244,7 @@ pub unsafe fn zero_memory<T>(dst: *mut T, count: uint) {
244244
#[inline]
245245
pub unsafe fn swap<T>(x: *mut T, y: *mut T) {
246246
// Give ourselves some scratch space to work with
247-
let mut tmp: T = mem::uninit();
247+
let mut tmp: T = mem::uninitialized();
248248
let t: *mut T = &mut tmp;
249249

250250
// Perform the swap
@@ -268,7 +268,7 @@ pub unsafe fn replace<T>(dest: *mut T, mut src: T) -> T {
268268
/// Reads the value from `*src` and returns it.
269269
#[inline(always)]
270270
pub unsafe fn read<T>(src: *T) -> T {
271-
let mut tmp: T = mem::uninit();
271+
let mut tmp: T = mem::uninitialized();
272272
copy_nonoverlapping_memory(&mut tmp, src, 1);
273273
tmp
274274
}

src/libnative/io/file_unix.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl rtio::RtioFileStream for FileDesc {
164164
}
165165

166166
fn fstat(&mut self) -> IoResult<io::FileStat> {
167-
let mut stat: libc::stat = unsafe { mem::uninit() };
167+
let mut stat: libc::stat = unsafe { mem::zeroed() };
168168
match retry(|| unsafe { libc::fstat(self.fd(), &mut stat) }) {
169169
0 => Ok(mkstat(&stat)),
170170
_ => Err(super::last_error()),
@@ -509,15 +509,15 @@ fn mkstat(stat: &libc::stat) -> io::FileStat {
509509
}
510510

511511
pub fn stat(p: &CString) -> IoResult<io::FileStat> {
512-
let mut stat: libc::stat = unsafe { mem::uninit() };
512+
let mut stat: libc::stat = unsafe { mem::zeroed() };
513513
match retry(|| unsafe { libc::stat(p.with_ref(|p| p), &mut stat) }) {
514514
0 => Ok(mkstat(&stat)),
515515
_ => Err(super::last_error()),
516516
}
517517
}
518518

519519
pub fn lstat(p: &CString) -> IoResult<io::FileStat> {
520-
let mut stat: libc::stat = unsafe { mem::uninit() };
520+
let mut stat: libc::stat = unsafe { mem::zeroed() };
521521
match retry(|| unsafe { libc::lstat(p.with_ref(|p| p), &mut stat) }) {
522522
0 => Ok(mkstat(&stat)),
523523
_ => Err(super::last_error()),

src/libnative/io/file_win32.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl rtio::RtioFileStream for FileDesc {
195195
}
196196

197197
fn fstat(&mut self) -> IoResult<io::FileStat> {
198-
let mut stat: libc::stat = unsafe { mem::uninit() };
198+
let mut stat: libc::stat = unsafe { mem::zeroed() };
199199
match unsafe { libc::fstat(self.fd(), &mut stat) } {
200200
0 => Ok(mkstat(&stat)),
201201
_ => Err(super::last_error()),
@@ -510,7 +510,7 @@ fn mkstat(stat: &libc::stat) -> io::FileStat {
510510
}
511511

512512
pub fn stat(p: &CString) -> IoResult<io::FileStat> {
513-
let mut stat: libc::stat = unsafe { mem::uninit() };
513+
let mut stat: libc::stat = unsafe { mem::zeroed() };
514514
as_utf16_p(p.as_str().unwrap(), |up| {
515515
match unsafe { libc::wstat(up, &mut stat) } {
516516
0 => Ok(mkstat(&stat)),

src/libregex_macros/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ fn exec<'t>(which: ::regex::native::MatchKind, input: &'t str,
254254
// The idea here is to avoid initializing threads that never
255255
// need to be initialized, particularly for larger regexs with
256256
// a lot of instructions.
257-
queue: unsafe { ::std::mem::uninit() },
258-
sparse: unsafe { ::std::mem::uninit() },
257+
queue: unsafe { ::std::mem::uninitialized() },
258+
sparse: unsafe { ::std::mem::uninitialized() },
259259
size: 0,
260260
}
261261
}

src/libstd/c_str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl<'a> ToCStr for &'a [u8] {
377377
// Unsafe function that handles possibly copying the &[u8] into a stack array.
378378
unsafe fn with_c_str<T>(v: &[u8], checked: bool, f: |*libc::c_char| -> T) -> T {
379379
if v.len() < BUF_LEN {
380-
let mut buf: [u8, .. BUF_LEN] = mem::uninit();
380+
let mut buf: [u8, .. BUF_LEN] = mem::uninitialized();
381381
slice::bytes::copy_memory(buf, v);
382382
buf[v.len()] = 0;
383383

src/libstd/os.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ pub fn page_size() -> uint {
969969
pub fn page_size() -> uint {
970970
use mem;
971971
unsafe {
972-
let mut info = mem::uninit();
972+
let mut info = mem::zeroed();
973973
libc::GetSystemInfo(&mut info);
974974

975975
return info.dwPageSize as uint;
@@ -1288,7 +1288,7 @@ impl MemoryMap {
12881288
pub fn granularity() -> uint {
12891289
use mem;
12901290
unsafe {
1291-
let mut info = mem::uninit();
1291+
let mut info = mem::zeroed();
12921292
libc::GetSystemInfo(&mut info);
12931293

12941294
return info.dwAllocationGranularity as uint;

src/libstd/rt/thread.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ mod imp {
227227
pub type rust_thread_return = *u8;
228228

229229
pub unsafe fn create(stack: uint, p: Box<proc():Send>) -> rust_thread {
230-
let mut native: libc::pthread_t = mem::uninit();
231-
let mut attr: libc::pthread_attr_t = mem::uninit();
230+
let mut native: libc::pthread_t = mem::zeroed();
231+
let mut attr: libc::pthread_attr_t = mem::zeroed();
232232
assert_eq!(pthread_attr_init(&mut attr), 0);
233233
assert_eq!(pthread_attr_setdetachstate(&mut attr,
234234
PTHREAD_CREATE_JOINABLE), 0);

src/test/run-pass/issue-10714.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010

1111
enum v {}
1212
pub fn main() {
13-
let y: v = unsafe { ::std::mem::uninit() };
13+
let y: v = unsafe { ::std::mem::uninitialized() };
1414
}

src/test/run-pass/uninit-empty-types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ struct Foo;
1717

1818
pub fn main() {
1919
unsafe {
20-
let _x: Foo = mem::uninit();
21-
let _x: [Foo, ..2] = mem::uninit();
20+
let _x: Foo = mem::uninitialized();
21+
let _x: [Foo, ..2] = mem::uninitialized();
2222
}
2323
}

0 commit comments

Comments
 (0)