Skip to content

Commit

Permalink
Try #19:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Aug 9, 2020
2 parents 2ecb96e + 95318a2 commit 335e2d9
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
14 changes: 9 additions & 5 deletions .buildbot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ 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 -y --no-modify-path
export PATH=`pwd`/.cargo/bin/:$PATH
rustup install nightly

cargo +nightly fmt --all -- --check
rustup toolchain install nightly --allow-downgrade --profile minimal
cargo check

if [ `which cargo-fmt` -ne 0 ]; then
rm -rf ${RUSTUP_HOME} ${CARGO_HOME}
sh rustup.sh --default-host x86_64-unknown-linux-gnu --default-toolchain none -y --no-modify-path
rustup install nightly
fi
cargo +nightly fmt --all -- --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

0 comments on commit 335e2d9

Please sign in to comment.