|
21 | 21 | //! the system libc library.
|
22 | 22 |
|
23 | 23 | #![crate_name = "rlibc"]
|
24 |
| -#![experimental] |
25 | 24 | #![license = "MIT/ASL2"]
|
26 | 25 | #![crate_type = "rlib"]
|
27 | 26 | #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
28 | 27 | html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
29 | 28 | html_root_url = "http://doc.rust-lang.org/master/")]
|
| 29 | +#![feature(intrinsics)] |
30 | 30 |
|
31 |
| -#![feature(intrinsics, phase)] |
32 | 31 | #![no_std]
|
| 32 | +#![experimental] |
33 | 33 |
|
34 | 34 | // This library defines the builtin functions, so it would be a shame for
|
35 | 35 | // LLVM to optimize these function calls to themselves!
|
36 | 36 | #![no_builtins]
|
37 | 37 |
|
| 38 | +#[cfg(test)] extern crate std; |
38 | 39 | #[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; |
44 | 40 |
|
45 | 41 | // Require the offset intrinsics for LLVM to properly optimize the
|
46 | 42 | // implementations below. If pointer arithmetic is done through integers the
|
@@ -99,107 +95,11 @@ pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, n: uint) -> i32 {
|
99 | 95 | let a = *offset(s1, i as int);
|
100 | 96 | let b = *offset(s2, i as int);
|
101 | 97 | if a != b {
|
102 |
| - return a as i32 - b as i32 |
| 98 | + return (a - b) as i32 |
103 | 99 | }
|
104 | 100 | i += 1;
|
105 | 101 | }
|
106 | 102 | return 0;
|
107 | 103 | }
|
108 | 104 |
|
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 |
| -} |
| 105 | +#[test] fn work_on_windows() { } // FIXME #10872 needed for a happy windows |
0 commit comments