diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6d1cd01..a2fa8a7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -105,7 +105,10 @@ jobs: run: cargo build --features alloc_ref - name: "Run cargo test with `alloc_ref` feature" - run: cargo test + run: cargo test --features alloc_ref + + - name: "Run cargo test with `use_spin_nightly` feature" + run: cargo test --features use_spin_nightly check_formatting: name: "Check Formatting" diff --git a/Cargo.toml b/Cargo.toml index c07447f..6c69132 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,10 +12,11 @@ documentation = "https://docs.rs/crate/linked_list_allocator" homepage = "http://os.phil-opp.com/kernel-heap.html#a-better-allocator" [features] -default = ["use_spin", "const_mut_refs"] +default = ["use_spin_nightly"] use_spin = ["spinning_top"] +use_spin_nightly = ["use_spin", "spinning_top/nightly", "const_mut_refs"] alloc_ref = [] -const_mut_refs = ["spinning_top/nightly"] +const_mut_refs = [] [dependencies.spinning_top] version = "0.1.0" diff --git a/Changelog.md b/Changelog.md index c311460..c4449fc 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,7 @@ # Unreleased +- Add new `use_spin_nightly` feature, which, together with `const_mut_refs`, makes the `empty` method of `LockedHeap` const ([#49](https://github.com/phil-opp/linked-list-allocator/pull/49)) + # 0.8.10 – 2020-12-28 - Made hole module public for external uses ([#47](https://github.com/phil-opp/linked-list-allocator/pull/47)) diff --git a/README.md b/README.md index f9dd2d2..4b6ec3b 100644 --- a/README.md +++ b/README.md @@ -32,6 +32,7 @@ pub fn init_heap() { - **`use_spin`** (default): Provide a `LockedHeap` type that implements the [`GlobalAlloc`] trait by using a spinlock. - **`const_mut_refs`** (default): Makes the `Heap::empty` function `const`; requires nightly Rust. +- **`use_spin_nightly`** (default): Makes the `LockedHeap::empty` function `const`, automatically enables `use_spin` and `const_mut_refs`; requires nightly Rust. - **`alloc_ref`**: Provide an implementation of the unstable [`AllocRef`] trait; requires nightly Rust. - Warning: The `AllocRef` trait is still regularly changed on the Rust side, so expect some regular breakage when using this feature. diff --git a/src/lib.rs b/src/lib.rs index e31cb96..243da64 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -155,8 +155,7 @@ impl Heap { } } -#[cfg(feature = "alloc_ref")] -#[cfg(feature = "use_spin")] +#[cfg(all(feature = "alloc_ref", feature = "use_spin"))] unsafe impl Allocator for LockedHeap { fn allocate(&self, layout: Layout) -> Result, AllocError> { if layout.size() == 0 { @@ -181,13 +180,13 @@ pub struct LockedHeap(Spinlock); #[cfg(feature = "use_spin")] impl LockedHeap { /// Creates an empty heap. All allocate calls will return `None`. - #[cfg(feature = "const_mut_refs")] + #[cfg(feature = "use_spin_nightly")] pub const fn empty() -> LockedHeap { LockedHeap(Spinlock::new(Heap::empty())) } /// Creates an empty heap. All allocate calls will return `None`. - #[cfg(not(feature = "const_mut_refs"))] + #[cfg(not(feature = "use_spin_nightly"))] pub fn empty() -> LockedHeap { LockedHeap(Spinlock::new(Heap::empty())) }