]> git.lizzy.rs Git - rust.git/commitdiff
Reduce libcore/liballoc's dependence on pointer sizes
authorDylan McKay <dylanmckay34@gmail.com>
Sat, 15 Aug 2015 05:17:17 +0000 (17:17 +1200)
committerDylan McKay <dylanmckay34@gmail.com>
Sat, 15 Aug 2015 07:19:13 +0000 (19:19 +1200)
src/liballoc/lib.rs
src/liballoc/raw_vec.rs
src/libcore/fmt/mod.rs
src/libcore/hash/mod.rs
src/libcore/iter.rs

index ca86850f5df6ebfb67f06dae9e5aad0131e27bcb..2db9cc7c4d8deb9e1342ace2e14d6b351a57ccb8 100644 (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)]
index 9311f44d9df00ff321b3a8d7b94469b9fc3f3b16..97acd0db52478348da758770ee7e4a4b4ddf39d7 100644 (file)
@@ -15,6 +15,7 @@
 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 @@ fn drop(&mut self) {
 // 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");
+    }
 }
index ea2a9d1cfaf60fed1e55433d42b755441a1c327b..86700583f2dc68e9e2690b0f129272ba61881157 100644 (file)
@@ -1340,12 +1340,7 @@ fn fmt(&self, f: &mut Formatter) -> Result {
             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);
index 361c6d700dec1d42f2fb423044853f6338420707..2a4c909d6384c5b877ade8e2970e2a2e0d4dd245 100644 (file)
@@ -144,11 +144,11 @@ fn write_u64(&mut self, i: u64) {
     #[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.
index 0471a08cd78f11b0c37cb863f6e3d0534a7c1117..b800ec24a95a72d61d35eb7c2378213da09be0ba 100644 (file)
@@ -2234,7 +2234,9 @@ fn steps_between(_a: &$t, _b: &$t, _by: &$t) -> Option<usize> {
 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.