Skip to content

Commit 05cd1d4

Browse files
committed
---
yaml --- r: 130483 b: refs/heads/try c: 6d8b5c9 h: refs/heads/master i: 130481: 25bc5fb 130479: c03bcdc v: v3
1 parent eeb7e5a commit 05cd1d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+865
-543
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
refs/heads/master: c964cb229bd342bdeb0b4506c3a6d32b03e575f6
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 67b97ab6d2b7de9b69fd97dc171fcf8feec932ff
5-
refs/heads/try: 38bf999f4a5337022211c9b990fcb7dfe0bccf32
5+
refs/heads/try: 6d8b5c9f7d1347b715242a837fba87a01ae61d7e
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c

branches/try/src/libcollections/bitv.rs

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -95,20 +95,6 @@ fn match_words <'a,'b>(a: &'a Bitv, b: &'b Bitv) -> (MatchWords<'a>, MatchWords<
9595
static TRUE: bool = true;
9696
static FALSE: bool = false;
9797

98-
#[deriving(Clone)]
99-
struct SmallBitv {
100-
/// only the lowest nbits of this value are used. the rest is undefined.
101-
bits: uint
102-
}
103-
104-
#[deriving(Clone)]
105-
struct BigBitv {
106-
storage: Vec<uint>
107-
}
108-
109-
#[deriving(Clone)]
110-
enum BitvVariant { Big(BigBitv), Small(SmallBitv) }
111-
11298
/// The bitvector type.
11399
///
114100
/// # Example
@@ -1653,6 +1639,7 @@ impl<'a> Iterator<uint> for TwoBitPositions<'a> {
16531639
#[cfg(test)]
16541640
mod tests {
16551641
use std::prelude::*;
1642+
use std::iter::range_step;
16561643
use std::uint;
16571644
use std::rand;
16581645
use std::rand::Rng;
@@ -2046,12 +2033,14 @@ mod tests {
20462033

20472034
#[test]
20482035
fn test_bitv_iterator() {
2049-
let bools = [true, false, true, true];
2036+
let bools = vec![true, false, true, true];
20502037
let bitv: Bitv = bools.iter().map(|n| *n).collect();
20512038

2052-
for (act, &ex) in bitv.iter().zip(bools.iter()) {
2053-
assert_eq!(ex, act);
2054-
}
2039+
assert_eq!(bitv.iter().collect::<Vec<bool>>(), bools)
2040+
2041+
let long = Vec::from_fn(10000, |i| i % 2 == 0);
2042+
let bitv: Bitv = long.iter().map(|n| *n).collect();
2043+
assert_eq!(bitv.iter().collect::<Vec<bool>>(), long)
20552044
}
20562045

20572046
#[test]
@@ -2061,6 +2050,12 @@ mod tests {
20612050

20622051
let idxs: Vec<uint> = bitv.iter().collect();
20632052
assert_eq!(idxs, vec!(0, 2, 3));
2053+
2054+
let long: BitvSet = range(0u, 10000).map(|n| n % 2 == 0).collect();
2055+
let real = range_step(0, 10000, 2).collect::<Vec<uint>>();
2056+
2057+
let idxs: Vec<uint> = long.iter().collect();
2058+
assert_eq!(idxs, real);
20642059
}
20652060

20662061
#[test]
@@ -2574,7 +2569,7 @@ mod tests {
25742569
}
25752570

25762571
#[bench]
2577-
fn bench_bitv_big(b: &mut Bencher) {
2572+
fn bench_bitv_set_big_fixed(b: &mut Bencher) {
25782573
let mut r = rng();
25792574
let mut bitv = Bitv::with_capacity(BENCH_BITS, false);
25802575
b.iter(|| {
@@ -2586,7 +2581,19 @@ mod tests {
25862581
}
25872582

25882583
#[bench]
2589-
fn bench_bitv_small(b: &mut Bencher) {
2584+
fn bench_bitv_set_big_variable(b: &mut Bencher) {
2585+
let mut r = rng();
2586+
let mut bitv = Bitv::with_capacity(BENCH_BITS, false);
2587+
b.iter(|| {
2588+
for i in range(0u, 100) {
2589+
bitv.set((r.next_u32() as uint) % BENCH_BITS, r.gen());
2590+
}
2591+
&bitv
2592+
})
2593+
}
2594+
2595+
#[bench]
2596+
fn bench_bitv_set_small(b: &mut Bencher) {
25902597
let mut r = rng();
25912598
let mut bitv = Bitv::with_capacity(uint::BITS, false);
25922599
b.iter(|| {
@@ -2598,7 +2605,7 @@ mod tests {
25982605
}
25992606

26002607
#[bench]
2601-
fn bench_bitv_set_small(b: &mut Bencher) {
2608+
fn bench_bitvset_small(b: &mut Bencher) {
26022609
let mut r = rng();
26032610
let mut bitv = BitvSet::new();
26042611
b.iter(|| {
@@ -2610,7 +2617,7 @@ mod tests {
26102617
}
26112618

26122619
#[bench]
2613-
fn bench_bitv_set_big(b: &mut Bencher) {
2620+
fn bench_bitvset_big(b: &mut Bencher) {
26142621
let mut r = rng();
26152622
let mut bitv = BitvSet::new();
26162623
b.iter(|| {

branches/try/src/libcollections/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl<T> Rawlink<T> {
9090
/// Convert the `Rawlink` into an Option value
9191
fn resolve_immut<'a>(&self) -> Option<&'a T> {
9292
unsafe {
93-
mem::transmute(self.p.to_option())
93+
self.p.as_ref()
9494
}
9595
}
9696

branches/try/src/libcore/ptr.rs

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,27 +256,46 @@ pub unsafe fn position<T>(buf: *const T, f: |&T| -> bool) -> uint {
256256
pub trait RawPtr<T> {
257257
/// Returns the null pointer.
258258
fn null() -> Self;
259+
259260
/// Returns true if the pointer is equal to the null pointer.
260261
fn is_null(&self) -> bool;
262+
261263
/// Returns true if the pointer is not equal to the null pointer.
262264
fn is_not_null(&self) -> bool { !self.is_null() }
265+
263266
/// Returns the value of this pointer (ie, the address it points to)
264267
fn to_uint(&self) -> uint;
265-
/// Returns `None` if the pointer is null, or else returns the value wrapped
266-
/// in `Some`.
268+
269+
/// Returns `None` if the pointer is null, or else returns a reference to the
270+
/// value wrapped in `Some`.
267271
///
268272
/// # Safety Notes
269273
///
270-
/// While this method is useful for null-safety, it is important to note
271-
/// that this is still an unsafe operation because the returned value could
272-
/// be pointing to invalid memory.
273-
unsafe fn to_option(&self) -> Option<&T>;
274+
/// While this method and its mutable counterpart are useful for null-safety,
275+
/// it is important to note that this is still an unsafe operation because
276+
/// the returned value could be pointing to invalid memory.
277+
unsafe fn as_ref<'a>(&self) -> Option<&'a T>;
278+
279+
/// A synonym for `as_ref`, except with incorrect lifetime semantics
280+
#[deprecated="Use `as_ref` instead"]
281+
unsafe fn to_option<'a>(&'a self) -> Option<&'a T> {
282+
mem::transmute(self.as_ref())
283+
}
284+
274285
/// Calculates the offset from a pointer. The offset *must* be in-bounds of
275286
/// the object, or one-byte-past-the-end. `count` is in units of T; e.g. a
276287
/// `count` of 3 represents a pointer offset of `3 * sizeof::<T>()` bytes.
277288
unsafe fn offset(self, count: int) -> Self;
278289
}
279290

291+
/// Methods on mutable raw pointers
292+
pub trait RawMutPtr<T>{
293+
/// Returns `None` if the pointer is null, or else returns a mutable reference
294+
/// to the value wrapped in `Some`. As with `as_ref`, this is unsafe because
295+
/// it cannot verify the validity of the returned pointer.
296+
unsafe fn as_mut<'a>(&self) -> Option<&'a mut T>;
297+
}
298+
280299
impl<T> RawPtr<T> for *const T {
281300
#[inline]
282301
fn null() -> *const T { null() }
@@ -293,7 +312,7 @@ impl<T> RawPtr<T> for *const T {
293312
}
294313

295314
#[inline]
296-
unsafe fn to_option(&self) -> Option<&T> {
315+
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
297316
if self.is_null() {
298317
None
299318
} else {
@@ -318,7 +337,7 @@ impl<T> RawPtr<T> for *mut T {
318337
}
319338

320339
#[inline]
321-
unsafe fn to_option(&self) -> Option<&T> {
340+
unsafe fn as_ref<'a>(&self) -> Option<&'a T> {
322341
if self.is_null() {
323342
None
324343
} else {
@@ -327,6 +346,17 @@ impl<T> RawPtr<T> for *mut T {
327346
}
328347
}
329348

349+
impl<T> RawMutPtr<T> for *mut T {
350+
#[inline]
351+
unsafe fn as_mut<'a>(&self) -> Option<&'a mut T> {
352+
if self.is_null() {
353+
None
354+
} else {
355+
Some(&mut **self)
356+
}
357+
}
358+
}
359+
330360
// Equality for pointers
331361
impl<T> PartialEq for *const T {
332362
#[inline]

branches/try/src/libcoretest/ptr.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,44 @@ fn test_is_null() {
102102
}
103103

104104
#[test]
105-
fn test_to_option() {
105+
fn test_as_ref() {
106106
unsafe {
107107
let p: *const int = null();
108-
assert_eq!(p.to_option(), None);
108+
assert_eq!(p.as_ref(), None);
109109

110110
let q: *const int = &2;
111-
assert_eq!(q.to_option().unwrap(), &2);
111+
assert_eq!(q.as_ref().unwrap(), &2);
112112

113113
let p: *mut int = mut_null();
114-
assert_eq!(p.to_option(), None);
114+
assert_eq!(p.as_ref(), None);
115115

116116
let q: *mut int = &mut 2;
117-
assert_eq!(q.to_option().unwrap(), &2);
117+
assert_eq!(q.as_ref().unwrap(), &2);
118+
119+
// Lifetime inference
120+
let u = 2i;
121+
{
122+
let p: *const int = &u as *const _;
123+
assert_eq!(p.as_ref().unwrap(), &2);
124+
}
125+
}
126+
}
127+
128+
#[test]
129+
fn test_as_mut() {
130+
unsafe {
131+
let p: *mut int = mut_null();
132+
assert!(p.as_mut() == None);
133+
134+
let q: *mut int = &mut 2;
135+
assert!(q.as_mut().unwrap() == &mut 2);
136+
137+
// Lifetime inference
138+
let mut u = 2i;
139+
{
140+
let p: *mut int = &mut u as *mut _;
141+
assert!(p.as_mut().unwrap() == &mut 2);
142+
}
118143
}
119144
}
120145

branches/try/src/liblibc/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2965,12 +2965,14 @@ pub mod consts {
29652965
pub static AF_INET6: c_int = 10;
29662966
pub static SOCK_STREAM: c_int = 2;
29672967
pub static SOCK_DGRAM: c_int = 1;
2968+
pub static SOCK_RAW: c_int = 3;
29682969
pub static IPPROTO_TCP: c_int = 6;
29692970
pub static IPPROTO_IP: c_int = 0;
29702971
pub static IPPROTO_IPV6: c_int = 41;
29712972
pub static IP_MULTICAST_TTL: c_int = 33;
29722973
pub static IP_MULTICAST_LOOP: c_int = 34;
29732974
pub static IP_TTL: c_int = 2;
2975+
pub static IP_HDRINCL: c_int = 3;
29742976
pub static IP_ADD_MEMBERSHIP: c_int = 35;
29752977
pub static IP_DROP_MEMBERSHIP: c_int = 36;
29762978
pub static IPV6_ADD_MEMBERSHIP: c_int = 20;
@@ -3021,8 +3023,12 @@ pub mod consts {
30213023
pub mod extra {
30223024
use types::os::arch::c95::c_int;
30233025

3026+
pub static AF_PACKET : c_int = 17;
3027+
pub static IPPROTO_RAW : c_int = 255;
3028+
30243029
pub static O_RSYNC : c_int = 16400;
30253030
pub static O_DSYNC : c_int = 16;
3031+
pub static O_NONBLOCK : c_int = 128;
30263032
pub static O_SYNC : c_int = 16400;
30273033

30283034
pub static PROT_GROWSDOWN : c_int = 0x01000000;

branches/try/src/liblog/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl Drop for DefaultLogger {
282282
pub fn log(level: u32, loc: &'static LogLocation, args: &fmt::Arguments) {
283283
// Test the literal string from args against the current filter, if there
284284
// is one.
285-
match unsafe { FILTER.to_option() } {
285+
match unsafe { FILTER.as_ref() } {
286286
Some(filter) if filter.is_match(args.to_string().as_slice()) => return,
287287
_ => {}
288288
}

0 commit comments

Comments
 (0)