Skip to content

Commit

Permalink
Merge pull request #248 from JohnTitor/allocator
Browse files Browse the repository at this point in the history
Rename `AllocRef` to `Allocator` and `(de)alloc` to `(de)allocate`
  • Loading branch information
ehuss authored Dec 5, 2020
2 parents d8383b6 + 3fd89d6 commit 79e60b5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/destructors.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ For instance, a custom implementation of `Box` might write `Drop` like this:
```rust
#![feature(ptr_internals, allocator_api)]

use std::alloc::{AllocRef, Global, GlobalAlloc, Layout};
use std::alloc::{Allocator, Global, GlobalAlloc, Layout};
use std::mem;
use std::ptr::{drop_in_place, NonNull, Unique};

Expand All @@ -39,7 +39,7 @@ impl<T> Drop for Box<T> {
unsafe {
drop_in_place(self.ptr.as_ptr());
let c: NonNull<T> = self.ptr.into();
Global.dealloc(c.cast(), Layout::new::<T>())
Global.deallocate(c.cast(), Layout::new::<T>())
}
}
}
Expand All @@ -55,7 +55,7 @@ However this wouldn't work:
```rust
#![feature(allocator_api, ptr_internals)]

use std::alloc::{AllocRef, Global, GlobalAlloc, Layout};
use std::alloc::{Allocator, Global, GlobalAlloc, Layout};
use std::ptr::{drop_in_place, Unique, NonNull};
use std::mem;

Expand All @@ -66,7 +66,7 @@ impl<T> Drop for Box<T> {
unsafe {
drop_in_place(self.ptr.as_ptr());
let c: NonNull<T> = self.ptr.into();
Global.dealloc(c.cast(), Layout::new::<T>());
Global.deallocate(c.cast(), Layout::new::<T>());
}
}
}
Expand All @@ -79,7 +79,7 @@ impl<T> Drop for SuperBox<T> {
// Hyper-optimized: deallocate the box's contents for it
// without `drop`ing the contents
let c: NonNull<T> = self.my_box.ptr.into();
Global.dealloc(c.cast::<u8>(), Layout::new::<T>());
Global.deallocate(c.cast::<u8>(), Layout::new::<T>());
}
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ of Self during `drop` is to use an Option:
```rust
#![feature(allocator_api, ptr_internals)]

use std::alloc::{AllocRef, GlobalAlloc, Global, Layout};
use std::alloc::{Allocator, GlobalAlloc, Global, Layout};
use std::ptr::{drop_in_place, Unique, NonNull};
use std::mem;

Expand All @@ -139,7 +139,7 @@ impl<T> Drop for Box<T> {
unsafe {
drop_in_place(self.ptr.as_ptr());
let c: NonNull<T> = self.ptr.into();
Global.dealloc(c.cast(), Layout::new::<T>());
Global.deallocate(c.cast(), Layout::new::<T>());
}
}
}
Expand All @@ -154,7 +154,7 @@ impl<T> Drop for SuperBox<T> {
// field as `None` to prevent Rust from trying to Drop it.
let my_box = self.my_box.take().unwrap();
let c: NonNull<T> = my_box.ptr.into();
Global.dealloc(c.cast(), Layout::new::<T>());
Global.deallocate(c.cast(), Layout::new::<T>());
mem::forget(my_box);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/vec-final.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::mem;
use std::ops::{Deref, DerefMut};
use std::marker::PhantomData;
use std::alloc::{
AllocRef,
Allocator,
Global,
GlobalAlloc,
Layout,
Expand Down Expand Up @@ -40,7 +40,7 @@ impl<T> RawVec<T> {
assert!(elem_size != 0, "capacity overflow");

let (new_cap, ptr) = if self.cap == 0 {
let ptr = Global.alloc(Layout::array::<T>(1).unwrap());
let ptr = Global.allocate(Layout::array::<T>(1).unwrap());
(1, ptr)
} else {
let new_cap = 2 * self.cap;
Expand Down Expand Up @@ -72,7 +72,7 @@ impl<T> Drop for RawVec<T> {
if self.cap != 0 && elem_size != 0 {
unsafe {
let c: NonNull<T> = self.ptr.into();
Global.dealloc(c.cast(),
Global.deallocate(c.cast(),
Layout::array::<T>(self.cap).unwrap());
}
}
Expand Down

0 comments on commit 79e60b5

Please sign in to comment.