Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update after recent rust-nightly changes. #19

Merged
merged 2 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions .buildbot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ export CARGO_HOME="`pwd`/.cargo"
export RUSTUP_HOME="`pwd`/.rustup"

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh
# Install no toolchain initially to ensure toolchain rollback.
sh rustup.sh --default-host x86_64-unknown-linux-gnu --default-toolchain none -y --no-modify-path

sh rustup.sh --default-host x86_64-unknown-linux-gnu \
--default-toolchain nightly \
--no-modify-path \
--profile minimal \
-y
export PATH=`pwd`/.cargo/bin/:$PATH
rustup install nightly
cargo check

rustup toolchain install nightly --allow-downgrade --component rustfmt
cargo +nightly fmt --all -- --check
cargo check
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 @@ -160,13 +160,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 @@ -180,11 +174,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