about summary refs log tree commit diff
path: root/src/liballoc
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-01-08 05:35:51 +0000
committerbors <bors@rust-lang.org>2015-01-08 05:35:51 +0000
commit5b3cd3900ceda838f5798c30ab96ceb41f962534 (patch)
tree7593bacffb7c8111eee7fa2a0a05d0357ccba763 /src/liballoc
parent9f1ead8fadc56bad30dc74f5cc50d78af4fbc972 (diff)
parent0abf4583486071a958aa1bd14ab8c5b8870fb74d (diff)
downloadrust-5b3cd3900ceda838f5798c30ab96ceb41f962534.tar.gz
rust-5b3cd3900ceda838f5798c30ab96ceb41f962534.zip
auto merge of #20733 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/liballoc')
-rw-r--r--src/liballoc/arc.rs28
-rw-r--r--src/liballoc/boxed.rs50
-rw-r--r--src/liballoc/heap.rs43
-rw-r--r--src/liballoc/lib.rs4
-rw-r--r--src/liballoc/rc.rs42
5 files changed, 116 insertions, 51 deletions
diff --git a/src/liballoc/arc.rs b/src/liballoc/arc.rs
index 5d47602b5e1..48136bc1d96 100644
--- a/src/liballoc/arc.rs
+++ b/src/liballoc/arc.rs
@@ -67,21 +67,20 @@
 //! }
 //! ```
 
+use core::prelude::*;
+
 use core::atomic;
 use core::atomic::Ordering::{Relaxed, Release, Acquire, SeqCst};
 use core::borrow::BorrowFrom;
-use core::clone::Clone;
 use core::fmt::{self, Show};
-use core::cmp::{Eq, Ord, PartialEq, PartialOrd, Ordering};
+use core::cmp::{Ordering};
 use core::default::Default;
-use core::marker::{Sync, Send};
-use core::mem::{min_align_of, size_of, drop};
+use core::mem::{min_align_of, size_of};
 use core::mem;
 use core::nonzero::NonZero;
-use core::ops::{Drop, Deref};
-use core::option::Option;
-use core::option::Option::{Some, None};
-use core::ptr::{self, PtrExt};
+use core::ops::Deref;
+use core::ptr;
+use core::hash::{Hash, Hasher};
 use heap::deallocate;
 
 /// An atomically reference counted wrapper for shared state.
@@ -586,11 +585,24 @@ impl<T: fmt::Show> fmt::Show for Arc<T> {
 }
 
 #[stable]
+impl<T: fmt::String> fmt::String for Arc<T> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        fmt::String::fmt(&**self, f)
+    }
+}
+
+#[stable]
 impl<T: Default + Sync + Send> Default for Arc<T> {
     #[stable]
     fn default() -> Arc<T> { Arc::new(Default::default()) }
 }
 
+impl<H: Hasher, T: Hash<H>> Hash<H> for Arc<T> {
+    fn hash(&self, state: &mut H) {
+        (**self).hash(state)
+    }
+}
+
 #[cfg(test)]
 #[allow(experimental)]
 mod tests {
diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs
index d46f18abf97..97b198164eb 100644
--- a/src/liballoc/boxed.rs
+++ b/src/liballoc/boxed.rs
@@ -1,4 +1,4 @@
-// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
+// Copyright 2012-2015 The Rust Project Developers. See the COPYRIGHT
 // file at the top-level directory of this distribution and at
 // http://rust-lang.org/COPYRIGHT.
 //
@@ -33,12 +33,15 @@ use core::ops::{Deref, DerefMut};
 /// The following two examples are equivalent:
 ///
 /// ```rust
+/// #![feature(box_syntax)]
 /// use std::boxed::HEAP;
 ///
+/// fn main() {
 /// # struct Bar;
 /// # impl Bar { fn new(_a: int) { } }
-/// let foo = box(HEAP) Bar::new(2);
-/// let foo = box Bar::new(2);
+///     let foo = box(HEAP) Bar::new(2);
+///     let foo = box Bar::new(2);
+/// }
 /// ```
 #[lang = "exchange_heap"]
 #[experimental = "may be renamed; uncertain about custom allocator design"]
@@ -49,6 +52,14 @@ pub static HEAP: () = ();
 #[stable]
 pub struct Box<T>(Unique<T>);
 
+impl<T> Box<T> {
+    /// Moves `x` into a freshly allocated box on the global exchange heap.
+    #[stable]
+    pub fn new(x: T) -> Box<T> {
+        box x
+    }
+}
+
 #[stable]
 impl<T: Default> Default for Box<T> {
     #[stable]
@@ -102,16 +113,24 @@ impl<T: ?Sized + Ord> Ord for Box<T> {
     fn cmp(&self, other: &Box<T>) -> Ordering {
         Ord::cmp(&**self, &**other)
     }
-
-#[stable]}
+}
+#[stable]
 impl<T: ?Sized + Eq> Eq for Box<T> {}
 
+#[cfg(stage0)]
 impl<S: hash::Writer, T: ?Sized + Hash<S>> Hash<S> for Box<T> {
     #[inline]
     fn hash(&self, state: &mut S) {
         (**self).hash(state);
     }
 }
+#[cfg(not(stage0))]
+impl<S: hash::Hasher, T: ?Sized + Hash<S>> Hash<S> for Box<T> {
+    #[inline]
+    fn hash(&self, state: &mut S) {
+        (**self).hash(state);
+    }
+}
 
 /// Extension methods for an owning `Any` trait object.
 #[unstable = "post-DST and coherence changes, this will not be a trait but \
@@ -149,6 +168,7 @@ impl<T: ?Sized + fmt::Show> fmt::Show for Box<T> {
     }
 }
 
+#[stable]
 impl<T: ?Sized + fmt::String> fmt::String for Box<T> {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         fmt::String::fmt(&**self, f)
@@ -177,27 +197,27 @@ impl<T: ?Sized> DerefMut for Box<T> {
 mod test {
     #[test]
     fn test_owned_clone() {
-        let a = box 5i;
+        let a = Box::new(5i);
         let b: Box<int> = a.clone();
         assert!(a == b);
     }
 
     #[test]
     fn any_move() {
-        let a = box 8u as Box<Any>;
-        let b = box Test as Box<Any>;
+        let a = Box::new(8u) as Box<Any>;
+        let b = Box::new(Test) as Box<Any>;
 
         match a.downcast::<uint>() {
-            Ok(a) => { assert!(a == box 8u); }
+            Ok(a) => { assert!(a == Box::new(8u)); }
             Err(..) => panic!()
         }
         match b.downcast::<Test>() {
-            Ok(a) => { assert!(a == box Test); }
+            Ok(a) => { assert!(a == Box::new(Test)); }
             Err(..) => panic!()
         }
 
-        let a = box 8u as Box<Any>;
-        let b = box Test as Box<Any>;
+        let a = Box::new(8u) as Box<Any>;
+        let b = Box::new(Test) as Box<Any>;
 
         assert!(a.downcast::<Box<Test>>().is_err());
         assert!(b.downcast::<Box<uint>>().is_err());
@@ -205,8 +225,8 @@ mod test {
 
     #[test]
     fn test_show() {
-        let a = box 8u as Box<Any>;
-        let b = box Test as Box<Any>;
+        let a = Box::new(8u) as Box<Any>;
+        let b = Box::new(Test) as Box<Any>;
         let a_str = a.to_str();
         let b_str = b.to_str();
         assert_eq!(a_str, "Box<Any>");
@@ -223,6 +243,6 @@ mod test {
     #[test]
     fn deref() {
         fn homura<T: Deref<Target=i32>>(_: T) { }
-        homura(box 765i32);
+        homura(Box::new(765i32));
     }
 }
diff --git a/src/liballoc/heap.rs b/src/liballoc/heap.rs
index c57435cdc8c..02933c763ef 100644
--- a/src/liballoc/heap.rs
+++ b/src/liballoc/heap.rs
@@ -115,16 +115,20 @@ unsafe fn exchange_free(ptr: *mut u8, old_size: uint, align: uint) {
 // The minimum alignment guaranteed by the architecture. This value is used to
 // add fast paths for low alignment values. In practice, the alignment is a
 // constant at the call site and the branch will be optimized out.
-#[cfg(any(target_arch = "arm",
-          target_arch = "mips",
-          target_arch = "mipsel"))]
+#[cfg(all(not(feature = "external_funcs"),
+          not(feature = "external_crate"),
+          any(target_arch = "arm",
+              target_arch = "mips",
+              target_arch = "mipsel")))]
 const MIN_ALIGN: uint = 8;
-#[cfg(any(target_arch = "x86",
-          target_arch = "x86_64",
-          target_arch = "aarch64"))]
+#[cfg(all(not(feature = "external_funcs"),
+          not(feature = "external_crate"),
+          any(target_arch = "x86",
+              target_arch = "x86_64",
+              target_arch = "aarch64")))]
 const MIN_ALIGN: uint = 16;
 
-#[cfg(external_funcs)]
+#[cfg(feature = "external_funcs")]
 mod imp {
     extern {
         fn rust_allocate(size: uint, align: uint) -> *mut u8;
@@ -142,14 +146,13 @@ mod imp {
     }
 
     #[inline]
-    pub unsafe fn reallocate_inplace(ptr: *mut u8, old_size: uint, size: uint,
-                                     align: uint) -> uint {
-        rust_reallocate_inplace(ptr, old_size, size, align)
+    pub unsafe fn deallocate(ptr: *mut u8, old_size: uint, align: uint) {
+        rust_deallocate(ptr, old_size, align)
     }
 
     #[inline]
-    pub unsafe fn deallocate(ptr: *mut u8, old_size: uint, align: uint) {
-        rust_deallocate(ptr, old_size, align)
+    pub unsafe fn reallocate(ptr: *mut u8, old_size: uint, size: uint, align: uint) -> *mut u8 {
+        rust_reallocate(ptr, old_size, size, align)
     }
 
     #[inline]
@@ -169,14 +172,16 @@ mod imp {
     }
 }
 
-#[cfg(external_crate)]
+#[cfg(feature = "external_crate")]
 mod imp {
     extern crate external;
     pub use self::external::{allocate, deallocate, reallocate_inplace, reallocate};
     pub use self::external::{usable_size, stats_print};
 }
 
-#[cfg(all(not(external_funcs), not(external_crate), jemalloc))]
+#[cfg(all(not(feature = "external_funcs"),
+          not(feature = "external_crate"),
+          jemalloc))]
 mod imp {
     use core::option::Option;
     use core::option::Option::None;
@@ -253,7 +258,10 @@ mod imp {
     }
 }
 
-#[cfg(all(not(external_funcs), not(external_crate), not(jemalloc), unix))]
+#[cfg(all(not(feature = "external_funcs"),
+          not(feature = "external_crate"),
+          not(jemalloc),
+          unix))]
 mod imp {
     use core::cmp;
     use core::ptr;
@@ -314,7 +322,10 @@ mod imp {
     pub fn stats_print() {}
 }
 
-#[cfg(all(not(external_funcs), not(external_crate), not(jemalloc), windows))]
+#[cfg(all(not(feature = "external_funcs"),
+          not(feature = "external_crate"),
+          not(jemalloc),
+          windows))]
 mod imp {
     use libc::{c_void, size_t};
     use libc;
diff --git a/src/liballoc/lib.rs b/src/liballoc/lib.rs
index ba6e89cdd76..0bb8ba669ec 100644
--- a/src/liballoc/lib.rs
+++ b/src/liballoc/lib.rs
@@ -58,6 +58,7 @@
 
 #![crate_name = "alloc"]
 #![experimental]
+#![staged_api]
 #![crate_type = "rlib"]
 #![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
        html_favicon_url = "http://www.rust-lang.org/favicon.ico",
@@ -66,9 +67,12 @@
 #![no_std]
 #![allow(unknown_features)]
 #![feature(lang_items, unsafe_destructor)]
+#![feature(box_syntax)]
 
 #[macro_use]
 extern crate core;
+
+#[cfg(all(not(feature = "external_funcs"), not(feature = "external_crate")))]
 extern crate libc;
 
 // Allow testing this library
diff --git a/src/liballoc/rc.rs b/src/liballoc/rc.rs
index 67b25427710..27b3f03002f 100644
--- a/src/liballoc/rc.rs
+++ b/src/liballoc/rc.rs
@@ -10,23 +10,26 @@
 
 //! Thread-local reference-counted boxes (the `Rc<T>` type).
 //!
-//! The `Rc<T>` 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 `Rc<T>` 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<T>` pointer to the box. A
-//! `Weak<T>` pointer can be upgraded to an `Rc<T>` pointer, but will return `None` if the value
-//! has already been dropped.
+//! The `downgrade` method can be used to create a non-owning `Weak<T>` pointer
+//! to the box. A `Weak<T>` pointer can be upgraded to an `Rc<T>` pointer, but
+//! will return `None` if the value has already been dropped.
 //!
-//! For example, a tree with parent pointers can be represented by putting the nodes behind strong
-//! `Rc<T>` pointers, and then storing the parent pointers as `Weak<T>` pointers.
+//! For example, a tree with parent pointers can be represented by putting the
+//! nodes behind strong `Rc<T>` pointers, and then storing the parent pointers
+//! as `Weak<T>` pointers.
 //!
 //! # Examples
 //!
-//! Consider a scenario where a set of `Gadget`s are owned by a given `Owner`.  We want to have our
-//! `Gadget`s point to their `Owner`. We can't do this with unique ownership, because more than one
-//! gadget may belong to the same `Owner`. `Rc<T>` allows us to share an `Owner` between multiple
-//! `Gadget`s, and have the `Owner` remain allocated as long as any `Gadget` points at it.
+//! Consider a scenario where a set of `Gadget`s are owned by a given `Owner`.
+//! We want to have our `Gadget`s point to their `Owner`. We can't do this with
+//! unique ownership, because more than one gadget may belong to the same
+//! `Owner`. `Rc<T>` allows us to share an `Owner` between multiple `Gadget`s,
+//! and have the `Owner` remain allocated as long as any `Gadget` points at it.
 //!
 //! ```rust
 //! use std::rc::Rc;
@@ -597,12 +600,20 @@ impl<T: Ord> Ord for Rc<T> {
 }
 
 // FIXME (#18248) Make `T` `Sized?`
+#[cfg(stage0)]
 impl<S: hash::Writer, T: Hash<S>> Hash<S> for Rc<T> {
     #[inline]
     fn hash(&self, state: &mut S) {
         (**self).hash(state);
     }
 }
+#[cfg(not(stage0))]
+impl<S: hash::Hasher, T: Hash<S>> Hash<S> for Rc<T> {
+    #[inline]
+    fn hash(&self, state: &mut S) {
+        (**self).hash(state);
+    }
+}
 
 #[experimental = "Show is experimental."]
 impl<T: fmt::Show> fmt::Show for Rc<T> {
@@ -611,6 +622,13 @@ impl<T: fmt::Show> fmt::Show for Rc<T> {
     }
 }
 
+#[stable]
+impl<T: fmt::String> fmt::String for Rc<T> {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        fmt::String::fmt(&**self, f)
+    }
+}
+
 /// A weak version of `Rc<T>`.
 ///
 /// Weak references do not count when determining if the inner value should be dropped.