use crate::*;
use crate::meta::*;
use winapi::um::combaseapi::{CoTaskMemAlloc, CoTaskMemRealloc, CoTaskMemFree};
use core::mem::MaybeUninit;
use core::ptr::NonNull;
#[doc = include_str!("_refs.md")]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)] #[repr(transparent)] pub struct CoTaskMem;
impl Meta for CoTaskMem {
type Error = ();
const MIN_ALIGN : Alignment = super::MEMORY_ALLOCATION_ALIGNMENT; const MAX_ALIGN : Alignment = super::MEMORY_ALLOCATION_ALIGNMENT; const MAX_SIZE : usize = usize::MAX;
const ZST_SUPPORTED : bool = true;
}
impl ZstSupported for CoTaskMem {}
unsafe impl Stateless for CoTaskMem {}
#[doc = include_str!("_refs.md")]
unsafe impl thin::Alloc for CoTaskMem {
fn alloc_uninit(&self, size: usize) -> Result<AllocNN, Self::Error> {
let alloc = unsafe { CoTaskMemAlloc(size) };
NonNull::new(alloc.cast()).ok_or(())
}
}
#[doc = include_str!("_refs.md")]
#[allow(clippy::missing_safety_doc)]
unsafe impl thin::Realloc for CoTaskMem {
const CAN_REALLOC_ZEROED : bool = false;
unsafe fn realloc_uninit(&self, ptr: AllocNN, new_size: usize) -> Result<AllocNN, Self::Error> {
if new_size == 0 {
let alloc = thin::Alloc::alloc_uninit(self, new_size)?;
unsafe { thin::Free::free(self, ptr) };
Ok(alloc)
} else {
let alloc = unsafe { CoTaskMemRealloc(ptr.as_ptr().cast(), new_size) };
NonNull::new(alloc.cast()).ok_or(())
}
}
unsafe fn realloc_zeroed(&self, _ptr: AllocNN, _new_size: usize) -> Result<AllocNN, Self::Error> {
Err(())
}
}
#[doc = include_str!("_refs.md")]
#[allow(clippy::missing_safety_doc)]
unsafe impl thin::Free for CoTaskMem {
unsafe fn free_nullable(&self, ptr: *mut MaybeUninit<u8>) {
unsafe { CoTaskMemFree(ptr.cast()) }
}
}
#[no_implicit_prelude] mod cleanroom {
use super::{impls, CoTaskMem};
impls! {
unsafe impl ialloc::fat::Alloc for CoTaskMem => ialloc::thin::Alloc;
unsafe impl ialloc::fat::Realloc for CoTaskMem => ialloc::thin::Realloc;
unsafe impl ialloc::fat::Free for CoTaskMem => ialloc::thin::Free;
}
}
#[test] fn thin_alignment() { thin::test::alignment(CoTaskMem) }
#[test] fn thin_edge_case_sizes() { thin::test::edge_case_sizes(CoTaskMem) }
#[test] fn thin_nullable() { thin::test::nullable(CoTaskMem) }
#[test] fn thin_uninit() { unsafe { thin::test::uninit_alloc_unsound(CoTaskMem) } }
#[test] fn thin_uninit_realloc() { thin::test::uninit_realloc(CoTaskMem) }
#[test] fn thin_zeroed() { thin::test::zeroed_alloc(CoTaskMem) }
#[test] fn thin_zeroed_realloc() { thin::test::zeroed_realloc(CoTaskMem) }
#[test] fn thin_zst_support() { thin::test::zst_supported_accurate(CoTaskMem) }
#[test] fn fat_alignment() { fat::test::alignment(CoTaskMem) }
#[test] fn fat_edge_case_sizes() { fat::test::edge_case_sizes(CoTaskMem) }
#[test] fn fat_uninit() { unsafe { fat::test::uninit_alloc_unsound(CoTaskMem) } }
#[test] fn fat_uninit_realloc() { fat::test::uninit_realloc(CoTaskMem) }
#[test] fn fat_zeroed() { fat::test::zeroed_alloc(CoTaskMem) }
#[test] fn fat_zeroed_realloc() { fat::test::zeroed_realloc(CoTaskMem) }
#[test] fn fat_zst_support() { fat::test::zst_supported_accurate(CoTaskMem) }