Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Commit

Permalink
AllocErr -> AllocError
Browse files Browse the repository at this point in the history
  • Loading branch information
KronicDeth committed Jan 29, 2021
1 parent 6bf926f commit 268589d
Show file tree
Hide file tree
Showing 19 changed files with 131 additions and 131 deletions.
16 changes: 8 additions & 8 deletions liblumen_alloc/src/blocks/block_bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::marker::PhantomData;
use core::mem;
use core::sync::atomic::{AtomicUsize, Ordering};

use liblumen_core::alloc::AllocErr;
use liblumen_core::alloc::AllocError;

use crate::mem::bit_size_of;

Expand All @@ -15,7 +15,7 @@ pub trait BlockBitSubset: Default {
/// and when you tried to allocate it, or a neighboring bit in the subset was flipped. You may
/// retry, or try searching for another block, or simply fail the allocation request. It is up
/// to the allocator.
fn alloc_block(&self, bit_len: usize) -> Result<usize, AllocErr>;
fn alloc_block(&self, bit_len: usize) -> Result<usize, AllocError>;

/// Return a count of the allocated blocks managed by this subset
fn count_allocated(&self) -> usize;
Expand All @@ -29,7 +29,7 @@ pub trait BlockBitSubset: Default {
pub struct ThreadSafeBlockBitSubset(AtomicUsize);

impl BlockBitSubset for ThreadSafeBlockBitSubset {
fn alloc_block(&self, bit_len: usize) -> Result<usize, AllocErr> {
fn alloc_block(&self, bit_len: usize) -> Result<usize, AllocError> {
assert!(bit_len <= bit_size_of::<Self>());

// On x86 this could use `bsf*` (Bit Scan Forward) instructions
Expand All @@ -51,7 +51,7 @@ impl BlockBitSubset for ThreadSafeBlockBitSubset {
}
}

Err(AllocErr)
Err(AllocError)
}

fn count_allocated(&self) -> usize {
Expand Down Expand Up @@ -187,11 +187,11 @@ impl<S: BlockBitSubset> BlockBitSet<S> {
/// Try to allocate block.
///
/// NOTE: This operation can fail, primarily in multi-threaded scenarios
/// with atomics in play. If `Err(AllocErr)` is returned, it means that either all blocks were
/// with atomics in play. If `Err(AllocError)` is returned, it means that either all blocks were
/// already allocated or a neighboring bit that was in the same subset
/// represented by `S` was flipped. You may retry or simply fail the allocation request. It is
/// up to the allocator.
pub fn alloc_block(&self) -> Result<usize, AllocErr> {
pub fn alloc_block(&self) -> Result<usize, AllocError> {
for subset_index in 0..self.subset_len() {
let subset = unsafe { self.subset(subset_index) };
let subset_bit_len = self.subset_bit_len(subset_index);
Expand All @@ -202,11 +202,11 @@ impl<S: BlockBitSubset> BlockBitSet<S> {

return Ok(set_bit);
}
Err(AllocErr) => continue,
Err(AllocError) => continue,
}
}

Err(AllocErr)
Err(AllocError)
}

/// Free the block represented by the given bit index
Expand Down
10 changes: 5 additions & 5 deletions liblumen_alloc/src/blocks/free_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use intrusive_collections::container_of;
use intrusive_collections::RBTreeLink;

use liblumen_core::alloc::utils as alloc_utils;
use liblumen_core::alloc::{AllocErr, Layout};
use liblumen_core::alloc::{AllocError, Layout};

use crate::sorted::{SortKey, SortOrder, Sortable};

Expand Down Expand Up @@ -169,14 +169,14 @@ impl FreeBlock {
/// NOTE: If the allocator changes such that blocks can be accessed by more
/// than one thread, the `Block` internals will need to be refactored to handle
/// that, it is _only_ designed to be accessed by one thread at a time.
pub fn try_alloc(&mut self, layout: &Layout) -> Result<NonNull<u8>, AllocErr> {
pub fn try_alloc(&mut self, layout: &Layout) -> Result<NonNull<u8>, AllocError> {
// This is here as a safety against trying to use a FreeBlock twice
if unlikely!(!self.header.is_free()) {
debug_assert!(
!self.header.is_free(),
"tried to allocate a free block twice"
);
return Err(AllocErr);
return Err(AllocError);
}

let mut ptr = unsafe { self.header.data() as *mut u8 };
Expand All @@ -194,14 +194,14 @@ impl FreeBlock {
let padding = (aligned_ptr as usize) - (ptr as usize);
if self.usable_size() < size + padding {
// No good
return Err(AllocErr);
return Err(AllocError);
}
ptr = aligned_ptr
} else {
// Alignment is good, check size
if self.usable_size() < size {
// No good
return Err(AllocErr);
return Err(AllocError);
}
}

Expand Down
6 changes: 3 additions & 3 deletions liblumen_alloc/src/carriers/slab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::mem;
use core::ptr::{self, NonNull};

use liblumen_core::alloc::size_classes::SizeClass;
use liblumen_core::alloc::AllocErr;
use liblumen_core::alloc::AllocError;

use crate::blocks::{BlockBitSet, BlockBitSubset};
use crate::sorted::Link;
Expand Down Expand Up @@ -80,7 +80,7 @@ where
}

/// Allocates a block within this carrier, if one is available
pub unsafe fn alloc_block(&self) -> Result<NonNull<u8>, AllocErr> {
pub unsafe fn alloc_block(&self) -> Result<NonNull<u8>, AllocError> {
match self.block_bit_set().alloc_block() {
Ok(index) => {
// We were able to mark this block allocated
Expand All @@ -95,7 +95,7 @@ where
Ok(NonNull::new_unchecked(block))
}
// No space available
Err(AllocErr) => Err(AllocErr),
Err(AllocError) => Err(AllocError),
}
}

Expand Down
6 changes: 3 additions & 3 deletions liblumen_alloc/src/erts/exception/alloc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloc::sync::Arc;
use core::alloc::AllocErr;
use core::alloc::AllocError;

use thiserror::Error;

Expand Down Expand Up @@ -33,9 +33,9 @@ impl PartialEq for Alloc {
}
}

impl From<AllocErr> for Alloc {
impl From<AllocError> for Alloc {
#[inline(always)]
fn from(_: AllocErr) -> Self {
fn from(_: AllocError) -> Self {
Self::new()
}
}
6 changes: 3 additions & 3 deletions liblumen_alloc/src/erts/process/alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub use self::term_alloc::TermAlloc;
pub use self::virtual_alloc::{VirtualAlloc, VirtualAllocator, VirtualHeap};
pub use self::virtual_binary_heap::VirtualBinaryHeap;

use core::alloc::{AllocErr, Layout};
use core::alloc::{AllocError, Layout};
use core::ffi::c_void;
use core::mem::transmute;
use core::ptr;
Expand Down Expand Up @@ -165,13 +165,13 @@ pub fn stack(num_pages: usize) -> AllocResult<Stack> {
/// Reallocate a process heap, in place
///
/// If reallocating and trying to grow the heap, if the allocation cannot be done
/// in place, then `Err(AllocErr)` will be returned
/// in place, then `Err(AllocError)` will be returned
#[inline]
pub unsafe fn realloc(
heap: *mut Term,
size: usize,
new_size: usize,
) -> Result<*mut Term, AllocErr> {
) -> Result<*mut Term, AllocError> {
PROC_ALLOC.realloc_in_place(heap, size, new_size)
}

Expand Down
6 changes: 3 additions & 3 deletions liblumen_alloc/src/erts/process/alloc/process_heap_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl ProcessHeapAlloc {
heap: *mut Term,
size: usize,
new_size: usize,
) -> Result<*mut Term, AllocErr> {
) -> Result<*mut Term, AllocError> {
// Nothing to do if the size didn't change
if size == new_size {
return Ok(heap);
Expand All @@ -121,7 +121,7 @@ impl ProcessHeapAlloc {
if new_size < size {
return Ok(heap);
}
return Err(AllocErr);
return Err(AllocError);
}

let layout = self.heap_layout(size);
Expand Down Expand Up @@ -149,7 +149,7 @@ impl ProcessHeapAlloc {
}
}

Err(AllocErr)
Err(AllocError)
}

/// Deallocate a process heap, releasing the memory back to the operating system
Expand Down
26 changes: 13 additions & 13 deletions liblumen_alloc/src/segmented_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl SegmentedAlloc {
/// allocator, or it will not be used, and will not be freed
unsafe fn create_carrier(
size_class: SizeClass,
) -> Result<*mut SlabCarrier<LinkedListLink, ThreadSafeBlockBitSubset>, AllocErr> {
) -> Result<*mut SlabCarrier<LinkedListLink, ThreadSafeBlockBitSubset>, AllocError> {
let size = SUPERALIGNED_CARRIER_SIZE;
assert!(size_class.to_bytes() < size);
let carrier_layout = Layout::from_size_align_unchecked(size, size);
Expand All @@ -87,7 +87,7 @@ impl SegmentedAlloc {

unsafe impl AllocRef for SegmentedAlloc {
#[inline]
fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result<MemoryBlock, AllocErr> {
fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result<MemoryBlock, AllocError> {
if layout.size() >= self.sbc_threshold {
return unsafe { self.alloc_large(layout, init) };
}
Expand All @@ -102,7 +102,7 @@ unsafe impl AllocRef for SegmentedAlloc {
new_size: usize,
placement: ReallocPlacement,
init: AllocInit,
) -> Result<MemoryBlock, AllocErr> {
) -> Result<MemoryBlock, AllocError> {
if layout.size() >= self.sbc_threshold {
// This was a single-block carrier
//
Expand All @@ -122,7 +122,7 @@ unsafe impl AllocRef for SegmentedAlloc {
layout: Layout,
new_size: usize,
placement: ReallocPlacement,
) -> Result<MemoryBlock, AllocErr> {
) -> Result<MemoryBlock, AllocError> {
if layout.size() >= self.sbc_threshold {
// This was a single-block carrier
//
Expand Down Expand Up @@ -152,7 +152,7 @@ impl SegmentedAlloc {
&mut self,
layout: Layout,
init: AllocInit,
) -> Result<MemoryBlock, AllocErr> {
) -> Result<MemoryBlock, AllocError> {
// Ensure allocated region has enough space for carrier header and aligned block
let data_layout = layout.clone();
let data_layout_size = data_layout.size();
Expand Down Expand Up @@ -198,9 +198,9 @@ impl SegmentedAlloc {
new_size: usize,
placement: ReallocPlacement,
init: AllocInit,
) -> Result<MemoryBlock, AllocErr> {
) -> Result<MemoryBlock, AllocError> {
if placement != ReallocPlacement::MayMove {
return Err(AllocErr);
return Err(AllocError);
}

// Allocate new carrier
Expand Down Expand Up @@ -263,7 +263,7 @@ impl SegmentedAlloc {
/// allocator, or it will not be used, and will not be freed
unsafe fn create_slab_carrier(
size_class: SizeClass,
) -> Result<*mut SlabCarrier<LinkedListLink, ThreadSafeBlockBitSubset>, AllocErr> {
) -> Result<*mut SlabCarrier<LinkedListLink, ThreadSafeBlockBitSubset>, AllocError> {
let size = SUPERALIGNED_CARRIER_SIZE;
assert!(size_class.to_bytes() < size);
let carrier_layout = Layout::from_size_align_unchecked(size, size);
Expand All @@ -280,11 +280,11 @@ impl SegmentedAlloc {
&mut self,
layout: Layout,
init: AllocInit,
) -> Result<MemoryBlock, AllocErr> {
) -> Result<MemoryBlock, AllocError> {
// Ensure allocated region has enough space for carrier header and aligned block
let size = layout.size();
if unlikely(size > Self::MAX_SIZE_CLASS.to_bytes()) {
return Err(AllocErr);
return Err(AllocError);
}
let size_class = self.size_class_for_unchecked(size);
let index = self.index_for(size_class);
Expand Down Expand Up @@ -327,9 +327,9 @@ impl SegmentedAlloc {
new_size: usize,
placement: ReallocPlacement,
init: AllocInit,
) -> Result<MemoryBlock, AllocErr> {
) -> Result<MemoryBlock, AllocError> {
if unlikely(new_size > Self::MAX_SIZE_CLASS.to_bytes()) {
return Err(AllocErr);
return Err(AllocError);
}
let size = layout.size();
let size_class = self.size_class_for_unchecked(size);
Expand All @@ -344,7 +344,7 @@ impl SegmentedAlloc {
// Otherwise we have to allocate in the new size class,
// copy to that new block, and deallocate the original block
if placement != ReallocPlacement::MayMove {
return Err(AllocErr);
return Err(AllocError);
}
let align = layout.align();
let new_layout = Layout::from_size_align_unchecked(new_size, align);
Expand Down
18 changes: 9 additions & 9 deletions liblumen_alloc/src/size_class_alloc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ impl SizeClassAlloc {
&self,
layout: Layout,
init: AllocInit,
) -> Result<MemoryBlock, AllocErr> {
) -> Result<MemoryBlock, AllocError> {
// Ensure allocated region has enough space for carrier header and aligned block
let size = layout.size();
if unlikely(size > self.max_size_class.to_bytes()) {
return Err(AllocErr);
return Err(AllocError);
}
let (index, size_class) =
binary_search_next_largest(&self.size_classes, |sc| sc.to_bytes().cmp(&size)).unwrap();
Expand Down Expand Up @@ -139,9 +139,9 @@ impl SizeClassAlloc {
new_size: usize,
placement: ReallocPlacement,
init: AllocInit,
) -> Result<MemoryBlock, AllocErr> {
) -> Result<MemoryBlock, AllocError> {
if unlikely(new_size > self.max_size_class.to_bytes()) {
return Err(AllocErr);
return Err(AllocError);
}
let size = layout.size();
let size_class = self.size_class_for_unchecked(size);
Expand All @@ -156,7 +156,7 @@ impl SizeClassAlloc {
// Otherwise we have to allocate in the new size class,
// copy to that new block, and deallocate the original block
if placement != ReallocPlacement::MayMove {
return Err(AllocErr);
return Err(AllocError);
}
let align = layout.align();
let new_layout = Layout::from_size_align_unchecked(new_size, align);
Expand Down Expand Up @@ -191,7 +191,7 @@ impl SizeClassAlloc {
/// allocator, or it will not be used, and will not be freed
unsafe fn create_carrier(
size_class: SizeClass,
) -> Result<*mut SlabCarrier<LinkedListLink, ThreadSafeBlockBitSubset>, AllocErr> {
) -> Result<*mut SlabCarrier<LinkedListLink, ThreadSafeBlockBitSubset>, AllocError> {
let size = SUPERALIGNED_CARRIER_SIZE;
assert!(size_class.to_bytes() < size);
let carrier_layout = Layout::from_size_align_unchecked(size, size);
Expand All @@ -206,7 +206,7 @@ impl SizeClassAlloc {

unsafe impl AllocRef for SizeClassAlloc {
#[inline]
fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result<MemoryBlock, AllocErr> {
fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result<MemoryBlock, AllocError> {
unsafe { self.allocate(layout, init) }
}

Expand All @@ -218,7 +218,7 @@ unsafe impl AllocRef for SizeClassAlloc {
new_size: usize,
placement: ReallocPlacement,
init: AllocInit,
) -> Result<MemoryBlock, AllocErr> {
) -> Result<MemoryBlock, AllocError> {
self.reallocate(ptr, layout, new_size, placement, init)
}

Expand All @@ -229,7 +229,7 @@ unsafe impl AllocRef for SizeClassAlloc {
layout: Layout,
new_size: usize,
placement: ReallocPlacement,
) -> Result<MemoryBlock, AllocErr> {
) -> Result<MemoryBlock, AllocError> {
self.reallocate(ptr, layout, new_size, placement, AllocInit::Uninitialized)
}

Expand Down
Loading

0 comments on commit 268589d

Please sign in to comment.