Skip to content

Commit 195a831

Browse files
committed
---
yaml --- r: 64174 b: refs/heads/snap-stage3 c: 6f5be90 h: refs/heads/master v: v3
1 parent 78102b6 commit 195a831

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: f74250e3a970f81388a73aeb8f3d53304d77c34b
4+
refs/heads/snap-stage3: 6f5be9063ddbfe18ce5321817f782abcd2f55110
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/ptr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use cast;
1414
use option::{Option, Some, None};
1515
use sys;
1616
use unstable::intrinsics;
17+
use util::swap;
1718

1819
#[cfg(not(test))] use cmp::{Eq, Ord};
1920
use uint;
@@ -177,9 +178,9 @@ pub unsafe fn swap_ptr<T>(x: *mut T, y: *mut T) {
177178
let t: *mut T = &mut tmp;
178179

179180
// Perform the swap
180-
copy_memory(t, x, 1);
181-
copy_memory(x, y, 1);
182-
copy_memory(y, t, 1);
181+
copy_nonoverlapping_memory(t, x, 1);
182+
copy_memory(x, y, 1); // `x` and `y` may overlap
183+
copy_nonoverlapping_memory(y, t, 1);
183184

184185
// y and t now point to the same thing, but we need to completely forget `tmp`
185186
// because it's no longer relevant.
@@ -192,7 +193,7 @@ pub unsafe fn swap_ptr<T>(x: *mut T, y: *mut T) {
192193
*/
193194
#[inline]
194195
pub unsafe fn replace_ptr<T>(dest: *mut T, mut src: T) -> T {
195-
swap_ptr(dest, &mut src);
196+
swap(cast::transmute(dest), &mut src); // cannot overlap
196197
src
197198
}
198199

@@ -202,8 +203,7 @@ pub unsafe fn replace_ptr<T>(dest: *mut T, mut src: T) -> T {
202203
#[inline(always)]
203204
pub unsafe fn read_ptr<T>(src: *mut T) -> T {
204205
let mut tmp: T = intrinsics::uninit();
205-
let t: *mut T = &mut tmp;
206-
copy_memory(t, src, 1);
206+
copy_nonoverlapping_memory(&mut tmp, src, 1);
207207
tmp
208208
}
209209

0 commit comments

Comments
 (0)