@@ -10,7 +10,10 @@ extern crate std;
10
10
#[ cfg( feature = "use_spin" ) ]
11
11
extern crate spin;
12
12
13
- use core:: alloc:: { Alloc , AllocErr , GlobalAlloc , Layout , Opaque } ;
13
+ extern crate alloc;
14
+
15
+ use alloc:: allocator:: { Alloc , AllocErr , Layout } ;
16
+ use core:: alloc:: { GlobalAlloc } ;
14
17
use core:: mem;
15
18
#[ cfg( feature = "use_spin" ) ]
16
19
use core:: ops:: Deref ;
@@ -69,7 +72,7 @@ impl Heap {
69
72
/// This function scans the list of free memory blocks and uses the first block that is big
70
73
/// enough. The runtime is in O(n) where n is the number of free blocks, but it should be
71
74
/// reasonably fast for small allocations.
72
- pub fn allocate_first_fit ( & mut self , layout : Layout ) -> Result < NonNull < Opaque > , AllocErr > {
75
+ pub fn allocate_first_fit ( & mut self , layout : Layout ) -> Result < NonNull < u8 > , AllocErr > {
73
76
let mut size = layout. size ( ) ;
74
77
if size < HoleList :: min_size ( ) {
75
78
size = HoleList :: min_size ( ) ;
@@ -87,7 +90,7 @@ impl Heap {
87
90
/// This function walks the list of free memory blocks and inserts the freed block at the
88
91
/// correct place. If the freed block is adjacent to another free block, the blocks are merged
89
92
/// again. This operation is in `O(n)` since the list needs to be sorted by address.
90
- pub unsafe fn deallocate ( & mut self , ptr : NonNull < Opaque > , layout : Layout ) {
93
+ pub unsafe fn deallocate ( & mut self , ptr : NonNull < u8 > , layout : Layout ) {
91
94
let mut size = layout. size ( ) ;
92
95
if size < HoleList :: min_size ( ) {
93
96
size = HoleList :: min_size ( ) ;
@@ -122,17 +125,17 @@ impl Heap {
122
125
let top = self . top ( ) ;
123
126
let layout = Layout :: from_size_align ( by, 1 ) . unwrap ( ) ;
124
127
self . holes
125
- . deallocate ( NonNull :: new_unchecked ( top as * mut Opaque ) , layout) ;
128
+ . deallocate ( NonNull :: new_unchecked ( top as * mut u8 ) , layout) ;
126
129
self . size += by;
127
130
}
128
131
}
129
132
130
133
unsafe impl Alloc for Heap {
131
- unsafe fn alloc ( & mut self , layout : Layout ) -> Result < NonNull < Opaque > , AllocErr > {
134
+ unsafe fn alloc ( & mut self , layout : Layout ) -> Result < NonNull < u8 > , AllocErr > {
132
135
self . allocate_first_fit ( layout)
133
136
}
134
137
135
- unsafe fn dealloc ( & mut self , ptr : NonNull < Opaque > , layout : Layout ) {
138
+ unsafe fn dealloc ( & mut self , ptr : NonNull < u8 > , layout : Layout ) {
136
139
self . deallocate ( ptr, layout)
137
140
}
138
141
}
@@ -171,15 +174,15 @@ impl Deref for LockedHeap {
171
174
172
175
#[ cfg( feature = "use_spin" ) ]
173
176
unsafe impl GlobalAlloc for LockedHeap {
174
- unsafe fn alloc ( & self , layout : Layout ) -> * mut Opaque {
177
+ unsafe fn alloc ( & self , layout : Layout ) -> * mut u8 {
175
178
self . 0
176
179
. lock ( )
177
180
. allocate_first_fit ( layout)
178
181
. ok ( )
179
- . map_or ( 0 as * mut Opaque , |allocation| allocation. as_ptr ( ) )
182
+ . map_or ( 0 as * mut u8 , |allocation| allocation. as_ptr ( ) )
180
183
}
181
184
182
- unsafe fn dealloc ( & self , ptr : * mut Opaque , layout : Layout ) {
185
+ unsafe fn dealloc ( & self , ptr : * mut u8 , layout : Layout ) {
183
186
self . 0
184
187
. lock ( )
185
188
. deallocate ( NonNull :: new_unchecked ( ptr) , layout)
0 commit comments