11#![ feature( const_fn) ]
2- #![ cfg_attr( feature = "alloc_ref" , feature( allocator_api, alloc_layout_extra) ) ]
2+ #![ cfg_attr(
3+ feature = "alloc_ref" ,
4+ feature( allocator_api, alloc_layout_extra, nonnull_slice_from_raw_parts)
5+ ) ]
36#![ no_std]
47
58#[ cfg( test) ]
@@ -13,7 +16,7 @@ extern crate alloc;
1316
1417use alloc:: alloc:: Layout ;
1518#[ cfg( feature = "alloc_ref" ) ]
16- use alloc:: alloc:: { AllocErr , AllocInit , AllocRef , MemoryBlock } ;
19+ use alloc:: alloc:: { AllocErr , AllocRef } ;
1720#[ cfg( feature = "use_spin" ) ]
1821use core:: alloc:: GlobalAlloc ;
1922use core:: mem;
@@ -158,22 +161,12 @@ impl Heap {
158161
159162#[ cfg( feature = "alloc_ref" ) ]
160163unsafe impl AllocRef for Heap {
161- fn alloc ( & mut self , layout : Layout , init : AllocInit ) -> Result < MemoryBlock , AllocErr > {
164+ fn alloc ( & mut self , layout : Layout ) -> Result < NonNull < [ u8 ] > , AllocErr > {
162165 if layout. size ( ) == 0 {
163- return Ok ( MemoryBlock {
164- ptr : layout. dangling ( ) ,
165- size : 0 ,
166- } ) ;
166+ return Ok ( NonNull :: slice_from_raw_parts ( layout. dangling ( ) , 0 ) ) ;
167167 }
168168 match self . allocate_first_fit ( layout) {
169- Ok ( ptr) => {
170- let block = MemoryBlock {
171- ptr,
172- size : layout. size ( ) ,
173- } ;
174- unsafe { init. init ( block) } ;
175- Ok ( block)
176- }
169+ Ok ( ptr) => Ok ( NonNull :: slice_from_raw_parts ( ptr, layout. size ( ) ) ) ,
177170 Err ( ( ) ) => Err ( AllocErr ) ,
178171 }
179172 }
0 commit comments