Skip to content

Commit 7ebc5e5

Browse files
author
Dylan McKay
committed
Reduce libcore/liballoc's dependence on pointer sizes
1 parent 1e1b7f3 commit 7ebc5e5

File tree

5 files changed

+14
-18
lines changed

5 files changed

+14
-18
lines changed

src/liballoc/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
#![feature(lang_items)]
8484
#![feature(no_std)]
8585
#![feature(nonzero)]
86+
#![feature(num_bits_bytes)]
8687
#![feature(optin_builtin_traits)]
8788
#![feature(placement_in_syntax)]
8889
#![feature(placement_new_protocol)]

src/liballoc/raw_vec.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use heap;
1515
use super::oom;
1616
use super::boxed::Box;
1717
use core::ops::Drop;
18+
use core;
1819

1920
/// A low-level utility for more ergonomically allocating, reallocating, and deallocating a
2021
/// 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> {
443444
// user-space. e.g. PAE or x32
444445

445446
#[inline]
446-
#[cfg(target_pointer_width = "64")]
447-
fn alloc_guard(_alloc_size: usize) { }
448-
449-
#[inline]
450-
#[cfg(target_pointer_width = "32")]
451447
fn alloc_guard(alloc_size: usize) {
452-
assert!(alloc_size <= ::core::isize::MAX as usize, "capacity overflow");
448+
if core::usize::BITS < 64 {
449+
assert!(alloc_size <= ::core::isize::MAX as usize, "capacity overflow");
450+
}
453451
}

src/libcore/fmt/mod.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,12 +1340,7 @@ impl<T> Pointer for *const T {
13401340
f.flags |= 1 << (FlagV1::SignAwareZeroPad as u32);
13411341

13421342
if let None = f.width {
1343-
// The formats need two extra bytes, for the 0x
1344-
if cfg!(target_pointer_width = "32") {
1345-
f.width = Some(10);
1346-
} else {
1347-
f.width = Some(18);
1348-
}
1343+
f.width = Some((::usize::BITS/4) + 2);
13491344
}
13501345
}
13511346
f.flags |= 1 << (FlagV1::Alternate as u32);

src/libcore/hash/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ pub trait Hasher {
144144
#[inline]
145145
#[stable(feature = "hasher_write", since = "1.3.0")]
146146
fn write_usize(&mut self, i: usize) {
147-
if cfg!(target_pointer_width = "32") {
148-
self.write_u32(i as u32)
149-
} else {
150-
self.write_u64(i as u64)
151-
}
147+
let bytes = unsafe {
148+
::slice::from_raw_parts(&i as *const usize as *const u8,
149+
mem::size_of::<usize>())
150+
};
151+
self.write(bytes);
152152
}
153153

154154
/// Write a single `i8` into this hasher.

src/libcore/iter.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2234,7 +2234,9 @@ step_impl_signed!(isize i8 i16 i32);
22342234
step_impl_unsigned!(u64);
22352235
#[cfg(target_pointer_width = "64")]
22362236
step_impl_signed!(i64);
2237-
#[cfg(target_pointer_width = "32")]
2237+
// If the target pointer width is not 64-bits, we
2238+
// assume here that it is less than 64-bits.
2239+
#[cfg(not(target_pointer_width = "64"))]
22382240
step_impl_no_between!(u64 i64);
22392241

22402242
/// An adapter for stepping range iterators by a custom amount.

0 commit comments

Comments
 (0)