+
Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/devices/allocate.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use super::Cpu;
use crate::arrays::CountElements;
use std::alloc::{alloc_zeroed, Layout};
use std::alloc::{alloc_zeroed, handle_alloc_error, Layout};
use std::boxed::Box;

/// Allocate an Nd array on the heap.
Expand All @@ -16,10 +16,11 @@ impl AllocateZeros for Cpu {
// TODO move to using safe code once we can allocate an array directly on the heap.
let layout = Layout::new::<T>();
debug_assert_eq!(layout.size(), T::NUM_BYTES);
unsafe {
let ptr = alloc_zeroed(layout) as *mut T;
Box::from_raw(ptr)
let ptr: *mut T = unsafe { alloc_zeroed(layout) as *mut T };
if ptr.is_null() {
handle_alloc_error(layout);
}
unsafe { Box::from_raw(ptr) }
}
}

Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载