Skip to content

Rename the Alloc trait to AllocHandle #60591

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/liballoc/alloc.rs
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ extern "Rust" {

/// The global memory allocator.
///
/// This type implements the [`Alloc`] trait by forwarding calls
/// This type implements the [`AllocHandle`] trait by forwarding calls
/// to the allocator registered with the `#[global_allocator]` attribute
/// if there is one, or the `std` crate’s default.
///
@@ -48,7 +48,7 @@ pub struct Global;
/// if there is one, or the `std` crate’s default.
///
/// This function is expected to be deprecated in favor of the `alloc` method
/// of the [`Global`] type when it and the [`Alloc`] trait become stable.
/// of the [`Global`] type when it and the [`AllocHandle`] trait become stable.
///
/// # Safety
///
@@ -82,7 +82,7 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
/// if there is one, or the `std` crate’s default.
///
/// This function is expected to be deprecated in favor of the `dealloc` method
/// of the [`Global`] type when it and the [`Alloc`] trait become stable.
/// of the [`Global`] type when it and the [`AllocHandle`] trait become stable.
///
/// # Safety
///
@@ -100,7 +100,7 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
/// if there is one, or the `std` crate’s default.
///
/// This function is expected to be deprecated in favor of the `realloc` method
/// of the [`Global`] type when it and the [`Alloc`] trait become stable.
/// of the [`Global`] type when it and the [`AllocHandle`] trait become stable.
///
/// # Safety
///
@@ -118,7 +118,7 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
/// if there is one, or the `std` crate’s default.
///
/// This function is expected to be deprecated in favor of the `alloc_zeroed` method
/// of the [`Global`] type when it and the [`Alloc`] trait become stable.
/// of the [`Global`] type when it and the [`AllocHandle`] trait become stable.
///
/// # Safety
///
@@ -145,7 +145,7 @@ pub unsafe fn alloc_zeroed(layout: Layout) -> *mut u8 {
}

#[unstable(feature = "allocator_api", issue = "32838")]
unsafe impl Alloc for Global {
unsafe impl AllocHandle for Global {
#[inline]
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
NonNull::new(alloc(layout)).ok_or(AllocErr)
@@ -232,7 +232,7 @@ mod tests {
extern crate test;
use test::Bencher;
use crate::boxed::Box;
use crate::alloc::{Global, Alloc, Layout, handle_alloc_error};
use crate::alloc::{Global, AllocHandle, Layout, handle_alloc_error};

#[test]
fn allocate_zeroed() {
2 changes: 1 addition & 1 deletion src/liballoc/collections/btree/node.rs
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@ use core::mem::{self, MaybeUninit};
use core::ptr::{self, Unique, NonNull};
use core::slice;

use crate::alloc::{Global, Alloc, Layout};
use crate::alloc::{Global, AllocHandle, Layout};
use crate::boxed::Box;

const B: usize = 6;
18 changes: 9 additions & 9 deletions src/liballoc/raw_vec.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ use core::ops::Drop;
use core::ptr::{self, NonNull, Unique};
use core::slice;

use crate::alloc::{Alloc, Layout, Global, handle_alloc_error};
use crate::alloc::{AllocHandle, Layout, Global, handle_alloc_error};
use crate::collections::CollectionAllocErr::{self, *};
use crate::boxed::Box;

@@ -39,13 +39,13 @@ use crate::boxed::Box;
/// field. This allows zero-sized types to not be special-cased by consumers of
/// this type.
#[allow(missing_debug_implementations)]
pub struct RawVec<T, A: Alloc = Global> {
pub struct RawVec<T, A: AllocHandle = Global> {
ptr: Unique<T>,
cap: usize,
a: A,
}

impl<T, A: Alloc> RawVec<T, A> {
impl<T, A: AllocHandle> RawVec<T, A> {
/// Like `new` but parameterized over the choice of allocator for
/// the returned RawVec.
pub const fn new_in(a: A) -> Self {
@@ -146,7 +146,7 @@ impl<T> RawVec<T, Global> {
}
}

impl<T, A: Alloc> RawVec<T, A> {
impl<T, A: AllocHandle> RawVec<T, A> {
/// Reconstitutes a RawVec from a pointer, capacity, and allocator.
///
/// # Undefined Behavior
@@ -189,7 +189,7 @@ impl<T> RawVec<T, Global> {
}
}

impl<T, A: Alloc> RawVec<T, A> {
impl<T, A: AllocHandle> RawVec<T, A> {
/// Gets a raw pointer to the start of the allocation. Note that this is
/// Unique::empty() if `cap = 0` or T is zero-sized. In the former case, you must
/// be careful.
@@ -629,7 +629,7 @@ enum ReserveStrategy {

use ReserveStrategy::*;

impl<T, A: Alloc> RawVec<T, A> {
impl<T, A: AllocHandle> RawVec<T, A> {
fn reserve_internal(
&mut self,
used_cap: usize,
@@ -700,7 +700,7 @@ impl<T> RawVec<T, Global> {
}
}

impl<T, A: Alloc> RawVec<T, A> {
impl<T, A: AllocHandle> RawVec<T, A> {
/// Frees the memory owned by the RawVec *without* trying to Drop its contents.
pub unsafe fn dealloc_buffer(&mut self) {
let elem_size = mem::size_of::<T>();
@@ -712,7 +712,7 @@ impl<T, A: Alloc> RawVec<T, A> {
}
}

unsafe impl<#[may_dangle] T, A: Alloc> Drop for RawVec<T, A> {
unsafe impl<#[may_dangle] T, A: AllocHandle> Drop for RawVec<T, A> {
/// Frees the memory owned by the RawVec *without* trying to Drop its contents.
fn drop(&mut self) {
unsafe { self.dealloc_buffer(); }
@@ -767,7 +767,7 @@ mod tests {
// A dumb allocator that consumes a fixed amount of fuel
// before allocation attempts start failing.
struct BoundedAlloc { fuel: usize }
unsafe impl Alloc for BoundedAlloc {
unsafe impl AllocHandle for BoundedAlloc {
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
let size = layout.size();
if size > self.fuel {
2 changes: 1 addition & 1 deletion src/liballoc/rc.rs
Original file line number Diff line number Diff line change
@@ -247,7 +247,7 @@ use core::slice::from_raw_parts_mut;
use core::convert::From;
use core::usize;

use crate::alloc::{Global, Alloc, Layout, box_free, handle_alloc_error};
use crate::alloc::{Global, AllocHandle, Layout, box_free, handle_alloc_error};
use crate::string::String;
use crate::vec::Vec;

2 changes: 1 addition & 1 deletion src/liballoc/sync.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ use core::{isize, usize};
use core::convert::From;
use core::slice::from_raw_parts_mut;

use crate::alloc::{Global, Alloc, Layout, box_free, handle_alloc_error};
use crate::alloc::{Global, AllocHandle, Layout, box_free, handle_alloc_error};
use crate::boxed::Box;
use crate::rc::is_dangling;
use crate::string::String;
4 changes: 2 additions & 2 deletions src/liballoc/tests/heap.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::alloc::{Global, Alloc, Layout, System};
use std::alloc::{Global, AllocHandle, Layout, System};

/// Issue #45955.
#[test]
@@ -11,7 +11,7 @@ fn std_heap_overaligned_request() {
check_overalign_requests(Global)
}

fn check_overalign_requests<T: Alloc>(mut allocator: T) {
fn check_overalign_requests<T: AllocHandle>(mut allocator: T) {
let size = 8;
let align = 16; // greater than size
let iterations = 100;
12 changes: 6 additions & 6 deletions src/libcore/alloc.rs
Original file line number Diff line number Diff line change
@@ -579,7 +579,7 @@ pub unsafe trait GlobalAlloc {
}
}

/// An implementation of `Alloc` can allocate, reallocate, and
/// A handle to a memory allocator that can allocate, reallocate, and
/// deallocate arbitrary blocks of data described via `Layout`.
///
/// Some of the methods require that a memory block be *currently
@@ -645,11 +645,11 @@ pub unsafe trait GlobalAlloc {
///
/// # Safety
///
/// The `Alloc` trait is an `unsafe` trait for a number of reasons, and
/// The `AllocHandle` trait is an `unsafe` trait for a number of reasons, and
/// implementors must ensure that they adhere to these contracts:
///
/// * Pointers returned from allocation functions must point to valid memory and
/// retain their validity until at least the instance of `Alloc` is dropped
/// retain their validity until at least the instance of `AllocHandle` is dropped
/// itself.
///
/// * `Layout` queries and calculations in general must be correct. Callers of
@@ -659,7 +659,7 @@ pub unsafe trait GlobalAlloc {
/// Note that this list may get tweaked over time as clarifications are made in
/// the future.
#[unstable(feature = "allocator_api", issue = "32838")]
pub unsafe trait Alloc {
pub unsafe trait AllocHandle {

// (Note: some existing allocators have unspecified but well-defined
// behavior in response to a zero size allocation request ;
@@ -1046,7 +1046,7 @@ pub unsafe trait Alloc {
/// must be considered "currently allocated" and must be
/// acceptable input to methods such as `realloc` or `dealloc`,
/// *even if* `T` is a zero-sized type. In other words, if your
/// `Alloc` implementation overrides this method in a manner
/// `AllocHandle` implementation overrides this method in a manner
/// that can return a zero-sized `ptr`, then all reallocation and
/// deallocation methods need to be similarly overridden to accept
/// such values as input.
@@ -1112,7 +1112,7 @@ pub unsafe trait Alloc {
/// must be considered "currently allocated" and must be
/// acceptable input to methods such as `realloc` or `dealloc`,
/// *even if* `T` is a zero-sized type. In other words, if your
/// `Alloc` implementation overrides this method in a manner
/// `AllocHandle` implementation overrides this method in a manner
/// that can return a zero-sized `ptr`, then all reallocation and
/// deallocation methods need to be similarly overridden to accept
/// such values as input.
2 changes: 1 addition & 1 deletion src/libstd/alloc.rs
Original file line number Diff line number Diff line change
@@ -135,7 +135,7 @@ pub struct System;

// The Alloc impl just forwards to the GlobalAlloc impl, which is in `std::sys::*::alloc`.
#[unstable(feature = "allocator_api", issue = "32838")]
unsafe impl Alloc for System {
unsafe impl AllocHandle for System {
#[inline]
unsafe fn alloc(&mut self, layout: Layout) -> Result<NonNull<u8>, AllocErr> {
NonNull::new(GlobalAlloc::alloc(self, layout)).ok_or(AllocErr)
2 changes: 1 addition & 1 deletion src/test/run-pass/allocator-alloc-one.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@

#![feature(allocator_api, nonnull)]

use std::alloc::{Alloc, Global, Layout, handle_alloc_error};
use std::alloc::{AllocHandle, Global, Layout, handle_alloc_error};

fn main() {
unsafe {
2 changes: 1 addition & 1 deletion src/test/run-pass/allocator/custom.rs
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@

extern crate helper;

use std::alloc::{self, Global, Alloc, System, Layout};
use std::alloc::{self, Global, AllocHandle, System, Layout};
use std::sync::atomic::{AtomicUsize, Ordering};

static HITS: AtomicUsize = AtomicUsize::new(0);
2 changes: 1 addition & 1 deletion src/test/run-pass/allocator/xcrate-use.rs
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
extern crate custom;
extern crate helper;

use std::alloc::{Global, Alloc, System, Layout};
use std::alloc::{Global, AllocHandle, System, Layout};
use std::sync::atomic::{Ordering, AtomicUsize};

#[global_allocator]
2 changes: 1 addition & 1 deletion src/test/run-pass/realloc-16687.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@

#![feature(allocator_api)]

use std::alloc::{Global, Alloc, Layout, handle_alloc_error};
use std::alloc::{Global, AllocHandle, Layout, handle_alloc_error};
use std::ptr::{self, NonNull};

fn main() {
2 changes: 1 addition & 1 deletion src/test/run-pass/regions/regions-mock-codegen.rs
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

#![feature(allocator_api)]

use std::alloc::{Alloc, Global, Layout, handle_alloc_error};
use std::alloc::{AllocHandle, Global, Layout, handle_alloc_error};
use std::ptr::NonNull;

struct arena(());