Skip to content

Commit

Permalink
Fix the rust allocator when std is not used
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Dec 11, 2024
1 parent 8058c06 commit 0ab2790
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions libbz2-rs-sys/src/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
//! the layout of an allocation to deallocate it, and C interfaces don't usually provide this
//! information. Luckily in the library we know in all cases how big the allocation was at the
//! point where we deallocate it.
#[cfg(feature = "rust-allocator")]
extern crate alloc;

use core::ffi::{c_int, c_void};

use crate::bzlib::{BzStream, StreamState};
Expand Down Expand Up @@ -148,7 +152,7 @@ impl Allocator {
#[cfg(feature = "rust-allocator")]
Allocator::Rust => {
let layout = core::alloc::Layout::array::<T>(count).unwrap();
let ptr = unsafe { std::alloc::alloc_zeroed(layout) };
let ptr = unsafe { alloc::alloc::alloc_zeroed(layout) };
(!ptr.is_null()).then_some(ptr.cast())
}
#[cfg(feature = "c-allocator")]
Expand Down Expand Up @@ -182,7 +186,7 @@ impl Allocator {
#[cfg(feature = "rust-allocator")]
Allocator::Rust => {
let layout = core::alloc::Layout::array::<T>(count).unwrap();
unsafe { std::alloc::dealloc(ptr.cast(), layout) }
unsafe { alloc::alloc::dealloc(ptr.cast(), layout) }
}
#[cfg(feature = "c-allocator")]
Allocator::C => {
Expand Down

0 comments on commit 0ab2790

Please sign in to comment.