Skip to content

Commit 26334b6

Browse files
committed
Merge pull request #4411 from wting/4203_rename_memcpy
Rename memcpy, memmove, memset
2 parents 9bb399a + 5cfde77 commit 26334b6

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

src/libcore/io.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ impl BytesReader: Reader {
530530
let count = uint::min(len, self.bytes.len() - self.pos);
531531
532532
let view = vec::view(self.bytes, self.pos, self.bytes.len());
533-
vec::bytes::memcpy(bytes, view, count);
533+
vec::bytes::copy_memory(bytes, view, count);
534534
535535
self.pos += count;
536536
@@ -1007,7 +1007,7 @@ impl BytesWriter: Writer {
10071007
10081008
{
10091009
let view = vec::mut_view(bytes, self.pos, count);
1010-
vec::bytes::memcpy(view, v, v_len);
1010+
vec::bytes::copy_memory(view, v, v_len);
10111011
}
10121012
10131013
self.pos += v_len;

src/libcore/ptr.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ pub pure fn is_not_null<T>(ptr: *const T) -> bool { !is_null(ptr) }
122122
* and destination may not overlap.
123123
*/
124124
#[inline(always)]
125-
pub unsafe fn memcpy<T>(dst: *mut T, src: *const T, count: uint) {
125+
pub unsafe fn copy_memory<T>(dst: *mut T, src: *const T, count: uint) {
126126
let n = count * sys::size_of::<T>();
127127
libc_::memcpy(dst as *mut c_void, src as *c_void, n as size_t);
128128
}
@@ -134,13 +134,13 @@ pub unsafe fn memcpy<T>(dst: *mut T, src: *const T, count: uint) {
134134
* and destination may overlap.
135135
*/
136136
#[inline(always)]
137-
pub unsafe fn memmove<T>(dst: *mut T, src: *const T, count: uint) {
137+
pub unsafe fn copy_overlapping_memory<T>(dst: *mut T, src: *const T, count: uint) {
138138
let n = count * sys::size_of::<T>();
139139
libc_::memmove(dst as *mut c_void, src as *c_void, n as size_t);
140140
}
141141

142142
#[inline(always)]
143-
pub unsafe fn memset<T>(dst: *mut T, c: int, count: uint) {
143+
pub unsafe fn set_memory<T>(dst: *mut T, c: int, count: uint) {
144144
let n = count * sys::size_of::<T>();
145145
libc_::memset(dst as *mut c_void, c as libc::c_int, n as size_t);
146146
}
@@ -326,13 +326,13 @@ pub fn test() {
326326
let mut v0 = ~[32000u16, 32001u16, 32002u16];
327327
let mut v1 = ~[0u16, 0u16, 0u16];
328328

329-
ptr::memcpy(ptr::mut_offset(vec::raw::to_mut_ptr(v1), 1u),
329+
ptr::copy_memory(ptr::mut_offset(vec::raw::to_mut_ptr(v1), 1u),
330330
ptr::offset(vec::raw::to_ptr(v0), 1u), 1u);
331331
assert (v1[0] == 0u16 && v1[1] == 32001u16 && v1[2] == 0u16);
332-
ptr::memcpy(vec::raw::to_mut_ptr(v1),
332+
ptr::copy_memory(vec::raw::to_mut_ptr(v1),
333333
ptr::offset(vec::raw::to_ptr(v0), 2u), 1u);
334334
assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 0u16);
335-
ptr::memcpy(ptr::mut_offset(vec::raw::to_mut_ptr(v1), 2u),
335+
ptr::copy_memory(ptr::mut_offset(vec::raw::to_mut_ptr(v1), 2u),
336336
vec::raw::to_ptr(v0), 1u);
337337
assert (v1[0] == 32002u16 && v1[1] == 32001u16 && v1[2] == 32000u16);
338338
}

src/libcore/str.rs

+4-4
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

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

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

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

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

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

20922092
do as_mut_buf(dst) |p_dst, _len_dst| {
20932093
do as_const_buf(src) |p_src, _len_src| {
2094-
ptr::memcpy(p_dst, p_src, count)
2094+
ptr::copy_memory(p_dst, p_src, count)
20952095
}
20962096
}
20972097
}
@@ -2102,13 +2102,13 @@ pub mod raw {
21022102
* Copies `count` bytes from `src` to `dst`. The source and destination
21032103
* may overlap.
21042104
*/
2105-
pub unsafe fn memmove<T>(dst: &[mut T], src: &[const T], count: uint) {
2105+
pub unsafe fn copy_overlapping_memory<T>(dst: &[mut T], src: &[const T], count: uint) {
21062106
assert dst.len() >= count;
21072107
assert src.len() >= count;
21082108

21092109
do as_mut_buf(dst) |p_dst, _len_dst| {
21102110
do as_const_buf(src) |p_src, _len_src| {
2111-
ptr::memmove(p_dst, p_src, count)
2111+
ptr::copy_overlapping_memory(p_dst, p_src, count)
21122112
}
21132113
}
21142114
}
@@ -2167,9 +2167,9 @@ pub mod bytes {
21672167
* Copies `count` bytes from `src` to `dst`. The source and destination
21682168
* may not overlap.
21692169
*/
2170-
pub fn memcpy(dst: &[mut u8], src: &[const u8], count: uint) {
2171-
// Bound checks are done at vec::raw::memcpy.
2172-
unsafe { vec::raw::memcpy(dst, src, count) }
2170+
pub fn copy_memory(dst: &[mut u8], src: &[const u8], count: uint) {
2171+
// Bound checks are done at vec::raw::copy_memory.
2172+
unsafe { vec::raw::copy_memory(dst, src, count) }
21732173
}
21742174

21752175
/**
@@ -2178,9 +2178,9 @@ pub mod bytes {
21782178
* Copies `count` bytes from `src` to `dst`. The source and destination
21792179
* may overlap.
21802180
*/
2181-
pub fn memmove(dst: &[mut u8], src: &[const u8], count: uint) {
2182-
// Bound checks are done at vec::raw::memmove.
2183-
unsafe { vec::raw::memmove(dst, src, count) }
2181+
pub fn copy_overlapping_memory(dst: &[mut u8], src: &[const u8], count: uint) {
2182+
// Bound checks are done at vec::raw::copy_overlapping_memory.
2183+
unsafe { vec::raw::copy_overlapping_memory(dst, src, count) }
21842184
}
21852185
}
21862186

@@ -3896,10 +3896,10 @@ mod tests {
38963896
#[test]
38973897
#[should_fail]
38983898
#[ignore(cfg(windows))]
3899-
fn test_memcpy_oob() unsafe {
3899+
fn test_copy_memory_oob() unsafe {
39003900
let a = [mut 1, 2, 3, 4];
39013901
let b = [1, 2, 3, 4, 5];
3902-
raw::memcpy(a, b, 5);
3902+
raw::copy_memory(a, b, 5);
39033903
}
39043904

39053905
}

src/libstd/net_tcp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ impl TcpSocketBuf: io::Reader {
827827
let mut data = ~[];
828828
self.data.buf <-> data;
829829

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

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

0 commit comments

Comments
 (0)