1
- use core:: alloc:: Layout ;
1
+ use core:: alloc:: { Layout , LayoutError } ;
2
2
use core:: mem;
3
3
use core:: mem:: { align_of, size_of} ;
4
4
use core:: ptr:: null_mut;
@@ -365,13 +365,13 @@ impl HoleList {
365
365
/// The [`allocate_first_fit`][HoleList::allocate_first_fit] and
366
366
/// [`deallocate`][HoleList::deallocate] methods perform the required alignment
367
367
/// themselves, so calling this function manually is not necessary.
368
- pub fn align_layout ( layout : Layout ) -> Layout {
368
+ pub fn align_layout ( layout : Layout ) -> Result < Layout , LayoutError > {
369
369
let mut size = layout. size ( ) ;
370
370
if size < Self :: min_size ( ) {
371
371
size = Self :: min_size ( ) ;
372
372
}
373
373
let size = align_up_size ( size, mem:: align_of :: < Hole > ( ) ) ;
374
- Layout :: from_size_align ( size, layout. align ( ) ) . unwrap ( )
374
+ Layout :: from_size_align ( size, layout. align ( ) )
375
375
}
376
376
377
377
/// Searches the list for a big enough hole.
@@ -389,7 +389,7 @@ impl HoleList {
389
389
// release to remove this clippy warning
390
390
#[ allow( clippy:: result_unit_err) ]
391
391
pub fn allocate_first_fit ( & mut self , layout : Layout ) -> Result < ( NonNull < u8 > , Layout ) , ( ) > {
392
- let aligned_layout = Self :: align_layout ( layout) ;
392
+ let aligned_layout = Self :: align_layout ( layout) . map_err ( |_| ( ) ) ? ;
393
393
let mut cursor = self . cursor ( ) . ok_or ( ( ) ) ?;
394
394
395
395
loop {
@@ -419,7 +419,7 @@ impl HoleList {
419
419
/// The function performs exactly the same layout adjustments as [`allocate_first_fit`] and
420
420
/// returns the aligned layout.
421
421
pub unsafe fn deallocate ( & mut self , ptr : NonNull < u8 > , layout : Layout ) -> Layout {
422
- let aligned_layout = Self :: align_layout ( layout) ;
422
+ let aligned_layout = Self :: align_layout ( layout) . unwrap ( ) ;
423
423
deallocate ( self , ptr. as_ptr ( ) , aligned_layout. size ( ) ) ;
424
424
aligned_layout
425
425
}
0 commit comments