Skip to content

Commit 7fa4a77

Browse files
committed
Update Alloc calls after recent nightly API changes
There are two PRs which affect us: rust-lang#74850 rust-lang#75152 Henceforth, we should probably be keeping a close eye on and contributing to: https://github.com/rust-lang/wg-allocators/issues
1 parent 4aa00e8 commit 7fa4a77

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

library/alloc/src/boehm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ unsafe impl GlobalAlloc for BoehmAllocator {
2828

2929
#[unstable(feature = "allocator_api", issue = "32838")]
3030
unsafe impl AllocRef for BoehmGcAllocator {
31-
fn alloc(&mut self, layout: Layout, _init: AllocInit) -> Result<MemoryBlock, AllocErr> {
31+
fn alloc(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
3232
let ptr = unsafe { GC_malloc(layout.size()) } as *mut u8;
3333
assert!(!ptr.is_null());
34-
Ok(MemoryBlock { ptr: unsafe { NonNull::new_unchecked(ptr) }, size: layout.size() })
34+
Ok(NonNull::slice_from_raw_parts(unsafe { NonNull::new_unchecked(ptr) }, layout.size()))
3535
}
3636

3737
unsafe fn dealloc(&mut self, _: NonNull<u8>, _: Layout) {}

library/alloc/src/gc.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use core::mem::{self, ManuallyDrop, MaybeUninit};
99
use core::ops::{Deref, DerefMut};
1010
use core::ptr::{self, NonNull};
1111

12-
use crate::alloc::{AllocInit, AllocRef};
12+
use crate::alloc::AllocRef;
1313
use crate::boehm::{self, BoehmGcAllocator};
1414
use crate::vec::Vec;
1515

@@ -120,8 +120,7 @@ struct GcBox<T: ?Sized>(ManuallyDrop<T>);
120120
impl<T> GcBox<T> {
121121
fn new(value: T) -> *mut GcBox<T> {
122122
let layout = Layout::new::<T>();
123-
let ptr = BoehmGcAllocator.alloc(layout, AllocInit::Uninitialized).unwrap().ptr.as_ptr()
124-
as *mut GcBox<T>;
123+
let ptr = BoehmGcAllocator.alloc(layout).unwrap().as_ptr() as *mut GcBox<T>;
125124
let gcbox = GcBox(ManuallyDrop::new(value));
126125

127126
unsafe {
@@ -137,9 +136,7 @@ impl<T> GcBox<T> {
137136

138137
fn new_from_layout(layout: Layout) -> NonNull<GcBox<MaybeUninit<T>>> {
139138
unsafe {
140-
let base_ptr =
141-
BoehmGcAllocator.alloc(layout, AllocInit::Uninitialized).unwrap().ptr.as_ptr()
142-
as *mut usize;
139+
let base_ptr = BoehmGcAllocator.alloc(layout).unwrap().as_ptr() as *mut usize;
143140
NonNull::new_unchecked((base_ptr.add(1)) as *mut GcBox<MaybeUninit<T>>)
144141
}
145142
}

0 commit comments

Comments
 (0)