///
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
unsafe fn grow(
- &mut self,
+ &self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
///
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
unsafe fn grow_zeroed(
- &mut self,
+ &self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
///
/// [`handle_alloc_error`]: ../../alloc/alloc/fn.handle_alloc_error.html
unsafe fn shrink(
- &mut self,
+ &self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
///
/// The returned adaptor also implements `AllocRef` and will simply borrow this.
#[inline(always)]
- fn by_ref(&mut self) -> &mut Self {
+ fn by_ref(&mut self) -> &Self {
self
}
}
#[unstable(feature = "allocator_api", issue = "32838")]
-unsafe impl<A> AllocRef for &mut A
+unsafe impl<A> AllocRef for &A
where
A: AllocRef + ?Sized,
{
#[inline]
unsafe fn grow(
- &mut self,
+ &self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
#[inline]
unsafe fn grow_zeroed(
- &mut self,
+ &self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
#[inline]
unsafe fn shrink(
- &mut self,
+ &self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
// SAFETY: Same as `AllocRef::grow`
#[inline]
unsafe fn grow_impl(
- &mut self,
+ &self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
old_size => unsafe {
let new_ptr = self.alloc_impl(new_layout, zeroed)?;
ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_mut_ptr(), old_size);
- self.dealloc(ptr, old_layout);
+ AllocRef::dealloc(&self, ptr, old_layout);
Ok(new_ptr)
},
}
#[inline]
unsafe fn grow(
- &mut self,
+ &self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
#[inline]
unsafe fn grow_zeroed(
- &mut self,
+ &self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
#[inline]
unsafe fn shrink(
- &mut self,
+ &self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
match new_layout.size() {
// SAFETY: conditions must be upheld by the caller
0 => unsafe {
- self.dealloc(ptr, old_layout);
+ AllocRef::dealloc(&self, ptr, old_layout);
Ok(NonNull::slice_from_raw_parts(new_layout.dangling(), 0))
},
// `new_ptr`. Thus, the call to `copy_nonoverlapping` is safe. The safety contract
// for `dealloc` must be upheld by the caller.
new_size => unsafe {
- let new_ptr = self.alloc(new_layout)?;
+ let new_ptr = AllocRef::alloc(&self, new_layout)?;
ptr::copy_nonoverlapping(ptr.as_ptr(), new_ptr.as_mut_ptr(), new_size);
- self.dealloc(ptr, old_layout);
+ AllocRef::dealloc(&self, ptr, old_layout);
Ok(new_ptr)
},
}
unsafe impl alloc::GlobalAlloc for A {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
HITS.fetch_add(1, Ordering::SeqCst);
- AllocRef::alloc(&System, layout).unwrap().as_mut_ptr()
+ alloc::GlobalAlloc::alloc(&System, layout)
}
unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {