Skip to content

Commit b79dcf3

Browse files
committed
Handle liballoc changes
1 parent 87452b5 commit b79dcf3

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// http://opensource.org/licenses/MIT>, at your option. This file may not be
66
// copied, modified, or distributed except according to those terms.
77
#![feature(asm, naked_functions, cfg_target_vendor, untagged_unions)]
8-
#![cfg_attr(feature = "alloc", feature(alloc, heap_api))]
8+
#![cfg_attr(feature = "alloc", feature(alloc, heap_api, allocator_api))]
99
#![cfg_attr(test, feature(test))]
1010
#![no_std]
1111

src/stack/owned_stack.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
extern crate alloc;
55

66
use core::slice;
7-
use self::alloc::heap;
7+
use self::alloc::heap::Heap;
8+
use self::alloc::allocator::{Alloc, Layout};
89
use self::alloc::boxed::Box;
910
use stack::Stack;
1011

@@ -18,7 +19,7 @@ impl OwnedStack {
1819
pub fn new(size: usize) -> OwnedStack {
1920
unsafe {
2021
let aligned_size = size & !(::STACK_ALIGNMENT - 1);
21-
let ptr = heap::allocate(aligned_size, ::STACK_ALIGNMENT);
22+
let ptr = Heap.alloc(Layout::from_size_align_unchecked(aligned_size, ::STACK_ALIGNMENT)).unwrap();
2223
OwnedStack(Box::from_raw(slice::from_raw_parts_mut(ptr, aligned_size)))
2324
}
2425
}

tests/stack.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,25 @@
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

99
extern crate alloc;
1010
extern crate fringe;
1111

12-
use alloc::heap;
12+
use alloc::heap::Heap;
13+
use alloc::allocator::{Alloc, Layout};
1314
use alloc::boxed::Box;
1415
use std::slice;
1516
use 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]
1823
fn 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]
2934
fn 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]
4045
fn 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")]
5257
fn 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

Comments
 (0)