Skip to content

int audit core::{hash, fmt}, std::sync #22700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions src/libcore/fmt/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ pub enum ExponentFormat {
pub enum SignificantDigits {
/// At most the given number of digits will be printed, truncating any
/// trailing zeroes.
DigMax(uint),
DigMax(usize),

/// Precisely the given number of digits will be printed.
DigExact(uint)
DigExact(usize)
}

/// How to emit the sign of a number.
Expand Down Expand Up @@ -240,27 +240,27 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(
// If reached left end of number, have to
// insert additional digit:
if i < 0
|| buf[i as uint] == b'-'
|| buf[i as uint] == b'+' {
for j in (i as uint + 1..end).rev() {
|| buf[i as usize] == b'-'
|| buf[i as usize] == b'+' {
for j in (i as usize + 1..end).rev() {
buf[j + 1] = buf[j];
}
buf[(i + 1) as uint] = value2ascii(1);
buf[(i + 1) as usize] = value2ascii(1);
end += 1;
break;
}

// Skip the '.'
if buf[i as uint] == b'.' { i -= 1; continue; }
if buf[i as usize] == b'.' { i -= 1; continue; }

// Either increment the digit,
// or set to 0 if max and carry the 1.
let current_digit = ascii2value(buf[i as uint]);
let current_digit = ascii2value(buf[i as usize]);
if current_digit < (radix - 1) {
buf[i as uint] = value2ascii(current_digit+1);
buf[i as usize] = value2ascii(current_digit+1);
break;
} else {
buf[i as uint] = value2ascii(0);
buf[i as usize] = value2ascii(0);
i -= 1;
}
}
Expand Down Expand Up @@ -311,7 +311,7 @@ pub fn float_to_str_bytes_common<T: Float, U, F>(

struct Filler<'a> {
buf: &'a mut [u8],
end: &'a mut uint,
end: &'a mut usize,
}

impl<'a> fmt::Write for Filler<'a> {
Expand Down
61 changes: 38 additions & 23 deletions src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,14 @@ pub trait Write {
/// traits.
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Formatter<'a> {
flags: uint,
#[cfg(not(stage0))]
flags: u32,
#[cfg(stage0)]
flags: usize,
fill: char,
align: rt::v1::Alignment,
width: Option<uint>,
precision: Option<uint>,
width: Option<usize>,
precision: Option<usize>,

buf: &'a mut (Write+'a),
curarg: slice::Iter<'a, ArgumentV1<'a>>,
Expand All @@ -140,7 +143,7 @@ pub struct ArgumentV1<'a> {

impl<'a> ArgumentV1<'a> {
#[inline(never)]
fn show_uint(x: &uint, f: &mut Formatter) -> Result {
fn show_usize(x: &usize, f: &mut Formatter) -> Result {
Display::fmt(x, f)
}

Expand All @@ -156,15 +159,22 @@ impl<'a> ArgumentV1<'a> {
}
}

#[cfg(stage0)]
#[doc(hidden)]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_uint(x: &uint) -> ArgumentV1 {
ArgumentV1::new(x, ArgumentV1::show_uint)
ArgumentV1::new(x, ArgumentV1::show_usize)
}
#[cfg(not(stage0))]
#[doc(hidden)]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn from_usize(x: &usize) -> ArgumentV1 {
ArgumentV1::new(x, ArgumentV1::show_usize)
}

fn as_uint(&self) -> Option<uint> {
if self.formatter as uint == ArgumentV1::show_uint as uint {
Some(unsafe { *(self.value as *const _ as *const uint) })
fn as_usize(&self) -> Option<usize> {
if self.formatter as usize == ArgumentV1::show_usize as usize {
Some(unsafe { *(self.value as *const _ as *const usize) })
} else {
None
}
Expand Down Expand Up @@ -194,7 +204,7 @@ impl<'a> Arguments<'a> {
/// The `pieces` array must be at least as long as `fmt` to construct
/// a valid Arguments structure. Also, any `Count` within `fmt` that is
/// `CountIsParam` or `CountIsNextParam` has to point to an argument
/// created with `argumentuint`. However, failing to do so doesn't cause
/// created with `argumentusize`. However, failing to do so doesn't cause
/// unsafety, but will ignore invalid .
#[doc(hidden)] #[inline]
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -434,15 +444,15 @@ impl<'a> Formatter<'a> {
(value.formatter)(value.value, self)
}

fn getcount(&mut self, cnt: &rt::v1::Count) -> Option<uint> {
fn getcount(&mut self, cnt: &rt::v1::Count) -> Option<usize> {
match *cnt {
rt::v1::Count::Is(n) => Some(n),
rt::v1::Count::Implied => None,
rt::v1::Count::Param(i) => {
self.args[i].as_uint()
self.args[i].as_usize()
}
rt::v1::Count::NextParam => {
self.curarg.next().and_then(|arg| arg.as_uint())
self.curarg.next().and_then(|arg| arg.as_usize())
}
}
}
Expand Down Expand Up @@ -476,12 +486,12 @@ impl<'a> Formatter<'a> {
let mut sign = None;
if !is_positive {
sign = Some('-'); width += 1;
} else if self.flags & (1 << (FlagV1::SignPlus as uint)) != 0 {
} else if self.flags & (1 << (FlagV1::SignPlus as u32)) != 0 {
sign = Some('+'); width += 1;
}

let mut prefixed = false;
if self.flags & (1 << (FlagV1::Alternate as uint)) != 0 {
if self.flags & (1 << (FlagV1::Alternate as u32)) != 0 {
prefixed = true; width += prefix.char_len();
}

Expand Down Expand Up @@ -511,7 +521,7 @@ impl<'a> Formatter<'a> {
}
// The sign and prefix goes before the padding if the fill character
// is zero
Some(min) if self.flags & (1 << (FlagV1::SignAwareZeroPad as uint)) != 0 => {
Some(min) if self.flags & (1 << (FlagV1::SignAwareZeroPad as u32)) != 0 => {
self.fill = '0';
try!(write_prefix(self));
self.with_padding(min - width, Alignment::Right, |f| {
Expand Down Expand Up @@ -581,7 +591,7 @@ impl<'a> Formatter<'a> {

/// Runs a callback, emitting the correct padding either before or
/// afterwards depending on whether right or left alignment is requested.
fn with_padding<F>(&mut self, padding: uint, default: Alignment,
fn with_padding<F>(&mut self, padding: usize, default: Alignment,
f: F) -> Result
where F: FnOnce(&mut Formatter) -> Result,
{
Expand Down Expand Up @@ -627,6 +637,11 @@ impl<'a> Formatter<'a> {
write(self.buf, fmt)
}

#[cfg(not(stage0))]
/// Flags for formatting (packed version of rt::Flag)
#[stable(feature = "rust1", since = "1.0.0")]
pub fn flags(&self) -> u32 { self.flags }
#[cfg(stage0)]
/// Flags for formatting (packed version of rt::Flag)
#[stable(feature = "rust1", since = "1.0.0")]
pub fn flags(&self) -> usize { self.flags }
Expand All @@ -641,11 +656,11 @@ impl<'a> Formatter<'a> {

/// Optionally specified integer width that the output should be
#[unstable(feature = "core", reason = "method was just created")]
pub fn width(&self) -> Option<uint> { self.width }
pub fn width(&self) -> Option<usize> { self.width }

/// Optionally specified precision for numeric types
#[unstable(feature = "core", reason = "method was just created")]
pub fn precision(&self) -> Option<uint> { self.precision }
pub fn precision(&self) -> Option<usize> { self.precision }
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down Expand Up @@ -731,9 +746,9 @@ impl Display for char {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> Pointer for *const T {
fn fmt(&self, f: &mut Formatter) -> Result {
f.flags |= 1 << (FlagV1::Alternate as uint);
let ret = LowerHex::fmt(&(*self as uint), f);
f.flags &= !(1 << (FlagV1::Alternate as uint));
f.flags |= 1 << (FlagV1::Alternate as u32);
let ret = LowerHex::fmt(&(*self as u32), f);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting the pointer to u32 loses part of it on 64bit, see #22854. Should this be usize instead?

f.flags &= !(1 << (FlagV1::Alternate as u32));
ret
}
}
Expand Down Expand Up @@ -889,7 +904,7 @@ impl<'a> Debug for &'a (any::Any+'a) {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Debug> Debug for [T] {
fn fmt(&self, f: &mut Formatter) -> Result {
if f.flags & (1 << (FlagV1::Alternate as uint)) == 0 {
if f.flags & (1 << (FlagV1::Alternate as u32)) == 0 {
try!(write!(f, "["));
}
let mut is_first = true;
Expand All @@ -901,7 +916,7 @@ impl<T: Debug> Debug for [T] {
}
try!(write!(f, "{:?}", *x))
}
if f.flags & (1 << (FlagV1::Alternate as uint)) == 0 {
if f.flags & (1 << (FlagV1::Alternate as u32)) == 0 {
try!(write!(f, "]"));
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ macro_rules! integer {
show! { $Uint with $SU }
}
}
integer! { int, uint, "i", "u" }
integer! { isize, usize, "i", "u" }
integer! { i8, u8 }
integer! { i16, u16 }
integer! { i32, u32 }
Expand Down
6 changes: 5 additions & 1 deletion src/libcore/fmt/rt/v1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ pub struct FormatSpec {
pub fill: char,
#[stable(feature = "rust1", since = "1.0.0")]
pub align: Alignment,
#[cfg(stage0)]
#[stable(feature = "rust1", since = "1.0.0")]
pub flags: uint,
pub flags: usize,
#[cfg(not(stage0))]
#[stable(feature = "rust1", since = "1.0.0")]
pub flags: u32,
#[stable(feature = "rust1", since = "1.0.0")]
pub precision: Count,
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/hash/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
//!
//! #[derive(Hash)]
//! struct Person {
//! id: uint,
//! id: u32,
//! name: String,
//! phone: u64,
//! }
Expand All @@ -38,7 +38,7 @@
//! use std::hash::{hash, Hash, Hasher, SipHasher};
//!
//! struct Person {
//! id: uint,
//! id: u32,
//! name: String,
//! phone: u64,
//! }
Expand Down
4 changes: 2 additions & 2 deletions src/libcore/hash/sip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ use super::Hasher;
pub struct SipHasher {
k0: u64,
k1: u64,
length: uint, // how many bytes we've processed
length: usize, // how many bytes we've processed
v0: u64, // hash state
v1: u64,
v2: u64,
v3: u64,
tail: u64, // unprocessed bytes le
ntail: uint, // how many bytes in tail are valid
ntail: usize, // how many bytes in tail are valid
}

// sadly, these macro definitions can't appear later,
Expand Down
25 changes: 12 additions & 13 deletions src/libfmt_macros/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
html_root_url = "http://doc.rust-lang.org/nightly/",
html_playground_url = "http://play.rust-lang.org/")]

#![feature(int_uint)]
#![feature(staged_api)]
#![feature(unicode)]

Expand Down Expand Up @@ -65,7 +64,7 @@ pub struct FormatSpec<'a> {
/// Optionally specified alignment
pub align: Alignment,
/// Packed version of various flags provided
pub flags: uint,
pub flags: u32,
/// The integer precision to use
pub precision: Count<'a>,
/// The string width requested for the resulting format
Expand All @@ -82,7 +81,7 @@ pub enum Position<'a> {
/// The argument will be in the next position. This is the default.
ArgumentNext,
/// The argument is located at a specific index.
ArgumentIs(uint),
ArgumentIs(usize),
/// The argument has a name.
ArgumentNamed(&'a str),
}
Expand Down Expand Up @@ -121,11 +120,11 @@ pub enum Flag {
#[derive(Copy, PartialEq)]
pub enum Count<'a> {
/// The count is specified explicitly.
CountIs(uint),
CountIs(usize),
/// The count is specified by the argument with the given name.
CountIsName(&'a str),
/// The count is specified by the argument at the given index.
CountIsParam(uint),
CountIsParam(usize),
/// The count is specified by the next parameter.
CountIsNextParam,
/// The count is implied and cannot be explicitly specified.
Expand Down Expand Up @@ -237,7 +236,7 @@ impl<'a> Parser<'a> {

/// Parses all of a string which is to be considered a "raw literal" in a
/// format string. This is everything outside of the braces.
fn string(&mut self, start: uint) -> &'a str {
fn string(&mut self, start: usize) -> &'a str {
loop {
// we may not consume the character, so clone the iterator
match self.cur.clone().next() {
Expand Down Expand Up @@ -314,13 +313,13 @@ impl<'a> Parser<'a> {
}
// Sign flags
if self.consume('+') {
spec.flags |= 1 << (FlagSignPlus as uint);
spec.flags |= 1 << (FlagSignPlus as u32);
} else if self.consume('-') {
spec.flags |= 1 << (FlagSignMinus as uint);
spec.flags |= 1 << (FlagSignMinus as u32);
}
// Alternate marker
if self.consume('#') {
spec.flags |= 1 << (FlagAlternate as uint);
spec.flags |= 1 << (FlagAlternate as u32);
}
// Width and precision
let mut havewidth = false;
Expand All @@ -333,7 +332,7 @@ impl<'a> Parser<'a> {
spec.width = CountIsParam(0);
havewidth = true;
} else {
spec.flags |= 1 << (FlagSignAwareZeroPad as uint);
spec.flags |= 1 << (FlagSignAwareZeroPad as u32);
}
}
if !havewidth {
Expand Down Expand Up @@ -413,7 +412,7 @@ impl<'a> Parser<'a> {

/// Optionally parses an integer at the current position. This doesn't deal
/// with overflow at all, it's just accumulating digits.
fn integer(&mut self) -> Option<uint> {
fn integer(&mut self) -> Option<usize> {
let mut cur = 0;
let mut found = false;
loop {
Expand Down Expand Up @@ -617,7 +616,7 @@ mod tests {
format: FormatSpec {
fill: None,
align: AlignUnknown,
flags: (1 << FlagSignMinus as uint),
flags: (1 << FlagSignMinus as u32),
precision: CountImplied,
width: CountImplied,
ty: "",
Expand All @@ -628,7 +627,7 @@ mod tests {
format: FormatSpec {
fill: None,
align: AlignUnknown,
flags: (1 << FlagSignPlus as uint) | (1 << FlagAlternate as uint),
flags: (1 << FlagSignPlus as u32) | (1 << FlagAlternate as u32),
precision: CountImplied,
width: CountImplied,
ty: "",
Expand Down
Loading