From 48ec45e4474448d5f43822870bee7b4ea6dfdfe0 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Thu, 10 Dec 2020 11:44:48 +0100 Subject: [PATCH] fix(alloc_ref): Use new nightly Allocator trait Due to nightly changes, `AllocRef` was renamed `Allocator` and the methods don't take a `&mut self` anymore. Therefore `Heap` cannot implement `Allocator` anymore. Implement it for `LockedHeap` instead, which requires the `use_spin` feature. --- src/lib.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index ece8274..ab6e512 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,7 +16,7 @@ extern crate alloc; use alloc::alloc::Layout; #[cfg(feature = "alloc_ref")] -use alloc::alloc::{AllocErr, AllocRef}; +use alloc::alloc::{AllocError, Allocator}; #[cfg(feature = "use_spin")] use core::alloc::GlobalAlloc; use core::mem; @@ -160,20 +160,21 @@ impl Heap { } #[cfg(feature = "alloc_ref")] -unsafe impl AllocRef for Heap { - fn alloc(&mut self, layout: Layout) -> Result, AllocErr> { +#[cfg(feature = "use_spin")] +unsafe impl Allocator for LockedHeap { + fn allocate(&self, layout: Layout) -> Result, AllocError> { if layout.size() == 0 { return Ok(NonNull::slice_from_raw_parts(layout.dangling(), 0)); } - match self.allocate_first_fit(layout) { + match self.0.lock().allocate_first_fit(layout) { Ok(ptr) => Ok(NonNull::slice_from_raw_parts(ptr, layout.size())), - Err(()) => Err(AllocErr), + Err(()) => Err(AllocError), } } - unsafe fn dealloc(&mut self, ptr: NonNull, layout: Layout) { + unsafe fn deallocate(&self, ptr: NonNull, layout: Layout) { if layout.size() != 0 { - self.deallocate(ptr, layout); + self.0.lock().deallocate(ptr, layout); } } }