Skip to content

Commit 5cfde77

Browse files
committed
Rename memcpy, memmove, memset to prevent any confusion with the C equivalents.
Closes #4203.
1 parent fa55778 commit 5cfde77

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

src/libcore/io.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ impl BytesReader: Reader {
503503
let count = uint::min(len, self.bytes.len() - self.pos);
504504
505505
let view = vec::view(self.bytes, self.pos, self.bytes.len());
506-
vec::bytes::memcpy(bytes, view, count);
506+
vec::bytes::copy_memory(bytes, view, count);
507507
508508
self.pos += count;
509509
@@ -950,7 +950,7 @@ impl BytesWriter: Writer {
950950
951951
{
952952
let view = vec::mut_view(bytes, self.pos, count);
953-
vec::bytes::memcpy(view, v, v_len);
953+
vec::bytes::copy_memory(view, v, v_len);
954954
}
955955
956956
self.pos += v_len;

src/libcore/ptr.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub pure fn is_not_null<T>(ptr: *const T) -> bool { !is_null(ptr) }
114114
* and destination may not overlap.
115115
*/
116116
#[inline(always)]
117-
pub unsafe fn memcpy<T>(dst: *mut T, src: *const T, count: uint) {
117+
pub unsafe fn copy_memory<T>(dst: *mut T, src: *const T, count: uint) {
118118
let n = count * sys::size_of::<T>();
119119
libc_::memcpy(dst as *mut c_void, src as *c_void, n as size_t);
120120
}
@@ -126,13 +126,13 @@ pub unsafe fn memcpy<T>(dst: *mut T, src: *const T, count: uint) {
126126
* and destination may overlap.
127127
*/
128128
#[inline(always)]
129-
pub unsafe fn memmove<T>(dst: *mut T, src: *const T, count: uint) {
129+
pub unsafe fn copy_overlapping_memory<T>(dst: *mut T, src: *const T, count: uint) {
130130
let n = count * sys::size_of::<T>();
131131
libc_::memmove(dst as *mut c_void, src as *c_void, n as size_t);
132132
}
133133

134134
#[inline(always)]
135-
pub unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
135+
pub unsafe fn set_memory<T>(dst: *mut T, c: int, count: uint) {
136136
let n = count * sys::size_of::<T>();
137137
libc_::memset(dst as *mut c_void, c as libc::c_int, n as size_t);
138138
}
@@ -306,13 +306,13 @@ pub fn test() {
306306
let mut v0 = ~[32000u16, 32001u16, 32002u16];
307307
let mut v1 = ~[0u16, 0u16, 0u16];
308308

309-
ptr::memcpy(ptr::mut_offset(vec::raw::to_mut_ptr(v1), 1u),
309+
ptr::copy_memory(ptr::mut_offset(vec::raw::to_mut_ptr(v1), 1u),
310310
ptr::offset(vec::raw::to_ptr(v0), 1u), 1u);
311311
assert (v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16);
312-
ptr::memcpy(vec::raw::to_mut_ptr(v1),
312+
ptr::copy_memory(vec::raw::to_mut_ptr(v1),
313313
ptr::offset(vec::raw::to_ptr(v0), 2u), 1u);
314314
assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 0u16);
315-
ptr::memcpy(ptr::mut_offset(vec::raw::to_mut_ptr(v1), 2u),
315+
ptr::copy_memory(ptr::mut_offset(vec::raw::to_mut_ptr(v1), 2u),
316316
vec::raw::to_ptr(v0), 1u);
317317
assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 32000u16);
318318
}

src/libcore/str.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub fn push_str_no_overallocate(lhs: &mut ~str, rhs: &str) {
169169
do as_buf(rhs) |rbuf, _rlen| {
170170
let dst = ptr::offset(lbuf, llen);
171171
let dst = ::cast::transmute_mut_unsafe(dst);
172-
ptr::memcpy(dst, rbuf, rlen);
172+
ptr::copy_memory(dst, rbuf, rlen);
173173
}
174174
}
175175
raw::set_len(lhs, llen + rlen);
@@ -186,7 +186,7 @@ pub fn push_str(lhs: &mut ~str, rhs: &str) {
186186
do as_buf(rhs) |rbuf, _rlen| {
187187
let dst = ptr::offset(lbuf, llen);
188188
let dst = ::cast::transmute_mut_unsafe(dst);
189-
ptr::memcpy(dst, rbuf, rlen);
189+
ptr::copy_memory(dst, rbuf, rlen);
190190
}
191191
}
192192
raw::set_len(lhs, llen + rlen);
@@ -1967,7 +1967,7 @@ pub mod raw {
19671967
pub unsafe fn from_buf_len(buf: *const u8, len: uint) -> ~str {
19681968
let mut v: ~[u8] = vec::with_capacity(len + 1);
19691969
vec::as_mut_buf(v, |vbuf, _len| {
1970-
ptr::memcpy(vbuf, buf as *u8, len)
1970+
ptr::copy_memory(vbuf, buf as *u8, len)
19711971
});
19721972
vec::raw::set_len(&mut v, len);
19731973
v.push(0u8);
@@ -2024,7 +2024,7 @@ pub mod raw {
20242024
do vec::as_imm_buf(v) |vbuf, _vlen| {
20252025
let vbuf = ::cast::transmute_mut_unsafe(vbuf);
20262026
let src = ptr::offset(sbuf, begin);
2027-
ptr::memcpy(vbuf, src, end - begin);
2027+
ptr::copy_memory(vbuf, src, end - begin);
20282028
}
20292029
vec::raw::set_len(&mut v, end - begin);
20302030
v.push(0u8);

src/libcore/vec.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -469,20 +469,20 @@ pub fn shift<T>(v: &mut ~[T]) -> T unsafe {
469469
// We still should have room to work where what last element was
470470
assert capacity(v) >= ln;
471471
// Pretend like we have the original length so we can use
472-
// the vector memcpy to overwrite the hole we just made
472+
// the vector copy_memory to overwrite the hole we just made
473473
raw::set_len(v, ln);
474474

475475
// Memcopy the head element (the one we want) to the location we just
476476
// popped. For the moment it unsafely exists at both the head and last
477477
// positions
478478
let first_slice = view(*v, 0, 1);
479479
let last_slice = mut_view(*v, next_ln, ln);
480-
raw::memcpy(last_slice, first_slice, 1);
480+
raw::copy_memory(last_slice, first_slice, 1);
481481

482482
// Memcopy everything to the left one element
483483
let init_slice = mut_view(*v, 0, next_ln);
484484
let tail_slice = view(*v, 1, ln);
485-
raw::memcpy(init_slice, tail_slice, next_ln);
485+
raw::copy_memory(init_slice, tail_slice, next_ln);
486486

487487
// Set the new length. Now the vector is back to normal
488488
raw::set_len(v, next_ln);
@@ -2071,7 +2071,7 @@ pub mod raw {
20712071
pub unsafe fn from_buf_raw<T>(ptr: *T, elts: uint) -> ~[T] {
20722072
let mut dst = with_capacity(elts);
20732073
set_len(&mut dst, elts);
2074-
as_mut_buf(dst, |p_dst, _len_dst| ptr::memcpy(p_dst, ptr, elts));
2074+
as_mut_buf(dst, |p_dst, _len_dst| ptr::copy_memory(p_dst, ptr, elts));
20752075
dst
20762076
}
20772077

@@ -2081,13 +2081,13 @@ pub mod raw {
20812081
* Copies `count` bytes from `src` to `dst`. The source and destination
20822082
* may overlap.
20832083
*/
2084-
pub unsafe fn memcpy<T>(dst: &[mut T], src: &[const T], count: uint) {
2084+
pub unsafe fn copy_memory<T>(dst: &[mut T], src: &[const T], count: uint) {
20852085
assert dst.len() >= count;
20862086
assert src.len() >= count;
20872087

20882088
do as_mut_buf(dst) |p_dst, _len_dst| {
20892089
do as_const_buf(src) |p_src, _len_src| {
2090-
ptr::memcpy(p_dst, p_src, count)
2090+
ptr::copy_memory(p_dst, p_src, count)
20912091
}
20922092
}
20932093
}
@@ -2098,13 +2098,13 @@ pub mod raw {
20982098
* Copies `count` bytes from `src` to `dst`. The source and destination
20992099
* may overlap.
21002100
*/
2101-
pub unsafe fn memmove<T>(dst: &[mut T], src: &[const T], count: uint) {
2101+
pub unsafe fn copy_overlapping_memory<T>(dst: &[mut T], src: &[const T], count: uint) {
21022102
assert dst.len() >= count;
21032103
assert src.len() >= count;
21042104

21052105
do as_mut_buf(dst) |p_dst, _len_dst| {
21062106
do as_const_buf(src) |p_src, _len_src| {
2107-
ptr::memmove(p_dst, p_src, count)
2107+
ptr::copy_overlapping_memory(p_dst, p_src, count)
21082108
}
21092109
}
21102110
}
@@ -2163,9 +2163,9 @@ pub mod bytes {
21632163
* Copies `count` bytes from `src` to `dst`. The source and destination
21642164
* may not overlap.
21652165
*/
2166-
pub fn memcpy(dst: &[mut u8], src: &[const u8], count: uint) {
2167-
// Bound checks are done at vec::raw::memcpy.
2168-
unsafe { vec::raw::memcpy(dst, src, count) }
2166+
pub fn copy_memory(dst: &[mut u8], src: &[const u8], count: uint) {
2167+
// Bound checks are done at vec::raw::copy_memory.
2168+
unsafe { vec::raw::copy_memory(dst, src, count) }
21692169
}
21702170

21712171
/**
@@ -2174,9 +2174,9 @@ pub mod bytes {
21742174
* Copies `count` bytes from `src` to `dst`. The source and destination
21752175
* may overlap.
21762176
*/
2177-
pub fn memmove(dst: &[mut u8], src: &[const u8], count: uint) {
2178-
// Bound checks are done at vec::raw::memmove.
2179-
unsafe { vec::raw::memmove(dst, src, count) }
2177+
pub fn copy_overlapping_memory(dst: &[mut u8], src: &[const u8], count: uint) {
2178+
// Bound checks are done at vec::raw::copy_overlapping_memory.
2179+
unsafe { vec::raw::copy_overlapping_memory(dst, src, count) }
21802180
}
21812181
}
21822182

@@ -3879,10 +3879,10 @@ mod tests {
38793879
#[test]
38803880
#[should_fail]
38813881
#[ignore(cfg(windows))]
3882-
fn test_memcpy_oob() unsafe {
3882+
fn test_copy_memory_oob() unsafe {
38833883
let a = [mut 1, 2, 3, 4];
38843884
let b = [1, 2, 3, 4, 5];
3885-
raw::memcpy(a, b, 5);
3885+
raw::copy_memory(a, b, 5);
38863886
}
38873887

38883888
}

src/libstd/net_tcp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ impl TcpSocketBuf: io::Reader {
826826
let mut data = ~[];
827827
self.data.buf <-> data;
828828

829-
vec::bytes::memcpy(buf, vec::view(data, 0, data.len()), count);
829+
vec::bytes::copy_memory(buf, vec::view(data, 0, data.len()), count);
830830

831831
self.data.buf.push_all(vec::view(data, count, data.len()));
832832

0 commit comments

Comments
 (0)