Skip to content

Commit d20a693

Browse files
bors[bot]ltratt
andauthored
Merge #19
19: Update after recent rust-nightly changes. r=vext01 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 2ecb96e + d5e2232 commit d20a693

File tree

4 files changed

+15
-24
lines changed

4 files changed

+15
-24
lines changed

.buildbot.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ export CARGO_HOME="`pwd`/.cargo"
66
export RUSTUP_HOME="`pwd`/.rustup"
77

88
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs > rustup.sh
9-
# Install no toolchain initially to ensure toolchain rollback.
10-
sh rustup.sh --default-host x86_64-unknown-linux-gnu --default-toolchain none -y --no-modify-path
11-
9+
sh rustup.sh --default-host x86_64-unknown-linux-gnu \
10+
--default-toolchain nightly \
11+
--no-modify-path \
12+
--profile minimal \
13+
-y
1214
export PATH=`pwd`/.cargo/bin/:$PATH
13-
rustup install nightly
15+
cargo check
1416

17+
rustup toolchain install nightly --allow-downgrade --component rustfmt
1518
cargo +nightly fmt --all -- --check
16-
cargo check

src/allocator.rs

Lines changed: 4 additions & 6 deletions
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

Lines changed: 3 additions & 13 deletions
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,
@@ -160,13 +160,7 @@ struct GcBox<T: ?Sized>(ManuallyDrop<T>);
160160
impl<T> GcBox<T> {
161161
fn new(value: T) -> *mut GcBox<T> {
162162
let layout = Layout::new::<T>();
163-
let ptr = unsafe {
164-
GC_ALLOCATOR
165-
.alloc(layout, AllocInit::Uninitialized)
166-
.unwrap()
167-
.ptr
168-
.as_ptr()
169-
} as *mut GcBox<T>;
163+
let ptr = unsafe { GC_ALLOCATOR.alloc(layout).unwrap().as_ptr() } as *mut GcBox<T>;
170164
let gcbox = GcBox(ManuallyDrop::new(value));
171165

172166
unsafe {
@@ -180,11 +174,7 @@ impl<T> GcBox<T> {
180174

181175
fn new_from_layout(layout: Layout) -> NonNull<GcBox<MaybeUninit<T>>> {
182176
unsafe {
183-
let base_ptr = GC_ALLOCATOR
184-
.alloc(layout, AllocInit::Uninitialized)
185-
.unwrap()
186-
.ptr
187-
.as_ptr() as *mut usize;
177+
let base_ptr = GC_ALLOCATOR.alloc(layout).unwrap().as_ptr() as *mut usize;
188178
NonNull::new_unchecked(base_ptr as *mut GcBox<MaybeUninit<T>>)
189179
}
190180
}

src/lib.rs

Lines changed: 1 addition & 0 deletions
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)