Skip to content

Commit ab45694

Browse files
committed
std: Stabilize some ptr functions
Specifically, the following actions were taken: * The `copy_memory` and `copy_nonoverlapping_memory` functions to drop the `_memory` suffix (as it's implied by the functionality). Both functions are now marked as `#[stable]`. * The `set_memory` function was renamed to `write_bytes` and is now stable. * The `zero_memory` function is now deprecated in favor of `write_bytes` directly. * The `Unique` pointer type is now behind its own feature gate called `unique` to facilitate future stabilization. * All type parameters now are `T: ?Sized` wherever possible and new clauses were added to the `offset` functions to require that the type is sized. [breaking-change]
1 parent 0bd1565 commit ab45694

File tree

15 files changed

+126
-122
lines changed

15 files changed

+126
-122
lines changed

Diff for: src/liballoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#![feature(unboxed_closures)]
7474
#![feature(unsafe_no_drop_flag)]
7575
#![feature(core)]
76+
#![feature(unique)]
7677
#![cfg_attr(test, feature(test, alloc, rustc_private))]
7778
#![cfg_attr(all(not(feature = "external_funcs"), not(feature = "external_crate")),
7879
feature(libc))]

Diff for: src/libcollections/btree/node.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -1136,12 +1136,12 @@ impl<K, V> Node<K, V> {
11361136
// This must be followed by insert_edge on an internal node.
11371137
#[inline]
11381138
unsafe fn insert_kv(&mut self, index: usize, key: K, val: V) -> &mut V {
1139-
ptr::copy_memory(
1139+
ptr::copy(
11401140
self.keys_mut().as_mut_ptr().offset(index as isize + 1),
11411141
self.keys().as_ptr().offset(index as isize),
11421142
self.len() - index
11431143
);
1144-
ptr::copy_memory(
1144+
ptr::copy(
11451145
self.vals_mut().as_mut_ptr().offset(index as isize + 1),
11461146
self.vals().as_ptr().offset(index as isize),
11471147
self.len() - index
@@ -1158,7 +1158,7 @@ impl<K, V> Node<K, V> {
11581158
// This can only be called immediately after a call to insert_kv.
11591159
#[inline]
11601160
unsafe fn insert_edge(&mut self, index: usize, edge: Node<K, V>) {
1161-
ptr::copy_memory(
1161+
ptr::copy(
11621162
self.edges_mut().as_mut_ptr().offset(index as isize + 1),
11631163
self.edges().as_ptr().offset(index as isize),
11641164
self.len() - index
@@ -1191,12 +1191,12 @@ impl<K, V> Node<K, V> {
11911191
let key = ptr::read(self.keys().get_unchecked(index));
11921192
let val = ptr::read(self.vals().get_unchecked(index));
11931193

1194-
ptr::copy_memory(
1194+
ptr::copy(
11951195
self.keys_mut().as_mut_ptr().offset(index as isize),
11961196
self.keys().as_ptr().offset(index as isize + 1),
11971197
self.len() - index - 1
11981198
);
1199-
ptr::copy_memory(
1199+
ptr::copy(
12001200
self.vals_mut().as_mut_ptr().offset(index as isize),
12011201
self.vals().as_ptr().offset(index as isize + 1),
12021202
self.len() - index - 1
@@ -1212,7 +1212,7 @@ impl<K, V> Node<K, V> {
12121212
unsafe fn remove_edge(&mut self, index: usize) -> Node<K, V> {
12131213
let edge = ptr::read(self.edges().get_unchecked(index));
12141214

1215-
ptr::copy_memory(
1215+
ptr::copy(
12161216
self.edges_mut().as_mut_ptr().offset(index as isize),
12171217
self.edges().as_ptr().offset(index as isize + 1),
12181218
self.len() - index + 1
@@ -1239,18 +1239,18 @@ impl<K, V> Node<K, V> {
12391239
unsafe {
12401240
right._len = self.len() / 2;
12411241
let right_offset = self.len() - right.len();
1242-
ptr::copy_nonoverlapping_memory(
1242+
ptr::copy_nonoverlapping(
12431243
right.keys_mut().as_mut_ptr(),
12441244
self.keys().as_ptr().offset(right_offset as isize),
12451245
right.len()
12461246
);
1247-
ptr::copy_nonoverlapping_memory(
1247+
ptr::copy_nonoverlapping(
12481248
right.vals_mut().as_mut_ptr(),
12491249
self.vals().as_ptr().offset(right_offset as isize),
12501250
right.len()
12511251
);
12521252
if !self.is_leaf() {
1253-
ptr::copy_nonoverlapping_memory(
1253+
ptr::copy_nonoverlapping(
12541254
right.edges_mut().as_mut_ptr(),
12551255
self.edges().as_ptr().offset(right_offset as isize),
12561256
right.len() + 1
@@ -1280,18 +1280,18 @@ impl<K, V> Node<K, V> {
12801280
ptr::write(self.keys_mut().get_unchecked_mut(old_len), key);
12811281
ptr::write(self.vals_mut().get_unchecked_mut(old_len), val);
12821282

1283-
ptr::copy_nonoverlapping_memory(
1283+
ptr::copy_nonoverlapping(
12841284
self.keys_mut().as_mut_ptr().offset(old_len as isize + 1),
12851285
right.keys().as_ptr(),
12861286
right.len()
12871287
);
1288-
ptr::copy_nonoverlapping_memory(
1288+
ptr::copy_nonoverlapping(
12891289
self.vals_mut().as_mut_ptr().offset(old_len as isize + 1),
12901290
right.vals().as_ptr(),
12911291
right.len()
12921292
);
12931293
if !self.is_leaf() {
1294-
ptr::copy_nonoverlapping_memory(
1294+
ptr::copy_nonoverlapping(
12951295
self.edges_mut().as_mut_ptr().offset(old_len as isize + 1),
12961296
right.edges().as_ptr(),
12971297
right.len() + 1

Diff for: src/libcollections/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#![feature(unboxed_closures)]
3131
#![feature(unicode)]
3232
#![feature(unsafe_destructor)]
33+
#![feature(unique)]
3334
#![feature(unsafe_no_drop_flag)]
3435
#![cfg_attr(test, feature(rand, rustc_private, test))]
3536
#![cfg_attr(test, allow(deprecated))] // rand

Diff for: src/libcollections/slice.rs

+12-14
Original file line numberDiff line numberDiff line change
@@ -1331,12 +1331,10 @@ fn insertion_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> O
13311331

13321332
if i != j {
13331333
let tmp = ptr::read(read_ptr);
1334-
ptr::copy_memory(buf_v.offset(j + 1),
1335-
&*buf_v.offset(j),
1336-
(i - j) as usize);
1337-
ptr::copy_nonoverlapping_memory(buf_v.offset(j),
1338-
&tmp,
1339-
1);
1334+
ptr::copy(buf_v.offset(j + 1),
1335+
&*buf_v.offset(j),
1336+
(i - j) as usize);
1337+
ptr::copy_nonoverlapping(buf_v.offset(j), &tmp, 1);
13401338
mem::forget(tmp);
13411339
}
13421340
}
@@ -1409,10 +1407,10 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order
14091407
// j + 1 could be `len` (for the last `i`), but in
14101408
// that case, `i == j` so we don't copy. The
14111409
// `.offset(j)` is always in bounds.
1412-
ptr::copy_memory(buf_dat.offset(j + 1),
1413-
&*buf_dat.offset(j),
1414-
i - j as usize);
1415-
ptr::copy_nonoverlapping_memory(buf_dat.offset(j), read_ptr, 1);
1410+
ptr::copy(buf_dat.offset(j + 1),
1411+
&*buf_dat.offset(j),
1412+
i - j as usize);
1413+
ptr::copy_nonoverlapping(buf_dat.offset(j), read_ptr, 1);
14161414
}
14171415
}
14181416
}
@@ -1460,11 +1458,11 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order
14601458
if left == right_start {
14611459
// the number remaining in this run.
14621460
let elems = (right_end as usize - right as usize) / mem::size_of::<T>();
1463-
ptr::copy_nonoverlapping_memory(out, &*right, elems);
1461+
ptr::copy_nonoverlapping(out, &*right, elems);
14641462
break;
14651463
} else if right == right_end {
14661464
let elems = (right_start as usize - left as usize) / mem::size_of::<T>();
1467-
ptr::copy_nonoverlapping_memory(out, &*left, elems);
1465+
ptr::copy_nonoverlapping(out, &*left, elems);
14681466
break;
14691467
}
14701468

@@ -1478,7 +1476,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order
14781476
} else {
14791477
step(&mut left)
14801478
};
1481-
ptr::copy_nonoverlapping_memory(out, &*to_copy, 1);
1479+
ptr::copy_nonoverlapping(out, &*to_copy, 1);
14821480
step(&mut out);
14831481
}
14841482
}
@@ -1492,7 +1490,7 @@ fn merge_sort<T, F>(v: &mut [T], mut compare: F) where F: FnMut(&T, &T) -> Order
14921490
// write the result to `v` in one go, so that there are never two copies
14931491
// of the same object in `v`.
14941492
unsafe {
1495-
ptr::copy_nonoverlapping_memory(v.as_mut_ptr(), &*buf_dat, len);
1493+
ptr::copy_nonoverlapping(v.as_mut_ptr(), &*buf_dat, len);
14961494
}
14971495

14981496
// increment the pointer, returning the old pointer.

Diff for: src/libcollections/string.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,9 @@ impl String {
568568

569569
let CharRange { ch, next } = self.char_range_at(idx);
570570
unsafe {
571-
ptr::copy_memory(self.vec.as_mut_ptr().offset(idx as isize),
572-
self.vec.as_ptr().offset(next as isize),
573-
len - next);
571+
ptr::copy(self.vec.as_mut_ptr().offset(idx as isize),
572+
self.vec.as_ptr().offset(next as isize),
573+
len - next);
574574
self.vec.set_len(len - (next - idx));
575575
}
576576
ch
@@ -598,12 +598,12 @@ impl String {
598598
let amt = ch.encode_utf8(&mut bits).unwrap();
599599

600600
unsafe {
601-
ptr::copy_memory(self.vec.as_mut_ptr().offset((idx + amt) as isize),
602-
self.vec.as_ptr().offset(idx as isize),
603-
len - idx);
604-
ptr::copy_memory(self.vec.as_mut_ptr().offset(idx as isize),
605-
bits.as_ptr(),
606-
amt);
601+
ptr::copy(self.vec.as_mut_ptr().offset((idx + amt) as isize),
602+
self.vec.as_ptr().offset(idx as isize),
603+
len - idx);
604+
ptr::copy(self.vec.as_mut_ptr().offset(idx as isize),
605+
bits.as_ptr(),
606+
amt);
607607
self.vec.set_len(len + amt);
608608
}
609609
}

Diff for: src/libcollections/vec.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ impl<T> Vec<T> {
267267
pub unsafe fn from_raw_buf(ptr: *const T, elts: usize) -> Vec<T> {
268268
let mut dst = Vec::with_capacity(elts);
269269
dst.set_len(elts);
270-
ptr::copy_nonoverlapping_memory(dst.as_mut_ptr(), ptr, elts);
270+
ptr::copy_nonoverlapping(dst.as_mut_ptr(), ptr, elts);
271271
dst
272272
}
273273

@@ -548,7 +548,7 @@ impl<T> Vec<T> {
548548
let p = self.as_mut_ptr().offset(index as isize);
549549
// Shift everything over to make space. (Duplicating the
550550
// `index`th element into two consecutive places.)
551-
ptr::copy_memory(p.offset(1), &*p, len - index);
551+
ptr::copy(p.offset(1), &*p, len - index);
552552
// Write it in, overwriting the first copy of the `index`th
553553
// element.
554554
ptr::write(&mut *p, element);
@@ -585,7 +585,7 @@ impl<T> Vec<T> {
585585
ret = ptr::read(ptr);
586586

587587
// Shift everything down to fill in that spot.
588-
ptr::copy_memory(ptr, &*ptr.offset(1), len - index - 1);
588+
ptr::copy(ptr, &*ptr.offset(1), len - index - 1);
589589
}
590590
self.set_len(len - 1);
591591
ret
@@ -718,7 +718,7 @@ impl<T> Vec<T> {
718718
self.reserve(other.len());
719719
let len = self.len();
720720
unsafe {
721-
ptr::copy_nonoverlapping_memory(
721+
ptr::copy_nonoverlapping(
722722
self.get_unchecked_mut(len),
723723
other.as_ptr(),
724724
other.len());
@@ -1036,7 +1036,7 @@ impl<T> Vec<T> {
10361036
self.set_len(at);
10371037
other.set_len(other_len);
10381038

1039-
ptr::copy_nonoverlapping_memory(
1039+
ptr::copy_nonoverlapping(
10401040
other.as_mut_ptr(),
10411041
self.as_ptr().offset(at as isize),
10421042
other.len());

Diff for: src/libcollections/vec_deque.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<T> VecDeque<T> {
134134
self.cap);
135135
debug_assert!(src + len <= self.cap, "dst={} src={} len={} cap={}", dst, src, len,
136136
self.cap);
137-
ptr::copy_memory(
137+
ptr::copy(
138138
self.ptr.offset(dst as isize),
139139
self.ptr.offset(src as isize),
140140
len);
@@ -147,7 +147,7 @@ impl<T> VecDeque<T> {
147147
self.cap);
148148
debug_assert!(src + len <= self.cap, "dst={} src={} len={} cap={}", dst, src, len,
149149
self.cap);
150-
ptr::copy_nonoverlapping_memory(
150+
ptr::copy_nonoverlapping(
151151
self.ptr.offset(dst as isize),
152152
self.ptr.offset(src as isize),
153153
len);
@@ -1343,22 +1343,22 @@ impl<T> VecDeque<T> {
13431343
// `at` lies in the first half.
13441344
let amount_in_first = first_len - at;
13451345

1346-
ptr::copy_nonoverlapping_memory(*other.ptr,
1347-
first_half.as_ptr().offset(at as isize),
1348-
amount_in_first);
1346+
ptr::copy_nonoverlapping(*other.ptr,
1347+
first_half.as_ptr().offset(at as isize),
1348+
amount_in_first);
13491349

13501350
// just take all of the second half.
1351-
ptr::copy_nonoverlapping_memory(other.ptr.offset(amount_in_first as isize),
1352-
second_half.as_ptr(),
1353-
second_len);
1351+
ptr::copy_nonoverlapping(other.ptr.offset(amount_in_first as isize),
1352+
second_half.as_ptr(),
1353+
second_len);
13541354
} else {
13551355
// `at` lies in the second half, need to factor in the elements we skipped
13561356
// in the first half.
13571357
let offset = at - first_len;
13581358
let amount_in_second = second_len - offset;
1359-
ptr::copy_nonoverlapping_memory(*other.ptr,
1360-
second_half.as_ptr().offset(offset as isize),
1361-
amount_in_second);
1359+
ptr::copy_nonoverlapping(*other.ptr,
1360+
second_half.as_ptr().offset(offset as isize),
1361+
amount_in_second);
13621362
}
13631363
}
13641364

Diff for: src/libcore/intrinsics.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ extern "rust-intrinsic" {
293293
/// }
294294
/// }
295295
/// ```
296-
#[unstable(feature = "core")]
296+
#[stable(feature = "rust1", since = "1.0.0")]
297297
pub fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
298298

299299
/// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
@@ -323,13 +323,12 @@ extern "rust-intrinsic" {
323323
/// }
324324
/// ```
325325
///
326-
#[unstable(feature = "core")]
326+
#[stable(feature = "rust1", since = "1.0.0")]
327327
pub fn copy_memory<T>(dst: *mut T, src: *const T, count: usize);
328328

329329
/// Invokes memset on the specified pointer, setting `count * size_of::<T>()`
330330
/// bytes of memory starting at `dst` to `c`.
331-
#[unstable(feature = "core",
332-
reason = "uncertain about naming and semantics")]
331+
#[stable(feature = "rust1", since = "1.0.0")]
333332
pub fn set_memory<T>(dst: *mut T, val: u8, count: usize);
334333

335334
/// Equivalent to the appropriate `llvm.memcpy.p0i8.0i8.*` intrinsic, with

Diff for: src/libcore/mem.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ pub fn swap<T>(x: &mut T, y: &mut T) {
203203
let mut t: T = uninitialized();
204204

205205
// Perform the swap, `&mut` pointers never alias
206-
ptr::copy_nonoverlapping_memory(&mut t, &*x, 1);
207-
ptr::copy_nonoverlapping_memory(x, &*y, 1);
208-
ptr::copy_nonoverlapping_memory(y, &t, 1);
206+
ptr::copy_nonoverlapping(&mut t, &*x, 1);
207+
ptr::copy_nonoverlapping(x, &*y, 1);
208+
ptr::copy_nonoverlapping(y, &t, 1);
209209

210210
// y and t now point to the same thing, but we need to completely forget `t`
211211
// because it's no longer relevant.

0 commit comments

Comments
 (0)