Skip to content

Commit

Permalink
allow feature = "std" when checking for presence of memory allocation
Browse files Browse the repository at this point in the history
Memory allocation (i.e. the Box and Arc) can be present even without the
allocator_api.  Allow feature = "std" when the code is simply checking for
the existence of Box and Arc, and the allocator API is not used.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
  • Loading branch information
bonzini authored and y86-dev committed Nov 29, 2024
1 parent f794151 commit d286b7e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions examples/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,12 @@ impl WaitEntry {
}
}

#[cfg(not(feature = "alloc"))]
#[cfg(not(any(feature = "std", feature = "alloc")))]
fn main() {}

#[allow(dead_code)]
#[cfg_attr(test, test)]
#[cfg(feature = "alloc")]
#[cfg(any(feature = "std", feature = "alloc"))]
fn main() {
let mtx: Pin<Arc<CMutex<usize>>> = Arc::pin_init(CMutex::new(0)).unwrap();
let mut handles = vec![];
Expand Down
2 changes: 1 addition & 1 deletion examples/pthread_mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ mod pthread_mtx {

#[cfg_attr(test, test)]
fn main() {
#[cfg(all(feature = "alloc", not(windows)))]
#[cfg(all(any(feature = "std", feature = "alloc"), not(windows)))]
{
use core::pin::Pin;
use pinned_init::*;
Expand Down
4 changes: 2 additions & 2 deletions examples/static_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ unsafe impl PinInit<CMutex<usize>> for CountInit {

pub static COUNT: StaticInit<CMutex<usize>, CountInit> = StaticInit::new(CountInit);

#[cfg(not(feature = "alloc"))]
#[cfg(not(any(feature = "std", feature = "alloc")))]
fn main() {}

#[cfg(feature = "alloc")]
#[cfg(any(feature = "std", feature = "alloc"))]
fn main() {
let mtx: Pin<Arc<CMutex<usize>>> = Arc::pin_init(CMutex::new(0)).unwrap();
let mut handles = vec![];
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ pub trait InPlaceWrite<T> {
fn write_pin_init<E>(self, init: impl PinInit<T, E>) -> Result<Pin<Self::Initialized>, E>;
}

#[cfg(feature = "alloc")]
#[cfg(any(feature = "std", feature = "alloc"))]
impl<T> InPlaceWrite<T> for Box<MaybeUninit<T>> {
type Initialized = Box<T>;

Expand Down Expand Up @@ -1405,7 +1405,7 @@ impl_zeroable! {
//
// In this case we are allowed to use `T: ?Sized`, since all zeros is the `None` variant.
{<T: ?Sized>} Option<NonNull<T>>,
#[cfg(feature = "alloc")]
#[cfg(any(feature = "std", feature = "alloc"))]
{<T: ?Sized>} Option<Box<T>>,

// SAFETY: `null` pointer is valid.
Expand Down
6 changes: 3 additions & 3 deletions tests/ring_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ fn even_stack() {
assert_eq!(val, Err(()));
}

#[cfg(feature = "alloc")]
#[cfg(any(feature = "std", feature = "alloc"))]
#[test]
fn even_failing() {
assert!(matches!(Box::try_pin_init(EvenU64::new2(3)), Err(Error)));
Expand Down Expand Up @@ -243,7 +243,7 @@ struct BigStruct {
oth: MaybeUninit<u8>,
}

#[cfg(all(feature = "alloc", not(miri)))]
#[cfg(all(any(feature = "std", feature = "alloc"), not(miri)))]
#[test]
fn big_struct() {
let x = Arc::init(init!(BigStruct {
Expand All @@ -258,7 +258,7 @@ fn big_struct() {
println!("{x:?}");
}

#[cfg(all(feature = "alloc", not(miri)))]
#[cfg(all(any(feature = "std", feature = "alloc"), not(miri)))]
#[test]
fn with_big_struct() {
let buf = Arc::pin_init(CMutex::new(RingBuffer::<BigStruct, 64>::new())).unwrap();
Expand Down

0 comments on commit d286b7e

Please sign in to comment.