Fix #118402: support overaligned types in MEM_CXX_CLASS_ALLOC_FUNCS
Previously, the alignment of structs that use `MEM_CXX_CLASS_ALLOC_FUNCS` were not taken into account when doing the allocation. This can cause some data to be mis-aligned and leads to crashes when cpu instructions or code expect the data to be aligned. The fix is to provide an overload of `operator new` that accepts the alignment as parameter. More info: https://en.cppreference.com/w/cpp/language/new (search for `align_val_t`). Pull Request: https://projects.blender.org/blender/blender/pulls/118526
This commit is contained in:
parent
d2f8af9b08
commit
ecc3e78d78
|
@ -341,6 +341,10 @@ template<typename T> inline T *MEM_cnew(const char *allocation_name, const T &ot
|
|||
{ \
|
||||
return MEM_mallocN(num_bytes, _id); \
|
||||
} \
|
||||
void *operator new(size_t num_bytes, std::align_val_t alignment) \
|
||||
{ \
|
||||
return MEM_mallocN_aligned(num_bytes, size_t(alignment), _id); \
|
||||
} \
|
||||
void operator delete(void *mem) \
|
||||
{ \
|
||||
if (mem) { \
|
||||
|
@ -351,6 +355,10 @@ template<typename T> inline T *MEM_cnew(const char *allocation_name, const T &ot
|
|||
{ \
|
||||
return MEM_mallocN(num_bytes, _id "[]"); \
|
||||
} \
|
||||
void *operator new[](size_t num_bytes, std::align_val_t alignment) \
|
||||
{ \
|
||||
return MEM_mallocN_aligned(num_bytes, size_t(alignment), _id "[]"); \
|
||||
} \
|
||||
void operator delete[](void *mem) \
|
||||
{ \
|
||||
if (mem) { \
|
||||
|
|
Loading…
Reference in New Issue