44// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
55// http://opensource.org/licenses/MIT>, at your option. This file may not be
66// copied, modified, or distributed except according to those terms.
7- #![ feature( alloc, heap_api) ]
7+ #![ feature( alloc, heap_api, allocator_api ) ]
88
99extern crate alloc;
1010extern crate fringe;
1111
12- use alloc:: heap;
12+ use alloc:: heap:: Heap ;
13+ use alloc:: allocator:: { Alloc , Layout } ;
1314use alloc:: boxed:: Box ;
1415use std:: slice;
1516use fringe:: { STACK_ALIGNMENT , Stack , SliceStack , OwnedStack , OsStack } ;
1617
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+
1722#[ test]
1823fn slice_aligned ( ) {
1924 unsafe {
20- let ptr = heap :: allocate ( 16384 , STACK_ALIGNMENT ) ;
25+ let ptr = heap_allocate ( 16384 , STACK_ALIGNMENT ) ;
2126 let mut slice = Box :: from_raw ( slice:: from_raw_parts_mut ( ptr, 16384 ) ) ;
2227 let stack = SliceStack :: new ( & mut slice[ 4096 ..8192 ] ) ;
2328 assert_eq ! ( stack. base( ) as usize & ( STACK_ALIGNMENT - 1 ) , 0 ) ;
@@ -28,7 +33,7 @@ fn slice_aligned() {
2833#[ test]
2934fn slice_unaligned ( ) {
3035 unsafe {
31- let ptr = heap :: allocate ( 16384 , STACK_ALIGNMENT ) ;
36+ let ptr = heap_allocate ( 16384 , STACK_ALIGNMENT ) ;
3237 let mut slice = Box :: from_raw ( slice:: from_raw_parts_mut ( ptr, 16384 ) ) ;
3338 let stack = SliceStack :: new ( & mut slice[ 4097 ..8193 ] ) ;
3439 assert_eq ! ( stack. base( ) as usize & ( STACK_ALIGNMENT - 1 ) , 0 ) ;
@@ -39,7 +44,7 @@ fn slice_unaligned() {
3944#[ test]
4045fn slice_too_small ( ) {
4146 unsafe {
42- let ptr = heap :: allocate ( STACK_ALIGNMENT , STACK_ALIGNMENT ) ;
47+ let ptr = heap_allocate ( STACK_ALIGNMENT , STACK_ALIGNMENT ) ;
4348 let mut slice = Box :: from_raw ( slice:: from_raw_parts_mut ( ptr, STACK_ALIGNMENT ) ) ;
4449 let stack = SliceStack :: new ( & mut slice[ 0 ..1 ] ) ;
4550 assert_eq ! ( stack. base( ) as usize & ( STACK_ALIGNMENT - 1 ) , 0 ) ;
@@ -51,7 +56,7 @@ fn slice_too_small() {
5156#[ should_panic( expected = "SliceStack too small" ) ]
5257fn slice_too_small_unaligned ( ) {
5358 unsafe {
54- let ptr = heap :: allocate ( STACK_ALIGNMENT , STACK_ALIGNMENT ) ;
59+ let ptr = heap_allocate ( STACK_ALIGNMENT , STACK_ALIGNMENT ) ;
5560 let mut slice = Box :: from_raw ( slice:: from_raw_parts_mut ( ptr, STACK_ALIGNMENT ) ) ;
5661 SliceStack :: new ( & mut slice[ 1 ..2 ] ) ;
5762 }
0 commit comments