Skip to content

Commit 5882ebc

Browse files
bors[bot]ltratt
andauthored
Merge #19
19: Update after recent rust-nightly changes. r=jacob-hughes a=ltratt There are two PRs which affect us: rust-lang/rust#74850 rust-lang/rust#75152 Henceforth, we should probably be keeping a close eye on and contributing to: https://github.com/rust-lang/wg-allocators/issues Co-authored-by: Laurence Tratt <[email protected]>
2 parents 10fdb18 + 57b1b9e commit 5882ebc

File tree

3 files changed

+8
-19
lines changed

3 files changed

+8
-19
lines changed

src/allocator.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
alloc::{AllocErr, AllocInit, AllocRef, GlobalAlloc, Layout, MemoryBlock},
2+
alloc::{AllocErr, AllocRef, GlobalAlloc, Layout},
33
ffi::c_void,
44
ptr::NonNull,
55
};
@@ -24,13 +24,11 @@ unsafe impl GlobalAlloc for BoehmAllocator {
2424
}
2525

2626
unsafe impl AllocRef for BoehmGcAllocator {
27-
fn alloc(&mut self, layout: Layout, _init: AllocInit) -> Result<MemoryBlock, AllocErr> {
27+
fn alloc(&mut self, layout: Layout) -> Result<NonNull<[u8]>, AllocErr> {
2828
let ptr = unsafe { boehm::GC_malloc(layout.size()) } as *mut u8;
2929
assert!(!ptr.is_null());
30-
Ok(MemoryBlock {
31-
ptr: unsafe { NonNull::new_unchecked(ptr) },
32-
size: layout.size(),
33-
})
30+
let ptr = unsafe { NonNull::new_unchecked(ptr) };
31+
Ok(NonNull::slice_from_raw_parts(ptr, layout.size()))
3432
}
3533

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

src/gc.rs

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use std::{
2-
alloc::{AllocInit, AllocRef, Layout},
2+
alloc::{AllocRef, Layout},
33
any::Any,
44
ffi::c_void,
55
fmt,
@@ -146,13 +146,7 @@ struct GcBox<T: ?Sized>(ManuallyDrop<T>);
146146
impl<T> GcBox<T> {
147147
fn new(value: T) -> *mut GcBox<T> {
148148
let layout = Layout::new::<T>();
149-
let ptr = unsafe {
150-
GC_ALLOCATOR
151-
.alloc(layout, AllocInit::Uninitialized)
152-
.unwrap()
153-
.ptr
154-
.as_ptr()
155-
} as *mut GcBox<T>;
149+
let ptr = unsafe { GC_ALLOCATOR.alloc(layout).unwrap().as_ptr() } as *mut GcBox<T>;
156150
let gcbox = GcBox(ManuallyDrop::new(value));
157151

158152
unsafe {
@@ -166,11 +160,7 @@ impl<T> GcBox<T> {
166160

167161
fn new_from_layout(layout: Layout) -> NonNull<GcBox<MaybeUninit<T>>> {
168162
unsafe {
169-
let base_ptr = GC_ALLOCATOR
170-
.alloc(layout, AllocInit::Uninitialized)
171-
.unwrap()
172-
.ptr
173-
.as_ptr() as *mut usize;
163+
let base_ptr = GC_ALLOCATOR.alloc(layout).unwrap().as_ptr() as *mut usize;
174164
NonNull::new_unchecked(base_ptr as *mut GcBox<MaybeUninit<T>>)
175165
}
176166
}

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#![feature(alloc_layout_extra)]
44
#![feature(arbitrary_self_types)]
55
#![feature(dispatch_from_dyn)]
6+
#![feature(nonnull_slice_from_raw_parts)]
67
#![feature(raw_vec_internals)]
78
#![feature(const_fn)]
89
#![feature(coerce_unsized)]

0 commit comments

Comments
 (0)