From 03603ab649b580a9f561f202b74b2888fd04757f Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 7 Apr 2020 10:23:45 +0200 Subject: [PATCH] Update AllocRef implementation for latest API changes --- src/lib.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 53d6f49..5124c21 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,7 @@ extern crate alloc; use alloc::alloc::Layout; #[cfg(feature = "alloc_ref")] -use alloc::alloc::{AllocErr, AllocRef}; +use alloc::alloc::{AllocErr, AllocInit, AllocRef, MemoryBlock}; use core::alloc::GlobalAlloc; use core::mem; #[cfg(feature = "use_spin")] @@ -133,12 +133,22 @@ impl Heap { #[cfg(feature = "alloc_ref")] unsafe impl AllocRef for Heap { - fn alloc(&mut self, layout: Layout) -> Result<(NonNull, usize), AllocErr> { + fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result { if layout.size() == 0 { - return Ok((layout.dangling(), 0)); + return Ok(MemoryBlock { + ptr: layout.dangling(), + size: 0, + }); } match self.allocate_first_fit(layout) { - Ok(ptr) => Ok((ptr, layout.size())), + Ok(ptr) => { + let block = MemoryBlock { + ptr, + size: layout.size(), + }; + unsafe { init.init(block) }; + Ok(block) + } Err(()) => Err(AllocErr), } }