Rename AllocRef to Allocator and (de)alloc to (de)allocate

This commit is contained in:
Tim Diekmann 2020-12-04 14:47:15 +01:00
parent e6225434ff
commit 9274b37d99
27 changed files with 337 additions and 335 deletions

View file

@ -8,9 +8,8 @@
extern crate helper;
use std::alloc::{self, AllocRef, Global, Layout, System};
use std::alloc::{self, Allocator, Global, Layout, System};
use std::sync::atomic::{AtomicUsize, Ordering};
use std::ptr::NonNull;
static HITS: AtomicUsize = AtomicUsize::new(0);
@ -24,7 +23,7 @@ unsafe impl alloc::GlobalAlloc for A {
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {
HITS.fetch_add(1, Ordering::SeqCst);
AllocRef::dealloc(&System, NonNull::new(ptr).unwrap(), layout)
alloc::GlobalAlloc::dealloc(&System, ptr, layout)
}
}
@ -39,10 +38,10 @@ fn main() {
unsafe {
let layout = Layout::from_size_align(4, 2).unwrap();
let memory = Global.alloc(layout.clone()).unwrap();
let memory = Global.allocate(layout.clone()).unwrap();
helper::work_with(&memory);
assert_eq!(HITS.load(Ordering::SeqCst), n + 1);
Global.dealloc(memory.as_non_null_ptr(), layout);
Global.deallocate(memory.as_non_null_ptr(), layout);
assert_eq!(HITS.load(Ordering::SeqCst), n + 2);
let s = String::with_capacity(10);
@ -51,10 +50,10 @@ fn main() {
drop(s);
assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
let memory = System.alloc(layout.clone()).unwrap();
assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
let memory = System.allocate(layout.clone()).unwrap();
helper::work_with(&memory);
System.dealloc(memory.as_non_null_ptr(), layout);
assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
System.deallocate(memory.as_non_null_ptr(), layout);
assert_eq!(HITS.load(Ordering::SeqCst), n + 4);
}
}

View file

@ -10,7 +10,7 @@
extern crate custom;
extern crate helper;
use std::alloc::{AllocRef, Global, Layout, System};
use std::alloc::{Allocator, Global, Layout, System};
use std::sync::atomic::{AtomicUsize, Ordering};
#[global_allocator]
@ -21,16 +21,16 @@ fn main() {
let n = GLOBAL.0.load(Ordering::SeqCst);
let layout = Layout::from_size_align(4, 2).unwrap();
let memory = Global.alloc(layout.clone()).unwrap();
let memory = Global.allocate(layout.clone()).unwrap();
helper::work_with(&memory);
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 1);
Global.dealloc(memory.as_non_null_ptr(), layout);
Global.deallocate(memory.as_non_null_ptr(), layout);
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
let memory = System.alloc(layout.clone()).unwrap();
let memory = System.allocate(layout.clone()).unwrap();
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
helper::work_with(&memory);
System.dealloc(memory.as_non_null_ptr(), layout);
System.deallocate(memory.as_non_null_ptr(), layout);
assert_eq!(GLOBAL.0.load(Ordering::SeqCst), n + 2);
}
}

View file

@ -6,7 +6,7 @@ LL | type Ty = Vec<[u8]>;
|
::: $SRC_DIR/alloc/src/vec.rs:LL:COL
|
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: AllocRef = Global> {
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
| - required by this bound in `Vec`
|
= help: the trait `Sized` is not implemented for `[u8]`

View file

@ -17,7 +17,7 @@ LL | let x: Vec<dyn Trait + Sized> = Vec::new();
|
::: $SRC_DIR/alloc/src/vec.rs:LL:COL
|
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: AllocRef = Global> {
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
| - required by this bound in `Vec`
|
= help: the trait `Sized` is not implemented for `dyn Trait`

View file

@ -1,26 +1,26 @@
#![feature(allocator_api)]
use std::alloc::{AllocError, AllocRef, Layout, System};
use std::alloc::{AllocError, Allocator, Layout, System};
use std::ptr::NonNull;
use std::boxed::Box;
struct Allocator {}
struct Alloc {}
unsafe impl AllocRef for Allocator {
fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
System.alloc(layout)
unsafe impl Allocator for Alloc {
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
System.allocate(layout)
}
unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout) {
System.dealloc(ptr, layout)
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
System.deallocate(ptr, layout)
}
}
fn use_value(_: u32) {}
fn main() {
let alloc = Allocator {};
let alloc = Alloc {};
let boxed = Box::new_in(10, alloc.by_ref());
let theref = Box::leak(boxed);
drop(alloc);

View file

@ -6,7 +6,7 @@ LL | impl AsRef<Q> for Box<Q> {
|
= note: conflicting implementation in crate `alloc`:
- impl<T, A> AsRef<T> for Box<T, A>
where A: AllocRef, T: ?Sized;
where A: Allocator, T: ?Sized;
error[E0119]: conflicting implementations of trait `std::convert::From<S>` for type `S`:
--> $DIR/conflict-with-std.rs:12:1

View file

@ -6,7 +6,7 @@ LL | fn iceman(c: Vec<[i32]>) {}
|
::: $SRC_DIR/alloc/src/vec.rs:LL:COL
|
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: AllocRef = Global> {
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
| - required by this bound in `Vec`
|
= help: the trait `Sized` is not implemented for `[i32]`

View file

@ -6,7 +6,7 @@ LL | impl<T> Drop for T where T: A {
|
= note: conflicting implementation in crate `alloc`:
- impl<T, A> Drop for Box<T, A>
where A: AllocRef, T: ?Sized;
where A: Allocator, T: ?Sized;
= note: downstream crates may implement trait `A` for type `std::boxed::Box<_, _>`
error[E0120]: the `Drop` trait may only be implemented for structs, enums, and unions

View file

@ -7,7 +7,7 @@
#![feature(allocator_api)]
#![feature(slice_ptr_get)]
use std::alloc::{handle_alloc_error, AllocRef, Global, Layout};
use std::alloc::{handle_alloc_error, Allocator, Global, Layout};
use std::ptr::{self, NonNull};
fn main() {
@ -42,7 +42,7 @@ unsafe fn test_triangle() -> bool {
println!("allocate({:?})", layout);
}
let ptr = Global.alloc(layout).unwrap_or_else(|_| handle_alloc_error(layout));
let ptr = Global.allocate(layout).unwrap_or_else(|_| handle_alloc_error(layout));
if PRINT {
println!("allocate({:?}) = {:?}", layout, ptr);
@ -56,7 +56,7 @@ unsafe fn test_triangle() -> bool {
println!("deallocate({:?}, {:?}", ptr, layout);
}
Global.dealloc(NonNull::new_unchecked(ptr), layout);
Global.deallocate(NonNull::new_unchecked(ptr), layout);
}
unsafe fn reallocate(ptr: *mut u8, old: Layout, new: Layout) -> *mut u8 {

View file

@ -4,7 +4,7 @@
// pretty-expanded FIXME #23616
#![feature(allocator_api)]
use std::alloc::{handle_alloc_error, AllocRef, Global, Layout};
use std::alloc::{handle_alloc_error, Allocator, Global, Layout};
use std::ptr::NonNull;
struct arena(());
@ -22,23 +22,23 @@ struct Ccx {
x: isize,
}
fn alloc(_bcx: &arena) -> &Bcx<'_> {
fn allocate(_bcx: &arena) -> &Bcx<'_> {
unsafe {
let layout = Layout::new::<Bcx>();
let ptr = Global.alloc(layout).unwrap_or_else(|_| handle_alloc_error(layout));
let ptr = Global.allocate(layout).unwrap_or_else(|_| handle_alloc_error(layout));
&*(ptr.as_ptr() as *const _)
}
}
fn h<'a>(bcx: &'a Bcx<'a>) -> &'a Bcx<'a> {
return alloc(bcx.fcx.arena);
return allocate(bcx.fcx.arena);
}
fn g(fcx: &Fcx) {
let bcx = Bcx { fcx };
let bcx2 = h(&bcx);
unsafe {
Global.dealloc(NonNull::new_unchecked(bcx2 as *const _ as *mut _), Layout::new::<Bcx>());
Global.deallocate(NonNull::new_unchecked(bcx2 as *const _ as *mut _), Layout::new::<Bcx>());
}
}

View file

@ -22,7 +22,7 @@ LL | fn clone(&self) -> Self;
|
LL | / pub struct Box<
LL | | T: ?Sized,
LL | | #[unstable(feature = "allocator_api", issue = "32838")] A: AllocRef = Global,
LL | | #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
LL | | >(Unique<T>, A);
| |________________- doesn't satisfy `Box<dyn Foo>: Clone`
|

View file

@ -19,7 +19,7 @@ LL | fn clone(&self) -> Self;
|
LL | / pub struct Box<
LL | | T: ?Sized,
LL | | #[unstable(feature = "allocator_api", issue = "32838")] A: AllocRef = Global,
LL | | #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
LL | | >(Unique<T>, A);
| |________________- doesn't satisfy `Box<R>: Clone`
|