Skip to content

Commit 9274b37

Browse files
committed
Rename AllocRef to Allocator and (de)alloc to (de)allocate
1 parent e622543 commit 9274b37

27 files changed

+337
-335
lines changed

library/alloc/src/alloc.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ extern "Rust" {
3838

3939
/// The global memory allocator.
4040
///
41-
/// This type implements the [`AllocRef`] trait by forwarding calls
41+
/// This type implements the [`Allocator`] trait by forwarding calls
4242
/// to the allocator registered with the `#[global_allocator]` attribute
4343
/// if there is one, or the `std` crate’s default.
4444
///
@@ -59,7 +59,7 @@ pub use std::alloc::Global;
5959
/// if there is one, or the `std` crate’s default.
6060
///
6161
/// This function is expected to be deprecated in favor of the `alloc` method
62-
/// of the [`Global`] type when it and the [`AllocRef`] trait become stable.
62+
/// of the [`Global`] type when it and the [`Allocator`] trait become stable.
6363
///
6464
/// # Safety
6565
///
@@ -93,7 +93,7 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
9393
/// if there is one, or the `std` crate’s default.
9494
///
9595
/// This function is expected to be deprecated in favor of the `dealloc` method
96-
/// of the [`Global`] type when it and the [`AllocRef`] trait become stable.
96+
/// of the [`Global`] type when it and the [`Allocator`] trait become stable.
9797
///
9898
/// # Safety
9999
///
@@ -111,7 +111,7 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
111111
/// if there is one, or the `std` crate’s default.
112112
///
113113
/// This function is expected to be deprecated in favor of the `realloc` method
114-
/// of the [`Global`] type when it and the [`AllocRef`] trait become stable.
114+
/// of the [`Global`] type when it and the [`Allocator`] trait become stable.
115115
///
116116
/// # Safety
117117
///
@@ -129,7 +129,7 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
129129
/// if there is one, or the `std` crate’s default.
130130
///
131131
/// This function is expected to be deprecated in favor of the `alloc_zeroed` method
132-
/// of the [`Global`] type when it and the [`AllocRef`] trait become stable.
132+
/// of the [`Global`] type when it and the [`Allocator`] trait become stable.
133133
///
134134
/// # Safety
135135
///
@@ -170,7 +170,7 @@ impl Global {
170170
}
171171
}
172172

173-
// SAFETY: Same as `AllocRef::grow`
173+
// SAFETY: Same as `Allocator::grow`
174174
#[inline]
175175
unsafe fn grow_impl(
176176
&self,
@@ -211,7 +211,7 @@ impl Global {
211211
old_size => unsafe {
212212
let new_ptr = self.alloc_impl(new_layout, zeroed)?;
213213
ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_mut_ptr(), old_size);
214-
self.dealloc(ptr, old_layout);
214+
self.deallocate(ptr, old_layout);
215215
Ok(new_ptr)
216216
},
217217
}
@@ -220,19 +220,19 @@ impl Global {
220220

221221
#[unstable(feature = "allocator_api", issue = "32838")]
222222
#[cfg(not(test))]
223-
unsafe impl AllocRef for Global {
223+
unsafe impl Allocator for Global {
224224
#[inline]
225-
fn alloc(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
225+
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
226226
self.alloc_impl(layout, false)
227227
}
228228

229229
#[inline]
230-
fn alloc_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
230+
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
231231
self.alloc_impl(layout, true)
232232
}
233233

234234
#[inline]
235-
unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout) {
235+
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
236236
if layout.size() != 0 {
237237
// SAFETY: `layout` is non-zero in size,
238238
// other conditions must be upheld by the caller
@@ -277,7 +277,7 @@ unsafe impl AllocRef for Global {
277277
match new_layout.size() {
278278
// SAFETY: conditions must be upheld by the caller
279279
0 => unsafe {
280-
self.dealloc(ptr, old_layout);
280+
self.deallocate(ptr, old_layout);
281281
Ok(NonNull::slice_from_raw_parts(new_layout.dangling(), 0))
282282
},
283283

@@ -297,9 +297,9 @@ unsafe impl AllocRef for Global {
297297
// `new_ptr`. Thus, the call to `copy_nonoverlapping` is safe. The safety contract
298298
// for `dealloc` must be upheld by the caller.
299299
new_size => unsafe {
300-
let new_ptr = self.alloc(new_layout)?;
300+
let new_ptr = self.allocate(new_layout)?;
301301
ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_mut_ptr(), new_size);
302-
self.dealloc(ptr, old_layout);
302+
self.deallocate(ptr, old_layout);
303303
Ok(new_ptr)
304304
},
305305
}
@@ -313,7 +313,7 @@ unsafe impl AllocRef for Global {
313313
#[inline]
314314
unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
315315
let layout = unsafe { Layout::from_size_align_unchecked(size, align) };
316-
match Global.alloc(layout) {
316+
match Global.allocate(layout) {
317317
Ok(ptr) => ptr.as_mut_ptr(),
318318
Err(_) => handle_alloc_error(layout),
319319
}
@@ -322,16 +322,16 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
322322
#[cfg_attr(not(test), lang = "box_free")]
323323
#[inline]
324324
// This signature has to be the same as `Box`, otherwise an ICE will happen.
325-
// When an additional parameter to `Box` is added (like `A: AllocRef`), this has to be added here as
325+
// When an additional parameter to `Box` is added (like `A: Allocator`), this has to be added here as
326326
// well.
327-
// For example if `Box` is changed to `struct Box<T: ?Sized, A: AllocRef>(Unique<T>, A)`,
328-
// this function has to be changed to `fn box_free<T: ?Sized, A: AllocRef>(Unique<T>, A)` as well.
329-
pub(crate) unsafe fn box_free<T: ?Sized, A: AllocRef>(ptr: Unique<T>, alloc: A) {
327+
// For example if `Box` is changed to `struct Box<T: ?Sized, A: Allocator>(Unique<T>, A)`,
328+
// this function has to be changed to `fn box_free<T: ?Sized, A: Allocator>(Unique<T>, A)` as well.
329+
pub(crate) unsafe fn box_free<T: ?Sized, A: Allocator>(ptr: Unique<T>, alloc: A) {
330330
unsafe {
331331
let size = size_of_val(ptr.as_ref());
332332
let align = min_align_of_val(ptr.as_ref());
333333
let layout = Layout::from_size_align_unchecked(size, align);
334-
alloc.dealloc(ptr.cast().into(), layout)
334+
alloc.deallocate(ptr.cast().into(), layout)
335335
}
336336
}
337337

library/alloc/src/alloc/tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ fn allocate_zeroed() {
99
unsafe {
1010
let layout = Layout::from_size_align(1024, 1).unwrap();
1111
let ptr =
12-
Global.alloc_zeroed(layout.clone()).unwrap_or_else(|_| handle_alloc_error(layout));
12+
Global.allocate_zeroed(layout.clone()).unwrap_or_else(|_| handle_alloc_error(layout));
1313

1414
let mut i = ptr.as_non_null_ptr().as_ptr();
1515
let end = i.add(layout.size());
1616
while i < end {
1717
assert_eq!(*i, 0);
1818
i = i.offset(1);
1919
}
20-
Global.dealloc(ptr.as_non_null_ptr(), layout);
20+
Global.deallocate(ptr.as_non_null_ptr(), layout);
2121
}
2222
}
2323

0 commit comments

Comments
 (0)