@@ -3,12 +3,26 @@ use core::alloc::Layout;
33use std:: mem:: { align_of, size_of, MaybeUninit } ;
44use std:: prelude:: v1:: * ;
55
6+ #[ repr( align( 128 ) ) ]
7+ struct Chonk < const N : usize > {
8+ data : [ MaybeUninit < u8 > ; N ]
9+ }
10+
11+ impl < const N : usize > Chonk < N > {
12+ pub fn new ( ) -> Self {
13+ Self {
14+ data : [ MaybeUninit :: uninit ( ) ; N ] ,
15+ }
16+ }
17+ }
18+
619fn new_heap ( ) -> Heap {
720 const HEAP_SIZE : usize = 1000 ;
8- let heap_space = Box :: leak ( Box :: new ( [ MaybeUninit :: uninit ( ) ; HEAP_SIZE ] ) ) ;
9- let assumed_location = heap_space. as_mut_ptr ( ) . cast ( ) ;
21+ let heap_space = Box :: leak ( Box :: new ( Chonk :: < HEAP_SIZE > :: new ( ) ) ) ;
22+ let data = & mut heap_space. data ;
23+ let assumed_location = data. as_mut_ptr ( ) . cast ( ) ;
1024
11- let heap = Heap :: from_slice ( heap_space ) ;
25+ let heap = Heap :: from_slice ( data ) ;
1226 assert ! ( heap. bottom == assumed_location) ;
1327 assert ! ( heap. size == HEAP_SIZE ) ;
1428 heap
@@ -73,8 +87,10 @@ fn allocate_and_free_double_usize() {
7387 * ( x. as_ptr ( ) as * mut ( usize , usize ) ) = ( 0xdeafdeadbeafbabe , 0xdeafdeadbeafbabe ) ;
7488
7589 heap. deallocate ( x, layout. clone ( ) ) ;
76- assert_eq ! ( ( * ( heap. bottom as * const Hole ) ) . size, heap. size) ;
77- assert ! ( ( * ( heap. bottom as * const Hole ) ) . next. is_none( ) ) ;
90+ let real_first = heap. holes ( ) . first . next . as_ref ( ) . unwrap ( ) ;
91+
92+ assert_eq ! ( real_first. size, heap. size) ;
93+ assert ! ( real_first. next. is_none( ) ) ;
7894 }
7995}
8096
0 commit comments