use crate::*;
use crate::meta::*;
use super::ffi;
use core::ptr::NonNull;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] pub struct NewDelete;
impl Meta for NewDelete {
type Error = ();
const MAX_ALIGN : Alignment = if !cfg!(target_env = "msvc") {
Alignment::of::<f64>() } else if core::mem::size_of::<usize>() >= 8 {
ALIGN_16
} else {
ALIGN_8
};
const MAX_SIZE : usize = usize::MAX; const ZST_SUPPORTED : bool = false; }
unsafe impl Stateless for NewDelete {}
unsafe impl thin::Alloc for NewDelete {
fn alloc_uninit(&self, size: usize) -> Result<AllocNN, Self::Error> {
NonNull::new(unsafe { ffi::operator_new_nothrow(size) }.cast()).ok_or(())
}
}
unsafe impl thin::Free for NewDelete {
unsafe fn free_nullable(&self, ptr: *mut core::mem::MaybeUninit<u8>) {
unsafe { ffi::operator_delete(ptr.cast()) };
}
}
unsafe impl fat::Realloc for NewDelete {}
#[no_implicit_prelude] mod cleanroom {
use super::{impls, NewDelete};
impls! {
unsafe impl ialloc::fat::Alloc for NewDelete => ialloc::thin::Alloc;
unsafe impl ialloc::fat::Free for NewDelete => ialloc::thin::Free;
}
}
#[cfg(test)] pub(crate) const OPERATOR_NEW_ZERO_INITS : bool = cfg!(any(
target_os = "linux", target_os = "macos", ));
#[test] fn thin_alignment() { thin::test::alignment(NewDelete) }
#[test] fn thin_edge_case_sizes() { thin::test::edge_case_sizes(NewDelete) }
#[test] fn thin_nullable() { thin::test::nullable(NewDelete) }
#[test] fn thin_uninit() { if !OPERATOR_NEW_ZERO_INITS { unsafe { thin::test::uninit_alloc_unsound(NewDelete) } } }
#[test] fn thin_zeroed() { thin::test::zeroed_alloc(NewDelete) }
#[test] fn thin_zst_support() { thin::test::zst_supported_conservative(NewDelete) }
#[test] fn fat_alignment() { fat::test::alignment(NewDelete) }
#[test] fn fat_edge_case_sizes() { fat::test::edge_case_sizes(NewDelete) }
#[test] fn fat_uninit() { if !OPERATOR_NEW_ZERO_INITS { unsafe { fat::test::uninit_alloc_unsound(NewDelete) } } }
#[test] fn fat_uninit_realloc() { fat::test::uninit_realloc(NewDelete) }
#[test] fn fat_zeroed() { fat::test::zeroed_alloc(NewDelete) }
#[test] fn fat_zeroed_realloc() { fat::test::zeroed_realloc(NewDelete) }
#[test] fn fat_zst_support() { fat::test::zst_supported_conservative(NewDelete) }