[*] Harden AuCastPointer
This commit is contained in:
parent
98b72f7e0a
commit
72335a09a9
@ -134,6 +134,26 @@ namespace Aurora::Memory
|
||||
|
||||
pHeap->_Free(pVoids);
|
||||
}
|
||||
|
||||
template <typename T, typename Z>
|
||||
static void DeleteThatCastedOnce(T *pThat)
|
||||
{
|
||||
static const auto kAlignment = AuMax(alignof(T), sizeof(void *));
|
||||
|
||||
auto pBaseClass = AuStaticCast<Z>(pThat);
|
||||
|
||||
if constexpr (AuIsClass_v<T>
|
||||
#if !defined(AURT_HEAP_NO_STL)
|
||||
&& !std::is_trivially_destructible_v<T>
|
||||
#endif
|
||||
)
|
||||
{
|
||||
pBaseClass->~Z();
|
||||
}
|
||||
|
||||
auto &pHeap = *(Heap **)(((char *)pBaseClass) - kAlignment);
|
||||
pHeap->_Free(&pHeap);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static void RetardedSpecWrittenByRetards(T *pThat)
|
||||
@ -354,10 +374,13 @@ namespace Aurora::Memory
|
||||
{
|
||||
return NullUniquePointer<Z>();
|
||||
}
|
||||
else if (pInPointer.get_deleter() == &Heap::DeleteThat<T>)
|
||||
{
|
||||
return AuUPtr<Z, decltype(&Heap::DeleteThat<Z>)>(AuStaticCast<Z>(pInPointer.release()), &Heap::DeleteThatCastedOnce<Z, T>);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto deleter = decltype(&Heap::DeleteThat<Z>)(pInPointer.get_deleter());
|
||||
return AuUPtr<Z, decltype(&Heap::DeleteThat<Z>)>(AuStaticCast<Z>(pInPointer.release()), deleter);
|
||||
return NullUniquePointer<Z>();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user