use crate::*;
use crate::meta::*;
use super::ffi;
use core::alloc::Layout;
use core::ptr::NonNull;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] pub struct NewDeleteAligned;
impl Meta for NewDeleteAligned {
type Error = ();
const MAX_ALIGN : Alignment = if cfg!(target_os = "macos") { ALIGN_MIN_2_GiB_MAX } else { Alignment::MAX };
const MAX_SIZE : usize = usize::MAX;
const ZST_SUPPORTED : bool = false; }
unsafe impl Stateless for NewDeleteAligned {}
unsafe impl fat::Alloc for NewDeleteAligned {
fn alloc_uninit(&self, layout: Layout) -> Result<AllocNN, Self::Error> {
if Self::MAX_ALIGN != Alignment::MAX && layout.align() > Self::MAX_ALIGN.as_usize() { return Err(()) }
NonNull::new(unsafe { ffi::operator_new_align_nothrow(layout.size(), layout.align()) }.cast()).ok_or(())
}
}
unsafe impl fat::Free for NewDeleteAligned {
unsafe fn free(&self, ptr: AllocNN, layout: Layout) {
unsafe { ffi::operator_delete_align(ptr.as_ptr().cast(), layout.align()) };
}
}
unsafe impl fat::Realloc for NewDeleteAligned {}
#[test] fn fat_alignment() { fat::test::alignment(NewDeleteAligned) }
#[test] fn fat_edge_case_sizes() { fat::test::edge_case_sizes(NewDeleteAligned) }
#[test] fn fat_uninit() { if !allocator::cpp::OPERATOR_NEW_ZERO_INITS { unsafe { fat::test::uninit_alloc_unsound(NewDeleteAligned) } } }
#[test] fn fat_uninit_realloc() { fat::test::uninit_realloc(NewDeleteAligned) }
#[test] fn fat_zeroed() { fat::test::zeroed_alloc(NewDeleteAligned) }
#[test] fn fat_zeroed_realloc() { fat::test::zeroed_realloc(NewDeleteAligned) }
#[test] fn fat_zst_support() { fat::test::zst_supported_conservative(NewDeleteAligned) }