about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-10-03 05:02:37 +0000
committerbors <bors@rust-lang.org>2014-10-03 05:02:37 +0000
commitaa034cd3bac3155e0f6c74c399314b5ee32f88fc (patch)
tree891acff8f9158a69e1884707ca3bfb70d749db2e /src/liballoc
parentd0af3feebb57bc58c52de69ab51f92dc7082500b (diff)
parentd911936dbdc645133ad9605f45d2bf10b73e2b20 (diff)
downloadrust-aa034cd3bac3155e0f6c74c399314b5ee32f88fc.tar.gz
rust-aa034cd3bac3155e0f6c74c399314b5ee32f88fc.zip
auto merge of #17725 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/heap.rs36
-rw-r--r--src/liballoc/lib.rs1
-rw-r--r--src/liballoc/rc.rs8
-rw-r--r--src/liballoc/util.rs30
4 files changed, 27 insertions, 48 deletions
diff --git a/src/liballoc/heap.rs b/src/liballoc/heap.rs
index 0d2872bcba0..ef3ccd5aead 100644
--- a/src/liballoc/heap.rs
+++ b/src/liballoc/heap.rs
@@ -182,9 +182,15 @@ mod imp {
 
     #[inline]
     pub unsafe fn reallocate_inplace(ptr: *mut u8, size: uint, align: uint,
-                                     _old_size: uint) -> bool {
+                                     old_size: uint) -> bool {
         let flags = align_to_flags(align);
-        je_xallocx(ptr as *mut c_void, size as size_t, 0, flags) == size as size_t
+        let new_size = je_xallocx(ptr as *mut c_void, size as size_t, 0, flags) as uint;
+        // checking for failure to shrink is tricky
+        if size < old_size {
+            usable_size(size, align) == new_size as uint
+        } else {
+            new_size >= size
+        }
     }
 
     #[inline]
@@ -250,9 +256,9 @@ mod imp {
     }
 
     #[inline]
-    pub unsafe fn reallocate_inplace(_ptr: *mut u8, _size: uint, _align: uint,
-                                     _old_size: uint) -> bool {
-        false
+    pub unsafe fn reallocate_inplace(_ptr: *mut u8, size: uint, _align: uint,
+                                     old_size: uint) -> bool {
+        size == old_size
     }
 
     #[inline]
@@ -312,9 +318,9 @@ mod imp {
     }
 
     #[inline]
-    pub unsafe fn reallocate_inplace(_ptr: *mut u8, _size: uint, _align: uint,
-                                     _old_size: uint) -> bool {
-        false
+    pub unsafe fn reallocate_inplace(_ptr: *mut u8, size: uint, _align: uint,
+                                     old_size: uint) -> bool {
+        size == old_size
     }
 
     #[inline]
@@ -335,9 +341,21 @@ mod imp {
 }
 
 #[cfg(test)]
-mod bench {
+mod test {
     extern crate test;
     use self::test::Bencher;
+    use heap;
+
+    #[test]
+    fn basic_reallocate_inplace_noop() {
+        unsafe {
+            let size = 4000;
+            let ptr = heap::allocate(size, 8);
+            let ret = heap::reallocate_inplace(ptr, size, 8, size);
+            heap::deallocate(ptr, size, 8);
+            assert!(ret);
+        }
+    }
 
     #[bench]
     fn alloc_owned_small(b: &mut Bencher) {
diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs
index 503c484e469..c31d746d8f2 100644
--- a/src/liballoc/lib.rs
+++ b/src/liballoc/lib.rs
@@ -92,7 +92,6 @@ pub use boxed as owned;
 
 pub mod heap;
 pub mod libc_heap;
-pub mod util;
 
 // Primitive types using the heaps above
 
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs
index ec19844a24a..049bf4eb1b0 100644
--- a/src/liballoc/rc.rs
+++ b/src/liballoc/rc.rs
@@ -542,14 +542,6 @@ mod tests {
     }
 
     #[test]
-    fn gc_inside() {
-        // see issue #11532
-        use std::gc::GC;
-        let a = Rc::new(RefCell::new(box(GC) 1i));
-        assert!(a.try_borrow_mut().is_some());
-    }
-
-    #[test]
     fn weak_self_cyclic() {
         struct Cycle {
             x: RefCell<Option<Weak<Cycle>>>
diff --git a/src/liballoc/util.rs b/src/liballoc/util.rs
deleted file mode 100644
index d5f0d25fb01..00000000000
--- a/src/liballoc/util.rs
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-#![doc(hidden)]
-
-use core::mem;
-use core::raw;
-
-#[inline]
-#[deprecated]
-pub fn get_box_size(body_size: uint, body_align: uint) -> uint {
-    let header_size = mem::size_of::<raw::GcBox<()>>();
-    let total_size = align_to(header_size, body_align) + body_size;
-    total_size
-}
-
-// Rounds size to the next alignment. Alignment is required to be a power of
-// two.
-#[inline]
-fn align_to(size: uint, align: uint) -> uint {
-    assert!(align != 0);
-    (size + align - 1) & !(align - 1)
-}