4
4
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
5
5
// http://opensource.org/licenses/MIT>, at your option. This file may not be
6
6
// copied, modified, or distributed except according to those terms.
7
- #![ feature( alloc, heap_api) ]
7
+ #![ feature( alloc, heap_api, allocator_api ) ]
8
8
9
9
extern crate alloc;
10
10
extern crate fringe;
11
11
12
- use alloc:: heap;
12
+ use alloc:: heap:: Heap ;
13
+ use alloc:: allocator:: { Alloc , Layout } ;
13
14
use alloc:: boxed:: Box ;
14
15
use std:: slice;
15
16
use fringe:: { STACK_ALIGNMENT , Stack , SliceStack , OwnedStack , OsStack } ;
16
17
18
+ unsafe fn heap_allocate ( size : usize , align : usize ) -> * mut u8 {
19
+ Heap . alloc ( Layout :: from_size_align_unchecked ( size, align) ) . expect ( "couldn't allocate" )
20
+ }
21
+
17
22
#[ test]
18
23
fn slice_aligned ( ) {
19
24
unsafe {
20
- let ptr = heap :: allocate ( 16384 , STACK_ALIGNMENT ) ;
25
+ let ptr = heap_allocate ( 16384 , STACK_ALIGNMENT ) ;
21
26
let mut slice = Box :: from_raw ( slice:: from_raw_parts_mut ( ptr, 16384 ) ) ;
22
27
let stack = SliceStack :: new ( & mut slice[ 4096 ..8192 ] ) ;
23
28
assert_eq ! ( stack. base( ) as usize & ( STACK_ALIGNMENT - 1 ) , 0 ) ;
@@ -28,7 +33,7 @@ fn slice_aligned() {
28
33
#[ test]
29
34
fn slice_unaligned ( ) {
30
35
unsafe {
31
- let ptr = heap :: allocate ( 16384 , STACK_ALIGNMENT ) ;
36
+ let ptr = heap_allocate ( 16384 , STACK_ALIGNMENT ) ;
32
37
let mut slice = Box :: from_raw ( slice:: from_raw_parts_mut ( ptr, 16384 ) ) ;
33
38
let stack = SliceStack :: new ( & mut slice[ 4097 ..8193 ] ) ;
34
39
assert_eq ! ( stack. base( ) as usize & ( STACK_ALIGNMENT - 1 ) , 0 ) ;
@@ -39,7 +44,7 @@ fn slice_unaligned() {
39
44
#[ test]
40
45
fn slice_too_small ( ) {
41
46
unsafe {
42
- let ptr = heap :: allocate ( STACK_ALIGNMENT , STACK_ALIGNMENT ) ;
47
+ let ptr = heap_allocate ( STACK_ALIGNMENT , STACK_ALIGNMENT ) ;
43
48
let mut slice = Box :: from_raw ( slice:: from_raw_parts_mut ( ptr, STACK_ALIGNMENT ) ) ;
44
49
let stack = SliceStack :: new ( & mut slice[ 0 ..1 ] ) ;
45
50
assert_eq ! ( stack. base( ) as usize & ( STACK_ALIGNMENT - 1 ) , 0 ) ;
@@ -51,7 +56,7 @@ fn slice_too_small() {
51
56
#[ should_panic( expected = "SliceStack too small" ) ]
52
57
fn slice_too_small_unaligned ( ) {
53
58
unsafe {
54
- let ptr = heap :: allocate ( STACK_ALIGNMENT , STACK_ALIGNMENT ) ;
59
+ let ptr = heap_allocate ( STACK_ALIGNMENT , STACK_ALIGNMENT ) ;
55
60
let mut slice = Box :: from_raw ( slice:: from_raw_parts_mut ( ptr, STACK_ALIGNMENT ) ) ;
56
61
SliceStack :: new ( & mut slice[ 1 ..2 ] ) ;
57
62
}
0 commit comments