Reduce libcore/liballoc's dependence on pointer sizes

This commit is contained in:
Dylan McKay 2015-08-15 17:17:17 +12:00
parent 1e1b7f3022
commit 7ebc5e5134
5 changed files with 14 additions and 18 deletions

View File

@ -83,6 +83,7 @@
#![feature(lang_items)]
#![feature(no_std)]
#![feature(nonzero)]
#![feature(num_bits_bytes)]
#![feature(optin_builtin_traits)]
#![feature(placement_in_syntax)]
#![feature(placement_new_protocol)]

View File

@ -15,6 +15,7 @@ use heap;
use super::oom;
use super::boxed::Box;
use core::ops::Drop;
use core;
/// A low-level utility for more ergonomically allocating, reallocating, and deallocating a
/// a buffer of memory on the heap without having to worry about all the corner cases
@ -443,11 +444,8 @@ impl<T> Drop for RawVec<T> {
// user-space. e.g. PAE or x32
#[inline]
#[cfg(target_pointer_width = "64")]
fn alloc_guard(_alloc_size: usize) { }
#[inline]
#[cfg(target_pointer_width = "32")]
fn alloc_guard(alloc_size: usize) {
assert!(alloc_size <= ::core::isize::MAX as usize, "capacity overflow");
if core::usize::BITS < 64 {
assert!(alloc_size <= ::core::isize::MAX as usize, "capacity overflow");
}
}

View File

@ -1340,12 +1340,7 @@ impl<T> Pointer for *const T {
f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32);
if let None = f.width {
// The formats need two extra bytes, for the 0x
if cfg!(target_pointer_width = "32") {
f.width = Some(10);
} else {
f.width = Some(18);
}
f.width = Some((::usize::BITS/4) + 2);
}
}
f.flags |= 1 << (FlagV1::Alternate as u32);

View File

@ -144,11 +144,11 @@ pub trait Hasher {
#[inline]
#[stable(feature = "hasher_write", since = "1.3.0")]
fn write_usize(&mut self, i: usize) {
if cfg!(target_pointer_width = "32") {
self.write_u32(i as u32)
} else {
self.write_u64(i as u64)
}
let bytes = unsafe {
::slice::from_raw_parts(&i as *const usize as *const u8,
mem::size_of::<usize>())
};
self.write(bytes);
}
/// Write a single `i8` into this hasher.

View File

@ -2234,7 +2234,9 @@ step_impl_signed!(isize i8 i16 i32);
step_impl_unsigned!(u64);
#[cfg(target_pointer_width = "64")]
step_impl_signed!(i64);
#[cfg(target_pointer_width = "32")]
// If the target pointer width is not 64-bits, we
// assume here that it is less than 64-bits.
#[cfg(not(target_pointer_width = "64"))]
step_impl_no_between!(u64 i64);
/// An adapter for stepping range iterators by a custom amount.