Skip to content

Commit 445d677

Browse files
Ilya Dmitrichenkoalexcrichton
authored andcommitted
---
yaml --- r: 132023 b: refs/heads/dist-snap c: d32fe7e h: refs/heads/master i: 132021: 6c907e2 132019: 5ef96e4 132015: 429b92f v: v3
1 parent 7d02350 commit 445d677

File tree

2 files changed

+105
-5
lines changed

2 files changed

+105
-5
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: 457a3c991d79b971be07fce75f9d0c12848fb37c
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: fcaee85ced65fae0aad4249e19ec85cbffd4d21c
9+
refs/heads/dist-snap: d32fe7e51bf520f4c0416df0dd9cdf0662ea1cbe
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librlibc/lib.rs

Lines changed: 104 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,26 @@
2121
//! the system libc library.
2222
2323
#![crate_name = "rlibc"]
24+
#![experimental]
2425
#![license = "MIT/ASL2"]
2526
#![crate_type = "rlib"]
2627
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
2728
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
2829
html_root_url = "http://doc.rust-lang.org/master/")]
29-
#![feature(intrinsics)]
3030

31+
#![feature(intrinsics, phase)]
3132
#![no_std]
32-
#![experimental]
3333

3434
// This library defines the builtin functions, so it would be a shame for
3535
// LLVM to optimize these function calls to themselves!
3636
#![no_builtins]
3737

38-
#[cfg(test)] extern crate std;
3938
#[cfg(test)] extern crate native;
39+
#[cfg(test)] extern crate test;
40+
#[cfg(test)] extern crate debug;
41+
42+
#[cfg(test)] #[phase(plugin, link)] extern crate std;
43+
#[cfg(test)] #[phase(plugin, link)] extern crate core;
4044

4145
// Require the offset intrinsics for LLVM to properly optimize the
4246
// implementations below. If pointer arithmetic is done through integers the
@@ -102,4 +106,100 @@ pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, n: uint) -> i32 {
102106
return 0;
103107
}
104108

105-
#[test] fn work_on_windows() { } // FIXME #10872 needed for a happy windows
109+
#[cfg(test)]
110+
mod test {
111+
use core::option::{Some, None};
112+
use core::iter::Iterator;
113+
use core::collections::Collection;
114+
use core::str::StrSlice;
115+
use core::slice::{MutableVector, ImmutableVector};
116+
117+
use super::{memcmp, memset, memcpy, memmove};
118+
119+
#[test]
120+
fn memcmp_single_byte_pointers() {
121+
unsafe {
122+
assert_eq!(memcmp(&0xFAu8, &0xFAu8, 1), 0x00);
123+
assert!(memcmp(&0xEFu8, &0xFEu8, 1) < 0x00);
124+
}
125+
}
126+
127+
#[test]
128+
fn memcmp_strings() {
129+
{
130+
let (x, z) = ("Hello!", "Good Bye.");
131+
let l = x.len();
132+
unsafe {
133+
assert_eq!(memcmp(x.as_ptr(), x.as_ptr(), l), 0);
134+
assert!(memcmp(x.as_ptr(), z.as_ptr(), l) > 0);
135+
assert!(memcmp(z.as_ptr(), x.as_ptr(), l) < 0);
136+
}
137+
}
138+
{
139+
let (x, z) = ("hey!", "hey.");
140+
let l = x.len();
141+
unsafe {
142+
assert!(memcmp(x.as_ptr(), z.as_ptr(), l) < 0);
143+
}
144+
}
145+
}
146+
147+
#[test]
148+
fn memset_single_byte_pointers() {
149+
let mut x: u8 = 0xFF;
150+
unsafe {
151+
memset(&mut x, 0xAA, 1);
152+
assert_eq!(x, 0xAA);
153+
memset(&mut x, 0x00, 1);
154+
assert_eq!(x, 0x00);
155+
x = 0x01;
156+
memset(&mut x, 0x12, 0);
157+
assert_eq!(x, 0x01);
158+
}
159+
}
160+
161+
#[test]
162+
fn memset_array() {
163+
let mut buffer = [b'X', .. 100];
164+
unsafe {
165+
memset(buffer.as_mut_ptr(), b'#' as i32, buffer.len());
166+
}
167+
for byte in buffer.iter() { assert_eq!(*byte, b'#'); }
168+
}
169+
170+
#[test]
171+
fn memcpy_and_memcmp_arrays() {
172+
let (src, mut dst) = ([b'X', .. 100], [b'Y', .. 100]);
173+
unsafe {
174+
assert!(memcmp(src.as_ptr(), dst.as_ptr(), 100) != 0);
175+
let _ = memcpy(dst.as_mut_ptr(), src.as_ptr(), 100);
176+
assert_eq!(memcmp(src.as_ptr(), dst.as_ptr(), 100), 0);
177+
}
178+
}
179+
180+
#[test]
181+
fn memmove_overlapping() {
182+
{
183+
let mut buffer = [ b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9' ];
184+
unsafe {
185+
memmove(&mut buffer[4], &buffer[0], 6);
186+
let mut i = 0;
187+
for byte in b"0123012345".iter() {
188+
assert_eq!(buffer[i], *byte);
189+
i += 1;
190+
}
191+
}
192+
}
193+
{
194+
let mut buffer = [ b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9' ];
195+
unsafe {
196+
memmove(&mut buffer[0], &buffer[4], 6);
197+
let mut i = 0;
198+
for byte in b"4567896789".iter() {
199+
assert_eq!(buffer[i], *byte);
200+
i += 1;
201+
}
202+
}
203+
}
204+
}
205+
}

0 commit comments

Comments
 (0)