Skip to content

Commit

Permalink
Merge #19
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bors[bot] and ltratt authored Aug 7, 2020
2 parents 10fdb18 + 57b1b9e commit 5882ebc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
10 changes: 4 additions & 6 deletions src/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
alloc::{AllocErr, AllocInit, AllocRef, GlobalAlloc, Layout, MemoryBlock},
alloc::{AllocErr, AllocRef, GlobalAlloc, Layout},
ffi::c_void,
ptr::NonNull,
};
Expand All @@ -24,13 +24,11 @@ unsafe impl GlobalAlloc for BoehmAllocator {
}

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

unsafe fn dealloc(&mut self, _: NonNull<u8>, _: Layout) {}
Expand Down
16 changes: 3 additions & 13 deletions src/gc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
alloc::{AllocInit, AllocRef, Layout},
alloc::{AllocRef, Layout},
any::Any,
ffi::c_void,
fmt,
Expand Down Expand Up @@ -146,13 +146,7 @@ struct GcBox<T: ?Sized>(ManuallyDrop<T>);
impl<T> GcBox<T> {
fn new(value: T) -> *mut GcBox<T> {
let layout = Layout::new::<T>();
let ptr = unsafe {
GC_ALLOCATOR
.alloc(layout, AllocInit::Uninitialized)
.unwrap()
.ptr
.as_ptr()
} as *mut GcBox<T>;
let ptr = unsafe { GC_ALLOCATOR.alloc(layout).unwrap().as_ptr() } as *mut GcBox<T>;
let gcbox = GcBox(ManuallyDrop::new(value));

unsafe {
Expand All @@ -166,11 +160,7 @@ impl<T> GcBox<T> {

fn new_from_layout(layout: Layout) -> NonNull<GcBox<MaybeUninit<T>>> {
unsafe {
let base_ptr = GC_ALLOCATOR
.alloc(layout, AllocInit::Uninitialized)
.unwrap()
.ptr
.as_ptr() as *mut usize;
let base_ptr = GC_ALLOCATOR.alloc(layout).unwrap().as_ptr() as *mut usize;
NonNull::new_unchecked(base_ptr as *mut GcBox<MaybeUninit<T>>)
}
}
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![feature(alloc_layout_extra)]
#![feature(arbitrary_self_types)]
#![feature(dispatch_from_dyn)]
#![feature(nonnull_slice_from_raw_parts)]
#![feature(raw_vec_internals)]
#![feature(const_fn)]
#![feature(coerce_unsized)]
Expand Down

0 comments on commit 5882ebc

Please sign in to comment.