]> git.lizzy.rs Git - rust.git/blobdiff - src/libarena/lib.rs
rollup merge of #18407 : thestinger/arena
[rust.git] / src / libarena / lib.rs
index ee3fd6ad0eb0db0f5a909c3b41ed799bc9a929f6..1528c313b738e804ff4b012ab8351be473e4b114 100644 (file)
@@ -26,7 +26,7 @@
 #![license = "MIT/ASL2"]
 #![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",
-       html_root_url = "http://doc.rust-lang.org/master/")]
+       html_root_url = "http://doc.rust-lang.org/nightly/")]
 
 #![feature(unsafe_destructor)]
 #![allow(missing_doc)]
@@ -69,7 +69,7 @@ unsafe fn as_ptr(&self) -> *const u8 {
 /// element). When the arena is destroyed, it iterates through all of its
 /// chunks, and uses the tydesc information to trace through the objects,
 /// calling the destructors on them. One subtle point that needs to be
-/// addressed is how to handle failures while running the user provided
+/// addressed is how to handle panics while running the user provided
 /// initializer function. It is important to not run the destructor on
 /// uninitialized objects, but how to detect them is somewhat subtle. Since
 /// `alloc()` can be invoked recursively, it is not sufficient to simply exclude
@@ -162,7 +162,7 @@ unsafe fn destroy_chunk(chunk: &Chunk) {
 
 // We encode whether the object a tydesc describes has been
 // initialized in the arena in the low bit of the tydesc pointer. This
-// is necessary in order to properly do cleanup if a failure occurs
+// is necessary in order to properly do cleanup if a panic occurs
 // during an initializer.
 #[inline]
 fn bitpack_tydesc_ptr(p: *const TyDesc, is_done: bool) -> uint {
@@ -208,13 +208,13 @@ fn alloc_copy_inner(&self, n_bytes: uint, align: uint) -> *const u8 {
     }
 
     #[inline]
-    fn alloc_copy<T>(&self, op: || -> T) -> &T {
+    fn alloc_copy<T>(&self, op: || -> T) -> &mut T {
         unsafe {
             let ptr = self.alloc_copy_inner(mem::size_of::<T>(),
                                             mem::min_align_of::<T>());
             let ptr = ptr as *mut T;
             ptr::write(&mut (*ptr), op());
-            return &*ptr;
+            return &mut *ptr;
         }
     }
 
@@ -262,7 +262,7 @@ fn alloc_noncopy_inner(&self, n_bytes: uint,
     }
 
     #[inline]
-    fn alloc_noncopy<T>(&self, op: || -> T) -> &T {
+    fn alloc_noncopy<T>(&self, op: || -> T) -> &mut T {
         unsafe {
             let tydesc = get_tydesc::<T>();
             let (ty_ptr, ptr) =
@@ -279,14 +279,14 @@ fn alloc_noncopy<T>(&self, op: || -> T) -> &T {
             // the object is there.
             *ty_ptr = bitpack_tydesc_ptr(tydesc, true);
 
-            return &*ptr;
+            return &mut *ptr;
         }
     }
 
     /// Allocates a new item in the arena, using `op` to initialize the value,
     /// and returns a reference to it.
     #[inline]
-    pub fn alloc<T>(&self, op: || -> T) -> &T {
+    pub fn alloc<T>(&self, op: || -> T) -> &mut T {
         unsafe {
             if intrinsics::needs_drop::<T>() {
                 self.alloc_noncopy(op)
@@ -337,10 +337,9 @@ fn test_arena_destructors_fail() {
         // things interesting.
         arena.alloc(|| { [0u8, 1u8, 2u8] });
     }
-    // Now, fail while allocating
+    // Now, panic while allocating
     arena.alloc::<Rc<int>>(|| {
-        // Now fail.
-        fail!();
+        panic!();
     });
 }
 
@@ -448,7 +447,7 @@ pub fn new() -> TypedArena<T> {
     #[inline]
     pub fn with_capacity(capacity: uint) -> TypedArena<T> {
         unsafe {
-            let chunk = TypedArenaChunk::<T>::new(ptr::mut_null(), capacity);
+            let chunk = TypedArenaChunk::<T>::new(ptr::null_mut(), capacity);
             TypedArena {
                 ptr: Cell::new((*chunk).start() as *const T),
                 end: Cell::new((*chunk).end() as *const T),
@@ -459,12 +458,12 @@ pub fn with_capacity(capacity: uint) -> TypedArena<T> {
 
     /// Allocates an object in the `TypedArena`, returning a reference to it.
     #[inline]
-    pub fn alloc(&self, object: T) -> &T {
+    pub fn alloc(&self, object: T) -> &mut T {
         if self.ptr == self.end {
             self.grow()
         }
 
-        let ptr: &T = unsafe {
+        let ptr: &mut T = unsafe {
             let ptr: &mut T = mem::transmute(self.ptr);
             ptr::write(ptr, object);
             self.ptr.set(self.ptr.get().offset(1));