Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -133,12 +133,22 @@ impl Heap {

#[cfg(feature = "alloc_ref")]
unsafe impl AllocRef for Heap {
fn alloc(&mut self, layout: Layout) -> Result<(NonNull<u8>, usize), AllocErr> {
fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result<MemoryBlock, AllocErr> {
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),
}
}
Expand Down