Skip to content

Commit 135bf58

Browse files
committed
---
yaml --- r: 142702 b: refs/heads/try2 c: 6f5be90 h: refs/heads/master v: v3
1 parent 11b1521 commit 135bf58

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: f74250e3a970f81388a73aeb8f3d53304d77c34b
8+
refs/heads/try2: 6f5be9063ddbfe18ce5321817f782abcd2f55110
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/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)