Skip to content

Fix some clippy warnings #39

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion benches/memory_allocator_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
c.bench_function("mutil thread random size", |b| {
b.iter(|| mutil_thread_random_size(black_box(&HEAP_ALLOCATOR)))
});
c.bench_function("threadtest", |b| b.iter(|| thread_test()));
c.bench_function("threadtest", |b| b.iter(thread_test));
}

criterion_group!(benches, criterion_benchmark);
Expand Down
9 changes: 8 additions & 1 deletion src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use spin::Mutex;

/// A frame allocator that uses buddy system, requiring a global allocator.
///
/// The max order of the allocator is determined by the const generic parameter `ORDER` (`MAX_ORDER = ORDER - 1`).
/// The max order of the allocator is determined by the const generic parameter `ORDER` (`MAX_ORDER = ORDER - 1`).
/// The frame allocator will only be able to allocate ranges of size up to 2<sup>MAX_ORDER</sup>, out of a total
/// range of size at most 2<sup>MAX_ORDER + 1</sup> - 1.
///
Expand Down Expand Up @@ -169,6 +169,12 @@ impl<const ORDER: usize> FrameAllocator<ORDER> {
}
}

impl<const ORDER: usize> Default for FrameAllocator<ORDER> {
fn default() -> Self {
Self::new()
}
}

/// A locked version of `FrameAllocator`
///
/// # Usage
Expand All @@ -187,6 +193,7 @@ impl<const ORDER: usize> FrameAllocator<ORDER> {
/// assert_eq!(num, Some(0));
/// ```
#[cfg(feature = "use_spin")]
#[derive(Default)]
pub struct LockedFrameAllocator<const ORDER: usize = 33>(Mutex<FrameAllocator<ORDER>>);

#[cfg(feature = "use_spin")]
Expand Down
9 changes: 8 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<const ORDER: usize> Heap<ORDER> {
while current_start + size_of::<usize>() <= end {
let lowbit = current_start & (!current_start + 1);
let mut size = min(lowbit, prev_power_of_two(end - current_start));

// If the order of size is larger than the max order,
// split it into smaller blocks.
let mut order = size.trailing_zeros() as usize;
Expand Down Expand Up @@ -214,6 +214,12 @@ impl<const ORDER: usize> Heap<ORDER> {
}
}

impl<const ORDER: usize> Default for Heap<ORDER> {
fn default() -> Self {
Self::new()
}
}

impl<const ORDER: usize> fmt::Debug for Heap<ORDER> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("Heap")
Expand Down Expand Up @@ -247,6 +253,7 @@ impl<const ORDER: usize> fmt::Debug for Heap<ORDER> {
/// }
/// ```
#[cfg(feature = "use_spin")]
#[derive(Default)]
pub struct LockedHeap<const ORDER: usize>(Mutex<Heap<ORDER>>);

#[cfg(feature = "use_spin")]
Expand Down
6 changes: 6 additions & 0 deletions src/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ impl LinkedList {
}
}

impl Default for LinkedList {
fn default() -> Self {
Self::new()
}
}

impl fmt::Debug for LinkedList {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_list().entries(self.iter()).finish()
Expand Down
5 changes: 3 additions & 2 deletions src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ fn test_heap_oom() {

#[test]
fn test_heap_oom_rescue() {
static mut SPACE: [usize; 100] = [0; 100];
const SPACE_SIZE: usize = 100;
static mut SPACE: [usize; 100] = [0; SPACE_SIZE];
let heap = LockedHeapWithRescue::new(|heap: &mut Heap<32>, _layout: &Layout| unsafe {
heap.add_to_heap(SPACE.as_ptr() as usize, SPACE.as_ptr().add(100) as usize);
heap.init(&raw mut SPACE as usize, SPACE_SIZE);
});

unsafe {
Expand Down