Skip to content

Commit 405c9a1

Browse files
committed
rust: import alloc
This brings the `alloc` crate in-tree. The code comes from Rust 1.54.0-beta.1, i.e. commit `bf62f4de3`. Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent dfaa42f commit 405c9a1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+38740
-0
lines changed

rust/alloc/alloc.rs

+423
Large diffs are not rendered by default.

rust/alloc/alloc/tests.rs

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use super::*;
2+
3+
extern crate test;
4+
use crate::boxed::Box;
5+
use test::Bencher;
6+
7+
#[test]
8+
fn allocate_zeroed() {
9+
unsafe {
10+
let layout = Layout::from_size_align(1024, 1).unwrap();
11+
let ptr =
12+
Global.allocate_zeroed(layout.clone()).unwrap_or_else(|_| handle_alloc_error(layout));
13+
14+
let mut i = ptr.as_non_null_ptr().as_ptr();
15+
let end = i.add(layout.size());
16+
while i < end {
17+
assert_eq!(*i, 0);
18+
i = i.offset(1);
19+
}
20+
Global.deallocate(ptr.as_non_null_ptr(), layout);
21+
}
22+
}
23+
24+
#[bench]
25+
#[cfg_attr(miri, ignore)] // isolated Miri does not support benchmarks
26+
fn alloc_owned_small(b: &mut Bencher) {
27+
b.iter(|| {
28+
let _: Box<_> = box 10;
29+
})
30+
}

0 commit comments

Comments
 (0)