@@ -7,11 +7,9 @@ fn new_heap() -> Heap {
7
7
const HEAP_SIZE : usize = 1000 ;
8
8
let heap_space = Box :: into_raw ( Box :: new ( [ 0u8 ; HEAP_SIZE ] ) ) ;
9
9
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 ) ;
15
13
heap
16
14
}
17
15
@@ -24,7 +22,7 @@ fn empty() {
24
22
#[ test]
25
23
fn oom ( ) {
26
24
let mut heap = new_heap ( ) ;
27
- let size = heap. top ( ) - heap . bottom ( ) + 1 ;
25
+ let size = heap. size ( ) + 1 ;
28
26
let addr = heap. allocate_first_fit ( size, align_of :: < usize > ( ) ) ;
29
27
assert ! ( addr. is_none( ) ) ;
30
28
}
@@ -39,11 +37,10 @@ fn allocate_double_usize() {
39
37
assert ! ( addr == heap. bottom) ;
40
38
let ( hole_addr, hole_size) = heap. holes . first_hole ( ) . expect ( "ERROR: no hole left" ) ;
41
39
assert ! ( hole_addr == heap. bottom + size) ;
42
- assert ! ( hole_size == heap. top - heap . bottom - size) ;
40
+ assert ! ( hole_size == heap. size - size) ;
43
41
44
42
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) ;
47
44
}
48
45
}
49
46
@@ -56,7 +53,7 @@ fn allocate_and_free_double_usize() {
56
53
* ( x as * mut ( usize , usize ) ) = ( 0xdeafdeadbeafbabe , 0xdeafdeadbeafbabe ) ;
57
54
58
55
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 ) ;
60
57
assert ! ( ( * ( heap. bottom as * const Hole ) ) . next. is_none( ) ) ;
61
58
}
62
59
}
@@ -76,7 +73,7 @@ fn deallocate_right_before() {
76
73
heap. deallocate ( x, size, 1 ) ;
77
74
assert_eq ! ( ( * ( x as * const Hole ) ) . size, size * 2 ) ;
78
75
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 ) ;
80
77
}
81
78
}
82
79
@@ -95,7 +92,7 @@ fn deallocate_right_behind() {
95
92
heap. deallocate ( y, size, 1 ) ;
96
93
assert_eq ! ( ( * ( x as * const Hole ) ) . size, size * 2 ) ;
97
94
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 ) ;
99
96
}
100
97
}
101
98
@@ -118,7 +115,7 @@ fn deallocate_middle() {
118
115
heap. deallocate ( y, size, 1 ) ;
119
116
assert_eq ! ( ( * ( x as * const Hole ) ) . size, size * 3 ) ;
120
117
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 ) ;
122
119
}
123
120
}
124
121
0 commit comments