From 9ca9c72e0e9ff1765bf463c716d7d1633dc3a647 Mon Sep 17 00:00:00 2001 From: Gerd Zellweger Date: Thu, 7 Feb 2019 17:18:13 -0800 Subject: [PATCH] Fix to work with new allocator APIs. --- src/lib.rs | 5 ++++- src/stack/owned_stack.rs | 14 ++++++++------ tests/stack.rs | 11 ++++++----- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index af4cf14..916da5b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,7 +5,7 @@ // http://opensource.org/licenses/MIT>, at your option. This file may not be // copied, modified, or distributed except according to those terms. #![feature(asm, naked_functions, cfg_target_vendor, untagged_unions)] -#![cfg_attr(feature = "alloc", feature(alloc, heap_api, allocator_api))] +#![cfg_attr(feature = "alloc", feature(alloc, allocator_api))] #![cfg_attr(test, feature(test))] #![no_std] @@ -33,6 +33,9 @@ #[macro_use] extern crate std; +#[cfg(feature = "alloc")] +extern crate alloc; + pub use stack::*; pub use generator::Generator; diff --git a/src/stack/owned_stack.rs b/src/stack/owned_stack.rs index a927bd9..11ecb3e 100644 --- a/src/stack/owned_stack.rs +++ b/src/stack/owned_stack.rs @@ -1,12 +1,11 @@ // This file is part of libfringe, a low-level green threading library. // Copyright (c) whitequark // See the LICENSE file included in this distribution. -extern crate alloc; use core::slice; -use self::alloc::heap::Global; -use self::alloc::allocator::{Alloc, Layout}; -use self::alloc::boxed::Box; +use alloc::alloc::alloc; +use alloc::boxed::Box; +use core::alloc::Layout; use stack::Stack; /// OwnedStack holds a non-guarded, heap-allocated stack. @@ -19,8 +18,11 @@ impl OwnedStack { pub fn new(size: usize) -> OwnedStack { unsafe { let aligned_size = size & !(::STACK_ALIGNMENT - 1); - let ptr = Global.alloc(Layout::from_size_align_unchecked(aligned_size, ::STACK_ALIGNMENT)).unwrap(); - OwnedStack(Box::from_raw(slice::from_raw_parts_mut(ptr.as_ptr() as *mut u8, aligned_size))) + let ptr = alloc(Layout::from_size_align_unchecked( + aligned_size, + ::STACK_ALIGNMENT, + )); + OwnedStack(Box::from_raw(slice::from_raw_parts_mut(ptr, aligned_size))) } } } diff --git a/tests/stack.rs b/tests/stack.rs index 719fead..17c51b2 100644 --- a/tests/stack.rs +++ b/tests/stack.rs @@ -4,20 +4,21 @@ // http://apache.org/licenses/LICENSE-2.0> or the MIT license , at your option. This file may not be // copied, modified, or distributed except according to those terms. -#![feature(alloc, heap_api, allocator_api)] +#![feature(alloc, allocator_api)] +extern crate core; extern crate alloc; extern crate fringe; -use alloc::heap::Global; -use alloc::allocator::{Alloc, Layout}; +use alloc::alloc::alloc; +use core::alloc::Layout; + use alloc::boxed::Box; use std::slice; use fringe::{STACK_ALIGNMENT, Stack, SliceStack, OwnedStack, OsStack}; unsafe fn heap_allocate(size: usize, align: usize) -> *mut u8 { - let ptr = Global.alloc(Layout::from_size_align_unchecked(size, align)).expect("couldn't allocate"); - ptr.as_ptr() as *mut u8 + alloc(Layout::from_size_align_unchecked(size, align)) } #[test]