Update allocator code to use unsafe also in unsafe functions

Required since Rust 2024
This commit is contained in:
Philipp Oppermann
2025-03-27 15:32:15 +01:00
parent a26d6c1b54
commit 6de3aeaac3
2 changed files with 22 additions and 10 deletions

View File

@@ -44,7 +44,9 @@ impl FixedSizeBlockAllocator {
/// heap bounds are valid and that the heap is unused. This method must be
/// called only once.
pub unsafe fn init(&mut self, heap_start: usize, heap_size: usize) {
self.fallback_allocator.init(heap_start, heap_size);
unsafe {
self.fallback_allocator.init(heap_start, heap_size);
}
}
/// Allocates using the fallback allocator.
@@ -91,12 +93,16 @@ unsafe impl GlobalAlloc for Locked<FixedSizeBlockAllocator> {
assert!(mem::size_of::<ListNode>() <= BLOCK_SIZES[index]);
assert!(mem::align_of::<ListNode>() <= BLOCK_SIZES[index]);
let new_node_ptr = ptr as *mut ListNode;
new_node_ptr.write(new_node);
allocator.list_heads[index] = Some(&mut *new_node_ptr);
unsafe {
new_node_ptr.write(new_node);
allocator.list_heads[index] = Some(&mut *new_node_ptr);
}
}
None => {
let ptr = NonNull::new(ptr).unwrap();
allocator.fallback_allocator.deallocate(ptr, layout);
unsafe {
allocator.fallback_allocator.deallocate(ptr, layout);
}
}
}
}