From e1c7e0df234be18a546799590c6b1a0ea6ce1a37 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Thu, 5 Mar 2020 23:21:52 +0000 Subject: [PATCH] Updated to new alloc API --- src/hole.rs | 4 ++-- src/lib.rs | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hole.rs b/src/hole.rs index e2e0bfc..ff4d534 100644 --- a/src/hole.rs +++ b/src/hole.rs @@ -49,7 +49,7 @@ impl HoleList { /// block is returned. /// This function uses the “first fit” strategy, so it uses the first hole that is big /// enough. Thus the runtime is in O(n) but it should be reasonably fast for small allocations. - pub fn allocate_first_fit(&mut self, layout: Layout) -> Result, AllocErr> { + pub fn allocate_first_fit(&mut self, layout: Layout) -> Result<(NonNull, usize), AllocErr> { assert!(layout.size() >= Self::min_size()); allocate_first_fit(&mut self.first, layout).map(|allocation| { @@ -59,7 +59,7 @@ impl HoleList { if let Some(padding) = allocation.back_padding { deallocate(&mut self.first, padding.addr, padding.size); } - NonNull::new(allocation.info.addr as *mut u8).unwrap() + (NonNull::new(allocation.info.addr as *mut u8).unwrap(), layout.size()) }) } diff --git a/src/lib.rs b/src/lib.rs index dbccde9..0fecadb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,7 +71,7 @@ impl Heap { /// This function scans the list of free memory blocks and uses the first block that is big /// enough. The runtime is in O(n) where n is the number of free blocks, but it should be /// reasonably fast for small allocations. - pub fn allocate_first_fit(&mut self, layout: Layout) -> Result, AllocErr> { + pub fn allocate_first_fit(&mut self, layout: Layout) -> Result<(NonNull, usize), AllocErr> { let mut size = layout.size(); if size < HoleList::min_size() { size = HoleList::min_size(); @@ -130,7 +130,7 @@ impl Heap { } unsafe impl AllocRef for Heap { - unsafe fn alloc(&mut self, layout: Layout) -> Result, AllocErr> { + unsafe fn alloc(&mut self, layout: Layout) -> Result<(NonNull, usize), AllocErr> { self.allocate_first_fit(layout) } @@ -178,7 +178,7 @@ unsafe impl GlobalAlloc for LockedHeap { .lock() .allocate_first_fit(layout) .ok() - .map_or(0 as *mut u8, |allocation| allocation.as_ptr()) + .map_or(0 as *mut u8, |allocation| allocation.0.as_ptr()) } unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) {