@@ -38,7 +38,7 @@ extern "Rust" {
38
38
39
39
/// The global memory allocator.
40
40
///
41
- /// This type implements the [`AllocRef `] trait by forwarding calls
41
+ /// This type implements the [`Allocator `] trait by forwarding calls
42
42
/// to the allocator registered with the `#[global_allocator]` attribute
43
43
/// if there is one, or the `std` crate’s default.
44
44
///
@@ -59,7 +59,7 @@ pub use std::alloc::Global;
59
59
/// if there is one, or the `std` crate’s default.
60
60
///
61
61
/// 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.
63
63
///
64
64
/// # Safety
65
65
///
@@ -93,7 +93,7 @@ pub unsafe fn alloc(layout: Layout) -> *mut u8 {
93
93
/// if there is one, or the `std` crate’s default.
94
94
///
95
95
/// 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.
97
97
///
98
98
/// # Safety
99
99
///
@@ -111,7 +111,7 @@ pub unsafe fn dealloc(ptr: *mut u8, layout: Layout) {
111
111
/// if there is one, or the `std` crate’s default.
112
112
///
113
113
/// 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.
115
115
///
116
116
/// # Safety
117
117
///
@@ -129,7 +129,7 @@ pub unsafe fn realloc(ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8
129
129
/// if there is one, or the `std` crate’s default.
130
130
///
131
131
/// 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.
133
133
///
134
134
/// # Safety
135
135
///
@@ -170,7 +170,7 @@ impl Global {
170
170
}
171
171
}
172
172
173
- // SAFETY: Same as `AllocRef ::grow`
173
+ // SAFETY: Same as `Allocator ::grow`
174
174
#[inline]
175
175
unsafe fn grow_impl(
176
176
&self,
@@ -211,7 +211,7 @@ impl Global {
211
211
old_size => unsafe {
212
212
let new_ptr = self.alloc_impl(new_layout, zeroed)?;
213
213
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);
215
215
Ok(new_ptr)
216
216
},
217
217
}
@@ -220,19 +220,19 @@ impl Global {
220
220
221
221
#[unstable(feature = "allocator_api", issue = "32838")]
222
222
#[cfg(not(test))]
223
- unsafe impl AllocRef for Global {
223
+ unsafe impl Allocator for Global {
224
224
#[inline]
225
- fn alloc (&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
225
+ fn allocate (&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
226
226
self.alloc_impl(layout, false)
227
227
}
228
228
229
229
#[inline]
230
- fn alloc_zeroed (&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
230
+ fn allocate_zeroed (&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError> {
231
231
self.alloc_impl(layout, true)
232
232
}
233
233
234
234
#[inline]
235
- unsafe fn dealloc (&self, ptr: NonNull<u8>, layout: Layout) {
235
+ unsafe fn deallocate (&self, ptr: NonNull<u8>, layout: Layout) {
236
236
if layout.size() != 0 {
237
237
// SAFETY: `layout` is non-zero in size,
238
238
// other conditions must be upheld by the caller
@@ -277,7 +277,7 @@ unsafe impl AllocRef for Global {
277
277
match new_layout.size() {
278
278
// SAFETY: conditions must be upheld by the caller
279
279
0 => unsafe {
280
- self.dealloc (ptr, old_layout);
280
+ self.deallocate (ptr, old_layout);
281
281
Ok(NonNull::slice_from_raw_parts(new_layout.dangling(), 0))
282
282
},
283
283
@@ -297,9 +297,9 @@ unsafe impl AllocRef for Global {
297
297
// `new_ptr`. Thus, the call to `copy_nonoverlapping` is safe. The safety contract
298
298
// for `dealloc` must be upheld by the caller.
299
299
new_size => unsafe {
300
- let new_ptr = self.alloc (new_layout)?;
300
+ let new_ptr = self.allocate (new_layout)?;
301
301
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);
303
303
Ok(new_ptr)
304
304
},
305
305
}
@@ -313,7 +313,7 @@ unsafe impl AllocRef for Global {
313
313
#[inline]
314
314
unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
315
315
let layout = unsafe { Layout::from_size_align_unchecked(size, align) };
316
- match Global.alloc (layout) {
316
+ match Global.allocate (layout) {
317
317
Ok(ptr) => ptr.as_mut_ptr(),
318
318
Err(_) => handle_alloc_error(layout),
319
319
}
@@ -322,16 +322,16 @@ unsafe fn exchange_malloc(size: usize, align: usize) -> *mut u8 {
322
322
#[cfg_attr(not(test), lang = "box_free")]
323
323
#[inline]
324
324
// 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
326
326
// 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) {
330
330
unsafe {
331
331
let size = size_of_val(ptr.as_ref());
332
332
let align = min_align_of_val(ptr.as_ref());
333
333
let layout = Layout::from_size_align_unchecked(size, align);
334
- alloc.dealloc (ptr.cast().into(), layout)
334
+ alloc.deallocate (ptr.cast().into(), layout)
335
335
}
336
336
}
337
337
0 commit comments