@@ -7,11 +7,9 @@ fn new_heap() -> Heap {
77 const HEAP_SIZE : usize = 1000 ;
88 let heap_space = Box :: into_raw ( Box :: new ( [ 0u8 ; HEAP_SIZE ] ) ) ;
99
10- let heap_bottom = heap_space as usize ;
11- let heap_top = heap_bottom + HEAP_SIZE ;
12- let heap = unsafe { Heap :: new ( heap_bottom, heap_top) } ;
13- assert ! ( heap. bottom == heap_bottom) ;
14- assert ! ( heap. top == heap_top) ;
10+ let heap = unsafe { Heap :: new ( heap_space as usize , HEAP_SIZE ) } ;
11+ assert ! ( heap. bottom == heap_space as usize ) ;
12+ assert ! ( heap. size == HEAP_SIZE ) ;
1513 heap
1614}
1715
@@ -24,7 +22,7 @@ fn empty() {
2422#[ test]
2523fn oom ( ) {
2624 let mut heap = new_heap ( ) ;
27- let size = heap. top ( ) - heap . bottom ( ) + 1 ;
25+ let size = heap. size ( ) + 1 ;
2826 let addr = heap. allocate_first_fit ( size, align_of :: < usize > ( ) ) ;
2927 assert ! ( addr. is_none( ) ) ;
3028}
@@ -39,11 +37,10 @@ fn allocate_double_usize() {
3937 assert ! ( addr == heap. bottom) ;
4038 let ( hole_addr, hole_size) = heap. holes . first_hole ( ) . expect ( "ERROR: no hole left" ) ;
4139 assert ! ( hole_addr == heap. bottom + size) ;
42- assert ! ( hole_size == heap. top - heap . bottom - size) ;
40+ assert ! ( hole_size == heap. size - size) ;
4341
4442 unsafe {
45- assert_eq ! ( ( * ( ( addr + size) as * const Hole ) ) . size,
46- heap. top - heap. bottom - size) ;
43+ assert_eq ! ( ( * ( ( addr + size) as * const Hole ) ) . size, heap. size - size) ;
4744 }
4845}
4946
@@ -56,7 +53,7 @@ fn allocate_and_free_double_usize() {
5653 * ( x as * mut ( usize , usize ) ) = ( 0xdeafdeadbeafbabe , 0xdeafdeadbeafbabe ) ;
5754
5855 heap. deallocate ( x, size_of :: < usize > ( ) * 2 , align_of :: < usize > ( ) ) ;
59- assert_eq ! ( ( * ( heap. bottom as * const Hole ) ) . size, heap. top - heap . bottom ) ;
56+ assert_eq ! ( ( * ( heap. bottom as * const Hole ) ) . size, heap. size ) ;
6057 assert ! ( ( * ( heap. bottom as * const Hole ) ) . next. is_none( ) ) ;
6158 }
6259}
@@ -76,7 +73,7 @@ fn deallocate_right_before() {
7673 heap. deallocate ( x, size, 1 ) ;
7774 assert_eq ! ( ( * ( x as * const Hole ) ) . size, size * 2 ) ;
7875 heap. deallocate ( z, size, 1 ) ;
79- assert_eq ! ( ( * ( x as * const Hole ) ) . size, heap. top - heap . bottom ) ;
76+ assert_eq ! ( ( * ( x as * const Hole ) ) . size, heap. size ) ;
8077 }
8178}
8279
@@ -95,7 +92,7 @@ fn deallocate_right_behind() {
9592 heap. deallocate ( y, size, 1 ) ;
9693 assert_eq ! ( ( * ( x as * const Hole ) ) . size, size * 2 ) ;
9794 heap. deallocate ( z, size, 1 ) ;
98- assert_eq ! ( ( * ( x as * const Hole ) ) . size, heap. top - heap . bottom ) ;
95+ assert_eq ! ( ( * ( x as * const Hole ) ) . size, heap. size ) ;
9996 }
10097}
10198
@@ -118,7 +115,7 @@ fn deallocate_middle() {
118115 heap. deallocate ( y, size, 1 ) ;
119116 assert_eq ! ( ( * ( x as * const Hole ) ) . size, size * 3 ) ;
120117 heap. deallocate ( a, size, 1 ) ;
121- assert_eq ! ( ( * ( x as * const Hole ) ) . size, heap. top - heap . bottom ) ;
118+ assert_eq ! ( ( * ( x as * const Hole ) ) . size, heap. size ) ;
122119 }
123120}
124121
0 commit comments