diff options
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/lib.rs | 26 | ||||
| -rw-r--r-- | src/libstd/owned.rs | 115 | ||||
| -rw-r--r-- | src/libstd/rc.rs | 300 | ||||
| -rw-r--r-- | src/libstd/rt/heap.rs | 197 | ||||
| -rw-r--r-- | src/libstd/rt/libc_heap.rs | 51 | ||||
| -rw-r--r-- | src/libstd/rt/local_heap.rs | 3 | ||||
| -rw-r--r-- | src/libstd/rt/mod.rs | 8 | ||||
| -rw-r--r-- | src/libstd/rt/util.rs | 17 |
8 files changed, 17 insertions, 700 deletions
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 119cd9aa2ca..a45f8a83a24 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -124,21 +124,21 @@ // Make and rand accessible for benchmarking/testcases #[cfg(test)] extern crate rand; -extern crate libc; +extern crate alloc; extern crate core; +extern crate libc; // Make std testable by not duplicating lang items. See #2912 #[cfg(test)] extern crate realstd = "std"; -#[cfg(test)] pub use kinds = realstd::kinds; -#[cfg(test)] pub use ops = realstd::ops; -#[cfg(test)] pub use cmp = realstd::cmp; -#[cfg(test)] pub use ty = realstd::ty; -#[cfg(test)] pub use owned = realstd::owned; +#[cfg(test)] pub use realstd::kinds; +#[cfg(test)] pub use realstd::ops; +#[cfg(test)] pub use realstd::cmp; +#[cfg(test)] pub use realstd::ty; -#[cfg(not(test))] pub use cmp = core::cmp; -#[cfg(not(test))] pub use kinds = core::kinds; -#[cfg(not(test))] pub use ops = core::ops; -#[cfg(not(test))] pub use ty = core::ty; +#[cfg(not(test))] pub use core::cmp; +#[cfg(not(test))] pub use core::kinds; +#[cfg(not(test))] pub use core::ops; +#[cfg(not(test))] pub use core::ty; pub use core::any; pub use core::bool; @@ -155,6 +155,9 @@ pub use core::raw; pub use core::tuple; pub use core::result; +pub use alloc::owned; +pub use alloc::rc; + // Run tests with libgreen instead of libnative. // // FIXME: This egregiously hacks around starting the test runner in a different @@ -205,10 +208,7 @@ pub mod strbuf; pub mod ascii; -pub mod rc; pub mod gc; -#[cfg(not(test))] -pub mod owned; /* Common traits */ diff --git a/src/libstd/owned.rs b/src/libstd/owned.rs deleted file mode 100644 index bd6684b3905..00000000000 --- a/src/libstd/owned.rs +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2012 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. - -//! Operations on unique pointer types - -use any::{Any, AnyRefExt}; -use clone::Clone; -use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering}; -use default::Default; -use fmt; -use intrinsics; -use mem; -use raw::TraitObject; -use result::{Ok, Err, Result}; - -/// A value that represents the global exchange heap. This is the default -/// place that the `box` keyword allocates into when no place is supplied. -/// -/// The following two examples are equivalent: -/// -/// let foo = box(HEAP) Bar::new(...); -/// let foo = box Bar::new(...); -#[lang="exchange_heap"] -pub static HEAP: () = (); - -/// A type that represents a uniquely-owned value. -#[lang="owned_box"] -pub struct Box<T>(*T); - -impl<T: Default> Default for Box<T> { - fn default() -> Box<T> { box Default::default() } -} - -impl<T: Clone> Clone for Box<T> { - /// Return a copy of the owned box. - #[inline] - fn clone(&self) -> Box<T> { box {(**self).clone()} } - - /// Perform copy-assignment from `source` by reusing the existing allocation. - #[inline] - fn clone_from(&mut self, source: &Box<T>) { - (**self).clone_from(&(**source)); - } -} - -// box pointers -impl<T:Eq> Eq for Box<T> { - #[inline] - fn eq(&self, other: &Box<T>) -> bool { *(*self) == *(*other) } - #[inline] - fn ne(&self, other: &Box<T>) -> bool { *(*self) != *(*other) } -} -impl<T:Ord> Ord for Box<T> { - #[inline] - fn lt(&self, other: &Box<T>) -> bool { *(*self) < *(*other) } - #[inline] - fn le(&self, other: &Box<T>) -> bool { *(*self) <= *(*other) } - #[inline] - fn ge(&self, other: &Box<T>) -> bool { *(*self) >= *(*other) } - #[inline] - fn gt(&self, other: &Box<T>) -> bool { *(*self) > *(*other) } -} -impl<T: TotalOrd> TotalOrd for Box<T> { - #[inline] - fn cmp(&self, other: &Box<T>) -> Ordering { (**self).cmp(*other) } -} -impl<T: TotalEq> TotalEq for Box<T> {} - -/// Extension methods for an owning `Any` trait object -pub trait AnyOwnExt { - /// Returns the boxed value if it is of type `T`, or - /// `Err(Self)` if it isn't. - fn move<T: 'static>(self) -> Result<Box<T>, Self>; -} - -impl AnyOwnExt for Box<Any> { - #[inline] - fn move<T: 'static>(self) -> Result<Box<T>, Box<Any>> { - if self.is::<T>() { - unsafe { - // Get the raw representation of the trait object - let to: TraitObject = - *mem::transmute::<&Box<Any>, &TraitObject>(&self); - - // Prevent destructor on self being run - intrinsics::forget(self); - - // Extract the data pointer - Ok(mem::transmute(to.data)) - } - } else { - Err(self) - } - } -} - -impl<T: fmt::Show> fmt::Show for Box<T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - (**self).fmt(f) - } -} - -#[cfg(not(stage0))] -impl fmt::Show for Box<Any> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.pad("Box<Any>") - } -} diff --git a/src/libstd/rc.rs b/src/libstd/rc.rs deleted file mode 100644 index 87c2f826af5..00000000000 --- a/src/libstd/rc.rs +++ /dev/null @@ -1,300 +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. - -/*! Task-local reference-counted boxes (`Rc` type) - -The `Rc` type provides shared ownership of an immutable value. Destruction is deterministic, and -will occur as soon as the last owner is gone. It is marked as non-sendable because it avoids the -overhead of atomic reference counting. - -The `downgrade` method can be used to create a non-owning `Weak` pointer to the box. A `Weak` -pointer can be upgraded to an `Rc` pointer, but will return `None` if the value has already been -freed. - -For example, a tree with parent pointers can be represented by putting the nodes behind `Strong` -pointers, and then storing the parent pointers as `Weak` pointers. - -*/ - -use mem::transmute; -use cell::Cell; -use clone::Clone; -use cmp::{Eq, Ord, TotalEq, TotalOrd, Ordering}; -use kinds::marker; -use ops::{Deref, Drop}; -use option::{Option, Some, None}; -use ptr; -use ptr::RawPtr; -use mem::{min_align_of, size_of}; -use rt::heap::deallocate; - -struct RcBox<T> { - value: T, - strong: Cell<uint>, - weak: Cell<uint> -} - -/// Immutable reference counted pointer type -#[unsafe_no_drop_flag] -pub struct Rc<T> { - ptr: *mut RcBox<T>, - nosend: marker::NoSend, - noshare: marker::NoShare -} - -impl<T> Rc<T> { - /// Construct a new reference-counted box - pub fn new(value: T) -> Rc<T> { - unsafe { - Rc { - // there is an implicit weak pointer owned by all the - // strong pointers, which ensures that the weak - // destructor never frees the allocation while the - // strong destructor is running, even if the weak - // pointer is stored inside the strong one. - ptr: transmute(box RcBox { - value: value, - strong: Cell::new(1), - weak: Cell::new(1) - }), - nosend: marker::NoSend, - noshare: marker::NoShare - } - } - } -} - -impl<T> Rc<T> { - /// Downgrade the reference-counted pointer to a weak reference - pub fn downgrade(&self) -> Weak<T> { - self.inc_weak(); - Weak { - ptr: self.ptr, - nosend: marker::NoSend, - noshare: marker::NoShare - } - } -} - -impl<T> Deref<T> for Rc<T> { - /// Borrow the value contained in the reference-counted box - #[inline(always)] - fn deref<'a>(&'a self) -> &'a T { - &self.inner().value - } -} - -#[unsafe_destructor] -impl<T> Drop for Rc<T> { - fn drop(&mut self) { - unsafe { - if !self.ptr.is_null() { - self.dec_strong(); - if self.strong() == 0 { - ptr::read(self.deref()); // destroy the contained object - - // remove the implicit "strong weak" pointer now - // that we've destroyed the contents. - self.dec_weak(); - - if self.weak() == 0 { - deallocate(self.ptr as *mut u8, size_of::<RcBox<T>>(), - min_align_of::<RcBox<T>>()) - } - } - } - } - } -} - -impl<T> Clone for Rc<T> { - #[inline] - fn clone(&self) -> Rc<T> { - self.inc_strong(); - Rc { ptr: self.ptr, nosend: marker::NoSend, noshare: marker::NoShare } - } -} - -impl<T: Eq> Eq for Rc<T> { - #[inline(always)] - fn eq(&self, other: &Rc<T>) -> bool { **self == **other } - #[inline(always)] - fn ne(&self, other: &Rc<T>) -> bool { **self != **other } -} - -impl<T: TotalEq> TotalEq for Rc<T> {} - -impl<T: Ord> Ord for Rc<T> { - #[inline(always)] - fn lt(&self, other: &Rc<T>) -> bool { **self < **other } - - #[inline(always)] - fn le(&self, other: &Rc<T>) -> bool { **self <= **other } - - #[inline(always)] - fn gt(&self, other: &Rc<T>) -> bool { **self > **other } - - #[inline(always)] - fn ge(&self, other: &Rc<T>) -> bool { **self >= **other } -} - -impl<T: TotalOrd> TotalOrd for Rc<T> { - #[inline] - fn cmp(&self, other: &Rc<T>) -> Ordering { (**self).cmp(&**other) } -} - -/// Weak reference to a reference-counted box -#[unsafe_no_drop_flag] -pub struct Weak<T> { - ptr: *mut RcBox<T>, - nosend: marker::NoSend, - noshare: marker::NoShare -} - -impl<T> Weak<T> { - /// Upgrade a weak reference to a strong reference - pub fn upgrade(&self) -> Option<Rc<T>> { - if self.strong() == 0 { - None - } else { - self.inc_strong(); - Some(Rc { ptr: self.ptr, nosend: marker::NoSend, noshare: marker::NoShare }) - } - } -} - -#[unsafe_destructor] -impl<T> Drop for Weak<T> { - fn drop(&mut self) { - unsafe { - if !self.ptr.is_null() { - self.dec_weak(); - // the weak count starts at 1, and will only go to - // zero if all the strong pointers have disappeared. - if self.weak() == 0 { - deallocate(self.ptr as *mut u8, size_of::<RcBox<T>>(), - min_align_of::<RcBox<T>>()) - } - } - } - } -} - -impl<T> Clone for Weak<T> { - #[inline] - fn clone(&self) -> Weak<T> { - self.inc_weak(); - Weak { ptr: self.ptr, nosend: marker::NoSend, noshare: marker::NoShare } - } -} - -#[doc(hidden)] -trait RcBoxPtr<T> { - fn inner<'a>(&'a self) -> &'a RcBox<T>; - - #[inline] - fn strong(&self) -> uint { self.inner().strong.get() } - - #[inline] - fn inc_strong(&self) { self.inner().strong.set(self.strong() + 1); } - - #[inline] - fn dec_strong(&self) { self.inner().strong.set(self.strong() - 1); } - - #[inline] - fn weak(&self) -> uint { self.inner().weak.get() } - - #[inline] - fn inc_weak(&self) { self.inner().weak.set(self.weak() + 1); } - - #[inline] - fn dec_weak(&self) { self.inner().weak.set(self.weak() - 1); } -} - -impl<T> RcBoxPtr<T> for Rc<T> { - #[inline(always)] - fn inner<'a>(&'a self) -> &'a RcBox<T> { unsafe { &(*self.ptr) } } -} - -impl<T> RcBoxPtr<T> for Weak<T> { - #[inline(always)] - fn inner<'a>(&'a self) -> &'a RcBox<T> { unsafe { &(*self.ptr) } } -} - -#[cfg(test)] -mod tests { - use prelude::*; - use super::*; - use cell::RefCell; - - #[test] - fn test_clone() { - let x = Rc::new(RefCell::new(5)); - let y = x.clone(); - *x.borrow_mut() = 20; - assert_eq!(*y.borrow(), 20); - } - - #[test] - fn test_simple() { - let x = Rc::new(5); - assert_eq!(*x, 5); - } - - #[test] - fn test_simple_clone() { - let x = Rc::new(5); - let y = x.clone(); - assert_eq!(*x, 5); - assert_eq!(*y, 5); - } - - #[test] - fn test_destructor() { - let x = Rc::new(box 5); - assert_eq!(**x, 5); - } - - #[test] - fn test_live() { - let x = Rc::new(5); - let y = x.downgrade(); - assert!(y.upgrade().is_some()); - } - - #[test] - fn test_dead() { - let x = Rc::new(5); - let y = x.downgrade(); - drop(x); - assert!(y.upgrade().is_none()); - } - - #[test] - fn gc_inside() { - // see issue #11532 - use gc::Gc; - let a = Rc::new(RefCell::new(Gc::new(1))); - assert!(a.try_borrow_mut().is_some()); - } - - #[test] - fn weak_self_cyclic() { - struct Cycle { - x: RefCell<Option<Weak<Cycle>>> - } - - let a = Rc::new(Cycle { x: RefCell::new(None) }); - let b = a.clone().downgrade(); - *a.x.borrow_mut() = Some(b); - - // hopefully we don't double-free (or leak)... - } -} diff --git a/src/libstd/rt/heap.rs b/src/libstd/rt/heap.rs deleted file mode 100644 index e616b9b8beb..00000000000 --- a/src/libstd/rt/heap.rs +++ /dev/null @@ -1,197 +0,0 @@ -// Copyright 2014 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. - -// FIXME: #13994: port to the sized deallocation API when available -// FIXME: #13996: need a way to mark the `allocate` and `reallocate` return values as `noalias` - -use intrinsics::{abort, cttz32}; -use libc::{c_char, c_int, c_void, size_t}; -use ptr::{RawPtr, mut_null, null}; -use option::{None, Option}; - -#[link(name = "jemalloc", kind = "static")] -extern { - fn je_mallocx(size: size_t, flags: c_int) -> *mut c_void; - fn je_rallocx(ptr: *mut c_void, size: size_t, flags: c_int) -> *mut c_void; - fn je_xallocx(ptr: *mut c_void, size: size_t, extra: size_t, flags: c_int) -> size_t; - fn je_dallocx(ptr: *mut c_void, flags: c_int); - fn je_nallocx(size: size_t, flags: c_int) -> size_t; - fn je_malloc_stats_print(write_cb: Option<extern "C" fn(cbopaque: *mut c_void, *c_char)>, - cbopaque: *mut c_void, - opts: *c_char); -} - -// -lpthread needs to occur after -ljemalloc, the earlier argument isn't enough -#[cfg(not(windows), not(target_os = "android"))] -#[link(name = "pthread")] -extern {} - -// MALLOCX_ALIGN(a) macro -#[inline(always)] -fn mallocx_align(a: uint) -> c_int { unsafe { cttz32(a as u32) as c_int } } - -/// Return a pointer to `size` bytes of memory. -/// -/// Behavior is undefined if the requested size is 0 or the alignment is not a power of 2. The -/// alignment must be no larger than the largest supported page size on the platform. -#[inline] -pub unsafe fn allocate(size: uint, align: uint) -> *mut u8 { - let ptr = je_mallocx(size as size_t, mallocx_align(align)) as *mut u8; - if ptr.is_null() { - abort() - } - ptr -} - -/// Extend or shrink the allocation referenced by `ptr` to `size` bytes of memory. -/// -/// Behavior is undefined if the requested size is 0 or the alignment is not a power of 2. The -/// alignment must be no larger than the largest supported page size on the platform. -/// -/// The `old_size` and `align` parameters are the parameters that were used to create the -/// allocation referenced by `ptr`. The `old_size` parameter may also be the value returned by -/// `usable_size` for the requested size. -#[inline] -#[allow(unused_variable)] // for the parameter names in the documentation -pub unsafe fn reallocate(ptr: *mut u8, size: uint, align: uint, old_size: uint) -> *mut u8 { - let ptr = je_rallocx(ptr as *mut c_void, size as size_t, mallocx_align(align)) as *mut u8; - if ptr.is_null() { - abort() - } - ptr -} - -/// Extend or shrink the allocation referenced by `ptr` to `size` bytes of memory in-place. -/// -/// Return true if successful, otherwise false if the allocation was not altered. -/// -/// Behavior is undefined if the requested size is 0 or the alignment is not a power of 2. The -/// alignment must be no larger than the largest supported page size on the platform. -/// -/// The `old_size` and `align` parameters are the parameters that were used to -/// create the allocation referenced by `ptr`. The `old_size` parameter may be -/// any value in range_inclusive(requested_size, usable_size). -#[inline] -#[allow(unused_variable)] // for the parameter names in the documentation -pub unsafe fn reallocate_inplace(ptr: *mut u8, size: uint, align: uint, old_size: uint) -> bool { - je_xallocx(ptr as *mut c_void, size as size_t, 0, mallocx_align(align)) == size as size_t -} - -/// Deallocate the memory referenced by `ptr`. -/// -/// The `ptr` parameter must not be null. -/// -/// The `size` and `align` parameters are the parameters that were used to create the -/// allocation referenced by `ptr`. The `size` parameter may also be the value returned by -/// `usable_size` for the requested size. -#[inline] -#[allow(unused_variable)] // for the parameter names in the documentation -pub unsafe fn deallocate(ptr: *mut u8, size: uint, align: uint) { - je_dallocx(ptr as *mut c_void, mallocx_align(align)) -} - -/// Return the usable size of an allocation created with the specified the `size` and `align`. -#[inline] -pub fn usable_size(size: uint, align: uint) -> uint { - unsafe { je_nallocx(size as size_t, mallocx_align(align)) as uint } -} - -/// Print implementation-defined allocator statistics. -/// -/// These statistics may be inconsistent if other threads use the allocator during the call. -#[unstable] -pub fn stats_print() { - unsafe { - je_malloc_stats_print(None, mut_null(), null()) - } -} - -/// The allocator for unique pointers. -#[cfg(not(test))] -#[lang="exchange_malloc"] -#[inline(always)] -pub unsafe fn exchange_malloc_(size: uint, align: uint) -> *mut u8 { - exchange_malloc(size, align) -} - -/// The allocator for unique pointers. -#[inline] -pub unsafe fn exchange_malloc(size: uint, align: uint) -> *mut u8 { - // The compiler never calls `exchange_free` on ~ZeroSizeType, so zero-size - // allocations can point to this `static`. It would be incorrect to use a null - // pointer, due to enums assuming types like unique pointers are never null. - static EMPTY: () = (); - - if size == 0 { - &EMPTY as *() as *mut u8 - } else { - allocate(size, align) - } -} - -#[cfg(not(test))] -#[lang="exchange_free"] -#[inline] -// FIXME: #13994 (rustc should pass align and size here) -unsafe fn exchange_free(ptr: *mut u8) { - deallocate(ptr, 0, 8); -} - -// FIXME: #7496 -#[cfg(not(test))] -#[lang="closure_exchange_malloc"] -#[inline] -unsafe fn closure_exchange_malloc(drop_glue: fn(*mut u8), size: uint, align: uint) -> *mut u8 { - let total_size = ::rt::util::get_box_size(size, align); - let p = allocate(total_size, 8); - - let alloc = p as *mut ::raw::Box<()>; - (*alloc).drop_glue = drop_glue; - - alloc as *mut u8 -} - -// hack for libcore -#[no_mangle] -#[doc(hidden)] -#[deprecated] -#[cfg(not(test))] -pub unsafe extern "C" fn rust_malloc(size: uint, align: uint) -> *mut u8 { - exchange_malloc(size, align) -} - -// hack for libcore -#[no_mangle] -#[doc(hidden)] -#[deprecated] -#[cfg(not(test))] -pub unsafe extern "C" fn rust_free(ptr: *mut u8, size: uint, align: uint) { - deallocate(ptr, size, align) -} - -#[cfg(test)] -mod bench { - extern crate test; - use self::test::Bencher; - - #[bench] - fn alloc_owned_small(b: &mut Bencher) { - b.iter(|| { - box 10 - }) - } - - #[bench] - fn alloc_owned_big(b: &mut Bencher) { - b.iter(|| { - box [10, ..1000] - }) - } -} diff --git a/src/libstd/rt/libc_heap.rs b/src/libstd/rt/libc_heap.rs deleted file mode 100644 index ece51ab9989..00000000000 --- a/src/libstd/rt/libc_heap.rs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2012 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. - - -//! The global (exchange) heap. - -use libc::{c_void, size_t, free, malloc, realloc}; -use ptr::{RawPtr, mut_null}; -use intrinsics::abort; - -/// A wrapper around libc::malloc, aborting on out-of-memory -#[inline] -pub unsafe fn malloc_raw(size: uint) -> *mut u8 { - // `malloc(0)` may allocate, but it may also return a null pointer - // http://pubs.opengroup.org/onlinepubs/9699919799/functions/malloc.html - if size == 0 { - mut_null() - } else { - let p = malloc(size as size_t); - if p.is_null() { - // we need a non-allocating way to print an error here - abort(); - } - p as *mut u8 - } -} - -/// A wrapper around libc::realloc, aborting on out-of-memory -#[inline] -pub unsafe fn realloc_raw(ptr: *mut u8, size: uint) -> *mut u8 { - // `realloc(ptr, 0)` may allocate, but it may also return a null pointer - // http://pubs.opengroup.org/onlinepubs/9699919799/functions/realloc.html - if size == 0 { - free(ptr as *mut c_void); - mut_null() - } else { - let p = realloc(ptr as *mut c_void, size as size_t); - if p.is_null() { - // we need a non-allocating way to print an error here - abort(); - } - p as *mut u8 - } -} diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs index 5feec7fd9d2..240d137adc6 100644 --- a/src/libstd/rt/local_heap.rs +++ b/src/libstd/rt/local_heap.rs @@ -10,6 +10,7 @@ //! The local, garbage collected heap +use alloc::util; use iter::Iterator; use libc::{c_void, free}; use mem; @@ -58,7 +59,7 @@ impl LocalHeap { #[inline] pub fn alloc(&mut self, drop_glue: fn(*mut u8), size: uint, align: uint) -> *mut Box { - let total_size = ::rt::util::get_box_size(size, align); + let total_size = util::get_box_size(size, align); let alloc = self.memory_region.malloc(total_size); { // Make sure that we can't use `mybox` outside of this scope diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index a04cbabedd6..daf18346fee 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -74,6 +74,8 @@ pub use self::unwind::{begin_unwind, begin_unwind_fmt}; pub use self::util::{Stdio, Stdout, Stderr}; +pub use alloc::{heap, libc_heap}; + // FIXME: these probably shouldn't be public... #[doc(hidden)] pub mod shouldnt_be_public { @@ -86,12 +88,6 @@ pub mod shouldnt_be_public { // Internal macros used by the runtime. mod macros; -/// Wrappers around malloc / realloc aborting on out-of-memory. -pub mod libc_heap; - -/// The low-level memory allocation API. -pub mod heap; - /// Implementations of language-critical runtime features like @. pub mod task; diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index 5f9ea14a647..c9e82bd16e5 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -26,23 +26,6 @@ use slice::ImmutableVector; // FIXME: Once the runtime matures remove the `true` below to turn off rtassert, etc. pub static ENFORCE_SANITY: bool = true || !cfg!(rtopt) || cfg!(rtdebug) || cfg!(rtassert); -#[deprecated] -#[doc(hidden)] -#[inline] -pub fn get_box_size(body_size: uint, body_align: uint) -> uint { - let header_size = ::mem::size_of::<::raw::Box<()>>(); - let total_size = align_to(header_size, body_align) + body_size; - total_size -} - -// Rounds |size| to the nearest |alignment|. Invariant: |alignment| is a power -// of two. -#[inline] -fn align_to(size: uint, align: uint) -> uint { - assert!(align != 0); - (size + align - 1) & !(align - 1) -} - /// Get the number of cores available pub fn num_cpus() -> uint { unsafe { |
