Skip to content

Commit 74d9de7

Browse files
committed
auto merge of #6979 : thestinger/rust/libc, r=brson
LLVM provides these functions as intrinsics, and will generate calls to libc when appropriate. They are exposed in the `ptr` module as `copy_nonoverlapping_memory`, `copy_memory` and `set_memory`. @graydon: r?
2 parents 5d2cadb + 8bcefef commit 74d9de7

File tree

2 files changed

+5
-36
lines changed

2 files changed

+5
-36
lines changed

src/libstd/libc.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ pub use libc::funcs::c95::stdlib::{free, getenv, labs, malloc, rand};
159159
pub use libc::funcs::c95::stdlib::{realloc, srand, strtod, strtol};
160160
pub use libc::funcs::c95::stdlib::{strtoul, system};
161161

162-
pub use libc::funcs::c95::string::{memchr, memcmp, memcpy, memmove};
163-
pub use libc::funcs::c95::string::{memset, strcat, strchr, strcmp};
162+
pub use libc::funcs::c95::string::{memchr, memcmp};
163+
pub use libc::funcs::c95::string::{strcat, strchr, strcmp};
164164
pub use libc::funcs::c95::string::{strcoll, strcpy, strcspn, strerror};
165165
pub use libc::funcs::c95::string::{strlen, strncat, strncmp, strncpy};
166166
pub use libc::funcs::c95::string::{strpbrk, strrchr, strspn, strstr};
@@ -1452,26 +1452,17 @@ pub mod funcs {
14521452
-> size_t;
14531453
unsafe fn wcslen(buf: *wchar_t) -> size_t;
14541454

1455+
// Omitted: memcpy, memmove, memset (provided by LLVM)
1456+
14551457
// These are fine to execute on the Rust stack. They must be,
14561458
// in fact, because LLVM generates calls to them!
14571459
#[rust_stack]
14581460
#[inline(always)]
1459-
unsafe fn memcpy(s: *c_void, ct: *c_void, n: size_t)
1460-
-> *c_void;
1461-
#[rust_stack]
1462-
#[inline(always)]
1463-
unsafe fn memmove(s: *c_void, ct: *c_void, n: size_t)
1464-
-> *c_void;
1465-
#[rust_stack]
1466-
#[inline(always)]
14671461
unsafe fn memcmp(cx: *c_void, ct: *c_void, n: size_t)
14681462
-> c_int;
14691463
#[rust_stack]
14701464
#[inline(always)]
14711465
unsafe fn memchr(cx: *c_void, c: c_int, n: size_t) -> *c_void;
1472-
#[rust_stack]
1473-
#[inline(always)]
1474-
unsafe fn memset(s: *c_void, c: c_int, n: size_t) -> *c_void;
14751466
}
14761467
}
14771468
}

src/libstd/ptr.rs

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,6 @@ use unstable::intrinsics;
2020
#[cfg(not(test))] use cmp::{Eq, Ord};
2121
use uint;
2222

23-
#[cfg(stage0)]
24-
pub mod libc_ {
25-
use libc::c_void;
26-
use libc;
27-
28-
#[nolink]
29-
#[abi = "cdecl"]
30-
pub extern {
31-
#[rust_stack]
32-
unsafe fn memset(dest: *mut c_void,
33-
c: libc::c_int,
34-
len: libc::size_t)
35-
-> *c_void;
36-
}
37-
}
38-
3923
/// Calculate the offset from a pointer
4024
#[inline(always)]
4125
pub fn offset<T>(ptr: *T, count: uint) -> *T {
@@ -178,13 +162,6 @@ pub unsafe fn copy_nonoverlapping_memory<T>(dst: *mut T, src: *const T, count: u
178162
memcpy64(dst, src as *T, count as u64);
179163
}
180164

181-
#[inline(always)]
182-
#[cfg(stage0)]
183-
pub unsafe fn set_memory<T>(dst: *mut T, c: int, count: uint) {
184-
let n = count * sys::size_of::<T>();
185-
libc_::memset(dst as *mut c_void, c as libc::c_int, n as size_t);
186-
}
187-
188165
/**
189166
* Invokes memset on the specified pointer, setting `count` bytes of memory
190167
* starting at `dst` to `c`.
@@ -601,6 +578,7 @@ pub mod ptr_tests {
601578
}
602579

603580
#[test]
581+
#[cfg(not(stage0))]
604582
fn test_set_memory() {
605583
let mut xs = [0u8, ..20];
606584
let ptr = vec::raw::to_mut_ptr(xs);

0 commit comments

Comments
 (0)