Skip to content

Commit aea8226

Browse files
committed
rollup merge of rust-lang#23503: alexcrichton/fix-ptr-docs
The method with which backwards compatibility was retained ended up leading to documentation that rustdoc didn't handle well and largely ended up confusing.
2 parents 6e0f1d3 + e24fe5b commit aea8226

File tree

8 files changed

+49
-41
lines changed

8 files changed

+49
-41
lines changed

src/libcollectionstest/slice.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ mod bench {
14281428
let mut v = Vec::<u8>::with_capacity(1024);
14291429
unsafe {
14301430
let vp = v.as_mut_ptr();
1431-
ptr::set_memory(vp, 0, 1024);
1431+
ptr::write_bytes(vp, 0, 1024);
14321432
v.set_len(1024);
14331433
}
14341434
v

src/libcore/intrinsics.rs

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444

4545
use marker::Sized;
4646

47+
#[cfg(stage0)] pub use self::copy_memory as copy;
48+
#[cfg(stage0)] pub use self::set_memory as write_bytes;
49+
#[cfg(stage0)] pub use self::copy_nonoverlapping_memory as copy_nonoverlapping;
50+
4751
extern "rust-intrinsic" {
4852

4953
// NB: These intrinsics take unsafe pointers because they mutate aliased
@@ -246,7 +250,7 @@ extern "rust-intrinsic" {
246250
/// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
247251
/// and destination may *not* overlap.
248252
///
249-
/// `copy_nonoverlapping_memory` is semantically equivalent to C's `memcpy`.
253+
/// `copy_nonoverlapping` is semantically equivalent to C's `memcpy`.
250254
///
251255
/// # Safety
252256
///
@@ -272,9 +276,9 @@ extern "rust-intrinsic" {
272276
/// let mut t: T = mem::uninitialized();
273277
///
274278
/// // Perform the swap, `&mut` pointers never alias
275-
/// ptr::copy_nonoverlapping_memory(&mut t, &*x, 1);
276-
/// ptr::copy_nonoverlapping_memory(x, &*y, 1);
277-
/// ptr::copy_nonoverlapping_memory(y, &t, 1);
279+
/// ptr::copy_nonoverlapping(&mut t, &*x, 1);
280+
/// ptr::copy_nonoverlapping(x, &*y, 1);
281+
/// ptr::copy_nonoverlapping(y, &t, 1);
278282
///
279283
/// // y and t now point to the same thing, but we need to completely forget `tmp`
280284
/// // because it's no longer relevant.
@@ -283,12 +287,18 @@ extern "rust-intrinsic" {
283287
/// }
284288
/// ```
285289
#[stable(feature = "rust1", since = "1.0.0")]
290+
#[cfg(not(stage0))]
291+
pub fn copy_nonoverlapping<T>(dst: *mut T, src: *const T, count: usize);
292+
293+
/// dox
294+
#[stable(feature = "rust1", since = "1.0.0")]
295+
#[cfg(stage0)]
286296
pub fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
287297

288298
/// Copies `count * size_of<T>` bytes from `src` to `dst`. The source
289299
/// and destination may overlap.
290300
///
291-
/// `copy_memory` is semantically equivalent to C's `memmove`.
301+
/// `copy` is semantically equivalent to C's `memmove`.
292302
///
293303
/// # Safety
294304
///
@@ -308,16 +318,28 @@ extern "rust-intrinsic" {
308318
/// unsafe fn from_buf_raw<T>(ptr: *const T, elts: uint) -> Vec<T> {
309319
/// let mut dst = Vec::with_capacity(elts);
310320
/// dst.set_len(elts);
311-
/// ptr::copy_memory(dst.as_mut_ptr(), ptr, elts);
321+
/// ptr::copy(dst.as_mut_ptr(), ptr, elts);
312322
/// dst
313323
/// }
314324
/// ```
315325
///
326+
#[cfg(not(stage0))]
327+
#[stable(feature = "rust1", since = "1.0.0")]
328+
pub fn copy<T>(dst: *mut T, src: *const T, count: usize);
329+
330+
/// dox
331+
#[cfg(stage0)]
316332
#[stable(feature = "rust1", since = "1.0.0")]
317333
pub fn copy_memory<T>(dst: *mut T, src: *const T, count: usize);
318334

319335
/// Invokes memset on the specified pointer, setting `count * size_of::<T>()`
320336
/// bytes of memory starting at `dst` to `c`.
337+
#[cfg(not(stage0))]
338+
#[stable(feature = "rust1", since = "1.0.0")]
339+
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);
340+
341+
/// dox
342+
#[cfg(stage0)]
321343
#[stable(feature = "rust1", since = "1.0.0")]
322344
pub fn set_memory<T>(dst: *mut T, val: u8, count: usize);
323345

src/libcore/ptr.rs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,27 +107,13 @@ use cmp::Ordering::{self, Less, Equal, Greater};
107107
// FIXME #19649: intrinsic docs don't render, so these have no docs :(
108108

109109
#[stable(feature = "rust1", since = "1.0.0")]
110-
pub use intrinsics::copy_nonoverlapping_memory as copy_nonoverlapping;
110+
pub use intrinsics::copy_nonoverlapping;
111111

112112
#[stable(feature = "rust1", since = "1.0.0")]
113-
pub use intrinsics::copy_memory as copy;
113+
pub use intrinsics::copy;
114114

115115
#[stable(feature = "rust1", since = "1.0.0")]
116-
pub use intrinsics::set_memory as write_bytes;
117-
118-
extern "rust-intrinsic" {
119-
#[unstable(feature = "core")]
120-
#[deprecated(since = "1.0.0", reason = "renamed to `copy_nonoverlapping`")]
121-
pub fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: usize);
122-
#[unstable(feature = "core")]
123-
#[deprecated(since = "1.0.0", reason = "renamed to `copy`")]
124-
pub fn copy_memory<T>(dst: *mut T, src: *const T, count: usize);
125-
126-
#[unstable(feature = "core",
127-
reason = "uncertain about naming and semantics")]
128-
#[deprecated(since = "1.0.0", reason = "renamed to `write_bytes`")]
129-
pub fn set_memory<T>(dst: *mut T, val: u8, count: usize);
130-
}
116+
pub use intrinsics::write_bytes;
131117

132118
/// Creates a null raw pointer.
133119
///

src/libcoretest/ptr.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ fn test() {
3535
let v0 = vec![32000u16, 32001u16, 32002u16];
3636
let mut v1 = vec![0u16, 0u16, 0u16];
3737

38-
copy_memory(v1.as_mut_ptr().offset(1),
39-
v0.as_ptr().offset(1), 1);
38+
copy(v1.as_mut_ptr().offset(1),
39+
v0.as_ptr().offset(1), 1);
4040
assert!((v1[0] == 0u16 &&
4141
v1[1] == 32001u16 &&
4242
v1[2] == 0u16));
43-
copy_memory(v1.as_mut_ptr(),
44-
v0.as_ptr().offset(2), 1);
43+
copy(v1.as_mut_ptr(),
44+
v0.as_ptr().offset(2), 1);
4545
assert!((v1[0] == 32002u16 &&
4646
v1[1] == 32001u16 &&
4747
v1[2] == 0u16));
48-
copy_memory(v1.as_mut_ptr().offset(2),
49-
v0.as_ptr(), 1);
48+
copy(v1.as_mut_ptr().offset(2),
49+
v0.as_ptr(), 1);
5050
assert!((v1[0] == 32002u16 &&
5151
v1[1] == 32001u16 &&
5252
v1[2] == 32000u16));
@@ -164,7 +164,7 @@ fn test_ptr_subtraction() {
164164
fn test_set_memory() {
165165
let mut xs = [0u8; 20];
166166
let ptr = xs.as_mut_ptr();
167-
unsafe { set_memory(ptr, 5u8, xs.len()); }
167+
unsafe { write_bytes(ptr, 5u8, xs.len()); }
168168
assert!(xs == [5u8; 20]);
169169
}
170170

src/librustc_trans/trans/intrinsic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
386386
InBoundsGEP(bcx, ptr, &[offset])
387387
}
388388

389-
(_, "copy_nonoverlapping_memory") => {
389+
(_, "copy_nonoverlapping") => {
390390
copy_intrinsic(bcx,
391391
false,
392392
false,
@@ -396,7 +396,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
396396
llargs[2],
397397
call_debug_location)
398398
}
399-
(_, "copy_memory") => {
399+
(_, "copy") => {
400400
copy_intrinsic(bcx,
401401
true,
402402
false,
@@ -406,7 +406,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
406406
llargs[2],
407407
call_debug_location)
408408
}
409-
(_, "set_memory") => {
409+
(_, "write_bytes") => {
410410
memset_intrinsic(bcx,
411411
false,
412412
*substs.types.get(FnSpace, 0),

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5381,7 +5381,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
53815381
mutbl: ast::MutImmutable
53825382
}))
53835383
}
5384-
"copy_memory" | "copy_nonoverlapping_memory" |
5384+
"copy" | "copy_nonoverlapping" |
53855385
"volatile_copy_memory" | "volatile_copy_nonoverlapping_memory" => {
53865386
(1,
53875387
vec!(
@@ -5397,7 +5397,7 @@ pub fn check_intrinsic_type(ccx: &CrateCtxt, it: &ast::ForeignItem) {
53975397
),
53985398
ty::mk_nil(tcx))
53995399
}
5400-
"set_memory" | "volatile_set_memory" => {
5400+
"write_bytes" | "volatile_set_memory" => {
54015401
(1,
54025402
vec!(
54035403
ty::mk_ptr(tcx, ty::mt {

src/libstd/old_io/extensions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ pub fn u64_to_be_bytes<T, F>(n: u64, size: uint, f: F) -> T where
159159
/// that many bytes are parsed. For example, if `size` is 4, then a
160160
/// 32-bit value is parsed.
161161
pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 {
162-
use ptr::{copy_nonoverlapping_memory};
162+
use ptr::{copy_nonoverlapping};
163163

164164
assert!(size <= 8);
165165

@@ -171,7 +171,7 @@ pub fn u64_from_be_bytes(data: &[u8], start: uint, size: uint) -> u64 {
171171
unsafe {
172172
let ptr = data.as_ptr().offset(start as int);
173173
let out = buf.as_mut_ptr();
174-
copy_nonoverlapping_memory(out.offset((8 - size) as int), ptr, size);
174+
copy_nonoverlapping(out.offset((8 - size) as int), ptr, size);
175175
(*(out as *const u64)).to_be()
176176
}
177177
}

src/test/bench/shootout-reverse-complement.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ extern crate libc;
4646

4747
use std::old_io::stdio::{stdin_raw, stdout_raw};
4848
use std::old_io::*;
49-
use std::ptr::{copy_memory, Unique};
49+
use std::ptr::{copy, Unique};
5050
use std::thread;
5151

5252
struct Tables {
@@ -181,8 +181,8 @@ fn reverse_complement(seq: &mut [u8], tables: &Tables) {
181181
let mut i = LINE_LEN;
182182
while i < len {
183183
unsafe {
184-
copy_memory(seq.as_mut_ptr().offset((i - off + 1) as int),
185-
seq.as_ptr().offset((i - off) as int), off);
184+
copy(seq.as_mut_ptr().offset((i - off + 1) as int),
185+
seq.as_ptr().offset((i - off) as int), off);
186186
*seq.get_unchecked_mut(i - off) = b'\n';
187187
}
188188
i += LINE_LEN + 1;

0 commit comments

Comments
 (0)