Merge branch 'blender-v4.2-release'
This commit is contained in:
@@ -353,7 +353,7 @@ template<typename T> inline T *MEM_cnew_array(const size_t length, const char *a
|
||||
template<typename T> inline T *MEM_cnew(const char *allocation_name, const T &other)
|
||||
{
|
||||
static_assert(std::is_trivial_v<T>, "For non-trivial types, MEM_new should be used.");
|
||||
T *new_object = static_cast<T *>(MEM_mallocN(sizeof(T), allocation_name));
|
||||
T *new_object = static_cast<T *>(MEM_mallocN_aligned(sizeof(T), alignof(T), allocation_name));
|
||||
if (new_object) {
|
||||
memcpy(new_object, &other, sizeof(T));
|
||||
}
|
||||
|
||||
@@ -511,12 +511,18 @@ void *MEM_guarded_malloc_arrayN(size_t len, size_t size, const char *str)
|
||||
|
||||
void *MEM_guarded_mallocN_aligned(size_t len, size_t alignment, const char *str)
|
||||
{
|
||||
/* We only support alignment to a power of two. */
|
||||
/* Huge alignment values doesn't make sense and they wouldn't fit into 'short' used in the
|
||||
* MemHead. */
|
||||
assert(alignment < 1024);
|
||||
|
||||
/* We only support alignments that are a power of two. */
|
||||
assert(IS_POW2(alignment));
|
||||
|
||||
/* Use a minimal alignment of 8. Otherwise MEM_guarded_freeN thinks it is an illegal pointer. */
|
||||
if (alignment < 8) {
|
||||
alignment = 8;
|
||||
/* Some OS specific aligned allocators require a certain minimal alignment. */
|
||||
/* And #MEM_guarded_freeN also checks that it is freeing a pointer aligned with `sizeof(void *)`.
|
||||
*/
|
||||
if (alignment < ALIGNED_MALLOC_MINIMUM_ALIGNMENT) {
|
||||
alignment = ALIGNED_MALLOC_MINIMUM_ALIGNMENT;
|
||||
}
|
||||
|
||||
/* It's possible that MemHead's size is not properly aligned,
|
||||
@@ -527,11 +533,6 @@ void *MEM_guarded_mallocN_aligned(size_t len, size_t alignment, const char *str)
|
||||
*/
|
||||
size_t extra_padding = MEMHEAD_ALIGN_PADDING(alignment);
|
||||
|
||||
/* Huge alignment values doesn't make sense and they
|
||||
* wouldn't fit into 'short' used in the MemHead.
|
||||
*/
|
||||
assert(alignment < 1024);
|
||||
|
||||
#ifdef WITH_MEM_VALGRIND
|
||||
const size_t len_unaligned = len;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user