Skip to content

Commit 6755edc

Browse files
committed
---
yaml --- r: 116735 b: refs/heads/snap-stage3 c: d64f18c h: refs/heads/master i: 116733: 8277969 116731: 3757f00 116727: c1dffa2 116719: 1df9534 116703: 7da4782 116671: 9ee6fce 116607: 06953f3 116479: e51a9cb 116223: 7b635a0 115711: c1fdba7 114687: 85a9d1d v: v3
1 parent 063296a commit 6755edc

36 files changed

+697
-244
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: bee4e6adac17f87b1cdc26ab69f8c0f5d82575a3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 09eb95f24165b2a7eec6a599b0a4bad86ff6892d
4+
refs/heads/snap-stage3: d64f18c490981f33f33e9c24e1ed1316e63f11fc
55
refs/heads/try: 009d898a9422ac04c1aa60c0e9aff3abc5fa4672
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libarena/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ impl<T> TypedArenaChunk<T> {
406406
None => {}
407407
Some(mut next) => {
408408
// We assume that the next chunk is completely filled.
409-
next.destroy(next.capacity)
409+
let capacity = next.capacity;
410+
next.destroy(capacity)
410411
}
411412
}
412413
}

branches/snap-stage3/src/libcollections/ringbuf.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ impl<T> Deque<T> for RingBuf<T> {
6666

6767
/// Return a mutable reference to the last element in the RingBuf
6868
fn back_mut<'a>(&'a mut self) -> Option<&'a mut T> {
69-
if self.nelts > 0 { Some(self.get_mut(self.nelts - 1)) } else { None }
69+
let nelts = self.nelts;
70+
if nelts > 0 { Some(self.get_mut(nelts - 1)) } else { None }
7071
}
7172

7273
/// Remove and return the first element in the RingBuf, or None if it is empty

branches/snap-stage3/src/libcollections/vec.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ impl<T> Vec<T> {
114114
unsafe {
115115
let mut xs = Vec::with_capacity(length);
116116
while xs.len < length {
117-
ptr::write(xs.as_mut_slice().unsafe_mut_ref(xs.len), op(xs.len));
117+
let len = xs.len;
118+
ptr::write(xs.as_mut_slice().unsafe_mut_ref(len), op(len));
118119
xs.len += 1;
119120
}
120121
xs
@@ -210,7 +211,8 @@ impl<T: Clone> Vec<T> {
210211
unsafe {
211212
let mut xs = Vec::with_capacity(length);
212213
while xs.len < length {
213-
ptr::write(xs.as_mut_slice().unsafe_mut_ref(xs.len),
214+
let len = xs.len;
215+
ptr::write(xs.as_mut_slice().unsafe_mut_ref(len),
214216
value.clone());
215217
xs.len += 1;
216218
}
@@ -321,9 +323,10 @@ impl<T:Clone> Clone for Vec<T> {
321323
let this_slice = self.as_slice();
322324
while vector.len < len {
323325
unsafe {
326+
let len = vector.len;
324327
ptr::write(
325-
vector.as_mut_slice().unsafe_mut_ref(vector.len),
326-
this_slice.unsafe_ref(vector.len).clone());
328+
vector.as_mut_slice().unsafe_mut_ref(len),
329+
this_slice.unsafe_ref(len).clone());
327330
}
328331
vector.len += 1;
329332
}

branches/snap-stage3/src/libcore/num/int_macros.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,33 @@ mod tests {
113113
assert!((0b1111001 as $T).count_zeros() == BITS as $T - 5);
114114
}
115115

116+
#[test]
117+
fn test_swap_bytes() {
118+
let n: $T = 0b0101100; assert_eq!(n.swap_bytes().swap_bytes(), n);
119+
let n: $T = 0b0100001; assert_eq!(n.swap_bytes().swap_bytes(), n);
120+
let n: $T = 0b1111001; assert_eq!(n.swap_bytes().swap_bytes(), n);
121+
122+
// Swapping these should make no difference
123+
let n: $T = 0; assert_eq!(n.swap_bytes(), n);
124+
let n: $T = -1; assert_eq!(n.swap_bytes(), n);
125+
}
126+
127+
#[test]
128+
fn test_rotate() {
129+
let n: $T = 0b0101100; assert_eq!(n.rotate_left(6).rotate_right(2).rotate_right(4), n);
130+
let n: $T = 0b0100001; assert_eq!(n.rotate_left(3).rotate_left(2).rotate_right(5), n);
131+
let n: $T = 0b1111001; assert_eq!(n.rotate_left(6).rotate_right(2).rotate_right(4), n);
132+
133+
// Rotating these should make no difference
134+
//
135+
// We test using 124 bits because to ensure that overlong bit shifts do
136+
// not cause undefined behaviour. See #10183.
137+
let n: $T = 0; assert_eq!(n.rotate_left(124), n);
138+
let n: $T = -1; assert_eq!(n.rotate_left(124), n);
139+
let n: $T = 0; assert_eq!(n.rotate_right(124), n);
140+
let n: $T = -1; assert_eq!(n.rotate_right(124), n);
141+
}
142+
116143
#[test]
117144
fn test_signed_checked_div() {
118145
assert!(10i.checked_div(&2) == Some(5));

branches/snap-stage3/src/libcore/num/mod.rs

Lines changed: 98 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -436,57 +436,135 @@ pub trait Bitwise: Bounded
436436
/// assert_eq!(n.trailing_zeros(), 3);
437437
/// ```
438438
fn trailing_zeros(&self) -> Self;
439+
440+
/// Reverses the byte order of a binary number.
441+
///
442+
/// # Example
443+
///
444+
/// ```rust
445+
/// use std::num::Bitwise;
446+
///
447+
/// let n = 0x0123456789ABCDEFu64;
448+
/// let m = 0xEFCDAB8967452301u64;
449+
/// assert_eq!(n.swap_bytes(), m);
450+
/// ```
451+
fn swap_bytes(&self) -> Self;
452+
453+
/// Shifts the bits to the left by a specified amount amount, `r`, wrapping
454+
/// the truncated bits to the end of the resulting value.
455+
///
456+
/// # Example
457+
///
458+
/// ```rust
459+
/// use std::num::Bitwise;
460+
///
461+
/// let n = 0x0123456789ABCDEFu64;
462+
/// let m = 0x3456789ABCDEF012u64;
463+
/// assert_eq!(n.rotate_left(12), m);
464+
/// ```
465+
fn rotate_left(&self, r: uint) -> Self;
466+
467+
/// Shifts the bits to the right by a specified amount amount, `r`, wrapping
468+
/// the truncated bits to the beginning of the resulting value.
469+
///
470+
/// # Example
471+
///
472+
/// ```rust
473+
/// use std::num::Bitwise;
474+
///
475+
/// let n = 0x0123456789ABCDEFu64;
476+
/// let m = 0xDEF0123456789ABCu64;
477+
/// assert_eq!(n.rotate_right(12), m);
478+
/// ```
479+
fn rotate_right(&self, r: uint) -> Self;
439480
}
440481

482+
/// Swapping a single byte does nothing. This is unsafe to be consistent with
483+
/// the other `bswap` intrinsics.
484+
#[inline]
485+
unsafe fn bswap8(x: u8) -> u8 { x }
486+
441487
macro_rules! bitwise_impl(
442-
($t:ty, $co:path, $lz:path, $tz:path) => {
488+
($t:ty, $bits:expr, $co:ident, $lz:ident, $tz:ident, $bs:path) => {
443489
impl Bitwise for $t {
444490
#[inline]
445-
fn count_ones(&self) -> $t { unsafe { $co(*self) } }
491+
fn count_ones(&self) -> $t { unsafe { intrinsics::$co(*self) } }
446492

447493
#[inline]
448-
fn leading_zeros(&self) -> $t { unsafe { $lz(*self) } }
494+
fn leading_zeros(&self) -> $t { unsafe { intrinsics::$lz(*self) } }
449495

450496
#[inline]
451-
fn trailing_zeros(&self) -> $t { unsafe { $tz(*self) } }
497+
fn trailing_zeros(&self) -> $t { unsafe { intrinsics::$tz(*self) } }
498+
499+
#[inline]
500+
fn swap_bytes(&self) -> $t { unsafe { $bs(*self) } }
501+
502+
#[inline]
503+
fn rotate_left(&self, r: uint) -> $t {
504+
// Protect against undefined behaviour for overlong bit shifts
505+
let r = r % $bits;
506+
(*self << r) | (*self >> ($bits - r))
507+
}
508+
509+
#[inline]
510+
fn rotate_right(&self, r: uint) -> $t {
511+
// Protect against undefined behaviour for overlong bit shifts
512+
let r = r % $bits;
513+
(*self >> r) | (*self << ($bits - r))
514+
}
452515
}
453516
}
454517
)
455518

456519
macro_rules! bitwise_cast_impl(
457-
($t:ty, $t_cast:ty, $co:path, $lz:path, $tz:path) => {
520+
($t:ty, $t_cast:ty, $bits:expr, $co:ident, $lz:ident, $tz:ident, $bs:path) => {
458521
impl Bitwise for $t {
459522
#[inline]
460-
fn count_ones(&self) -> $t { unsafe { $co(*self as $t_cast) as $t } }
523+
fn count_ones(&self) -> $t { unsafe { intrinsics::$co(*self as $t_cast) as $t } }
524+
525+
#[inline]
526+
fn leading_zeros(&self) -> $t { unsafe { intrinsics::$lz(*self as $t_cast) as $t } }
527+
528+
#[inline]
529+
fn trailing_zeros(&self) -> $t { unsafe { intrinsics::$tz(*self as $t_cast) as $t } }
461530

462531
#[inline]
463-
fn leading_zeros(&self) -> $t { unsafe { $lz(*self as $t_cast) as $t } }
532+
fn swap_bytes(&self) -> $t { unsafe { $bs(*self as $t_cast) as $t } }
464533

465534
#[inline]
466-
fn trailing_zeros(&self) -> $t { unsafe { $tz(*self as $t_cast) as $t } }
535+
fn rotate_left(&self, r: uint) -> $t {
536+
// cast to prevent the sign bit from being corrupted
537+
(*self as $t_cast).rotate_left(r) as $t
538+
}
539+
540+
#[inline]
541+
fn rotate_right(&self, r: uint) -> $t {
542+
// cast to prevent the sign bit from being corrupted
543+
(*self as $t_cast).rotate_right(r) as $t
544+
}
467545
}
468546
}
469547
)
470548

471549
#[cfg(target_word_size = "32")]
472-
bitwise_cast_impl!(uint, u32, intrinsics::ctpop32, intrinsics::ctlz32, intrinsics::cttz32)
550+
bitwise_cast_impl!(uint, u32, 32, ctpop32, ctlz32, cttz32, intrinsics::bswap32)
473551
#[cfg(target_word_size = "64")]
474-
bitwise_cast_impl!(uint, u64, intrinsics::ctpop64, intrinsics::ctlz64, intrinsics::cttz64)
552+
bitwise_cast_impl!(uint, u64, 64, ctpop64, ctlz64, cttz64, intrinsics::bswap64)
475553

476-
bitwise_impl!(u8, intrinsics::ctpop8, intrinsics::ctlz8, intrinsics::cttz8)
477-
bitwise_impl!(u16, intrinsics::ctpop16, intrinsics::ctlz16, intrinsics::cttz16)
478-
bitwise_impl!(u32, intrinsics::ctpop32, intrinsics::ctlz32, intrinsics::cttz32)
479-
bitwise_impl!(u64, intrinsics::ctpop64, intrinsics::ctlz64, intrinsics::cttz64)
554+
bitwise_impl!(u8, 8, ctpop8, ctlz8, cttz8, bswap8)
555+
bitwise_impl!(u16, 16, ctpop16, ctlz16, cttz16, intrinsics::bswap16)
556+
bitwise_impl!(u32, 32, ctpop32, ctlz32, cttz32, intrinsics::bswap32)
557+
bitwise_impl!(u64, 64, ctpop64, ctlz64, cttz64, intrinsics::bswap64)
480558

481559
#[cfg(target_word_size = "32")]
482-
bitwise_cast_impl!(int, u32, intrinsics::ctpop32, intrinsics::ctlz32, intrinsics::cttz32)
560+
bitwise_cast_impl!(int, u32, 32, ctpop32, ctlz32, cttz32, intrinsics::bswap32)
483561
#[cfg(target_word_size = "64")]
484-
bitwise_cast_impl!(int, u64, intrinsics::ctpop64, intrinsics::ctlz64, intrinsics::cttz64)
562+
bitwise_cast_impl!(int, u64, 64, ctpop64, ctlz64, cttz64, intrinsics::bswap64)
485563

486-
bitwise_cast_impl!(i8, u8, intrinsics::ctpop8, intrinsics::ctlz8, intrinsics::cttz8)
487-
bitwise_cast_impl!(i16, u16, intrinsics::ctpop16, intrinsics::ctlz16, intrinsics::cttz16)
488-
bitwise_cast_impl!(i32, u32, intrinsics::ctpop32, intrinsics::ctlz32, intrinsics::cttz32)
489-
bitwise_cast_impl!(i64, u64, intrinsics::ctpop64, intrinsics::ctlz64, intrinsics::cttz64)
564+
bitwise_cast_impl!(i8, u8, 8, ctpop8, ctlz8, cttz8, bswap8)
565+
bitwise_cast_impl!(i16, u16, 16, ctpop16, ctlz16, cttz16, intrinsics::bswap16)
566+
bitwise_cast_impl!(i32, u32, 32, ctpop32, ctlz32, cttz32, intrinsics::bswap32)
567+
bitwise_cast_impl!(i64, u64, 64, ctpop64, ctlz64, cttz64, intrinsics::bswap64)
490568

491569
/// Specifies the available operations common to all of Rust's core numeric primitives.
492570
/// These may not always make sense from a purely mathematical point of view, but

branches/snap-stage3/src/libcore/num/uint_macros.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,33 @@ mod tests {
6464
assert!((0b1111001 as $T).count_zeros() == BITS as $T - 5);
6565
}
6666

67+
#[test]
68+
fn test_swap_bytes() {
69+
let n: $T = 0b0101100; assert_eq!(n.swap_bytes().swap_bytes(), n);
70+
let n: $T = 0b0100001; assert_eq!(n.swap_bytes().swap_bytes(), n);
71+
let n: $T = 0b1111001; assert_eq!(n.swap_bytes().swap_bytes(), n);
72+
73+
// Swapping these should make no difference
74+
let n: $T = 0; assert_eq!(n.swap_bytes(), n);
75+
let n: $T = MAX; assert_eq!(n.swap_bytes(), n);
76+
}
77+
78+
#[test]
79+
fn test_rotate() {
80+
let n: $T = 0b0101100; assert_eq!(n.rotate_left(6).rotate_right(2).rotate_right(4), n);
81+
let n: $T = 0b0100001; assert_eq!(n.rotate_left(3).rotate_left(2).rotate_right(5), n);
82+
let n: $T = 0b1111001; assert_eq!(n.rotate_left(6).rotate_right(2).rotate_right(4), n);
83+
84+
// Rotating these should make no difference
85+
//
86+
// We test using 124 bits because to ensure that overlong bit shifts do
87+
// not cause undefined behaviour. See #10183.
88+
let n: $T = 0; assert_eq!(n.rotate_left(124), n);
89+
let n: $T = MAX; assert_eq!(n.rotate_left(124), n);
90+
let n: $T = 0; assert_eq!(n.rotate_right(124), n);
91+
let n: $T = MAX; assert_eq!(n.rotate_right(124), n);
92+
}
93+
6794
#[test]
6895
fn test_unsigned_checked_div() {
6996
assert!(10u.checked_div(&2) == Some(5));

branches/snap-stage3/src/libdebug/repr.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,15 @@ impl<'a> ReprVisitor<'a> {
127127
#[inline]
128128
pub fn get<T>(&mut self, f: |&mut ReprVisitor, &T| -> bool) -> bool {
129129
unsafe {
130-
f(self, mem::transmute::<*u8,&T>(self.ptr))
130+
let ptr = self.ptr;
131+
f(self, mem::transmute::<*u8,&T>(ptr))
131132
}
132133
}
133134

134135
#[inline]
135136
pub fn visit_inner(&mut self, inner: *TyDesc) -> bool {
136-
self.visit_ptr_inner(self.ptr, inner)
137+
let ptr = self.ptr;
138+
self.visit_ptr_inner(ptr, inner)
137139
}
138140

139141
#[inline]

branches/snap-stage3/src/libnative/io/net.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -637,16 +637,15 @@ impl rtio::RtioUdpSocket for UdpSocket {
637637
mem::size_of::<libc::sockaddr_storage>() as libc::socklen_t;
638638

639639
let dolock = || self.lock_nonblocking();
640-
let doread = |nb| unsafe {
640+
let n = try!(read(fd, self.read_deadline, dolock, |nb| unsafe {
641641
let flags = if nb {c::MSG_DONTWAIT} else {0};
642642
libc::recvfrom(fd,
643643
buf.as_mut_ptr() as *mut libc::c_void,
644644
buf.len() as msglen_t,
645645
flags,
646646
storagep,
647647
&mut addrlen) as libc::c_int
648-
};
649-
let n = try!(read(fd, self.read_deadline, dolock, doread));
648+
}));
650649
sockaddr_to_addr(&storage, addrlen as uint).and_then(|addr| {
651650
Ok((n as uint, addr))
652651
})

branches/snap-stage3/src/libregex/parse/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,19 @@ impl<'a> Parser<'a> {
345345
}
346346

347347
fn push_literal(&mut self, c: char) -> Result<(), Error> {
348+
let flags = self.flags;
348349
match c {
349350
'.' => {
350-
self.push(Dot(self.flags))
351+
self.push(Dot(flags))
351352
}
352353
'^' => {
353-
self.push(Begin(self.flags))
354+
self.push(Begin(flags))
354355
}
355356
'$' => {
356-
self.push(End(self.flags))
357+
self.push(End(flags))
357358
}
358359
_ => {
359-
self.push(Literal(c, self.flags))
360+
self.push(Literal(c, flags))
360361
}
361362
}
362363
Ok(())

0 commit comments

Comments
 (0)