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

Commit 37dcc5f

Browse files
committed
AllocErr -> AllocError
Port rust-lang/rust#77315
1 parent 6f9c13b commit 37dcc5f

File tree

19 files changed

+131
-131
lines changed

19 files changed

+131
-131
lines changed

Diff for: liblumen_alloc/src/blocks/block_bit_set.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core::marker::PhantomData;
22
use core::mem;
33
use core::sync::atomic::{AtomicUsize, Ordering};
44

5-
use liblumen_core::alloc::AllocErr;
5+
use liblumen_core::alloc::AllocError;
66

77
use crate::mem::bit_size_of;
88

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

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

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

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

54-
Err(AllocErr)
54+
Err(AllocError)
5555
}
5656

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

203203
return Ok(set_bit);
204204
}
205-
Err(AllocErr) => continue,
205+
Err(AllocError) => continue,
206206
}
207207
}
208208

209-
Err(AllocErr)
209+
Err(AllocError)
210210
}
211211

212212
/// Free the block represented by the given bit index

Diff for: liblumen_alloc/src/blocks/free_block.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use intrusive_collections::container_of;
99
use intrusive_collections::RBTreeLink;
1010

1111
use liblumen_core::alloc::utils as alloc_utils;
12-
use liblumen_core::alloc::{AllocErr, Layout};
12+
use liblumen_core::alloc::{AllocError, Layout};
1313

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

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

182182
let mut ptr = unsafe { self.header.data() as *mut u8 };
@@ -194,14 +194,14 @@ impl FreeBlock {
194194
let padding = (aligned_ptr as usize) - (ptr as usize);
195195
if self.usable_size() < size + padding {
196196
// No good
197-
return Err(AllocErr);
197+
return Err(AllocError);
198198
}
199199
ptr = aligned_ptr
200200
} else {
201201
// Alignment is good, check size
202202
if self.usable_size() < size {
203203
// No good
204-
return Err(AllocErr);
204+
return Err(AllocError);
205205
}
206206
}
207207

Diff for: liblumen_alloc/src/carriers/slab.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use core::mem;
22
use core::ptr::{self, NonNull};
33

44
use liblumen_core::alloc::size_classes::SizeClass;
5-
use liblumen_core::alloc::AllocErr;
5+
use liblumen_core::alloc::AllocError;
66

77
use crate::blocks::{BlockBitSet, BlockBitSubset};
88
use crate::sorted::Link;
@@ -80,7 +80,7 @@ where
8080
}
8181

8282
/// Allocates a block within this carrier, if one is available
83-
pub unsafe fn alloc_block(&self) -> Result<NonNull<u8>, AllocErr> {
83+
pub unsafe fn alloc_block(&self) -> Result<NonNull<u8>, AllocError> {
8484
match self.block_bit_set().alloc_block() {
8585
Ok(index) => {
8686
// We were able to mark this block allocated
@@ -95,7 +95,7 @@ where
9595
Ok(NonNull::new_unchecked(block))
9696
}
9797
// No space available
98-
Err(AllocErr) => Err(AllocErr),
98+
Err(AllocError) => Err(AllocError),
9999
}
100100
}
101101

Diff for: liblumen_alloc/src/erts/exception/alloc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use alloc::sync::Arc;
2-
use core::alloc::AllocErr;
2+
use core::alloc::AllocError;
33

44
use thiserror::Error;
55

@@ -33,9 +33,9 @@ impl PartialEq for Alloc {
3333
}
3434
}
3535

36-
impl From<AllocErr> for Alloc {
36+
impl From<AllocError> for Alloc {
3737
#[inline(always)]
38-
fn from(_: AllocErr) -> Self {
38+
fn from(_: AllocError) -> Self {
3939
Self::new()
4040
}
4141
}

Diff for: liblumen_alloc/src/erts/process/alloc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub use self::term_alloc::TermAlloc;
1818
pub use self::virtual_alloc::{VirtualAlloc, VirtualAllocator, VirtualHeap};
1919
pub use self::virtual_binary_heap::VirtualBinaryHeap;
2020

21-
use core::alloc::{AllocErr, Layout};
21+
use core::alloc::{AllocError, Layout};
2222
use core::ffi::c_void;
2323
use core::mem::transmute;
2424
use core::ptr;
@@ -165,13 +165,13 @@ pub fn stack(num_pages: usize) -> AllocResult<Stack> {
165165
/// Reallocate a process heap, in place
166166
///
167167
/// If reallocating and trying to grow the heap, if the allocation cannot be done
168-
/// in place, then `Err(AllocErr)` will be returned
168+
/// in place, then `Err(AllocError)` will be returned
169169
#[inline]
170170
pub unsafe fn realloc(
171171
heap: *mut Term,
172172
size: usize,
173173
new_size: usize,
174-
) -> Result<*mut Term, AllocErr> {
174+
) -> Result<*mut Term, AllocError> {
175175
PROC_ALLOC.realloc_in_place(heap, size, new_size)
176176
}
177177

Diff for: liblumen_alloc/src/erts/process/alloc/process_heap_alloc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl ProcessHeapAlloc {
105105
heap: *mut Term,
106106
size: usize,
107107
new_size: usize,
108-
) -> Result<*mut Term, AllocErr> {
108+
) -> Result<*mut Term, AllocError> {
109109
// Nothing to do if the size didn't change
110110
if size == new_size {
111111
return Ok(heap);
@@ -121,7 +121,7 @@ impl ProcessHeapAlloc {
121121
if new_size < size {
122122
return Ok(heap);
123123
}
124-
return Err(AllocErr);
124+
return Err(AllocError);
125125
}
126126

127127
let layout = self.heap_layout(size);
@@ -149,7 +149,7 @@ impl ProcessHeapAlloc {
149149
}
150150
}
151151

152-
Err(AllocErr)
152+
Err(AllocError)
153153
}
154154

155155
/// Deallocate a process heap, releasing the memory back to the operating system

Diff for: liblumen_alloc/src/segmented_alloc.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl SegmentedAlloc {
7272
/// allocator, or it will not be used, and will not be freed
7373
unsafe fn create_carrier(
7474
size_class: SizeClass,
75-
) -> Result<*mut SlabCarrier<LinkedListLink, ThreadSafeBlockBitSubset>, AllocErr> {
75+
) -> Result<*mut SlabCarrier<LinkedListLink, ThreadSafeBlockBitSubset>, AllocError> {
7676
let size = SUPERALIGNED_CARRIER_SIZE;
7777
assert!(size_class.to_bytes() < size);
7878
let carrier_layout = Layout::from_size_align_unchecked(size, size);
@@ -87,7 +87,7 @@ impl SegmentedAlloc {
8787

8888
unsafe impl AllocRef for SegmentedAlloc {
8989
#[inline]
90-
fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result<MemoryBlock, AllocErr> {
90+
fn alloc(&mut self, layout: Layout, init: AllocInit) -> Result<MemoryBlock, AllocError> {
9191
if layout.size() >= self.sbc_threshold {
9292
return unsafe { self.alloc_large(layout, init) };
9393
}
@@ -102,7 +102,7 @@ unsafe impl AllocRef for SegmentedAlloc {
102102
new_size: usize,
103103
placement: ReallocPlacement,
104104
init: AllocInit,
105-
) -> Result<MemoryBlock, AllocErr> {
105+
) -> Result<MemoryBlock, AllocError> {
106106
if layout.size() >= self.sbc_threshold {
107107
// This was a single-block carrier
108108
//
@@ -122,7 +122,7 @@ unsafe impl AllocRef for SegmentedAlloc {
122122
layout: Layout,
123123
new_size: usize,
124124
placement: ReallocPlacement,
125-
) -> Result<MemoryBlock, AllocErr> {
125+
) -> Result<MemoryBlock, AllocError> {
126126
if layout.size() >= self.sbc_threshold {
127127
// This was a single-block carrier
128128
//
@@ -152,7 +152,7 @@ impl SegmentedAlloc {
152152
&mut self,
153153
layout: Layout,
154154
init: AllocInit,
155-
) -> Result<MemoryBlock, AllocErr> {
155+
) -> Result<MemoryBlock, AllocError> {
156156
// Ensure allocated region has enough space for carrier header and aligned block
157157
let data_layout = layout.clone();
158158
let data_layout_size = data_layout.size();
@@ -198,9 +198,9 @@ impl SegmentedAlloc {
198198
new_size: usize,
199199
placement: ReallocPlacement,
200200
init: AllocInit,
201-
) -> Result<MemoryBlock, AllocErr> {
201+
) -> Result<MemoryBlock, AllocError> {
202202
if placement != ReallocPlacement::MayMove {
203-
return Err(AllocErr);
203+
return Err(AllocError);
204204
}
205205

206206
// Allocate new carrier
@@ -263,7 +263,7 @@ impl SegmentedAlloc {
263263
/// allocator, or it will not be used, and will not be freed
264264
unsafe fn create_slab_carrier(
265265
size_class: SizeClass,
266-
) -> Result<*mut SlabCarrier<LinkedListLink, ThreadSafeBlockBitSubset>, AllocErr> {
266+
) -> Result<*mut SlabCarrier<LinkedListLink, ThreadSafeBlockBitSubset>, AllocError> {
267267
let size = SUPERALIGNED_CARRIER_SIZE;
268268
assert!(size_class.to_bytes() < size);
269269
let carrier_layout = Layout::from_size_align_unchecked(size, size);
@@ -280,11 +280,11 @@ impl SegmentedAlloc {
280280
&mut self,
281281
layout: Layout,
282282
init: AllocInit,
283-
) -> Result<MemoryBlock, AllocErr> {
283+
) -> Result<MemoryBlock, AllocError> {
284284
// Ensure allocated region has enough space for carrier header and aligned block
285285
let size = layout.size();
286286
if unlikely(size > Self::MAX_SIZE_CLASS.to_bytes()) {
287-
return Err(AllocErr);
287+
return Err(AllocError);
288288
}
289289
let size_class = self.size_class_for_unchecked(size);
290290
let index = self.index_for(size_class);
@@ -327,9 +327,9 @@ impl SegmentedAlloc {
327327
new_size: usize,
328328
placement: ReallocPlacement,
329329
init: AllocInit,
330-
) -> Result<MemoryBlock, AllocErr> {
330+
) -> Result<MemoryBlock, AllocError> {
331331
if unlikely(new_size > Self::MAX_SIZE_CLASS.to_bytes()) {
332-
return Err(AllocErr);
332+
return Err(AllocError);
333333
}
334334
let size = layout.size();
335335
let size_class = self.size_class_for_unchecked(size);
@@ -344,7 +344,7 @@ impl SegmentedAlloc {
344344
// Otherwise we have to allocate in the new size class,
345345
// copy to that new block, and deallocate the original block
346346
if placement != ReallocPlacement::MayMove {
347-
return Err(AllocErr);
347+
return Err(AllocError);
348348
}
349349
let align = layout.align();
350350
let new_layout = Layout::from_size_align_unchecked(new_size, align);

Diff for: liblumen_alloc/src/size_class_alloc.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ impl SizeClassAlloc {
9393
&self,
9494
layout: Layout,
9595
init: AllocInit,
96-
) -> Result<MemoryBlock, AllocErr> {
96+
) -> Result<MemoryBlock, AllocError> {
9797
// Ensure allocated region has enough space for carrier header and aligned block
9898
let size = layout.size();
9999
if unlikely(size > self.max_size_class.to_bytes()) {
100-
return Err(AllocErr);
100+
return Err(AllocError);
101101
}
102102
let (index, size_class) =
103103
binary_search_next_largest(&self.size_classes, |sc| sc.to_bytes().cmp(&size)).unwrap();
@@ -139,9 +139,9 @@ impl SizeClassAlloc {
139139
new_size: usize,
140140
placement: ReallocPlacement,
141141
init: AllocInit,
142-
) -> Result<MemoryBlock, AllocErr> {
142+
) -> Result<MemoryBlock, AllocError> {
143143
if unlikely(new_size > self.max_size_class.to_bytes()) {
144-
return Err(AllocErr);
144+
return Err(AllocError);
145145
}
146146
let size = layout.size();
147147
let size_class = self.size_class_for_unchecked(size);
@@ -156,7 +156,7 @@ impl SizeClassAlloc {
156156
// Otherwise we have to allocate in the new size class,
157157
// copy to that new block, and deallocate the original block
158158
if placement != ReallocPlacement::MayMove {
159-
return Err(AllocErr);
159+
return Err(AllocError);
160160
}
161161
let align = layout.align();
162162
let new_layout = Layout::from_size_align_unchecked(new_size, align);
@@ -191,7 +191,7 @@ impl SizeClassAlloc {
191191
/// allocator, or it will not be used, and will not be freed
192192
unsafe fn create_carrier(
193193
size_class: SizeClass,
194-
) -> Result<*mut SlabCarrier<LinkedListLink, ThreadSafeBlockBitSubset>, AllocErr> {
194+
) -> Result<*mut SlabCarrier<LinkedListLink, ThreadSafeBlockBitSubset>, AllocError> {
195195
let size = SUPERALIGNED_CARRIER_SIZE;
196196
assert!(size_class.to_bytes() < size);
197197
let carrier_layout = Layout::from_size_align_unchecked(size, size);
@@ -206,7 +206,7 @@ impl SizeClassAlloc {
206206

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

@@ -218,7 +218,7 @@ unsafe impl AllocRef for SizeClassAlloc {
218218
new_size: usize,
219219
placement: ReallocPlacement,
220220
init: AllocInit,
221-
) -> Result<MemoryBlock, AllocErr> {
221+
) -> Result<MemoryBlock, AllocError> {
222222
self.reallocate(ptr, layout, new_size, placement, init)
223223
}
224224

@@ -229,7 +229,7 @@ unsafe impl AllocRef for SizeClassAlloc {
229229
layout: Layout,
230230
new_size: usize,
231231
placement: ReallocPlacement,
232-
) -> Result<MemoryBlock, AllocErr> {
232+
) -> Result<MemoryBlock, AllocError> {
233233
self.reallocate(ptr, layout, new_size, placement, AllocInit::Uninitialized)
234234
}
235235

0 commit comments

Comments
 (0)