Skip to content

Commit de5b26d

Browse files
committed
Use new std::alloc::Allocator interface.
This was changed in core.
1 parent 47acece commit de5b26d

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
88b81970ba7a989a728b32039dd075dc206f1360
1+
3ff10e74a74ed093fcabac1de27fe1cd65bbbb4a

tests/run-pass/heap_allocator.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
#![feature(allocator_api, slice_ptr_get)]
22

33
use std::ptr::NonNull;
4-
use std::alloc::{Global, AllocRef, Layout, System};
4+
use std::alloc::{Global, Allocator, Layout, System};
55
use std::slice;
66

7-
fn check_alloc<T: AllocRef>(allocator: T) { unsafe {
7+
fn check_alloc<T: Allocator>(allocator: T) { unsafe {
88
for &align in &[4, 8, 16, 32] {
99
let layout_20 = Layout::from_size_align(20, align).unwrap();
1010
let layout_40 = Layout::from_size_align(40, 4*align).unwrap();
1111
let layout_10 = Layout::from_size_align(10, align/2).unwrap();
1212

1313
for _ in 0..32 {
14-
let a = allocator.alloc(layout_20).unwrap().as_non_null_ptr();
14+
let a = allocator.allocate(layout_20).unwrap().as_non_null_ptr();
1515
assert_eq!(a.as_ptr() as usize % layout_20.align(), 0, "pointer is incorrectly aligned");
16-
allocator.dealloc(a, layout_20);
16+
allocator.deallocate(a, layout_20);
1717
}
1818

19-
let p1 = allocator.alloc_zeroed(layout_20).unwrap().as_non_null_ptr();
19+
let p1 = allocator.allocate_zeroed(layout_20).unwrap().as_non_null_ptr();
2020
assert_eq!(p1.as_ptr() as usize % layout_20.align(), 0, "pointer is incorrectly aligned");
2121
assert_eq!(*p1.as_ptr(), 0);
2222

@@ -38,17 +38,17 @@ fn check_alloc<T: AllocRef>(allocator: T) { unsafe {
3838
let slice = slice::from_raw_parts(p4.as_ptr(), 10);
3939
assert_eq!(&slice, &[0_u8; 10]);
4040

41-
allocator.dealloc(p4, layout_10);
41+
allocator.deallocate(p4, layout_10);
4242
}
4343
} }
4444

45-
fn check_align_requests<T: AllocRef>(allocator: T) {
45+
fn check_align_requests<T: Allocator>(allocator: T) {
4646
for &size in &[2, 8, 64] { // size less than and bigger than alignment
4747
for &align in &[4, 8, 16, 32] { // Be sure to cover less than and bigger than `MIN_ALIGN` for all architectures
4848
let iterations = 32;
4949
unsafe {
5050
let pointers: Vec<_> = (0..iterations).map(|_| {
51-
allocator.alloc(Layout::from_size_align(size, align).unwrap()).unwrap().as_non_null_ptr()
51+
allocator.allocate(Layout::from_size_align(size, align).unwrap()).unwrap().as_non_null_ptr()
5252
}).collect();
5353
for &ptr in &pointers {
5454
assert_eq!((ptr.as_ptr() as usize) % align, 0,
@@ -57,7 +57,7 @@ fn check_align_requests<T: AllocRef>(allocator: T) {
5757

5858
// Clean up.
5959
for &ptr in &pointers {
60-
allocator.dealloc(ptr, Layout::from_size_align(size, align).unwrap())
60+
allocator.deallocate(ptr, Layout::from_size_align(size, align).unwrap())
6161
}
6262
}
6363
}
@@ -69,7 +69,7 @@ fn global_to_box() {
6969
let l = Layout::new::<T>();
7070
// allocate manually with global allocator, then turn into Box and free there
7171
unsafe {
72-
let ptr = Global.alloc(l).unwrap().as_non_null_ptr().as_ptr() as *mut T;
72+
let ptr = Global.allocate(l).unwrap().as_non_null_ptr().as_ptr() as *mut T;
7373
let b = Box::from_raw(ptr);
7474
drop(b);
7575
}
@@ -82,7 +82,7 @@ fn box_to_global() {
8282
unsafe {
8383
let b = Box::new(T::default());
8484
let ptr = Box::into_raw(b);
85-
Global.dealloc(NonNull::new(ptr as *mut u8).unwrap(), l);
85+
Global.deallocate(NonNull::new(ptr as *mut u8).unwrap(), l);
8686
}
8787
}
8888

0 commit comments

Comments
 (0)