Commit 287fdde1 authored by Jeremy Soller's avatar Jeremy Soller

Update to new heap API

parent 79df020c
......@@ -2,8 +2,9 @@
extern crate rusttype;
use alloc::allocator::{Alloc, Layout};
use alloc::heap::Heap;
use alloc::heap::Global;
use std::{cmp, slice};
use std::ptr::NonNull;
use primitive::{fast_set32, fast_set64, fast_copy};
......@@ -42,7 +43,7 @@ impl Display {
#[cfg(not(feature="rusttype"))]
pub fn new(width: usize, height: usize, onscreen: usize) -> Display {
let size = width * height;
let offscreen = unsafe { Heap.alloc(Layout::from_size_align_unchecked(size * 4, 4096)).unwrap() };
let offscreen = unsafe { Global.alloc(Layout::from_size_align_unchecked(size * 4, 4096)).unwrap().as_ptr() };
unsafe { fast_set64(offscreen as *mut u64, 0, size/2) };
Display {
width: width,
......@@ -55,7 +56,7 @@ impl Display {
#[cfg(feature="rusttype")]
pub fn new(width: usize, height: usize, onscreen: usize) -> Display {
let size = width * height;
let offscreen = unsafe { Heap.alloc(Layout::from_size_align_unchecked(size * 4, 4096)).unwrap() };
let offscreen = unsafe { Global.alloc(Layout::from_size_align_unchecked(size * 4, 4096)).unwrap().as_ptr() };
unsafe { fast_set64(offscreen as *mut u64, 0, size/2) };
Display {
width: width,
......@@ -74,7 +75,7 @@ impl Display {
println!("Resize display to {}, {}", width, height);
let size = width * height;
let offscreen = unsafe { Heap.alloc(Layout::from_size_align_unchecked(size * 4, 4096)).unwrap() };
let offscreen = unsafe { Global.alloc(Layout::from_size_align_unchecked(size * 4, 4096)).unwrap().as_ptr() };
{
let mut old_ptr = self.offscreen.as_ptr();
......@@ -107,7 +108,7 @@ impl Display {
let onscreen = self.onscreen.as_mut_ptr();
self.onscreen = unsafe { slice::from_raw_parts_mut(onscreen, size) };
unsafe { Heap.dealloc(self.offscreen.as_mut_ptr() as *mut u8, Layout::from_size_align_unchecked(self.offscreen.len() * 4, 4096)) };
unsafe { Global.dealloc(NonNull::new_unchecked(self.offscreen.as_mut_ptr() as *mut u8).as_opaque(), Layout::from_size_align_unchecked(self.offscreen.len() * 4, 4096)) };
self.offscreen = unsafe { slice::from_raw_parts_mut(offscreen as *mut u32, size) };
} else {
println!("Display is already {}, {}", width, height);
......@@ -276,6 +277,6 @@ impl Display {
impl Drop for Display {
fn drop(&mut self) {
unsafe { Heap.dealloc(self.offscreen.as_mut_ptr() as *mut u8, Layout::from_size_align_unchecked(self.offscreen.len() * 4, 4096)) };
unsafe { Global.dealloc(NonNull::new_unchecked(self.offscreen.as_mut_ptr() as *mut u8).as_opaque(), Layout::from_size_align_unchecked(self.offscreen.len() * 4, 4096)) };
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment