Skip to content
Snippets Groups Projects
Commit 8ea425d9 authored by Jacques Lucke's avatar Jacques Lucke
Browse files

Fix #118402: enforce expected minimum alignment in MEM_CXX_CLASS_ALLOC_FUNCS

This `operator new` added in ecc3e78d
are only called if the alignment is greater than `__STDCPP_DEFAULT_NEW_ALIGNMENT__`.
This is generally 8 or 16 depending on the platform. `MEM_mallocN` does
guarantee 16 byte alignment currently (in fact it's usually not 16 byte aligned
because of `MemHead`). Now `MEM_mallocN_aligned` is used with the default
alignment, even if we don't know that the type does not require it.

An alternative would be to pass the alignment to `MEM_CXX_CLASS_ALLOC_FUNCS`,
but that would be more intrusive.

Pull Request: https://projects.blender.org/blender/blender/pulls/118568
parent 1d0bbefb
Branches
No related tags found
No related merge requests found
...@@ -339,7 +339,7 @@ template<typename T> inline T *MEM_cnew(const char *allocation_name, const T &ot ...@@ -339,7 +339,7 @@ template<typename T> inline T *MEM_cnew(const char *allocation_name, const T &ot
public: \ public: \
void *operator new(size_t num_bytes) \ void *operator new(size_t num_bytes) \
{ \ { \
return MEM_mallocN(num_bytes, _id); \ return MEM_mallocN_aligned(num_bytes, __STDCPP_DEFAULT_NEW_ALIGNMENT__, _id); \
} \ } \
void *operator new(size_t num_bytes, std::align_val_t alignment) \ void *operator new(size_t num_bytes, std::align_val_t alignment) \
{ \ { \
...@@ -353,7 +353,7 @@ template<typename T> inline T *MEM_cnew(const char *allocation_name, const T &ot ...@@ -353,7 +353,7 @@ template<typename T> inline T *MEM_cnew(const char *allocation_name, const T &ot
} \ } \
void *operator new[](size_t num_bytes) \ void *operator new[](size_t num_bytes) \
{ \ { \
return MEM_mallocN(num_bytes, _id "[]"); \ return MEM_mallocN_aligned(num_bytes, __STDCPP_DEFAULT_NEW_ALIGNMENT__, _id "[]"); \
} \ } \
void *operator new[](size_t num_bytes, std::align_val_t alignment) \ void *operator new[](size_t num_bytes, std::align_val_t alignment) \
{ \ { \
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment