Skip to content

Commit

Permalink
Add feature flag for alloc dependency.
Browse files Browse the repository at this point in the history
This allows parts of the crate to be used without a global allocator.
This can be useful for programs which need some limited allocation
without allowing arbitrary allocation.
  • Loading branch information
qwandor committed Jun 28, 2024
1 parent 7b49a0e commit 31c2b1e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ jobs:
run: rustup default ${{ matrix.rust }}
- name: Build
run: cargo build --verbose
- name: Build without default features
run: cargo build --no-default-features --verbose
- name: Run tests
run: cargo test --verbose
11 changes: 8 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ homepage = "https://github.com/rcore-os/buddy_system_allocator"
repository = "https://github.com/rcore-os/buddy_system_allocator"
keywords = ["allocator", "no_std", "heap"]
version = "0.9.1"
authors = ["Jiajie Chen <[email protected]>", "Vinay Chandra Dommeti <[email protected]>", "Andrew Walbran <[email protected]>"]
authors = [
"Jiajie Chen <[email protected]>",
"Vinay Chandra Dommeti <[email protected]>",
"Andrew Walbran <[email protected]>",
]
edition = "2021"
license = "MIT"

[features]
default = ["use_spin"]
use_spin = ["spin"]
default = ["alloc", "use_spin"]
alloc = []
const_fn = []
use_spin = ["spin"]

[dependencies.spin]
version = "0.9.8"
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ You can also use `FrameAllocator` and `LockedHeapWithRescue`, see their document

## Features

- **`use_spin`** (default): Provide a `LockedHeap` type that implements the [`GlobalAlloc`] trait by using a spinlock.
- **`alloc`** (default): Provide `FrameAllocator` and `LockedFrameAllocator`, which depend on a
global allocator.
- **`use_spin`** (default): Provide a `LockedHeap` type that implements the [`GlobalAlloc`] trait by
using a spinlock.
- **`const_fn`** (nightly only): Provide const fn version of `LockedHeapWithRescue::new`.

[`GlobalAlloc`]: https://doc.rust-lang.org/nightly/core/alloc/trait.GlobalAlloc.html
Expand All @@ -41,7 +44,7 @@ Some code comes from phil-opp's linked-list-allocator.

Licensed under MIT License. Thanks phill-opp's linked-list-allocator for inspirations and interface.

[crate-img]: https://img.shields.io/crates/v/buddy_system_allocator.svg
[crate]: https://crates.io/crates/buddy_system_allocator
[docs-img]: https://docs.rs/buddy_system_allocator/badge.svg
[docs]: https://docs.rs/buddy_system_allocator
[crate-img]: https://img.shields.io/crates/v/buddy_system_allocator.svg
[crate]: https://crates.io/crates/buddy_system_allocator
[docs-img]: https://docs.rs/buddy_system_allocator/badge.svg
[docs]: https://docs.rs/buddy_system_allocator
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern crate std;
#[cfg(feature = "use_spin")]
extern crate spin;

#[cfg(feature = "alloc")]
extern crate alloc;

#[cfg(feature = "use_spin")]
Expand All @@ -22,11 +23,13 @@ use core::ptr::NonNull;
#[cfg(feature = "use_spin")]
use spin::Mutex;

#[cfg(feature = "alloc")]
mod frame;
pub mod linked_list;
#[cfg(test)]
mod test;

#[cfg(feature = "alloc")]
pub use frame::*;

/// A heap that uses buddy system with configurable order.
Expand Down

0 comments on commit 31c2b1e

Please sign in to comment.