Fix to work with new allocator APIs.
This commit is contained in:
parent
1d97ab9d02
commit
9ca9c72e0e
|
@ -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;
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
// This file is part of libfringe, a low-level green threading library.
|
||||
// Copyright (c) whitequark <whitequark@whitequark.org>
|
||||
// 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)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,20 +4,21 @@
|
|||
// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
|
||||
// http://opensource.org/licenses/MIT>, 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]
|
||||
|
|
Loading…
Reference in New Issue