Cleanup: Remove void * handling from MEM_freen<T>.
Followup to 48e26c3afe, and discussions in !134771 about keeping
'C-style' and 'C++ template type-safe style' implementations of our
guardedalloc separated. And it makes `MEM_freeN<T>` code simpler.
Also skip type-checking in `MEM_freeN<T>` only with MSVC, as clang-cl on
windows-arm64 does work fine with DNA structs using
`DNA_DEFINE_CXX_METHODS`.
Pull Request: https://projects.blender.org/blender/blender/pulls/134861
This commit is contained in:
committed by
Bastien Montagne
parent
4b10c63617
commit
318ae49f1e
@@ -201,7 +201,7 @@ extern size_t (*MEM_get_peak_memory)(void) ATTR_WARN_UNUSED_RESULT;
|
||||
# define MEM_SAFE_FREE(v) \
|
||||
do { \
|
||||
if (v) { \
|
||||
MEM_freeN<std::remove_pointer_t<std::decay_t<decltype(v)>>>(v); \
|
||||
MEM_freeN(v); \
|
||||
(v) = nullptr; \
|
||||
} \
|
||||
} while (0)
|
||||
@@ -399,21 +399,15 @@ template<typename T> inline T *MEM_cnew(const char *allocation_name, const T &ot
|
||||
|
||||
template<typename T> inline void MEM_freeN(T *ptr)
|
||||
{
|
||||
if constexpr (std::is_void_v<T>) {
|
||||
mem_guarded::internal::mem_freeN_ex(const_cast<void *>(ptr),
|
||||
mem_guarded::internal::AllocationType::ALLOC_FREE);
|
||||
}
|
||||
else {
|
||||
# ifndef _WIN32
|
||||
/* MSVC seems to consider C-style types using the MEM_CXX_CLASS_ALLOC_FUNCS as non-trivial. GCC
|
||||
* and clang (both on linux and OSX) do not.
|
||||
*
|
||||
* So for now, disable the triviality check on Windows. */
|
||||
static_assert(std::is_trivial_v<T>, "For non-trivial types, MEM_delete must be used.");
|
||||
# ifndef _MSC_VER
|
||||
/* MSVC seems to consider C-style types using the DNA_DEFINE_CXX_METHODS as non-trivial. GCC
|
||||
* and clang (both on linux, OSX and clang-cl on Windows on Arm) do not.
|
||||
*
|
||||
* So for now, disable the triviality check on MSVC. */
|
||||
static_assert(std::is_trivial_v<T>, "For non-trivial types, MEM_delete must be used.");
|
||||
# endif
|
||||
mem_guarded::internal::mem_freeN_ex(const_cast<void *>(static_cast<const void *>(ptr)),
|
||||
mem_guarded::internal::AllocationType::ALLOC_FREE);
|
||||
}
|
||||
mem_guarded::internal::mem_freeN_ex(const_cast<void *>(static_cast<const void *>(ptr)),
|
||||
mem_guarded::internal::AllocationType::ALLOC_FREE);
|
||||
}
|
||||
|
||||
/** Allocation functions (for C++ only). */
|
||||
|
||||
Reference in New Issue
Block a user