Refactor: Replace MEM_cnew with a type-aware template version of MEM_callocN.

The general idea is to keep the 'old', C-style MEM_callocN signature, and slowly
replace most of its usages with the new, C++-style type-safer template version.

* `MEM_cnew<T>` allocation version is renamed to `MEM_callocN<T>`.
* `MEM_cnew_array<T>` allocation version is renamed to `MEM_calloc_arrayN<T>`.
* `MEM_cnew<T>` duplicate version is renamed to `MEM_dupallocN<T>`.

Similar templates type-safe version of `MEM_mallocN` will be added soon
as well.

Following discussions in !134452.

NOTE: For now static type checking in `MEM_callocN` and related are slightly
different for Windows MSVC. This compiler seems to consider structs using the
`DNA_DEFINE_CXX_METHODS` macro as non-trivial (likely because their default
copy constructors are deleted). So using checks on trivially
constructible/destructible instead on this compiler/system.

Pull Request: https://projects.blender.org/blender/blender/pulls/134771
This commit is contained in:
Bastien Montagne 2025-03-05 16:35:09 +01:00 • committed by Bastien Montagne
parent 65889672e2
commit dd168a35c5
423 changed files with 1122 additions and 1024 deletions

View file

@ -52,7 +52,7 @@ extern "C" {
extern size_t (*MEM_allocN_len)(const void *vmemh) ATTR_WARN_UNUSED_RESULT;
/**
* Release memory previously allocated by the C-style and #MEM_cnew functions of this module.
* Release memory previously allocated by the C-style functions of this module.
*
* It is illegal to call this function with data allocated by #MEM_new.
*/
@ -69,7 +69,7 @@ extern short (*MEM_testN)(void *vmemh);
* Duplicates a block of memory, and returns a pointer to the
* newly allocated block.
* NULL-safe; will return NULL when receiving a NULL pointer. */
extern void *(*MEM_dupallocN)(const void *vmemh) /* ATTR_MALLOC */ ATTR_WARN_UNUSED_RESULT;
void *MEM_dupallocN(const void *vmemh) /* ATTR_MALLOC */ ATTR_WARN_UNUSED_RESULT;
/**
* Reallocates a block of memory, and returns pointer to the newly
@ -97,17 +97,17 @@ extern void *(*MEM_recallocN_id)(void *vmemh,
* memory is cleared. The name must be static, because only a
* pointer to it is stored!
*/
extern void *(*MEM_callocN)(size_t len, const char *str) /* ATTR_MALLOC */ ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2);
void *MEM_callocN(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1)
ATTR_NONNULL(2);
/**
* Allocate a block of memory of size (len * size), with tag name
* str, aborting in case of integer overflows to prevent vulnerabilities.
* The memory is cleared. The name must be static, because only a
* pointer to it is stored! */
extern void *(*MEM_calloc_arrayN)(size_t len,
size_t size,
const char *str) /* ATTR_MALLOC */ ATTR_WARN_UNUSED_RESULT
void *MEM_calloc_arrayN(size_t len,
size_t size,
const char *str) /* ATTR_MALLOC */ ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1, 2) ATTR_NONNULL(3);
/**
@ -325,8 +325,8 @@ inline T *MEM_new(const char *allocation_name, Args &&...args)
*
* As with the `delete` C++ operator, passing in `nullptr` is allowed and does nothing.
*
* It is illegal to call this function with data allocated by #MEM_cnew or the C-style allocation
* functions of this module.
* It is illegal to call this function with data allocated by the C-style allocation functions of
* this module.
*/
template<typename T> inline void MEM_delete(const T *ptr)
{
@ -356,23 +356,49 @@ template<typename T> inline void MEM_delete(const T *ptr)
/**
* Allocate zero-initialized memory for an object of type #T. The constructor of #T is not called,
* therefore this should only be used with trivial types (like all C types).
* therefore this must only be used with trivial types (like all C types).
*
* When allocating an enforced specific amount of bytes, the C version of this function should be
* used instead. While this should be avoided in C++ code, it is still required in some cases, e.g.
* for ID allocation based on #IDTypeInfo::struct_size.
*
* #MEM_freeN must be used to free a pointer returned by this call. Calling #MEM_delete on it is
* illegal.
*/
template<typename T> inline T *MEM_cnew(const char *allocation_name)
template<typename T> inline T *MEM_callocN(const char *allocation_name)
{
# ifdef _MSC_VER
/* MSVC considers C-style types using the DNA_DEFINE_CXX_METHODS as non-trivial (more
* specifically, non-trivially copyable, likely because the default copy constructors are
* deleted). GCC and clang (both on linux, OSX, and clang-cl on Windows on Arm) do not.
*
* So for now, use a more restricted check on MSVC, should still catch most of actual invalid
* cases. */
static_assert(std::is_trivially_constructible_v<T>,
"For non-trivial types, MEM_new must be used.");
# else
static_assert(std::is_trivial_v<T>, "For non-trivial types, MEM_new must be used.");
# endif
return static_cast<T *>(MEM_calloc_arrayN_aligned(1, sizeof(T), alignof(T), allocation_name));
}
/**
* Same as MEM_cnew but for arrays, better alternative to #MEM_calloc_arrayN.
* Type-safe version of #MEM_calloc_arrayN/#MEM_calloc_array_alignedN.
*/
template<typename T> inline T *MEM_cnew_array(const size_t length, const char *allocation_name)
template<typename T> inline T *MEM_calloc_arrayN(const size_t length, const char *allocation_name)
{
# ifdef _MSC_VER
/* MSVC considers C-style types using the DNA_DEFINE_CXX_METHODS as non-trivial (more
* specifically, non-trivially copyable, likely because the default copy constructors are
* deleted). GCC and clang (both on linux, OSX, and clang-cl on Windows on Arm) do not.
*
* So for now, use a more restricted check on MSVC, should still catch most of actual invalid
* cases. */
static_assert(std::is_trivially_constructible_v<T>,
"For non-trivial types, MEM_new must be used.");
# else
static_assert(std::is_trivial_v<T>, "For non-trivial types, MEM_new must be used.");
# endif
return static_cast<T *>(
MEM_calloc_arrayN_aligned(length, sizeof(T), alignof(T), allocation_name));
}
@ -385,11 +411,23 @@ template<typename T> inline T *MEM_cnew_array(const size_t length, const char *a
* deprecated fields: some compilers will generate access deprecated field warnings in implicitly
* defined copy constructors.
*
* This is a better alternative to #MEM_dupallocN.
* This is a better alternative to the C-style implementation of #MEM_dupallocN, unless the source
* is an array or of a non-fully-defined type.
*/
template<typename T> inline T *MEM_cnew(const char *allocation_name, const T &other)
template<typename T> inline T *MEM_dupallocN(const char *allocation_name, const T &other)
{
# ifdef _MSC_VER
/* MSVC considers C-style types using the DNA_DEFINE_CXX_METHODS as non-trivial (more
* specifically, non-trivially copyable, likely because the default copy constructors are
* deleted). GCC and clang (both on linux, OSX, and clang-cl on Windows on Arm) do not.
*
* So for now, use a more restricted check on MSVC, should still catch most of actual invalid
* cases. */
static_assert(std::is_trivially_constructible_v<T>,
"For non-trivial types, MEM_new must be used.");
# else
static_assert(std::is_trivial_v<T>, "For non-trivial types, MEM_new must be used.");
# endif
T *new_object = static_cast<T *>(MEM_mallocN_aligned(sizeof(T), alignof(T), allocation_name));
if (new_object) {
memcpy(new_object, &other, sizeof(T));

View file

@ -36,11 +36,13 @@ const char *malloc_conf =
size_t (*MEM_allocN_len)(const void *vmemh) = MEM_lockfree_allocN_len;
void (*mem_guarded::internal::mem_freeN_ex)(void *vmemh,
AllocationType allocation_type) = MEM_lockfree_freeN;
void *(*MEM_dupallocN)(const void *vmemh) = MEM_lockfree_dupallocN;
void *(*mem_guarded::internal::mem_dupallocN)(const void *vmemh) = MEM_lockfree_dupallocN;
void *(*MEM_reallocN_id)(void *vmemh, size_t len, const char *str) = MEM_lockfree_reallocN_id;
void *(*MEM_recallocN_id)(void *vmemh, size_t len, const char *str) = MEM_lockfree_recallocN_id;
void *(*MEM_callocN)(size_t len, const char *str) = MEM_lockfree_callocN;
void *(*MEM_calloc_arrayN)(size_t len, size_t size, const char *str) = MEM_lockfree_calloc_arrayN;
void *(*mem_guarded::internal::mem_callocN)(size_t len, const char *str) = MEM_lockfree_callocN;
void *(*mem_guarded::internal::mem_calloc_arrayN)(size_t len,
size_t size,
const char *str) = MEM_lockfree_calloc_arrayN;
void *(*MEM_mallocN)(size_t len, const char *str) = MEM_lockfree_mallocN;
void *(*MEM_malloc_arrayN)(size_t len, size_t size, const char *str) = MEM_lockfree_malloc_arrayN;
void *(*mem_guarded::internal::mem_mallocN_aligned_ex)(size_t len,
@ -111,11 +113,26 @@ void MEM_freeN(void *vmemh)
mem_freeN_ex(vmemh, AllocationType::ALLOC_FREE);
}
void *MEM_callocN(size_t len, const char *str)
{
return mem_callocN(len, str);
}
void *MEM_calloc_arrayN(size_t len, size_t size, const char *str)
{
return mem_calloc_arrayN(len, size, str);
}
void *MEM_mallocN_aligned(size_t len, size_t alignment, const char *str)
{
return mem_mallocN_aligned_ex(len, alignment, str, AllocationType::ALLOC_FREE);
}
void *MEM_dupallocN(const void *vmemh)
{
return mem_dupallocN(vmemh);
}
/**
* Perform assert checks on allocator type change.
*
@ -142,11 +159,11 @@ void MEM_use_lockfree_allocator()
MEM_allocN_len = MEM_lockfree_allocN_len;
mem_freeN_ex = MEM_lockfree_freeN;
MEM_dupallocN = MEM_lockfree_dupallocN;
mem_dupallocN = MEM_lockfree_dupallocN;
MEM_reallocN_id = MEM_lockfree_reallocN_id;
MEM_recallocN_id = MEM_lockfree_recallocN_id;
MEM_callocN = MEM_lockfree_callocN;
MEM_calloc_arrayN = MEM_lockfree_calloc_arrayN;
mem_callocN = MEM_lockfree_callocN;
mem_calloc_arrayN = MEM_lockfree_calloc_arrayN;
MEM_mallocN = MEM_lockfree_mallocN;
MEM_malloc_arrayN = MEM_lockfree_malloc_arrayN;
mem_mallocN_aligned_ex = MEM_lockfree_mallocN_aligned;
@ -178,11 +195,11 @@ void MEM_use_guarded_allocator()
MEM_allocN_len = MEM_guarded_allocN_len;
mem_freeN_ex = MEM_guarded_freeN;
MEM_dupallocN = MEM_guarded_dupallocN;
mem_dupallocN = MEM_guarded_dupallocN;
MEM_reallocN_id = MEM_guarded_reallocN_id;
MEM_recallocN_id = MEM_guarded_recallocN_id;
MEM_callocN = MEM_guarded_callocN;
MEM_calloc_arrayN = MEM_guarded_calloc_arrayN;
mem_callocN = MEM_guarded_callocN;
mem_calloc_arrayN = MEM_guarded_calloc_arrayN;
MEM_mallocN = MEM_guarded_mallocN;
MEM_malloc_arrayN = MEM_guarded_malloc_arrayN;
mem_mallocN_aligned_ex = MEM_guarded_mallocN_aligned;

View file

@ -720,7 +720,7 @@ static void *mem_guarded_malloc_arrayN_aligned(const size_t len,
return nullptr;
}
if (alignment <= MEM_MIN_CPP_ALIGNMENT) {
return MEM_callocN(r_bytes_num, str);
return mem_callocN(r_bytes_num, str);
}
return MEM_mallocN_aligned(r_bytes_num, alignment, str);
}

View file

@ -20,6 +20,22 @@ enum class AllocationType {
/** Internal implementation of #MEM_freeN, exposed because #MEM_delete needs access to it. */
extern void (*mem_freeN_ex)(void *vmemh, AllocationType allocation_type);
/**
* Internal implementation of #MEM_callocN, exposed because public #MEM_callocN cannot be a
* function pointer, to allow its overload by C++ template version.
*/
extern void *(*mem_callocN)(size_t len, const char *str) /* ATTR_MALLOC */ ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2);
/**
* Internal implementation of #MEM_calloc_arrayN, exposed because public #MEM_calloc_arrayN cannot
* be a function pointer, to allow its overload by C++ template version.
*/
extern void *(*mem_calloc_arrayN)(size_t len,
size_t size,
const char *str) /* ATTR_MALLOC */ ATTR_WARN_UNUSED_RESULT
ATTR_ALLOC_SIZE(1, 2) ATTR_NONNULL(3);
/** Internal implementation of #MEM_mallocN_aligned, exposed because #MEM_new needs access to it.
*/
extern void *(*mem_mallocN_aligned_ex)(size_t len,
@ -27,6 +43,12 @@ extern void *(*mem_mallocN_aligned_ex)(size_t len,
const char *str,
AllocationType allocation_type);
/**
* Internal implementation of #MEM_dupallocN, exposed because public #MEM_dupallocN cannot be a
* function pointer, to allow its overload by C++ template version.
*/
extern void *(*mem_dupallocN)(const void *vmemh) /* ATTR_MALLOC */ ATTR_WARN_UNUSED_RESULT;
/**
* Store a std::any into a static opaque storage vector. The only purpose of this call is to
* control the lifetime of the given data, there is no way to access it from here afterwards. User

View file

@ -474,7 +474,7 @@ static void *mem_lockfree_malloc_arrayN_aligned(const size_t len,
return nullptr;
}
if (alignment <= MEM_MIN_CPP_ALIGNMENT) {
return MEM_mallocN(r_bytes_num, str);
return mem_callocN(r_bytes_num, str);
}
void *ptr = MEM_mallocN_aligned(r_bytes_num, alignment, str);
return ptr;

View file

@ -512,7 +512,7 @@ OCIO_PackedImageDesc *FallbackImpl::createOCIO_PackedImageDesc(float *data,
long xStrideBytes,
long yStrideBytes)
{
OCIO_PackedImageDescription *desc = MEM_cnew<OCIO_PackedImageDescription>(
OCIO_PackedImageDescription *desc = MEM_callocN<OCIO_PackedImageDescription>(
"OCIO_PackedImageDescription");
desc->data = data;
desc->width = width;

View file

@ -83,7 +83,7 @@ template<typename T> static void grow_array(T **array, int *num, const int add_n
{
BLI_assert(add_num > 0);
const int new_array_num = *num + add_num;
T *new_array = MEM_cnew_array<T>(new_array_num, "animrig::action/grow_array");
T *new_array = MEM_calloc_arrayN<T>(new_array_num, "animrig::action/grow_array");
blender::uninitialized_relocate_n(*array, *num, new_array);
MEM_SAFE_FREE(*array);
@ -103,7 +103,7 @@ static void grow_array_and_insert(T **array, int *num, const int index, T item)
{
BLI_assert(index >= 0 && index <= *num);
const int new_array_num = *num + 1;
T *new_array = MEM_cnew_array<T>(new_array_num, __func__);
T *new_array = MEM_calloc_arrayN<T>(new_array_num, __func__);
blender::uninitialized_relocate_n(*array, index, new_array);
new_array[index] = item;
@ -119,7 +119,7 @@ template<typename T> static void shrink_array(T **array, int *num, const int shr
{
BLI_assert(shrink_num > 0);
const int new_array_num = *num - shrink_num;
T *new_array = MEM_cnew_array<T>(new_array_num, __func__);
T *new_array = MEM_calloc_arrayN<T>(new_array_num, __func__);
blender::uninitialized_move_n(*array, new_array_num, new_array);
MEM_freeN(*array);
@ -132,7 +132,7 @@ template<typename T> static void shrink_array_and_remove(T **array, int *num, co
{
BLI_assert(index >= 0 && index < *num);
const int new_array_num = *num - 1;
T *new_array = MEM_cnew_array<T>(new_array_num, __func__);
T *new_array = MEM_calloc_arrayN<T>(new_array_num, __func__);
blender::uninitialized_move_n(*array, index, new_array);
blender::uninitialized_move_n(*array + index + 1, *num - index - 1, new_array + index);
@ -151,7 +151,7 @@ template<typename T> static void shrink_array_and_swap_remove(T **array, int *nu
{
BLI_assert(index >= 0 && index < *num);
const int new_array_num = *num - 1;
T *new_array = MEM_cnew_array<T>(new_array_num, __func__);
T *new_array = MEM_calloc_arrayN<T>(new_array_num, __func__);
blender::uninitialized_move_n(*array, index, new_array);
if (index < new_array_num) {
@ -913,12 +913,12 @@ static float2 get_frame_range_of_fcurves(Span<const FCurve *> fcurves,
Layer *Layer::duplicate_with_shallow_strip_copies(const StringRefNull allocation_name) const
{
ActionLayer *copy = MEM_cnew<ActionLayer>(allocation_name.c_str());
ActionLayer *copy = MEM_callocN<ActionLayer>(allocation_name.c_str());
*copy = *reinterpret_cast<const ActionLayer *>(this);
/* Make a shallow copy of the Strips, without copying their data. */
copy->strip_array = MEM_cnew_array<ActionStrip *>(this->strip_array_num,
allocation_name.c_str());
copy->strip_array = MEM_calloc_arrayN<ActionStrip *>(this->strip_array_num,
allocation_name.c_str());
for (int i : this->strips().index_range()) {
Strip *strip_copy = MEM_new<Strip>(allocation_name.c_str(), *this->strip(i));
copy->strip_array[i] = strip_copy;
@ -1634,7 +1634,7 @@ std::optional<std::pair<Action *, Slot *>> get_action_slot_pair(ID &animated_id)
Strip &Strip::create(Action &owning_action, const Strip::Type type)
{
/* Create the strip. */
ActionStrip *strip = MEM_cnew<ActionStrip>(__func__);
ActionStrip *strip = MEM_callocN<ActionStrip>(__func__);
memcpy(strip, DNA_struct_default_get(ActionStrip), sizeof(*strip));
strip->strip_type = int8_t(type);
@ -1712,8 +1712,8 @@ StripKeyframeData::StripKeyframeData(const StripKeyframeData &other)
{
memcpy(this, &other, sizeof(*this));
this->channelbag_array = MEM_cnew_array<ActionChannelbag *>(other.channelbag_array_num,
__func__);
this->channelbag_array = MEM_calloc_arrayN<ActionChannelbag *>(other.channelbag_array_num,
__func__);
Span<const Channelbag *> channelbags_src = other.channelbags();
for (int i : channelbags_src.index_range()) {
this->channelbag_array[i] = MEM_new<animrig::Channelbag>(__func__, *other.channelbag(i));
@ -2138,14 +2138,14 @@ Channelbag::Channelbag(const Channelbag &other)
this->slot_handle = other.slot_handle;
this->fcurve_array_num = other.fcurve_array_num;
this->fcurve_array = MEM_cnew_array<FCurve *>(other.fcurve_array_num, __func__);
this->fcurve_array = MEM_calloc_arrayN<FCurve *>(other.fcurve_array_num, __func__);
for (int i = 0; i < other.fcurve_array_num; i++) {
const FCurve *fcu_src = other.fcurve_array[i];
this->fcurve_array[i] = BKE_fcurve_copy(fcu_src);
}
this->group_array_num = other.group_array_num;
this->group_array = MEM_cnew_array<bActionGroup *>(other.group_array_num, __func__);
this->group_array = MEM_calloc_arrayN<bActionGroup *>(other.group_array_num, __func__);
for (int i = 0; i < other.group_array_num; i++) {
const bActionGroup *group_src = other.group_array[i];
this->group_array[i] = static_cast<bActionGroup *>(MEM_dupallocN(group_src));
@ -3032,7 +3032,7 @@ Action *convert_to_layered_action(Main &bmain, const Action &legacy_action)
Channelbag *bag = &strip.data<StripKeyframeData>(converted_action).channelbag_for_slot_add(slot);
const int fcu_count = BLI_listbase_count(&legacy_action.curves);
bag->fcurve_array = MEM_cnew_array<FCurve *>(fcu_count, "Convert to layered action");
bag->fcurve_array = MEM_calloc_arrayN<FCurve *>(fcu_count, "Convert to layered action");
bag->fcurve_array_num = fcu_count;
int i = 0;

View file

@ -1253,7 +1253,7 @@ TEST_F(ActionLayersTest, action_move_slot)
/* Allocate fcu->bezt, and also return a unique_ptr to it for easily freeing the memory. */
static void allocate_keyframes(FCurve &fcu, const size_t num_keyframes)
{
fcu.bezt = MEM_cnew_array<BezTriple>(num_keyframes, __func__);
fcu.bezt = MEM_calloc_arrayN<BezTriple>(num_keyframes, __func__);
}
/* Append keyframe, assumes that fcu->bezt is allocated and has enough space. */
@ -1328,7 +1328,7 @@ TEST_F(ActionQueryTest, BKE_action_frame_range_calc)
/* One curve with one key. */
{
FCurve &fcu = *MEM_cnew<FCurve>(__func__);
FCurve &fcu = *MEM_callocN<FCurve>(__func__);
allocate_keyframes(fcu, 1);
add_keyframe(fcu, 1.0f, 2.0f);
@ -1342,8 +1342,8 @@ TEST_F(ActionQueryTest, BKE_action_frame_range_calc)
/* Two curves with one key each on different frames. */
{
FCurve &fcu1 = *MEM_cnew<FCurve>(__func__);
FCurve &fcu2 = *MEM_cnew<FCurve>(__func__);
FCurve &fcu1 = *MEM_callocN<FCurve>(__func__);
FCurve &fcu2 = *MEM_callocN<FCurve>(__func__);
allocate_keyframes(fcu1, 1);
allocate_keyframes(fcu2, 1);
add_keyframe(fcu1, 1.0f, 2.0f);
@ -1360,7 +1360,7 @@ TEST_F(ActionQueryTest, BKE_action_frame_range_calc)
/* One curve with two keys. */
{
FCurve &fcu = *MEM_cnew<FCurve>(__func__);
FCurve &fcu = *MEM_callocN<FCurve>(__func__);
allocate_keyframes(fcu, 2);
add_keyframe(fcu, 1.0f, 2.0f);
add_keyframe(fcu, 1.5f, 2.0f);

View file

@ -58,7 +58,7 @@ BoneCollection *ANIM_bonecoll_new(const char *name)
/* NOTE: the collection name may change after the collection is added to an
* armature, to ensure it is unique within the armature. */
BoneCollection *bcoll = MEM_cnew<BoneCollection>(__func__);
BoneCollection *bcoll = MEM_callocN<BoneCollection>(__func__);
STRNCPY_UTF8(bcoll->name, name);
bcoll->flags = default_flags;
@ -87,7 +87,7 @@ void ANIM_bonecoll_free(BoneCollection *bcoll, const bool do_id_user_count)
static void add_reverse_pointers(BoneCollection *bcoll)
{
LISTBASE_FOREACH (BoneCollectionMember *, member, &bcoll->bones) {
BoneCollectionReference *ref = MEM_cnew<BoneCollectionReference>(__func__);
BoneCollectionReference *ref = MEM_callocN<BoneCollectionReference>(__func__);
ref->bcoll = bcoll;
BLI_addtail(&member->bone->runtime.collections, ref);
}
@ -866,14 +866,14 @@ void ANIM_armature_bonecoll_is_expanded_set(BoneCollection *bcoll, bool is_expan
/* Store the bone's membership on the collection. */
static void add_membership(BoneCollection *bcoll, Bone *bone)
{
BoneCollectionMember *member = MEM_cnew<BoneCollectionMember>(__func__);
BoneCollectionMember *member = MEM_callocN<BoneCollectionMember>(__func__);
member->bone = bone;
BLI_addtail(&bcoll->bones, member);
}
/* Store reverse membership on the bone. */
static void add_reference(Bone *bone, BoneCollection *bcoll)
{
BoneCollectionReference *ref = MEM_cnew<BoneCollectionReference>(__func__);
BoneCollectionReference *ref = MEM_callocN<BoneCollectionReference>(__func__);
ref->bcoll = bcoll;
BLI_addtail(&bone->runtime.collections, ref);
}
@ -905,7 +905,7 @@ bool ANIM_armature_bonecoll_assign_editbone(BoneCollection *bcoll, EditBone *ebo
/* Store membership on the edit bone. Bones will be rebuilt when the armature
* goes out of edit mode, and by then the newly created bones will be added to
* the actual collection on the Armature. */
BoneCollectionReference *ref = MEM_cnew<BoneCollectionReference>(__func__);
BoneCollectionReference *ref = MEM_callocN<BoneCollectionReference>(__func__);
ref->bcoll = bcoll;
BLI_addtail(&ebone->bone_collections, ref);

View file

@ -115,9 +115,9 @@ void convert_legacy_animato_action(bAction &dna_action)
Channelbag &bag = strip.data<StripKeyframeData>(action).channelbag_for_slot_ensure(slot);
const int fcu_count = BLI_listbase_count(&action.curves);
const int group_count = BLI_listbase_count(&action.groups);
bag.fcurve_array = MEM_cnew_array<FCurve *>(fcu_count, "Action versioning - fcurves");
bag.fcurve_array = MEM_calloc_arrayN<FCurve *>(fcu_count, "Action versioning - fcurves");
bag.fcurve_array_num = fcu_count;
bag.group_array = MEM_cnew_array<bActionGroup *>(group_count, "Action versioning - groups");
bag.group_array = MEM_calloc_arrayN<bActionGroup *>(group_count, "Action versioning - groups");
bag.group_array_num = group_count;
int group_index = 0;

View file

@ -176,13 +176,13 @@ static void action_copy_data(Main * /*bmain*/,
action_dst.last_slot_handle = action_src.last_slot_handle;
/* Layers, and (recursively) Strips. */
action_dst.layer_array = MEM_cnew_array<ActionLayer *>(action_src.layer_array_num, __func__);
action_dst.layer_array = MEM_calloc_arrayN<ActionLayer *>(action_src.layer_array_num, __func__);
for (int i : action_src.layers().index_range()) {
action_dst.layer_array[i] = action_src.layer(i)->duplicate_with_shallow_strip_copies(__func__);
}
/* Strip data. */
action_dst.strip_keyframe_data_array = MEM_cnew_array<ActionStripKeyframeData *>(
action_dst.strip_keyframe_data_array = MEM_calloc_arrayN<ActionStripKeyframeData *>(
action_src.strip_keyframe_data_array_num, __func__);
for (int i : action_src.strip_keyframe_data().index_range()) {
action_dst.strip_keyframe_data_array[i] = MEM_new<animrig::StripKeyframeData>(
@ -190,7 +190,7 @@ static void action_copy_data(Main * /*bmain*/,
}
/* Slots. */
action_dst.slot_array = MEM_cnew_array<ActionSlot *>(action_src.slot_array_num, __func__);
action_dst.slot_array = MEM_calloc_arrayN<ActionSlot *>(action_src.slot_array_num, __func__);
for (int i : action_src.slots().index_range()) {
action_dst.slot_array[i] = MEM_new<animrig::Slot>(__func__, *action_src.slot(i));
}

View file

@ -137,7 +137,7 @@ ListBase BKE_asset_catalog_path_list_duplicate(const ListBase &catalog_path_list
ListBase duplicated_list = {nullptr};
LISTBASE_FOREACH (AssetCatalogPathLink *, catalog_path, &catalog_path_list) {
AssetCatalogPathLink *copied_path = MEM_cnew<AssetCatalogPathLink>(__func__);
AssetCatalogPathLink *copied_path = MEM_callocN<AssetCatalogPathLink>(__func__);
copied_path->path = BLI_strdup(catalog_path->path);
BLI_addtail(&duplicated_list, copied_path);
@ -173,7 +173,7 @@ bool BKE_asset_catalog_path_list_has_path(const ListBase &catalog_path_list,
void BKE_asset_catalog_path_list_add_path(ListBase &catalog_path_list, const char *catalog_path)
{
AssetCatalogPathLink *new_path = MEM_cnew<AssetCatalogPathLink>(__func__);
AssetCatalogPathLink *new_path = MEM_callocN<AssetCatalogPathLink>(__func__);
new_path->path = BLI_strdup(catalog_path);
BLI_addtail(&catalog_path_list, new_path);
}

View file

@ -60,14 +60,14 @@ NodesModifierPackedBake *pack_bake_from_disk(const BakePath &bake_path, ReportLi
const Vector<NodesModifierBakeFile> blob_bake_files = pack_files_from_directory(
bake_path.blobs_dir, reports);
NodesModifierPackedBake *packed_bake = MEM_cnew<NodesModifierPackedBake>(__func__);
NodesModifierPackedBake *packed_bake = MEM_callocN<NodesModifierPackedBake>(__func__);
packed_bake->meta_files_num = meta_bake_files.size();
packed_bake->blob_files_num = blob_bake_files.size();
packed_bake->meta_files = MEM_cnew_array<NodesModifierBakeFile>(packed_bake->meta_files_num,
__func__);
packed_bake->blob_files = MEM_cnew_array<NodesModifierBakeFile>(packed_bake->blob_files_num,
__func__);
packed_bake->meta_files = MEM_calloc_arrayN<NodesModifierBakeFile>(packed_bake->meta_files_num,
__func__);
packed_bake->blob_files = MEM_calloc_arrayN<NodesModifierBakeFile>(packed_bake->blob_files_num,
__func__);
uninitialized_copy_n(meta_bake_files.data(), meta_bake_files.size(), packed_bake->meta_files);
uninitialized_copy_n(blob_bake_files.data(), blob_bake_files.size(), packed_bake->blob_files);

View file

@ -111,7 +111,7 @@ static void restore_materials(Material ***materials,
}
BLI_assert(*materials == nullptr);
*materials_num = materials_list->size();
*materials = MEM_cnew_array<Material *>(materials_list->size(), __func__);
*materials = MEM_calloc_arrayN<Material *>(materials_list->size(), __func__);
if (!data_block_map) {
return;
}

View file

@ -865,7 +865,7 @@ static Mesh *try_load_mesh(const DictionaryValue &io_geometry,
if (value->type() != io::serialize::eValueType::String) {
return cancel();
}
bDeformGroup *defgroup = MEM_cnew<bDeformGroup>(__func__);
bDeformGroup *defgroup = MEM_callocN<bDeformGroup>(__func__);
STRNCPY(defgroup->name, value->as_string_value()->value().c_str());
BLI_addtail(&mesh->vertex_group_names, defgroup);
}

View file

@ -98,7 +98,7 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu,
MemFileUndoData *BKE_memfile_undo_encode(Main *bmain, MemFileUndoData *mfu_prev)
{
MemFileUndoData *mfu = MEM_cnew<MemFileUndoData>(__func__);
MemFileUndoData *mfu = MEM_callocN<MemFileUndoData>(__func__);
/* This flag used to be set because the undo step was written as #BLENDER_QUIT_FILE. It's not
* clear whether there are still good reasons to keep it. Undo can also be thought of as a kind

View file

@ -1576,7 +1576,7 @@ UserDef *BKE_blendfile_userdef_from_defaults()
bool BKE_blendfile_userdef_write(const char *filepath, ReportList *reports)
{
Main *mainb = MEM_cnew<Main>("empty main");
Main *mainb = MEM_callocN<Main>("empty main");
bool ok = false;
BlendFileWriteParams params{};
@ -1707,7 +1707,7 @@ WorkspaceConfigFileData *BKE_blendfile_workspace_config_read(const char *filepat
}
if (bfd) {
workspace_config = MEM_cnew<WorkspaceConfigFileData>(__func__);
workspace_config = MEM_callocN<WorkspaceConfigFileData>(__func__);
workspace_config->main = bfd->main;
/* Only 2.80+ files have actual workspaces, don't try to use screens

View file

@ -84,8 +84,8 @@ static void brush_copy_data(Main * /*bmain*/,
brush_dst->automasking_cavity_curve = BKE_curvemapping_copy(brush_src->automasking_cavity_curve);
if (brush_src->gpencil_settings != nullptr) {
brush_dst->gpencil_settings = MEM_cnew<BrushGpencilSettings>(__func__,
*(brush_src->gpencil_settings));
brush_dst->gpencil_settings = MEM_dupallocN<BrushGpencilSettings>(
__func__, *(brush_src->gpencil_settings));
brush_dst->gpencil_settings->curve_sensitivity = BKE_curvemapping_copy(
brush_src->gpencil_settings->curve_sensitivity);
brush_dst->gpencil_settings->curve_strength = BKE_curvemapping_copy(
@ -107,7 +107,7 @@ static void brush_copy_data(Main * /*bmain*/,
brush_src->gpencil_settings->curve_rand_value);
}
if (brush_src->curves_sculpt_settings != nullptr) {
brush_dst->curves_sculpt_settings = MEM_cnew<BrushCurvesSculptSettings>(
brush_dst->curves_sculpt_settings = MEM_dupallocN<BrushCurvesSculptSettings>(
__func__, *(brush_src->curves_sculpt_settings));
brush_dst->curves_sculpt_settings->curve_parameter_falloff = BKE_curvemapping_copy(
brush_src->curves_sculpt_settings->curve_parameter_falloff);
@ -548,7 +548,7 @@ Brush *BKE_brush_add(Main *bmain, const char *name, const eObjectMode ob_mode)
void BKE_brush_init_gpencil_settings(Brush *brush)
{
if (brush->gpencil_settings == nullptr) {
brush->gpencil_settings = MEM_cnew<BrushGpencilSettings>("BrushGpencilSettings");
brush->gpencil_settings = MEM_callocN<BrushGpencilSettings>("BrushGpencilSettings");
}
brush->gpencil_settings->draw_smoothlvl = 1;
@ -590,7 +590,7 @@ bool BKE_brush_delete(Main *bmain, Brush *brush)
void BKE_brush_init_curves_sculpt_settings(Brush *brush)
{
if (brush->curves_sculpt_settings == nullptr) {
brush->curves_sculpt_settings = MEM_cnew<BrushCurvesSculptSettings>(__func__);
brush->curves_sculpt_settings = MEM_callocN<BrushCurvesSculptSettings>(__func__);
}
BrushCurvesSculptSettings *settings = brush->curves_sculpt_settings;
settings->flag = BRUSH_CURVES_SCULPT_FLAG_INTERPOLATE_RADIUS;
@ -1468,7 +1468,7 @@ static bool brush_gen_texture(const Brush *br,
ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br, bool secondary, bool display_gradient)
{
ImBuf *im = MEM_cnew<ImBuf>("radial control texture");
ImBuf *im = MEM_callocN<ImBuf>("radial control texture");
int side = 512;
int half = side / 2;

View file

@ -832,7 +832,8 @@ static void cloth_from_mesh(ClothModifierData *clmd, const Object *ob, Mesh *mes
/* Allocate our vertices. */
clmd->clothObject->mvert_num = mvert_num;
clmd->clothObject->verts = MEM_cnew_array<ClothVertex>(clmd->clothObject->mvert_num, __func__);
clmd->clothObject->verts = MEM_calloc_arrayN<ClothVertex>(clmd->clothObject->mvert_num,
__func__);
if (clmd->clothObject->verts == nullptr) {
cloth_free_modifier(clmd);
BKE_modifier_set_error(ob, &(clmd->modifier), "Out of memory on allocating vertices");

View file

@ -1453,7 +1453,7 @@ static bool collection_object_remove(
static void collection_exporter_copy(Collection *collection, CollectionExport *data)
{
CollectionExport *new_data = MEM_cnew<CollectionExport>("CollectionExport");
CollectionExport *new_data = MEM_callocN<CollectionExport>("CollectionExport");
STRNCPY(new_data->fh_idname, data->fh_idname);
new_data->export_properties = IDP_CopyProperty(data->export_properties);
new_data->flag = data->flag;

View file

@ -1230,7 +1230,7 @@ static void add_collision_object(ListBase *relations,
ModifierData *cmd = BKE_modifiers_findby_type(ob, modifier_type);
if (cmd) {
CollisionRelation *relation = MEM_cnew<CollisionRelation>(__func__);
CollisionRelation *relation = MEM_callocN<CollisionRelation>(__func__);
relation->ob = ob;
BLI_addtail(relations, relation);
}
@ -1259,7 +1259,7 @@ ListBase *BKE_collision_relations_create(Depsgraph *depsgraph,
const bool for_render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
const int base_flag = (for_render) ? BASE_ENABLED_RENDER : BASE_ENABLED_VIEWPORT;
ListBase *relations = MEM_cnew<ListBase>(__func__);
ListBase *relations = MEM_callocN<ListBase>(__func__);
for (; base; base = base->next) {
if (base->flag & base_flag) {
@ -1293,7 +1293,7 @@ Object **BKE_collision_objects_create(Depsgraph *depsgraph,
int maxnum = BLI_listbase_count(relations);
int num = 0;
Object **objects = MEM_cnew_array<Object *>(maxnum, __func__);
Object **objects = MEM_calloc_arrayN<Object *>(maxnum, __func__);
LISTBASE_FOREACH (CollisionRelation *, relation, relations) {
/* Get evaluated object. */
@ -1347,10 +1347,10 @@ ListBase *BKE_collider_cache_create(Depsgraph *depsgraph, Object *self, Collecti
ob, eModifierType_Collision);
if (cmd && cmd->bvhtree) {
if (cache == nullptr) {
cache = MEM_cnew<ListBase>(__func__);
cache = MEM_callocN<ListBase>(__func__);
}
ColliderCache *col = MEM_cnew<ColliderCache>(__func__);
ColliderCache *col = MEM_callocN<ColliderCache>(__func__);
col->ob = ob;
col->collmd = cmd;
/* make sure collider is properly set up */
@ -1577,8 +1577,8 @@ int cloth_bvh_collision(
eModifierType_Collision);
if (collobjs) {
coll_counts_obj = MEM_cnew_array<uint>(numcollobj, "CollCounts");
overlap_obj = MEM_cnew_array<BVHTreeOverlap *>(numcollobj, "BVHOverlap");
coll_counts_obj = MEM_calloc_arrayN<uint>(numcollobj, "CollCounts");
overlap_obj = MEM_calloc_arrayN<BVHTreeOverlap *>(numcollobj, "BVHOverlap");
for (i = 0; i < numcollobj; i++) {
Object *collob = collobjs[i];
@ -1618,7 +1618,7 @@ int cloth_bvh_collision(
CollPair **collisions;
bool collided = false;
collisions = MEM_cnew_array<CollPair *>(numcollobj, "CollPair");
collisions = MEM_calloc_arrayN<CollPair *>(numcollobj, "CollPair");
for (i = 0; i < numcollobj; i++) {
Object *collob = collobjs[i];

View file

@ -103,14 +103,14 @@ struct bContext {
bContext *CTX_create()
{
bContext *C = MEM_cnew<bContext>(__func__);
bContext *C = MEM_callocN<bContext>(__func__);
return C;
}
bContext *CTX_copy(const bContext *C)
{
bContext *newC = MEM_cnew<bContext>(__func__);
bContext *newC = MEM_callocN<bContext>(__func__);
*newC = *C;
memset(&newC->wm.operator_poll_msg_dyn_params, 0, sizeof(newC->wm.operator_poll_msg_dyn_params));
@ -609,7 +609,7 @@ static void data_dir_add(ListBase *lb, const char *member, const bool use_all)
return;
}
link = MEM_cnew<LinkData>(__func__);
link = MEM_callocN<LinkData>(__func__);
link->data = (void *)member;
BLI_addtail(lb, link);
}

View file

@ -309,13 +309,13 @@ void BKE_cryptomatte_matte_id_to_entries(NodeCryptomatte *node_storage, const ch
token = token.substr(first, (last - first + 1));
if (*token.begin() == '<' && *(--token.end()) == '>') {
float encoded_hash = atof(token.substr(1, token.length() - 2).c_str());
entry = MEM_cnew<CryptomatteEntry>(__func__);
entry = MEM_callocN<CryptomatteEntry>(__func__);
entry->encoded_hash = encoded_hash;
}
else {
const char *name = token.c_str();
int name_len = token.length();
entry = MEM_cnew<CryptomatteEntry>(__func__);
entry = MEM_callocN<CryptomatteEntry>(__func__);
STRNCPY(entry->name, name);
uint32_t hash = BKE_cryptomatte_hash(name, name_len);
entry->encoded_hash = BKE_cryptomatte_hash_to_float(hash);

View file

@ -2609,7 +2609,7 @@ void BKE_curve_bevelList_make(Object *ob, const ListBase *nurbs, const bool for_
if (nu->type == CU_POLY) {
len = nu->pntsu;
BevList *bl = MEM_cnew<BevList>(__func__);
BevList *bl = MEM_callocN<BevList>(__func__);
bl->bevpoints = (BevPoint *)MEM_calloc_arrayN(len, sizeof(BevPoint), __func__);
if (need_seglen && (nu->flagu & CU_NURB_CYCLIC) == 0) {
bl->seglen = (float *)MEM_malloc_arrayN(segcount, sizeof(float), __func__);
@ -2659,7 +2659,7 @@ void BKE_curve_bevelList_make(Object *ob, const ListBase *nurbs, const bool for_
/* in case last point is not cyclic */
len = segcount * resolu + 1;
BevList *bl = MEM_cnew<BevList>(__func__);
BevList *bl = MEM_callocN<BevList>(__func__);
bl->bevpoints = (BevPoint *)MEM_calloc_arrayN(len, sizeof(BevPoint), __func__);
if (need_seglen && (nu->flagu & CU_NURB_CYCLIC) == 0) {
bl->seglen = (float *)MEM_malloc_arrayN(segcount, sizeof(float), __func__);
@ -2795,7 +2795,7 @@ void BKE_curve_bevelList_make(Object *ob, const ListBase *nurbs, const bool for_
if (nu->pntsv == 1) {
len = (resolu * segcount);
BevList *bl = MEM_cnew<BevList>(__func__);
BevList *bl = MEM_callocN<BevList>(__func__);
bl->bevpoints = (BevPoint *)MEM_calloc_arrayN(len, sizeof(BevPoint), __func__);
if (need_seglen && (nu->flagu & CU_NURB_CYCLIC) == 0) {
bl->seglen = (float *)MEM_malloc_arrayN(segcount, sizeof(float), __func__);

View file

@ -32,7 +32,7 @@
CurveProfile *BKE_curveprofile_add(eCurveProfilePresets preset)
{
CurveProfile *profile = MEM_cnew<CurveProfile>(__func__);
CurveProfile *profile = MEM_callocN<CurveProfile>(__func__);
BKE_curveprofile_set_defaults(profile);
profile->preset = preset;

View file

@ -4816,7 +4816,7 @@ void CustomData_external_add(CustomData *data,
}
if (!external) {
external = MEM_cnew<CustomDataExternal>(__func__);
external = MEM_callocN<CustomDataExternal>(__func__);
data->external = external;
}
STRNCPY(external->filepath, filepath);

View file

@ -468,7 +468,7 @@ void data_transfer_layersmapping_add_item(ListBase *r_map,
cd_datatransfer_interp interp,
void *interp_data)
{
CustomDataTransferLayerMap *item = MEM_cnew<CustomDataTransferLayerMap>(__func__);
CustomDataTransferLayerMap *item = MEM_callocN<CustomDataTransferLayerMap>(__func__);
BLI_assert(data_dst != nullptr);

View file

@ -49,7 +49,7 @@ bDeformGroup *BKE_object_defgroup_new(Object *ob, const StringRef name)
BLI_assert(OB_TYPE_SUPPORT_VGROUP(ob->type));
defgroup = MEM_cnew<bDeformGroup>(__func__);
defgroup = MEM_callocN<bDeformGroup>(__func__);
name.copy_utf8_truncated(defgroup->name);
@ -84,7 +84,7 @@ bDeformGroup *BKE_defgroup_duplicate(const bDeformGroup *ingroup)
return nullptr;
}
bDeformGroup *outgroup = MEM_cnew<bDeformGroup>(__func__);
bDeformGroup *outgroup = MEM_callocN<bDeformGroup>(__func__);
/* For now, just copy everything over. */
memcpy(outgroup, ingroup, sizeof(bDeformGroup));

View file

@ -165,7 +165,7 @@ static void curve_to_displist(const Curve *cu,
* and resolution > 1. */
const bool use_cyclic_sample = is_cyclic && (samples_len != 2);
DispList *dl = MEM_cnew<DispList>(__func__);
DispList *dl = MEM_callocN<DispList>(__func__);
/* Add one to the length because of 'BKE_curve_forward_diff_bezier'. */
dl->verts = (float *)MEM_mallocN(sizeof(float[3]) * (samples_len + 1), __func__);
BLI_addtail(r_dispbase, dl);
@ -220,7 +220,7 @@ static void curve_to_displist(const Curve *cu,
}
else if (nu->type == CU_NURBS) {
const int len = (resolution * SEGMENTSU(nu));
DispList *dl = MEM_cnew<DispList>(__func__);
DispList *dl = MEM_callocN<DispList>(__func__);
dl->verts = (float *)MEM_mallocN(len * sizeof(float[3]), __func__);
BLI_addtail(r_dispbase, dl);
dl->parts = 1;
@ -233,7 +233,7 @@ static void curve_to_displist(const Curve *cu,
}
else if (nu->type == CU_POLY) {
const int len = nu->pntsu;
DispList *dl = MEM_cnew<DispList>(__func__);
DispList *dl = MEM_callocN<DispList>(__func__);
dl->verts = (float *)MEM_mallocN(len * sizeof(float[3]), __func__);
BLI_addtail(r_dispbase, dl);
dl->parts = 1;
@ -324,7 +324,7 @@ void BKE_displist_fill(const ListBase *dispbase,
const int triangles_len = BLI_scanfill_calc_ex(&sf_ctx, scanfill_flag, normal_proj);
if (totvert != 0 && triangles_len != 0) {
DispList *dlnew = MEM_cnew<DispList>(__func__);
DispList *dlnew = MEM_callocN<DispList>(__func__);
dlnew->type = DL_INDEX3;
dlnew->flag = (dl_flag_accum & (DL_BACK_CURVE | DL_FRONT_CURVE));
dlnew->rt = (dl_rt_accum & CU_SMOOTH);
@ -379,7 +379,7 @@ static void bevels_to_filledpoly(const Curve *cu, ListBase *dispbase)
if (dl->type == DL_SURF) {
if ((dl->flag & DL_CYCL_V) && (dl->flag & DL_CYCL_U) == 0) {
if ((cu->flag & CU_BACK) && (dl->flag & DL_BACK_CURVE)) {
DispList *dlnew = MEM_cnew<DispList>(__func__);
DispList *dlnew = MEM_callocN<DispList>(__func__);
BLI_addtail(&front, dlnew);
dlnew->verts = (float *)MEM_mallocN(sizeof(float[3]) * dl->parts, __func__);
dlnew->nr = dl->parts;
@ -398,7 +398,7 @@ static void bevels_to_filledpoly(const Curve *cu, ListBase *dispbase)
}
}
if ((cu->flag & CU_FRONT) && (dl->flag & DL_FRONT_CURVE)) {
DispList *dlnew = MEM_cnew<DispList>(__func__);
DispList *dlnew = MEM_callocN<DispList>(__func__);
BLI_addtail(&back, dlnew);
dlnew->verts = (float *)MEM_mallocN(sizeof(float[3]) * dl->parts, __func__);
dlnew->nr = dl->parts;
@ -820,7 +820,7 @@ static blender::bke::GeometrySet evaluate_surface_object(Depsgraph *depsgraph,
if (nu->pntsv == 1) {
const int len = SEGMENTSU(nu) * resolu;
DispList *dl = MEM_cnew<DispList>(__func__);
DispList *dl = MEM_callocN<DispList>(__func__);
dl->verts = (float *)MEM_mallocN(len * sizeof(float[3]), __func__);
BLI_addtail(r_dispbase, dl);
@ -843,7 +843,7 @@ static blender::bke::GeometrySet evaluate_surface_object(Depsgraph *depsgraph,
else {
const int len = (nu->pntsu * resolu) * (nu->pntsv * resolv);
DispList *dl = MEM_cnew<DispList>(__func__);
DispList *dl = MEM_callocN<DispList>(__func__);
dl->verts = (float *)MEM_mallocN(len * sizeof(float[3]), __func__);
BLI_addtail(r_dispbase, dl);
@ -945,7 +945,7 @@ static void fillBevelCap(const Nurb *nu,
const float *prev_fp,
ListBase *dispbase)
{
DispList *dl = MEM_cnew<DispList>(__func__);
DispList *dl = MEM_callocN<DispList>(__func__);
dl->verts = (float *)MEM_mallocN(sizeof(float[3]) * dlb->nr, __func__);
memcpy(dl->verts, prev_fp, sizeof(float[3]) * dlb->nr);
@ -1147,7 +1147,7 @@ static blender::bke::GeometrySet evaluate_curve_type_object(Depsgraph *depsgraph
/* exception handling; curve without bevel or extrude, with width correction */
if (BLI_listbase_is_empty(&dlbev)) {
DispList *dl = MEM_cnew<DispList>("makeDispListbev");
DispList *dl = MEM_callocN<DispList>("makeDispListbev");
dl->verts = (float *)MEM_mallocN(sizeof(float[3]) * bl->nr, "dlverts");
BLI_addtail(r_dispbase, dl);
@ -1197,7 +1197,7 @@ static blender::bke::GeometrySet evaluate_curve_type_object(Depsgraph *depsgraph
LISTBASE_FOREACH (DispList *, dlb, &dlbev) {
/* For each part of the bevel use a separate display-block. */
DispList *dl = MEM_cnew<DispList>(__func__);
DispList *dl = MEM_callocN<DispList>(__func__);
dl->verts = data = (float *)MEM_mallocN(sizeof(float[3]) * dlb->nr * steps, __func__);
BLI_addtail(r_dispbase, dl);
@ -1323,7 +1323,7 @@ void BKE_displist_make_curveTypes(Depsgraph *depsgraph,
* which may reset the object data pointer in some cases. */
const Curve &original_curve = *static_cast<const Curve *>(ob->data);
ob->runtime->curve_cache = MEM_cnew<CurveCache>(__func__);
ob->runtime->curve_cache = MEM_callocN<CurveCache>(__func__);
ListBase *dispbase = &ob->runtime->curve_cache->disp;
if (ob->type == OB_SURF) {

View file

@ -742,7 +742,7 @@ static void surfaceGenerateGrid(DynamicPaintSurface *surface)
freeGrid(sData);
}
bData->grid = MEM_cnew<DynamicPaintVolumeGrid>(__func__);
bData->grid = MEM_callocN<DynamicPaintVolumeGrid>(__func__);
grid = bData->grid;
{
@ -1036,7 +1036,7 @@ void dynamicPaint_Modifier_free(DynamicPaintModifierData *pmd)
DynamicPaintSurface *dynamicPaint_createNewSurface(DynamicPaintCanvasSettings *canvas,
Scene *scene)
{
DynamicPaintSurface *surface = MEM_cnew<DynamicPaintSurface>(__func__);
DynamicPaintSurface *surface = MEM_callocN<DynamicPaintSurface>(__func__);
if (!surface) {
return nullptr;
}
@ -1119,7 +1119,7 @@ bool dynamicPaint_createType(DynamicPaintModifierData *pmd, int type, Scene *sce
dynamicPaint_freeCanvas(pmd);
}
canvas = pmd->canvas = MEM_cnew<DynamicPaintCanvasSettings>(__func__);
canvas = pmd->canvas = MEM_callocN<DynamicPaintCanvasSettings>(__func__);
if (!canvas) {
return false;
}
@ -1136,7 +1136,7 @@ bool dynamicPaint_createType(DynamicPaintModifierData *pmd, int type, Scene *sce
dynamicPaint_freeBrush(pmd);
}
brush = pmd->brush = MEM_cnew<DynamicPaintBrushSettings>(__func__);
brush = pmd->brush = MEM_callocN<DynamicPaintBrushSettings>(__func__);
if (!brush) {
return false;
}
@ -1402,7 +1402,7 @@ static void dynamicPaint_initAdjacencyData(DynamicPaintSurface *surface, const b
}
/* allocate memory */
ad = sData->adj_data = MEM_cnew<PaintAdjData>(__func__);
ad = sData->adj_data = MEM_callocN<PaintAdjData>(__func__);
if (!ad) {
return;
}
@ -1765,7 +1765,7 @@ bool dynamicPaint_resetSurface(const Scene *scene, DynamicPaintSurface *surface)
}
/* allocate memory */
surface->data = MEM_cnew<PaintSurfaceData>(__func__);
surface->data = MEM_callocN<PaintSurfaceData>(__func__);
if (!surface->data) {
return false;
}
@ -2879,7 +2879,7 @@ int dynamicPaint_createUVSurface(Scene *scene,
if (surface->data) {
dynamicPaint_freeSurfaceData(surface);
}
sData = surface->data = MEM_cnew<PaintSurfaceData>(__func__);
sData = surface->data = MEM_callocN<PaintSurfaceData>(__func__);
if (!surface->data) {
return setError(canvas, N_("Not enough free memory"));
}
@ -3106,7 +3106,7 @@ int dynamicPaint_createUVSurface(Scene *scene,
*do_update = true;
/* Create final surface data without inactive points */
ImgSeqFormatData *f_data = MEM_cnew<ImgSeqFormatData>(__func__);
ImgSeqFormatData *f_data = MEM_callocN<ImgSeqFormatData>(__func__);
if (f_data) {
f_data->uv_p = static_cast<PaintUVPoint *>(
MEM_callocN(active_points * sizeof(*f_data->uv_p), "PaintUVPoint"));

View file

@ -4420,7 +4420,7 @@ void BKE_fluid_particle_system_create(Main *bmain,
/* add particle system */
part = BKE_particlesettings_add(bmain, pset_name);
psys = MEM_cnew<ParticleSystem>(__func__);
psys = MEM_callocN<ParticleSystem>(__func__);
part->type = psys_type;
part->totpart = 0;

View file

@ -1432,8 +1432,8 @@ void Layer::prepare_for_dna_write()
const size_t frames_num = size_t(frames().size());
frames_storage.num = int(frames_num);
frames_storage.keys = MEM_cnew_array<int>(frames_num, __func__);
frames_storage.values = MEM_cnew_array<GreasePencilFrame>(frames_num, __func__);
frames_storage.keys = MEM_calloc_arrayN<int>(frames_num, __func__);
frames_storage.values = MEM_calloc_arrayN<GreasePencilFrame>(frames_num, __func__);
const Span<int> sorted_keys_data = sorted_keys();
for (const int64_t i : sorted_keys_data.index_range()) {
frames_storage.keys[i] = sorted_keys_data[i];
@ -2300,7 +2300,7 @@ void BKE_grease_pencil_duplicate_drawing_array(const GreasePencil *grease_pencil
using namespace blender;
grease_pencil_dst->drawing_array_num = grease_pencil_src->drawing_array_num;
if (grease_pencil_dst->drawing_array_num > 0) {
grease_pencil_dst->drawing_array = MEM_cnew_array<GreasePencilDrawingBase *>(
grease_pencil_dst->drawing_array = MEM_calloc_arrayN<GreasePencilDrawingBase *>(
grease_pencil_src->drawing_array_num, __func__);
bke::greasepencil::copy_drawing_array(grease_pencil_src->drawings(),
grease_pencil_dst->drawings());
@ -2697,7 +2697,7 @@ template<typename T> static void grow_array(T **array, int *num, const int add_n
{
BLI_assert(add_num > 0);
const int new_array_num = *num + add_num;
T *new_array = MEM_cnew_array<T>(new_array_num, __func__);
T *new_array = MEM_calloc_arrayN<T>(new_array_num, __func__);
blender::uninitialized_relocate_n(*array, *num, new_array);
if (*array != nullptr) {
@ -2718,7 +2718,7 @@ template<typename T> static void shrink_array(T **array, int *num, const int shr
return;
}
T *new_array = MEM_cnew_array<T>(new_array_num, __func__);
T *new_array = MEM_calloc_arrayN<T>(new_array_num, __func__);
blender::uninitialized_move_n(*array, new_array_num, new_array);
MEM_freeN(*array);

View file

@ -1191,7 +1191,7 @@ static bNodeTree *offset_radius_node_tree_add(ConversionData &conversion_data, L
&conversion_data.bmain, library, OFFSET_RADIUS_NODETREE_NAME, "GeometryNodeTree");
if (!group->geometry_node_asset_traits) {
group->geometry_node_asset_traits = MEM_cnew<GeometryNodeAssetTraits>(__func__);
group->geometry_node_asset_traits = MEM_callocN<GeometryNodeAssetTraits>(__func__);
}
group->geometry_node_asset_traits->flag |= GEO_NODE_ASSET_MODIFIER;
@ -1769,7 +1769,7 @@ static void legacy_object_modifier_dash(ConversionData &conversion_data,
md_dash.segment_active_index = legacy_md_dash.segment_active_index;
md_dash.segments_num = legacy_md_dash.segments_len;
MEM_SAFE_FREE(md_dash.segments_array);
md_dash.segments_array = MEM_cnew_array<GreasePencilDashModifierSegment>(
md_dash.segments_array = MEM_calloc_arrayN<GreasePencilDashModifierSegment>(
legacy_md_dash.segments_len, __func__);
for (const int i : IndexRange(md_dash.segments_num)) {
GreasePencilDashModifierSegment &dst_segment = md_dash.segments_array[i];
@ -2481,7 +2481,7 @@ static void legacy_object_modifier_time(ConversionData &conversion_data,
md_time.segment_active_index = legacy_md_time.segment_active_index;
md_time.segments_num = legacy_md_time.segments_len;
MEM_SAFE_FREE(md_time.segments_array);
md_time.segments_array = MEM_cnew_array<GreasePencilTimeModifierSegment>(
md_time.segments_array = MEM_calloc_arrayN<GreasePencilTimeModifierSegment>(
legacy_md_time.segments_len, __func__);
for (const int i : IndexRange(md_time.segments_num)) {
GreasePencilTimeModifierSegment &dst_segment = md_time.segments_array[i];

View file

@ -56,7 +56,7 @@ int ensure_vertex_group(const StringRef name, ListBase &vertex_group_names)
{
int def_nr = BKE_defgroup_name_index(&vertex_group_names, name);
if (def_nr < 0) {
bDeformGroup *defgroup = MEM_cnew<bDeformGroup>(__func__);
bDeformGroup *defgroup = MEM_callocN<bDeformGroup>(__func__);
name.copy_utf8_truncated(defgroup->name);
BLI_addtail(&vertex_group_names, defgroup);
def_nr = BLI_listbase_count(&vertex_group_names) - 1;
@ -80,7 +80,7 @@ void assign_to_vertex_group_from_mask(bke::CurvesGeometry &curves,
/* Lazily add the vertex group if any vertex is selected. */
if (def_nr < 0) {
bDeformGroup *defgroup = MEM_cnew<bDeformGroup>(__func__);
bDeformGroup *defgroup = MEM_callocN<bDeformGroup>(__func__);
name.copy_utf8_truncated(defgroup->name);
BLI_addtail(&vertex_group_names, defgroup);
def_nr = BLI_listbase_count(&vertex_group_names) - 1;
@ -113,7 +113,7 @@ void assign_to_vertex_group(Drawing &drawing, const StringRef name, const float
if (selection[i]) {
/* Lazily add the vertex group if any vertex is selected. */
if (def_nr < 0) {
bDeformGroup *defgroup = MEM_cnew<bDeformGroup>(__func__);
bDeformGroup *defgroup = MEM_callocN<bDeformGroup>(__func__);
name.copy_utf8_truncated(defgroup->name);
BLI_addtail(&vertex_group_names, defgroup);

View file

@ -671,7 +671,7 @@ void BKE_image_free_data(Image *ima)
static ImageTile *imagetile_alloc(int tile_number)
{
ImageTile *tile = MEM_cnew<ImageTile>("Image Tile");
ImageTile *tile = MEM_callocN<ImageTile>("Image Tile");
tile->tile_number = tile_number;
tile->gen_x = 1024;
tile->gen_y = 1024;
@ -705,7 +705,7 @@ static void image_init(Image *ima, short source, short type)
image_runtime_reset(ima);
BKE_color_managed_colorspace_settings_init(&ima->colorspace_settings);
ima->stereo3d_format = MEM_cnew<Stereo3dFormat>("Image Stereo Format");
ima->stereo3d_format = MEM_callocN<Stereo3dFormat>("Image Stereo Format");
}
static Image *image_alloc(Main *bmain,
@ -2438,7 +2438,7 @@ void BKE_render_result_stamp_info(Scene *scene,
}
if (!rr->stamp_data) {
stamp_data = MEM_cnew<StampData>("RenderResult.stamp_data");
stamp_data = MEM_callocN<StampData>("RenderResult.stamp_data");
}
else {
stamp_data = rr->stamp_data;
@ -2463,7 +2463,7 @@ StampData *BKE_stamp_info_from_scene_static(const Scene *scene)
/* Memory is allocated here (instead of by the caller) so that the caller
* doesn't have to know the size of the StampData struct. */
stamp_data = MEM_cnew<StampData>(__func__);
stamp_data = MEM_callocN<StampData>(__func__);
stampdata(scene, nullptr, stamp_data, 0, false);
return stamp_data;
@ -2561,7 +2561,7 @@ void BKE_render_result_stamp_data(RenderResult *rr, const char *key, const char
{
StampData *stamp_data;
if (rr->stamp_data == nullptr) {
rr->stamp_data = MEM_cnew<StampData>("RenderResult.stamp_data");
rr->stamp_data = MEM_callocN<StampData>("RenderResult.stamp_data");
}
stamp_data = rr->stamp_data;
StampDataCustomField *field = static_cast<StampDataCustomField *>(
@ -2639,7 +2639,7 @@ static void metadata_copy_custom_fields(const char *field, const char *value, vo
void BKE_stamp_info_from_imbuf(RenderResult *rr, ImBuf *ibuf)
{
if (rr->stamp_data == nullptr) {
rr->stamp_data = MEM_cnew<StampData>("RenderResult.stamp_data");
rr->stamp_data = MEM_callocN<StampData>("RenderResult.stamp_data");
}
StampData *stamp_data = rr->stamp_data;
IMB_metadata_ensure(&ibuf->metadata);
@ -3909,7 +3909,7 @@ static void image_init_multilayer_multiview(Image *ima, RenderResult *rr)
if (rr) {
LISTBASE_FOREACH (RenderView *, rv, &rr->views) {
ImageView *iv = MEM_cnew<ImageView>("Viewer Image View");
ImageView *iv = MEM_callocN<ImageView>("Viewer Image View");
STRNCPY(iv->name, rv->name);
BLI_addtail(&ima->views, iv);
}
@ -4234,7 +4234,7 @@ static ImBuf *image_load_movie_file(Image *ima, ImageUser *iuser, int frame)
for (int i = 0; i < tot_viewfiles; i++) {
/* allocate the ImageAnim */
ImageAnim *ia = MEM_cnew<ImageAnim>("Image Anim");
ImageAnim *ia = MEM_callocN<ImageAnim>("Image Anim");
BLI_addtail(&ima->anims, ia);
}
}
@ -5038,7 +5038,7 @@ struct ImagePool {
ImagePool *BKE_image_pool_new()
{
ImagePool *pool = MEM_cnew<ImagePool>("Image Pool");
ImagePool *pool = MEM_callocN<ImagePool>("Image Pool");
pool->memory_pool = BLI_mempool_create(sizeof(ImagePoolItem), 0, 128, BLI_MEMPOOL_NOP);
BLI_mutex_init(&pool->mutex);
@ -5739,7 +5739,7 @@ static void image_update_views_format(Image *ima, ImageUser *iuser)
RenderSlot *BKE_image_add_renderslot(Image *ima, const char *name)
{
RenderSlot *slot = MEM_cnew<RenderSlot>("Image new Render Slot");
RenderSlot *slot = MEM_callocN<RenderSlot>("Image new Render Slot");
if (name && name[0]) {
STRNCPY(slot->name, name);
}

View file

@ -147,7 +147,7 @@ static GPUTexture *gpu_texture_create_tile_array(Image *ima, ImBuf *main_ibuf)
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, &iuser, nullptr);
if (ibuf) {
PackTile *packtile = MEM_cnew<PackTile>(__func__);
PackTile *packtile = MEM_callocN<PackTile>(__func__);
packtile->tile = tile;
packtile->boxpack.w = ibuf->x;
packtile->boxpack.h = ibuf->y;

View file

@ -1843,7 +1843,7 @@ KeyBlock *BKE_keyblock_add(Key *key, const char *name)
curpos = kb->pos;
}
kb = MEM_cnew<KeyBlock>("Keyblock");
kb = MEM_callocN<KeyBlock>("Keyblock");
BLI_addtail(&key->block, kb);
kb->type = KEY_LINEAR;

View file

@ -76,7 +76,7 @@ static void object_bases_iterator_next(BLI_Iterator *iter, const int flag);
static LayerCollection *layer_collection_add(ListBase *lb_parent, Collection *collection)
{
LayerCollection *lc = MEM_cnew<LayerCollection>("Collection Base");
LayerCollection *lc = MEM_callocN<LayerCollection>("Collection Base");
lc->collection = collection;
lc->local_collections_bits = ~(0);
BLI_addtail(lb_parent, lc);
@ -99,7 +99,7 @@ static void layer_collection_free(ViewLayer *view_layer, LayerCollection *lc)
static Base *object_base_new(Object *ob)
{
Base *base = MEM_cnew<Base>("Object Base");
Base *base = MEM_callocN<Base>("Object Base");
base->object = ob;
base->local_view_bits = ~(0);
if (ob->base_flag & BASE_SELECTED) {
@ -163,7 +163,7 @@ static ViewLayer *view_layer_add(const char *name)
name = DATA_("ViewLayer");
}
ViewLayer *view_layer = MEM_cnew<ViewLayer>("View Layer");
ViewLayer *view_layer = MEM_callocN<ViewLayer>("View Layer");
view_layer->flag = VIEW_LAYER_RENDER | VIEW_LAYER_FREESTYLE;
STRNCPY_UTF8(view_layer->name, name);
@ -210,7 +210,7 @@ ViewLayer *BKE_view_layer_add(Scene *scene,
}
case VIEWLAYER_ADD_COPY: {
/* Allocate and copy view layer data */
view_layer_new = MEM_cnew<ViewLayer>("View Layer");
view_layer_new = MEM_callocN<ViewLayer>("View Layer");
*view_layer_new = *view_layer_source;
BKE_view_layer_copy_data(scene, scene, view_layer_new, view_layer_source, 0);
BLI_addtail(&scene->view_layers, view_layer_new);
@ -2068,7 +2068,7 @@ static void object_bases_iterator_begin(BLI_Iterator *iter, void *data_in_v, con
return;
}
LayerObjectBaseIteratorData *data = MEM_cnew<LayerObjectBaseIteratorData>(__func__);
LayerObjectBaseIteratorData *data = MEM_callocN<LayerObjectBaseIteratorData>(__func__);
iter->data = data;
data->v3d = v3d;
@ -2530,7 +2530,7 @@ static void viewlayer_aov_active_set(ViewLayer *view_layer, ViewLayerAOV *aov)
ViewLayerAOV *BKE_view_layer_add_aov(ViewLayer *view_layer)
{
ViewLayerAOV *aov;
aov = MEM_cnew<ViewLayerAOV>(__func__);
aov = MEM_callocN<ViewLayerAOV>(__func__);
aov->type = AOV_TYPE_COLOR;
STRNCPY_UTF8(aov->name, DATA_("AOV"));
BLI_addtail(&view_layer->aovs, aov);
@ -2655,7 +2655,7 @@ static void viewlayer_lightgroup_active_set(ViewLayer *view_layer, ViewLayerLigh
ViewLayerLightgroup *BKE_view_layer_add_lightgroup(ViewLayer *view_layer, const char *name)
{
ViewLayerLightgroup *lightgroup;
lightgroup = MEM_cnew<ViewLayerLightgroup>(__func__);
lightgroup = MEM_callocN<ViewLayerLightgroup>(__func__);
STRNCPY_UTF8(lightgroup->name, (name && name[0]) ? name : DATA_("Lightgroup"));
BLI_addtail(&view_layer->lightgroups, lightgroup);
viewlayer_lightgroup_active_set(view_layer, lightgroup);
@ -2748,7 +2748,7 @@ void BKE_lightgroup_membership_set(LightgroupMembership **lgm, const char *name)
{
if (name[0] != '\0') {
if (*lgm == nullptr) {
*lgm = MEM_cnew<LightgroupMembership>(__func__);
*lgm = MEM_callocN<LightgroupMembership>(__func__);
}
BLI_strncpy((*lgm)->name, name, sizeof((*lgm)->name));
}

View file

@ -104,7 +104,7 @@ BLI_INLINE IDOverrideLibraryRuntime *override_library_runtime_ensure(
IDOverrideLibrary *liboverride)
{
if (liboverride->runtime == nullptr) {
liboverride->runtime = MEM_cnew<IDOverrideLibraryRuntime>(__func__);
liboverride->runtime = MEM_callocN<IDOverrideLibraryRuntime>(__func__);
}
return liboverride->runtime;
}
@ -168,7 +168,7 @@ IDOverrideLibrary *BKE_lib_override_library_init(ID *local_id, ID *reference_id)
BLI_assert(local_id->override_library == nullptr);
/* Else, generate new empty override. */
local_id->override_library = MEM_cnew<IDOverrideLibrary>(__func__);
local_id->override_library = MEM_callocN<IDOverrideLibrary>(__func__);
local_id->override_library->reference = reference_id;
if (reference_id) {
id_us_plus(local_id->override_library->reference);
@ -582,7 +582,7 @@ bool BKE_lib_override_library_create_from_tag(Main *bmain,
if ((reference_id->tag & ID_TAG_DOIT) != 0 && reference_id->lib == reference_library &&
BKE_idtype_idcode_is_linkable(GS(reference_id->name)))
{
todo_id_iter = MEM_cnew<LinkData>(__func__);
todo_id_iter = MEM_callocN<LinkData>(__func__);
todo_id_iter->data = reference_id;
BLI_addtail(&todo_ids, todo_id_iter);
}
@ -3266,7 +3266,7 @@ static void lib_override_resync_tagging_finalize(Main *bmain,
if (!BLI_ghash_ensure_p(
id_roots, hierarchy_root, reinterpret_cast<void ***>(&id_resync_roots_p)))
{
*id_resync_roots_p = MEM_cnew<LinkNodePair>(__func__);
*id_resync_roots_p = MEM_callocN<LinkNodePair>(__func__);
}
BLI_linklist_append(*id_resync_roots_p, id_iter);
}
@ -3906,7 +3906,7 @@ IDOverrideLibraryProperty *BKE_lib_override_library_property_get(IDOverrideLibra
IDOverrideLibraryProperty *op = BKE_lib_override_library_property_find(liboverride, rna_path);
if (op == nullptr) {
op = MEM_cnew<IDOverrideLibraryProperty>(__func__);
op = MEM_callocN<IDOverrideLibraryProperty>(__func__);
op->rna_path = BLI_strdup(rna_path);
BLI_addtail(&liboverride->properties, op);
@ -4197,7 +4197,7 @@ IDOverrideLibraryPropertyOperation *BKE_lib_override_library_property_operation_
r_strict);
if (opop == nullptr) {
opop = MEM_cnew<IDOverrideLibraryPropertyOperation>(__func__);
opop = MEM_callocN<IDOverrideLibraryPropertyOperation>(__func__);
opop->operation = operation;
if (subitem_locname) {
opop->subitem_local_name = BLI_strdup(subitem_locname);

View file

@ -98,7 +98,7 @@ void BKE_light_linking_collection_assign_only(Object *object,
/* Allocate light linking on demand. */
if (new_collection && !object->light_linking) {
object->light_linking = MEM_cnew<LightLinking>(__func__);
object->light_linking = MEM_callocN<LightLinking>(__func__);
}
if (object->light_linking) {

View file

@ -775,7 +775,7 @@ void BKE_main_library_weak_reference_add(ID *local_id,
const char *library_id_name)
{
if (local_id->library_weak_reference == nullptr) {
local_id->library_weak_reference = MEM_cnew<LibraryWeakReference>(__func__);
local_id->library_weak_reference = MEM_callocN<LibraryWeakReference>(__func__);
}
STRNCPY(local_id->library_weak_reference->library_filepath, library_filepath);

View file

@ -283,7 +283,7 @@ MaskSplinePoint *BKE_mask_spline_point_array_from_point(MaskSpline *spline,
MaskLayer *BKE_mask_layer_new(Mask *mask, const char *name)
{
MaskLayer *masklay = MEM_cnew<MaskLayer>(__func__);
MaskLayer *masklay = MEM_callocN<MaskLayer>(__func__);
STRNCPY(masklay->name, name && name[0] ? name : DATA_("MaskLayer"));
@ -347,7 +347,7 @@ void BKE_mask_layer_rename(Mask *mask,
MaskLayer *BKE_mask_layer_copy(const MaskLayer *masklay)
{
MaskLayer *masklay_new = MEM_cnew<MaskLayer>("new mask layer");
MaskLayer *masklay_new = MEM_callocN<MaskLayer>("new mask layer");
STRNCPY(masklay_new->name, masklay->name);
@ -378,7 +378,7 @@ MaskLayer *BKE_mask_layer_copy(const MaskLayer *masklay)
/* correct animation */
if (masklay->splines_shapes.first) {
LISTBASE_FOREACH (MaskLayerShape *, masklay_shape, &masklay->splines_shapes) {
MaskLayerShape *masklay_shape_new = MEM_cnew<MaskLayerShape>("new mask layer shape");
MaskLayerShape *masklay_shape_new = MEM_callocN<MaskLayerShape>("new mask layer shape");
masklay_shape_new->data = static_cast<float *>(MEM_dupallocN(masklay_shape->data));
masklay_shape_new->tot_vert = masklay_shape->tot_vert;
@ -405,12 +405,12 @@ void BKE_mask_layer_copy_list(ListBase *masklayers_new, const ListBase *masklaye
MaskSpline *BKE_mask_spline_add(MaskLayer *masklay)
{
MaskSpline *spline = MEM_cnew<MaskSpline>("new mask spline");
MaskSpline *spline = MEM_callocN<MaskSpline>("new mask spline");
BLI_addtail(&masklay->splines, spline);
/* spline shall have one point at least */
spline->points = MEM_cnew<MaskSplinePoint>("new mask spline point");
spline->points = MEM_callocN<MaskSplinePoint>("new mask spline point");
spline->tot_point = 1;
/* cyclic shapes are more usually used */
@ -872,7 +872,7 @@ MaskSplinePointUW *BKE_mask_point_sort_uw(MaskSplinePoint *point, MaskSplinePoin
void BKE_mask_point_add_uw(MaskSplinePoint *point, float u, float w)
{
if (!point->uw) {
point->uw = MEM_cnew<MaskSplinePointUW>("mask point uw");
point->uw = MEM_callocN<MaskSplinePointUW>("mask point uw");
}
else {
point->uw = static_cast<MaskSplinePointUW *>(
@ -1032,7 +1032,7 @@ static MaskSplinePoint *mask_spline_points_copy(const MaskSplinePoint *points, i
MaskSpline *BKE_mask_spline_copy(const MaskSpline *spline)
{
MaskSpline *nspline = MEM_cnew<MaskSpline>("new spline");
MaskSpline *nspline = MEM_callocN<MaskSpline>("new spline");
*nspline = *spline;
@ -1051,10 +1051,10 @@ MaskLayerShape *BKE_mask_layer_shape_alloc(MaskLayer *masklay, const int frame)
MaskLayerShape *masklay_shape;
int tot_vert = BKE_mask_layer_shape_totvert(masklay);
masklay_shape = MEM_cnew<MaskLayerShape>(__func__);
masklay_shape = MEM_callocN<MaskLayerShape>(__func__);
masklay_shape->frame = frame;
masklay_shape->tot_vert = tot_vert;
masklay_shape->data = MEM_cnew_array<float>(tot_vert * MASK_OBJECT_SHAPE_ELEM_SIZE, __func__);
masklay_shape->data = MEM_calloc_arrayN<float>(tot_vert * MASK_OBJECT_SHAPE_ELEM_SIZE, __func__);
return masklay_shape;
}
@ -1474,7 +1474,7 @@ void BKE_mask_spline_ensure_deform(MaskSpline *spline)
MEM_freeN(spline->points_deform);
}
spline->points_deform = MEM_cnew_array<MaskSplinePoint>(spline->tot_point, __func__);
spline->points_deform = MEM_calloc_arrayN<MaskSplinePoint>(spline->tot_point, __func__);
}
else {
// printf("alloc spline done\n");
@ -1849,8 +1849,8 @@ void BKE_mask_layer_shape_changed_add(MaskLayer *masklay,
float *data_resized;
masklay_shape->tot_vert++;
data_resized = MEM_cnew_array<float>(masklay_shape->tot_vert * MASK_OBJECT_SHAPE_ELEM_SIZE,
__func__);
data_resized = MEM_calloc_arrayN<float>(
masklay_shape->tot_vert * MASK_OBJECT_SHAPE_ELEM_SIZE, __func__);
if (index > 0) {
memcpy(data_resized,
masklay_shape->data,
@ -1909,8 +1909,8 @@ void BKE_mask_layer_shape_changed_remove(MaskLayer *masklay, int index, int coun
float *data_resized;
masklay_shape->tot_vert -= count;
data_resized = MEM_cnew_array<float>(masklay_shape->tot_vert * MASK_OBJECT_SHAPE_ELEM_SIZE,
__func__);
data_resized = MEM_calloc_arrayN<float>(
masklay_shape->tot_vert * MASK_OBJECT_SHAPE_ELEM_SIZE, __func__);
if (index > 0) {
memcpy(data_resized,
masklay_shape->data,

View file

@ -133,7 +133,7 @@ float (*BKE_mask_spline_differentiate_with_resolution(MaskSpline *spline,
/* len+1 because of 'forward_diff_bezier' function */
*r_tot_diff_point = tot;
diff_points = fp = MEM_cnew_array<float[2]>(tot + 1, "mask spline vets");
diff_points = fp = MEM_calloc_arrayN<float[2]>(tot + 1, "mask spline vets");
a = spline->tot_point - 1;
if (spline->flag & MASK_SPLINE_CYCLIC) {
@ -200,7 +200,7 @@ static void feather_bucket_add_edge(FeatherEdgesBucket *bucket, int start, int e
if (bucket->tot_segment >= bucket->alloc_segment) {
if (!bucket->segments) {
bucket->segments = MEM_cnew_array<int[2]>(alloc_delta, "feather bucket segments");
bucket->segments = MEM_calloc_arrayN<int[2]>(alloc_delta, "feather bucket segments");
}
else {
bucket->segments = static_cast<int(*)[2]>(MEM_reallocN(
@ -400,7 +400,7 @@ void BKE_mask_spline_feather_collapse_inner_loops(MaskSpline *spline,
bucket_scale[1] = 1.0f / ((max[1] - min[1]) * bucket_size);
/* fill in buckets' edges */
buckets = MEM_cnew_array<FeatherEdgesBucket>(tot_bucket, "feather buckets");
buckets = MEM_calloc_arrayN<FeatherEdgesBucket>(tot_bucket, "feather buckets");
for (int i = 0; i < tot_feather_point; i++) {
int start = i, end = i + 1;
@ -501,7 +501,7 @@ static float (
int a;
/* tot+1 because of 'forward_diff_bezier' function */
feather = fp = MEM_cnew_array<float[2]>(tot + 1, "mask spline feather diff points");
feather = fp = MEM_calloc_arrayN<float[2]>(tot + 1, "mask spline feather diff points");
a = spline->tot_point - 1;
if (spline->flag & MASK_SPLINE_CYCLIC) {
@ -582,7 +582,7 @@ static float (*mask_spline_feather_differentiated_points_with_resolution__double
/* len+1 because of 'forward_diff_bezier' function */
*r_tot_feather_point = tot;
feather = fp = MEM_cnew_array<float[2]>(tot + 1, "mask spline vets");
feather = fp = MEM_calloc_arrayN<float[2]>(tot + 1, "mask spline vets");
a = spline->tot_point - 1;
if (spline->flag & MASK_SPLINE_CYCLIC) {
@ -734,7 +734,7 @@ float (*BKE_mask_spline_feather_points(MaskSpline *spline, int *r_tot_feather_po
}
/* create data */
feather = fp = MEM_cnew_array<float[2]>(tot, "mask spline feather points");
feather = fp = MEM_calloc_arrayN<float[2]>(tot, "mask spline feather points");
for (i = 0; i < spline->tot_point; i++) {
MaskSplinePoint *point = &points_array[i];
@ -772,7 +772,7 @@ float *BKE_mask_point_segment_feather_diff(
float *feather, *fp;
uint resol = BKE_mask_spline_feather_resolution(spline, width, height);
feather = fp = MEM_cnew_array<float>(2 * resol, "mask point spline feather diff points");
feather = fp = MEM_calloc_arrayN<float>(2 * resol, "mask point spline feather diff points");
for (uint i = 0; i < resol; i++, fp += 2) {
float u = float(i % resol) / resol, weight;
@ -809,7 +809,7 @@ float *BKE_mask_point_segment_diff(
/* resol+1 because of 'forward_diff_bezier' function */
*r_tot_diff_point = resol + 1;
diff_points = fp = MEM_cnew_array<float>(2 * (resol + 1), "mask segment vets");
diff_points = fp = MEM_calloc_arrayN<float>(2 * (resol + 1), "mask segment vets");
for (j = 0; j < 2; j++) {
BKE_curve_forward_diff_bezier(bezt->vec[1][j],

View file

@ -209,7 +209,7 @@ MaskRasterHandle *BKE_maskrasterize_handle_new()
{
MaskRasterHandle *mr_handle;
mr_handle = MEM_cnew<MaskRasterHandle>("MaskRasterHandle");
mr_handle = MEM_callocN<MaskRasterHandle>("MaskRasterHandle");
return mr_handle;
}
@ -428,8 +428,8 @@ static void layer_bucket_init(MaskRasterLayer *layer, const float pixel_size)
float(*cos)[3] = layer->face_coords;
const uint bucket_tot = layer->buckets_x * layer->buckets_y;
LinkNode **bucketstore = MEM_cnew_array<LinkNode *>(bucket_tot, __func__);
uint *bucketstore_tot = MEM_cnew_array<uint>(bucket_tot, __func__);
LinkNode **bucketstore = MEM_calloc_arrayN<LinkNode *>(bucket_tot, __func__);
uint *bucketstore_tot = MEM_calloc_arrayN<uint>(bucket_tot, __func__);
uint face_index;
@ -527,12 +527,12 @@ static void layer_bucket_init(MaskRasterLayer *layer, const float pixel_size)
if (true) {
/* Now convert link-nodes into arrays for faster per pixel access. */
uint **buckets_face = MEM_cnew_array<uint *>(bucket_tot, __func__);
uint **buckets_face = MEM_calloc_arrayN<uint *>(bucket_tot, __func__);
uint bucket_index;
for (bucket_index = 0; bucket_index < bucket_tot; bucket_index++) {
if (bucketstore_tot[bucket_index]) {
uint *bucket = MEM_cnew_array<uint>((bucketstore_tot[bucket_index] + 1), __func__);
uint *bucket = MEM_calloc_arrayN<uint>((bucketstore_tot[bucket_index] + 1), __func__);
LinkNode *bucket_node;
buckets_face[bucket_index] = bucket;
@ -580,7 +580,7 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle,
MemArena *sf_arena;
mr_handle->layers_tot = uint(BLI_listbase_count(&mask->masklayers));
mr_handle->layers = MEM_cnew_array<MaskRasterLayer>(mr_handle->layers_tot, "MaskRasterLayer");
mr_handle->layers = MEM_calloc_arrayN<MaskRasterLayer>(mr_handle->layers_tot, "MaskRasterLayer");
BLI_rctf_init_minmax(&mr_handle->bounds);
sf_arena = BLI_memarena_new(BLI_SCANFILL_ARENA_SIZE, __func__);
@ -615,7 +615,7 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle,
}
tot_splines = uint(BLI_listbase_count(&masklay->splines));
open_spline_ranges = MEM_cnew_array<MaskRasterSplineInfo>(tot_splines, __func__);
open_spline_ranges = MEM_calloc_arrayN<MaskRasterSplineInfo>(tot_splines, __func__);
BLI_scanfill_begin_arena(&sf_ctx, sf_arena);
@ -685,8 +685,8 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle,
if (do_mask_aa == true) {
if (do_feather == false) {
tot_diff_feather_points = tot_diff_point;
diff_feather_points = MEM_cnew_array<float[2]>(size_t(tot_diff_feather_points),
__func__);
diff_feather_points = MEM_calloc_arrayN<float[2]>(size_t(tot_diff_feather_points),
__func__);
/* add single pixel feather */
maskrasterize_spline_differentiate_point_outset(
diff_feather_points, diff_points, tot_diff_point, pixel_size, false);
@ -757,8 +757,8 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle,
if (diff_feather_points) {
if (spline->flag & MASK_SPLINE_NOINTERSECT) {
diff_feather_points_flip = MEM_cnew_array<float[2]>(tot_diff_feather_points,
"diff_feather_points_flip");
diff_feather_points_flip = MEM_calloc_arrayN<float[2]>(tot_diff_feather_points,
"diff_feather_points_flip");
float co_diff[2];
for (j = 0; j < tot_diff_point; j++) {
@ -912,7 +912,7 @@ void BKE_maskrasterize_handle_init(MaskRasterHandle *mr_handle,
ListBase isect_remedgebase = {nullptr, nullptr};
/* now we have all the splines */
face_coords = MEM_cnew_array<float[3]>(sf_vert_tot, "maskrast_face_coords");
face_coords = MEM_calloc_arrayN<float[3]>(sf_vert_tot, "maskrast_face_coords");
/* init bounds */
BLI_rctf_init_minmax(&bounds);

View file

@ -590,7 +590,7 @@ void BKE_id_material_append(Main *bmain, ID *id, Material *ma)
Material ***matar = BKE_id_material_array_p(id);
if (matar) {
short *totcol = BKE_id_material_len_p(id);
Material **mat = MEM_cnew_array<Material *>((*totcol) + 1, "newmatar");
Material **mat = MEM_calloc_arrayN<Material *>((*totcol) + 1, "newmatar");
if (*totcol) {
memcpy(mat, *matar, sizeof(void *) * (*totcol));
}
@ -980,8 +980,8 @@ void BKE_object_material_resize(Main *bmain, Object *ob, const short totcol, boo
}
}
else if (ob->totcol < totcol) {
newmatar = MEM_cnew_array<Material *>(totcol, "newmatar");
newmatbits = MEM_cnew_array<char>(totcol, "newmatbits");
newmatar = MEM_calloc_arrayN<Material *>(totcol, "newmatar");
newmatbits = MEM_calloc_arrayN<char>(totcol, "newmatbits");
if (ob->totcol) {
memcpy(newmatar, ob->mat, sizeof(void *) * ob->totcol);
memcpy(newmatbits, ob->matbits, sizeof(char) * ob->totcol);
@ -1070,7 +1070,7 @@ void BKE_id_material_assign(Main *bmain, ID *id, Material *ma, short act)
}
if (act > *totcolp) {
matar = MEM_cnew_array<Material *>(act, "matarray1");
matar = MEM_calloc_arrayN<Material *>(act, "matarray1");
if (*totcolp) {
memcpy(matar, *matarar, sizeof(void *) * (*totcolp));
@ -1119,7 +1119,7 @@ static void object_material_assign(
}
if (act > *totcolp) {
matar = MEM_cnew_array<Material *>(act, "matarray1");
matar = MEM_calloc_arrayN<Material *>(act, "matarray1");
if (*totcolp) {
memcpy(matar, *matarar, sizeof(void *) * (*totcolp));
@ -1306,7 +1306,7 @@ void BKE_object_material_from_eval_data(Main *bmain, Object *ob_orig, const ID *
/* Create new material slots based on materials on evaluated geometry. */
*orig_totcol = *eval_totcol;
*orig_mat = *eval_totcol > 0 ? MEM_cnew_array<Material *>(*eval_totcol, __func__) : nullptr;
*orig_mat = *eval_totcol > 0 ? MEM_calloc_arrayN<Material *>(*eval_totcol, __func__) : nullptr;
for (int i = 0; i < *eval_totcol; i++) {
Material *material_eval = (*eval_mat)[i];
if (material_eval != nullptr) {

View file

@ -183,7 +183,7 @@ MetaBall *BKE_mball_add(Main *bmain, const char *name)
MetaElem *BKE_mball_element_add(MetaBall *mb, const int type)
{
MetaElem *ml = MEM_cnew<MetaElem>(__func__);
MetaElem *ml = MEM_callocN<MetaElem>(__func__);
unit_qt(ml->quat);

View file

@ -199,7 +199,7 @@ void mesh_calc_edges(Mesh &mesh, bool keep_existing_edges, const bool select_new
/* Create new edges. */
MutableAttributeAccessor attributes = mesh.attributes_for_write();
attributes.add<int>(".corner_edge", AttrDomain::Corner, AttributeInitConstruct());
MutableSpan<int2> new_edges(MEM_cnew_array<int2>(edge_offsets.total_size(), __func__),
MutableSpan<int2> new_edges(MEM_calloc_arrayN<int2>(edge_offsets.total_size(), __func__),
edge_offsets.total_size());
calc_edges::serialize_and_initialize_deduplicated_edges(edge_maps, edge_offsets, new_edges);
calc_edges::update_edge_indices_in_face_loops(mesh.faces(),

View file

@ -358,14 +358,14 @@ struct VertLink {
static void prependPolyLineVert(ListBase *lb, uint index)
{
VertLink *vl = MEM_cnew<VertLink>("VertLink");
VertLink *vl = MEM_callocN<VertLink>("VertLink");
vl->index = index;
BLI_addhead(lb, vl);
}
static void appendPolyLineVert(ListBase *lb, uint index)
{
VertLink *vl = MEM_cnew<VertLink>("VertLink");
VertLink *vl = MEM_callocN<VertLink>("VertLink");
vl->index = index;
BLI_addtail(lb, vl);
}
@ -393,7 +393,7 @@ void BKE_mesh_to_curve_nurblist(const Mesh *mesh, ListBase *nurblist, const int
/* create edges from all faces (so as to find edges not in any faces) */
for (const int i : mesh_edges.index_range()) {
if (edge_users[i] == edge_users_test) {
EdgeLink *edl = MEM_cnew<EdgeLink>("EdgeLink");
EdgeLink *edl = MEM_callocN<EdgeLink>("EdgeLink");
edl->edge = &mesh_edges[i];
BLI_addtail(&edges, edl);
@ -1045,7 +1045,7 @@ static void move_shapekey_layers_to_keyblocks(const Mesh &mesh,
if (kb->totelem != mesh.verts_num) {
MEM_SAFE_FREE(kb->data);
kb->totelem = mesh.verts_num;
kb->data = MEM_cnew_array<float3>(kb->totelem, __func__);
kb->data = MEM_calloc_arrayN<float3>(kb->totelem, __func__);
CLOG_ERROR(&LOG, "Data for shape key '%s' on mesh missing from evaluated mesh ", kb->name);
}
}

View file

@ -2124,7 +2124,7 @@ static bNodeTree *add_auto_smooth_node_tree(Main &bmain, Library *owner_library)
bNodeTree *group = node_tree_add_in_lib(
&bmain, owner_library, DATA_("Auto Smooth"), "GeometryNodeTree");
if (!group->geometry_node_asset_traits) {
group->geometry_node_asset_traits = MEM_cnew<GeometryNodeAssetTraits>(__func__);
group->geometry_node_asset_traits = MEM_callocN<GeometryNodeAssetTraits>(__func__);
}
group->geometry_node_asset_traits->flag |= GEO_NODE_ASSET_MODIFIER;

View file

@ -73,7 +73,7 @@ static int *dm_getCornerEdgeArray(DerivedMesh *dm)
static int *dm_getPolyArray(DerivedMesh *dm)
{
if (!dm->face_offsets) {
dm->face_offsets = MEM_cnew_array<int>(dm->getNumPolys(dm) + 1, __func__);
dm->face_offsets = MEM_calloc_arrayN<int>(dm->getNumPolys(dm) + 1, __func__);
dm->copyPolyArray(dm, dm->face_offsets);
}
return dm->face_offsets;
@ -285,7 +285,7 @@ static void cdDM_release(DerivedMesh *dm)
/**************** CDDM interface functions ****************/
static CDDerivedMesh *cdDM_create(const char *desc)
{
CDDerivedMesh *cddm = MEM_cnew<CDDerivedMesh>(desc);
CDDerivedMesh *cddm = MEM_callocN<CDDerivedMesh>(desc);
DerivedMesh *dm = &cddm->dm;
dm->getNumVerts = cdDM_getNumVerts;

View file

@ -196,7 +196,7 @@ void BKE_mesh_vert_corner_tri_map_create(MeshElemMap **r_map,
const int *corner_verts,
const int /*corners_num*/)
{
MeshElemMap *map = MEM_cnew_array<MeshElemMap>(size_t(totvert), __func__);
MeshElemMap *map = MEM_calloc_arrayN<MeshElemMap>(size_t(totvert), __func__);
int *indices = static_cast<int *>(MEM_mallocN(sizeof(int) * size_t(tris_num) * 3, __func__));
int *index_step;
int i;
@ -236,7 +236,7 @@ void BKE_mesh_origindex_map_create(MeshElemMap **r_map,
const int *final_origindex,
const int totfinal)
{
MeshElemMap *map = MEM_cnew_array<MeshElemMap>(size_t(totsource), __func__);
MeshElemMap *map = MEM_calloc_arrayN<MeshElemMap>(size_t(totsource), __func__);
int *indices = static_cast<int *>(MEM_mallocN(sizeof(int) * size_t(totfinal), __func__));
int *index_step;
int i;
@ -277,7 +277,7 @@ void BKE_mesh_origindex_map_create_corner_tri(MeshElemMap **r_map,
const int *corner_tri_faces,
const int corner_tris_num)
{
MeshElemMap *map = MEM_cnew_array<MeshElemMap>(size_t(faces.size()), __func__);
MeshElemMap *map = MEM_calloc_arrayN<MeshElemMap>(size_t(faces.size()), __func__);
int *indices = static_cast<int *>(MEM_mallocN(sizeof(int) * size_t(corner_tris_num), __func__));
int *index_step;
@ -332,7 +332,7 @@ static Array<int> reverse_indices_in_groups(const Span<int> group_indices,
* atomically by many threads in parallel. `calloc` can be measurably faster than a parallel fill
* of zero. Alternatively the offsets could be copied and incremented directly, but the cost of
* the copy is slightly higher than the cost of `calloc`. */
int *counts = MEM_cnew_array<int>(size_t(offsets.size()), __func__);
int *counts = MEM_calloc_arrayN<int>(size_t(offsets.size()), __func__);
BLI_SCOPED_DEFER([&]() { MEM_freeN(counts); })
Array<int> results(group_indices.size());
threading::parallel_for(group_indices.index_range(), 1024, [&](const IndexRange range) {
@ -352,7 +352,7 @@ static void reverse_group_indices_in_groups(const OffsetIndices<int> groups,
const OffsetIndices<int> offsets,
MutableSpan<int> results)
{
int *counts = MEM_cnew_array<int>(size_t(offsets.size()), __func__);
int *counts = MEM_calloc_arrayN<int>(size_t(offsets.size()), __func__);
BLI_SCOPED_DEFER([&]() { MEM_freeN(counts); })
threading::parallel_for(groups.index_range(), 1024, [&](const IndexRange range) {
for (const int64_t face : range) {
@ -392,7 +392,7 @@ GroupedSpan<int> build_vert_to_edge_map(const Span<int2> edges,
r_indices.reinitialize(offsets.total_size());
/* Version of #reverse_indices_in_groups that accounts for storing two indices for each edge. */
int *counts = MEM_cnew_array<int>(size_t(offsets.size()), __func__);
int *counts = MEM_calloc_arrayN<int>(size_t(offsets.size()), __func__);
BLI_SCOPED_DEFER([&]() { MEM_freeN(counts); })
threading::parallel_for(edges.index_range(), 1024, [&](const IndexRange range) {
for (const int64_t edge : range) {

View file

@ -553,7 +553,7 @@ CDMaskLink *BKE_modifier_calc_data_masks(const Scene *scene,
for (; md; md = md->next) {
const ModifierTypeInfo *mti = BKE_modifier_get_info(ModifierType(md->type));
curr = MEM_cnew<CDMaskLink>(__func__);
curr = MEM_callocN<CDMaskLink>(__func__);
if (BKE_modifier_is_enabled(scene, md, required_mode)) {
if (mti->type == ModifierTypeType::OnlyDeform) {

View file

@ -213,7 +213,7 @@ static void ntree_copy_data(Main * /*bmain*/,
}
if (ntree_src->geometry_node_asset_traits) {
ntree_dst->geometry_node_asset_traits = MEM_cnew<GeometryNodeAssetTraits>(
ntree_dst->geometry_node_asset_traits = MEM_dupallocN<GeometryNodeAssetTraits>(
__func__, *ntree_src->geometry_node_asset_traits);
}
@ -462,7 +462,7 @@ static bNodeSocket *make_socket(bNodeTree *ntree,
return nullptr;
}
bNodeSocket *sock = MEM_cnew<bNodeSocket>(__func__);
bNodeSocket *sock = MEM_callocN<bNodeSocket>(__func__);
sock->runtime = MEM_new<bNodeSocketRuntime>(__func__);
StringRef(stype->idname).copy_utf8_truncated(sock->idname);
sock->in_out = int(in_out);
@ -1946,7 +1946,7 @@ static bNodeSocket *make_socket(bNodeTree *ntree,
BLI_uniquename_cb(
unique_identifier_check, lb, "socket", '_', auto_identifier, sizeof(auto_identifier));
bNodeSocket *sock = MEM_cnew<bNodeSocket>(__func__);
bNodeSocket *sock = MEM_callocN<bNodeSocket>(__func__);
sock->runtime = MEM_new<bNodeSocketRuntime>(__func__);
sock->in_out = in_out;
@ -2661,7 +2661,7 @@ void node_unique_id(bNodeTree &ntree, bNode &node)
bNode *node_add_node(const bContext *C, bNodeTree &ntree, const StringRef idname)
{
bNode *node = MEM_cnew<bNode>(__func__);
bNode *node = MEM_callocN<bNode>(__func__);
node->runtime = MEM_new<bNodeRuntime>(__func__);
BLI_addtail(&ntree.nodes, node);
node_unique_id(ntree, *node);
@ -2954,7 +2954,7 @@ bNodeLink &node_add_link(
bNodeLink *link = nullptr;
if (eNodeSocketInOut(fromsock.in_out) == SOCK_OUT && eNodeSocketInOut(tosock.in_out) == SOCK_IN)
{
link = MEM_cnew<bNodeLink>(__func__);
link = MEM_callocN<bNodeLink>(__func__);
BLI_addtail(&ntree.links, link);
link->fromnode = &fromnode;
link->fromsock = &fromsock;
@ -2965,7 +2965,7 @@ bNodeLink &node_add_link(
eNodeSocketInOut(tosock.in_out) == SOCK_OUT)
{
/* OK but flip */
link = MEM_cnew<bNodeLink>(__func__);
link = MEM_callocN<bNodeLink>(__func__);
BLI_addtail(&ntree.links, link);
link->fromnode = &tonode;
link->fromsock = &tosock;

View file

@ -191,7 +191,7 @@ static void *make_socket_data(const StringRef socket_type)
void *socket_data = nullptr;
socket_data_to_static_type_tag(socket_type, [&socket_data](auto type_tag) {
using SocketDataType = typename decltype(type_tag)::type;
SocketDataType *new_socket_data = MEM_cnew<SocketDataType>(__func__);
SocketDataType *new_socket_data = MEM_callocN<SocketDataType>(__func__);
socket_data_init_impl(*new_socket_data);
socket_data = new_socket_data;
});
@ -448,7 +448,7 @@ static void panel_init(bNodeTreeInterfacePanel &panel,
UidGeneratorFn generate_uid)
{
panel.items_num = items_src.size();
panel.items_array = MEM_cnew_array<bNodeTreeInterfaceItem *>(panel.items_num, __func__);
panel.items_array = MEM_calloc_arrayN<bNodeTreeInterfaceItem *>(panel.items_num, __func__);
/* Copy buffers. */
for (const int i : items_src.index_range()) {
@ -887,7 +887,7 @@ void bNodeTreeInterfacePanel::insert_item(bNodeTreeInterfaceItem &item, int posi
blender::MutableSpan<bNodeTreeInterfaceItem *> old_items = this->items();
items_num++;
items_array = MEM_cnew_array<bNodeTreeInterfaceItem *>(items_num, __func__);
items_array = MEM_calloc_arrayN<bNodeTreeInterfaceItem *>(items_num, __func__);
this->items().take_front(position).copy_from(old_items.take_front(position));
this->items().drop_front(position + 1).copy_from(old_items.drop_front(position));
this->items()[position] = &item;
@ -906,7 +906,7 @@ bool bNodeTreeInterfacePanel::remove_item(bNodeTreeInterfaceItem &item, const bo
blender::MutableSpan<bNodeTreeInterfaceItem *> old_items = this->items();
items_num--;
items_array = MEM_cnew_array<bNodeTreeInterfaceItem *>(items_num, __func__);
items_array = MEM_calloc_arrayN<bNodeTreeInterfaceItem *>(items_num, __func__);
this->items().take_front(position).copy_from(old_items.take_front(position));
this->items().drop_front(position).copy_from(old_items.drop_front(position + 1));
@ -1078,7 +1078,7 @@ static bNodeTreeInterfaceSocket *make_socket(const int uid,
return nullptr;
}
bNodeTreeInterfaceSocket *new_socket = MEM_cnew<bNodeTreeInterfaceSocket>(__func__);
bNodeTreeInterfaceSocket *new_socket = MEM_callocN<bNodeTreeInterfaceSocket>(__func__);
BLI_assert(new_socket);
/* Init common socket properties. */
@ -1140,7 +1140,7 @@ static bNodeTreeInterfacePanel *make_panel(const int uid,
{
BLI_assert(!name.is_empty());
bNodeTreeInterfacePanel *new_panel = MEM_cnew<bNodeTreeInterfacePanel>(__func__);
bNodeTreeInterfacePanel *new_panel = MEM_callocN<bNodeTreeInterfacePanel>(__func__);
new_panel->item.item_type = NODE_INTERFACE_PANEL;
new_panel->name = BLI_strdupn(name.data(), name.size());
new_panel->description = description.is_empty() ?

View file

@ -3644,7 +3644,7 @@ void BKE_object_empty_draw_type_set(Object *ob, const int value)
if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
if (!ob->iuser) {
ob->iuser = MEM_cnew<ImageUser>("image user");
ob->iuser = MEM_callocN<ImageUser>("image user");
ob->iuser->flag |= IMA_ANIM_ALWAYS;
ob->iuser->frames = 100;
ob->iuser->sfra = 1;
@ -4246,7 +4246,7 @@ int BKE_object_insert_ptcache(Object *ob)
}
}
link = MEM_cnew<LinkData>("PCLink");
link = MEM_callocN<LinkData>("PCLink");
link->data = POINTER_FROM_INT(i);
BLI_addtail(&ob->pc_ids, link);

View file

@ -258,7 +258,7 @@ static DupliObject *make_dupli(const DupliContext *ctx,
/* Add a #DupliObject instance to the result container. */
if (ctx->duplilist) {
dob = MEM_cnew<DupliObject>("dupli object");
dob = MEM_callocN<DupliObject>("dupli object");
BLI_addtail(ctx->duplilist, dob);
}
else {
@ -1786,7 +1786,7 @@ static const DupliGenerator *get_dupli_generator(const DupliContext *ctx)
ListBase *object_duplilist(Depsgraph *depsgraph, Scene *sce, Object *ob)
{
ListBase *duplilist = MEM_cnew<ListBase>("duplilist");
ListBase *duplilist = MEM_callocN<ListBase>("duplilist");
DupliContext ctx;
Vector<Object *> instance_stack;
Vector<short> dupli_gen_type_stack({0});
@ -1805,7 +1805,7 @@ ListBase *object_duplilist_preview(Depsgraph *depsgraph,
Object *ob_eval,
const ViewerPath *viewer_path)
{
ListBase *duplilist = MEM_cnew<ListBase>("duplilist");
ListBase *duplilist = MEM_callocN<ListBase>("duplilist");
DupliContext ctx;
Vector<Object *> instance_stack;
Vector<short> dupli_gen_type_stack({0});

View file

@ -1372,7 +1372,7 @@ Palette *BKE_palette_add(Main *bmain, const char *name)
PaletteColor *BKE_palette_color_add(Palette *palette)
{
PaletteColor *color = MEM_cnew<PaletteColor>(__func__);
PaletteColor *color = MEM_callocN<PaletteColor>(__func__);
BLI_addtail(&palette->colors, color);
return color;
}
@ -1690,34 +1690,34 @@ bool BKE_paint_ensure(ToolSettings *ts, Paint **r_paint)
}
if (((VPaint **)r_paint == &ts->vpaint) || ((VPaint **)r_paint == &ts->wpaint)) {
VPaint *data = MEM_cnew<VPaint>(__func__);
VPaint *data = MEM_callocN<VPaint>(__func__);
paint = &data->paint;
}
else if ((Sculpt **)r_paint == &ts->sculpt) {
Sculpt *data = MEM_cnew<Sculpt>(__func__);
Sculpt *data = MEM_callocN<Sculpt>(__func__);
*data = *DNA_struct_default_get(Sculpt);
paint = &data->paint;
}
else if ((GpPaint **)r_paint == &ts->gp_paint) {
GpPaint *data = MEM_cnew<GpPaint>(__func__);
GpPaint *data = MEM_callocN<GpPaint>(__func__);
paint = &data->paint;
}
else if ((GpVertexPaint **)r_paint == &ts->gp_vertexpaint) {
GpVertexPaint *data = MEM_cnew<GpVertexPaint>(__func__);
GpVertexPaint *data = MEM_callocN<GpVertexPaint>(__func__);
paint = &data->paint;
}
else if ((GpSculptPaint **)r_paint == &ts->gp_sculptpaint) {
GpSculptPaint *data = MEM_cnew<GpSculptPaint>(__func__);
GpSculptPaint *data = MEM_callocN<GpSculptPaint>(__func__);
paint = &data->paint;
}
else if ((GpWeightPaint **)r_paint == &ts->gp_weightpaint) {
GpWeightPaint *data = MEM_cnew<GpWeightPaint>(__func__);
GpWeightPaint *data = MEM_callocN<GpWeightPaint>(__func__);
paint = &data->paint;
}
else if ((CurvesSculpt **)r_paint == &ts->curves_sculpt) {
CurvesSculpt *data = MEM_cnew<CurvesSculpt>(__func__);
CurvesSculpt *data = MEM_callocN<CurvesSculpt>(__func__);
paint = &data->paint;
}
else if (*r_paint == &ts->imapaint.paint) {

View file

@ -352,7 +352,7 @@ static void scene_copy_data(Main *bmain,
/* Copy sequencer, this is local data! */
if (scene_src->ed) {
scene_dst->ed = MEM_cnew<Editing>(__func__);
scene_dst->ed = MEM_callocN<Editing>(__func__);
scene_dst->ed->seqbasep = &scene_dst->ed->seqbase;
scene_dst->ed->cache_flag = scene_src->ed->cache_flag;
scene_dst->ed->show_missing_media_flag = scene_src->ed->show_missing_media_flag;
@ -2648,7 +2648,7 @@ SceneRenderView *BKE_scene_add_render_view(Scene *sce, const char *name)
name = DATA_("RenderView");
}
SceneRenderView *srv = MEM_cnew<SceneRenderView>(__func__);
SceneRenderView *srv = MEM_callocN<SceneRenderView>(__func__);
STRNCPY(srv->name, name);
BLI_uniquename(&sce->r.views,
srv,
@ -3282,7 +3282,7 @@ static Depsgraph **scene_get_depsgraph_p(Scene *scene,
}
/* Depsgraph was not found in the ghash, but the key still needs allocating. */
*key_ptr = MEM_cnew<DepsgraphKey>(__func__);
*key_ptr = MEM_callocN<DepsgraphKey>(__func__);
**key_ptr = key;
*depsgraph_ptr = nullptr;

View file

@ -330,7 +330,7 @@ static void panel_list_copy(ListBase *newlb, const ListBase *lb)
BLI_listbase_clear(&new_panel->layout_panel_states);
LISTBASE_FOREACH (LayoutPanelState *, src_state, &old_panel->layout_panel_states) {
LayoutPanelState *new_state = MEM_cnew<LayoutPanelState>(__func__, *src_state);
LayoutPanelState *new_state = MEM_dupallocN<LayoutPanelState>(__func__, *src_state);
new_state->idname = BLI_strdup(src_state->idname);
BLI_addtail(&new_panel->layout_panel_states, new_state);
}
@ -379,7 +379,7 @@ ARegion *BKE_area_region_copy(const SpaceType *st, const ARegion *region)
ARegion *BKE_area_region_new()
{
ARegion *region = MEM_cnew<ARegion>(__func__);
ARegion *region = MEM_callocN<ARegion>(__func__);
region->runtime = MEM_new<blender::bke::ARegionRuntime>(__func__);
return region;
}
@ -519,7 +519,7 @@ LayoutPanelState *BKE_panel_layout_panel_state_ensure(Panel *panel,
return state;
}
}
LayoutPanelState *state = MEM_cnew<LayoutPanelState>(__func__);
LayoutPanelState *state = MEM_callocN<LayoutPanelState>(__func__);
state->idname = BLI_strdupn(idname.data(), idname.size());
SET_FLAG_FROM_TEST(state->flag, !default_closed, LAYOUT_PANEL_STATE_FLAG_OPEN);
BLI_addtail(&panel->layout_panel_states, state);
@ -528,7 +528,7 @@ LayoutPanelState *BKE_panel_layout_panel_state_ensure(Panel *panel,
Panel *BKE_panel_new(PanelType *panel_type)
{
Panel *panel = MEM_cnew<Panel>(__func__);
Panel *panel = MEM_callocN<Panel>(__func__);
panel->runtime = MEM_new<Panel_Runtime>(__func__);
panel->type = panel_type;
if (panel_type) {
@ -1237,7 +1237,7 @@ static void direct_link_region(BlendDataReader *reader, ARegion *region, int spa
if (region->regiondata == nullptr) {
/* To avoid crashing on some old files. */
region->regiondata = MEM_cnew<RegionView3D>("region view3d");
region->regiondata = MEM_callocN<RegionView3D>("region view3d");
}
RegionView3D *rv3d = static_cast<RegionView3D *>(region->regiondata);

View file

@ -114,7 +114,7 @@ Subdiv *new_from_converter(const Settings *settings, OpenSubdiv_Converter *conve
* The thing here is: OpenSubdiv can only deal with faces, but our
* side of subdiv also deals with loose vertices and edges. */
}
Subdiv *subdiv = MEM_cnew<Subdiv>(__func__);
Subdiv *subdiv = MEM_callocN<Subdiv>(__func__);
subdiv->settings = *settings;
subdiv->topology_refiner = osd_topology_refiner;
subdiv->evaluator = nullptr;

View file

@ -438,7 +438,7 @@ void displacement_attach_from_multires(Subdiv *subdiv, Mesh *mesh, const Multire
return;
}
/* Allocate all required memory. */
Displacement *displacement = MEM_cnew<Displacement>("multires displacement");
Displacement *displacement = MEM_callocN<Displacement>("multires displacement");
displacement->user_data = MEM_new<MultiresDisplacementData>("multires displacement data");
displacement_init_data(displacement, subdiv, mesh, mmd);
displacement_init_functions(displacement);

View file

@ -58,7 +58,7 @@ bool BKE_subsurf_modifier_runtime_init(SubsurfModifierData *smd, const bool use_
/* Allocate runtime data if it did not exist yet. */
if (runtime_data == nullptr) {
runtime_data = MEM_cnew<SubsurfRuntimeData>(__func__);
runtime_data = MEM_callocN<SubsurfRuntimeData>(__func__);
smd->modifier.runtime = runtime_data;
}
runtime_data->settings = settings;

View file

@ -1531,7 +1531,7 @@ static CCGDerivedMesh *getCCGDerivedMesh(CCGSubSurf *ss,
int useSubsurfUv,
DerivedMesh *dm)
{
CCGDerivedMesh *ccgdm = MEM_cnew<CCGDerivedMesh>(__func__);
CCGDerivedMesh *ccgdm = MEM_callocN<CCGDerivedMesh>(__func__);
DM_from_template(&ccgdm->dm,
dm,
DM_TYPE_CCGDM,

View file

@ -229,7 +229,7 @@ void BKE_texture_mtex_foreach_id(LibraryForeachIDData *data, MTex *mtex)
TexMapping *BKE_texture_mapping_add(int type)
{
TexMapping *texmap = MEM_cnew<TexMapping>("TexMapping");
TexMapping *texmap = MEM_callocN<TexMapping>("TexMapping");
BKE_texture_mapping_default(texmap, type);
@ -332,7 +332,7 @@ void BKE_texture_mapping_init(TexMapping *texmap)
ColorMapping *BKE_texture_colormapping_add()
{
ColorMapping *colormap = MEM_cnew<ColorMapping>("ColorMapping");
ColorMapping *colormap = MEM_callocN<ColorMapping>("ColorMapping");
BKE_texture_colormapping_default(colormap);

View file

@ -197,7 +197,7 @@ static void tracking_tracks_copy(TrackingCopyContext *ctx,
BLI_listbase_clear(tracks_dst);
LISTBASE_FOREACH (MovieTrackingTrack *, track_src, tracks_src) {
MovieTrackingTrack *track_dst = MEM_cnew<MovieTrackingTrack>(__func__, *track_src);
MovieTrackingTrack *track_dst = MEM_dupallocN<MovieTrackingTrack>(__func__, *track_src);
if (track_src->markers) {
track_dst->markers = static_cast<MovieTrackingMarker *>(MEM_dupallocN(track_src->markers));
}
@ -221,12 +221,12 @@ static void tracking_plane_tracks_copy(TrackingCopyContext *ctx,
BLI_listbase_clear(plane_tracks_list_dst);
LISTBASE_FOREACH (MovieTrackingPlaneTrack *, plane_track_src, plane_tracks_list_src) {
MovieTrackingPlaneTrack *plane_track_dst = MEM_cnew(__func__, *plane_track_src);
MovieTrackingPlaneTrack *plane_track_dst = MEM_dupallocN(__func__, *plane_track_src);
if (plane_track_src->markers) {
plane_track_dst->markers = static_cast<MovieTrackingPlaneMarker *>(
MEM_dupallocN(plane_track_src->markers));
}
plane_track_dst->point_tracks = MEM_cnew_array<MovieTrackingTrack *>(
plane_track_dst->point_tracks = MEM_calloc_arrayN<MovieTrackingTrack *>(
sizeof(*plane_track_dst->point_tracks) * plane_track_dst->point_tracksnr, __func__);
for (int i = 0; i < plane_track_dst->point_tracksnr; i++) {
plane_track_dst->point_tracks[i] = static_cast<MovieTrackingTrack *>(
@ -300,7 +300,7 @@ static void tracking_objects_copy(ListBase *tracking_objects_dst,
BLI_listbase_clear(tracking_objects_dst);
LISTBASE_FOREACH (MovieTrackingObject *, tracking_object_src, tracking_objects_src) {
MovieTrackingObject *tracking_object_dst = MEM_cnew<MovieTrackingObject>(__func__);
MovieTrackingObject *tracking_object_dst = MEM_callocN<MovieTrackingObject>(__func__);
tracking_object_copy(tracking_object_dst, tracking_object_src, flag);
BLI_addtail(tracking_objects_dst, tracking_object_dst);
}
@ -502,7 +502,7 @@ MovieTrackingTrack *BKE_tracking_track_add_empty(MovieTracking *tracking, ListBa
{
const MovieTrackingSettings *settings = &tracking->settings;
MovieTrackingTrack *track = MEM_cnew<MovieTrackingTrack>("add_marker_exec track");
MovieTrackingTrack *track = MEM_callocN<MovieTrackingTrack>("add_marker_exec track");
STRNCPY(track->name, CTX_DATA_(BLT_I18NCONTEXT_ID_MOVIECLIP, "Track"));
/* Fill track's settings from default settings. */
@ -567,7 +567,7 @@ MovieTrackingTrack *BKE_tracking_track_duplicate(MovieTrackingTrack *track)
{
MovieTrackingTrack *new_track;
new_track = MEM_cnew<MovieTrackingTrack>("tracking_track_duplicate new_track");
new_track = MEM_callocN<MovieTrackingTrack>("tracking_track_duplicate new_track");
*new_track = *track;
new_track->next = new_track->prev = nullptr;
@ -656,7 +656,7 @@ MovieTrackingTrack **BKE_tracking_selected_tracks_in_active_object(MovieTracking
return nullptr;
}
MovieTrackingTrack **source_tracks = MEM_cnew_array<MovieTrackingTrack *>(
MovieTrackingTrack **source_tracks = MEM_calloc_arrayN<MovieTrackingTrack *>(
num_selected_tracks, "selected tracks array");
int source_track_index = 0;
LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking_object->tracks) {
@ -798,7 +798,7 @@ void BKE_tracking_tracks_join(MovieTracking *tracking,
MovieTrackingMarker *markers;
tot = dst_track->markersnr + src_track->markersnr;
markers = MEM_cnew_array<MovieTrackingMarker>(tot, "tmp tracking joined tracks");
markers = MEM_calloc_arrayN<MovieTrackingMarker>(tot, "tmp tracking joined tracks");
while (a < src_track->markersnr || b < dst_track->markersnr) {
if (b >= dst_track->markersnr) {
@ -894,7 +894,7 @@ void BKE_tracking_tracks_join(MovieTracking *tracking,
MEM_freeN(dst_track->markers);
dst_track->markers = MEM_cnew_array<MovieTrackingMarker>(i, "tracking joined tracks");
dst_track->markers = MEM_calloc_arrayN<MovieTrackingMarker>(i, "tracking joined tracks");
memcpy(dst_track->markers, markers, i * sizeof(MovieTrackingMarker));
dst_track->markersnr = i;
@ -955,9 +955,9 @@ static void tracking_average_markers(MovieTrackingTrack *dst_track,
const int num_frames = last_frame - first_frame + 1;
/* Allocate temporary array where averaging will happen into. */
MovieTrackingMarker *accumulator = MEM_cnew_array<MovieTrackingMarker>(
MovieTrackingMarker *accumulator = MEM_calloc_arrayN<MovieTrackingMarker>(
num_frames, "tracks average accumulator");
int *counters = MEM_cnew_array<int>(num_frames, "tracks accumulator counters");
int *counters = MEM_calloc_arrayN<int>(num_frames, "tracks accumulator counters");
for (int frame = first_frame; frame <= last_frame; ++frame) {
const int frame_index = frame - first_frame;
accumulator[frame_index].framenr = frame;
@ -1144,7 +1144,7 @@ float *tracking_track_get_mask_for_region(const int frame_width,
if (layer != nullptr) {
const int mask_width = region_max[0] - region_min[0];
const int mask_height = region_max[1] - region_min[1];
mask = MEM_cnew_array<float>(mask_width * mask_height, "track mask");
mask = MEM_calloc_arrayN<float>(mask_width * mask_height, "track mask");
track_mask_gpencil_layer_rasterize(
frame_width, frame_height, region_min, layer, mask, mask_width, mask_height);
}
@ -1264,7 +1264,7 @@ MovieTrackingMarker *BKE_tracking_marker_insert(MovieTrackingTrack *track,
MEM_reallocN(track->markers, sizeof(MovieTrackingMarker) * track->markersnr));
}
else {
track->markers = MEM_cnew<MovieTrackingMarker>("MovieTracking markers");
track->markers = MEM_callocN<MovieTrackingMarker>("MovieTracking markers");
}
/* shift array to "free" space for new marker */
@ -1571,7 +1571,7 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_add(MovieTracking *tracking,
}
/* Allocate new plane track. */
plane_track = MEM_cnew<MovieTrackingPlaneTrack>("new plane track");
plane_track = MEM_callocN<MovieTrackingPlaneTrack>("new plane track");
/* Use some default name. */
STRNCPY(plane_track->name, DATA_("Plane Track"));
@ -1579,8 +1579,8 @@ MovieTrackingPlaneTrack *BKE_tracking_plane_track_add(MovieTracking *tracking,
plane_track->image_opacity = 1.0f;
/* Use selected tracks from given list as a plane. */
plane_track->point_tracks = MEM_cnew_array<MovieTrackingTrack *>(num_selected_tracks,
"new plane tracks array");
plane_track->point_tracks = MEM_calloc_arrayN<MovieTrackingTrack *>(num_selected_tracks,
"new plane tracks array");
int track_index = 0;
LISTBASE_FOREACH (MovieTrackingTrack *, track, tracks) {
if (TRACK_SELECTED(track)) {
@ -1656,7 +1656,7 @@ bool BKE_tracking_plane_track_remove_point_track(MovieTrackingPlaneTrack *plane_
return false;
}
MovieTrackingTrack **new_point_tracks = MEM_cnew_array<MovieTrackingTrack *>(
MovieTrackingTrack **new_point_tracks = MEM_calloc_arrayN<MovieTrackingTrack *>(
plane_track->point_tracksnr - 1, "new point tracks array");
for (int i = 0, track_index = 0; i < plane_track->point_tracksnr; i++) {
@ -1896,7 +1896,7 @@ void BKE_tracking_plane_marker_get_subframe_corners(MovieTrackingPlaneTrack *pla
MovieTrackingObject *BKE_tracking_object_add(MovieTracking *tracking, const char *name)
{
MovieTrackingObject *tracking_object = MEM_cnew<MovieTrackingObject>("tracking object");
MovieTrackingObject *tracking_object = MEM_callocN<MovieTrackingObject>("tracking object");
if (tracking->tot_object == 0) {
/* first object is always camera */
@ -2269,7 +2269,7 @@ MovieDistortion *BKE_tracking_distortion_new(MovieTracking *tracking,
tracking_cameraIntrinscisOptionsFromTracking(
tracking, calibration_width, calibration_height, &camera_intrinsics_options);
distortion = MEM_cnew<MovieDistortion>("BKE_tracking_distortion_create");
distortion = MEM_callocN<MovieDistortion>("BKE_tracking_distortion_create");
distortion->intrinsics = libmv_cameraIntrinsicsNew(&camera_intrinsics_options);
const MovieTrackingCamera *camera = &tracking->camera;
@ -2313,7 +2313,7 @@ MovieDistortion *BKE_tracking_distortion_copy(MovieDistortion *distortion)
{
MovieDistortion *new_distortion;
new_distortion = MEM_cnew<MovieDistortion>("BKE_tracking_distortion_create");
new_distortion = MEM_callocN<MovieDistortion>("BKE_tracking_distortion_create");
*new_distortion = *distortion;
new_distortion->intrinsics = libmv_cameraIntrinsicsCopy(distortion->intrinsics);
@ -3208,7 +3208,8 @@ static void tracking_dopesheet_channels_segments_calc(MovieTrackingDopesheetChan
return;
}
channel->segments = MEM_cnew_array<int>(2 * channel->tot_segment, "tracking channel segments");
channel->segments = MEM_calloc_arrayN<int>(2 * channel->tot_segment,
"tracking channel segments");
/* create segments */
i = 0;
@ -3267,7 +3268,7 @@ static void tracking_dopesheet_channels_calc(MovieTracking *tracking)
continue;
}
MovieTrackingDopesheetChannel *channel = MEM_cnew<MovieTrackingDopesheetChannel>(
MovieTrackingDopesheetChannel *channel = MEM_callocN<MovieTrackingDopesheetChannel>(
"tracking dopesheet channel");
channel->track = track;
@ -3374,7 +3375,7 @@ static void tracking_dopesheet_calc_coverage(MovieTracking *tracking)
frames = end_frame - start_frame + 1;
/* this is a per-frame counter of markers (how many markers belongs to the same frame) */
per_frame_counter = MEM_cnew_array<int>(frames, "per frame track counter");
per_frame_counter = MEM_calloc_arrayN<int>(frames, "per frame track counter");
/* find per-frame markers count */
LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking_object->tracks) {
@ -3413,7 +3414,7 @@ static void tracking_dopesheet_calc_coverage(MovieTracking *tracking)
end_segment_frame++;
}
coverage_segment = MEM_cnew<MovieTrackingDopesheetCoverageSegment>(
coverage_segment = MEM_callocN<MovieTrackingDopesheetCoverageSegment>(
"tracking coverage segment");
coverage_segment->coverage = prev_coverage;
coverage_segment->start_frame = last_segment_frame;

View file

@ -411,8 +411,8 @@ static void autotrack_context_init_image_accessor(AutoTrackContext *context)
clips[i] = context->autotrack_clips[i].clip;
}
MovieTrackingTrack **tracks = MEM_cnew_array<MovieTrackingTrack *>(context->num_all_tracks,
"image accessor init tracks");
MovieTrackingTrack **tracks = MEM_calloc_arrayN<MovieTrackingTrack *>(
context->num_all_tracks, "image accessor init tracks");
for (int i = 0; i < context->num_all_tracks; ++i) {
tracks[i] = context->all_autotrack_tracks[i].track;
}
@ -467,8 +467,8 @@ static void autotrack_context_init_autotrack(AutoTrackContext *context)
}
/* Allocate memory for all the markers. */
libmv_Marker *libmv_markers = MEM_cnew_array<libmv_Marker>(num_trackable_markers,
"libmv markers array");
libmv_Marker *libmv_markers = MEM_calloc_arrayN<libmv_Marker>(num_trackable_markers,
"libmv markers array");
/* Fill in markers array. */
int num_filled_libmv_markers = 0;
@ -508,8 +508,8 @@ static void autotrack_context_init_markers(AutoTrackContext *context)
}
/* Allocate required memory. */
context->autotrack_markers = MEM_cnew_array<AutoTrackMarker>(context->num_autotrack_markers,
"auto track options");
context->autotrack_markers = MEM_calloc_arrayN<AutoTrackMarker>(context->num_autotrack_markers,
"auto track options");
/* Fill in all the markers. */
int autotrack_marker_index = 0;
@ -542,7 +542,7 @@ AutoTrackContext *BKE_autotrack_context_new(MovieClip *clip,
MovieClipUser *user,
const bool is_backwards)
{
AutoTrackContext *context = MEM_cnew<AutoTrackContext>("autotrack context");
AutoTrackContext *context = MEM_callocN<AutoTrackContext>("autotrack context");
context->start_scene_frame = user->framenr;
context->is_backwards = is_backwards;
@ -572,8 +572,8 @@ static void reference_keyframed_image_buffers(AutoTrackContext *context)
/* NOTE: This is potentially over-allocating, but it simplifies memory manipulation.
* In practice this is unlikely to be noticed in the profiler as the memory footprint of this
* data is way less of what the tracking process will use. */
context->referenced_image_buffers = MEM_cnew_array<ImBuf *>(context->num_autotrack_markers,
__func__);
context->referenced_image_buffers = MEM_calloc_arrayN<ImBuf *>(context->num_autotrack_markers,
__func__);
context->num_referenced_image_buffers = 0;
@ -651,7 +651,7 @@ static void autotrack_context_step_cb(void *__restrict userdata,
const int new_marker_frame = libmv_current_marker.frame + frame_delta;
AutoTrackTrackingResult *autotrack_result = MEM_cnew<AutoTrackTrackingResult>(
AutoTrackTrackingResult *autotrack_result = MEM_callocN<AutoTrackTrackingResult>(
"autotrack result");
autotrack_result->libmv_marker = libmv_current_marker;
autotrack_result->libmv_marker.frame = new_marker_frame;

View file

@ -26,8 +26,8 @@ static int point_markers_correspondences_on_both_image(
{
Vec2 *x1, *x2;
*r_x1 = x1 = MEM_cnew_array<Vec2>(plane_track->point_tracksnr, "point correspondences x1");
*r_x2 = x2 = MEM_cnew_array<Vec2>(plane_track->point_tracksnr, "point correspondences x2");
*r_x1 = x1 = MEM_calloc_arrayN<Vec2>(plane_track->point_tracksnr, "point correspondences x1");
*r_x2 = x2 = MEM_calloc_arrayN<Vec2>(plane_track->point_tracksnr, "point correspondences x2");
int correspondence_index = 0;
for (int i = 0; i < plane_track->point_tracksnr; i++) {

View file

@ -76,7 +76,7 @@ static float *track_get_search_floatbuf(ImBuf *ibuf,
width = searchibuf->x;
height = searchibuf->y;
gray_pixels = MEM_cnew_array<float>(width * height, "tracking floatBuf");
gray_pixels = MEM_calloc_arrayN<float>(width * height, "tracking floatBuf");
if (searchibuf->float_buffer.data) {
float_rgba_to_gray(

View file

@ -162,7 +162,7 @@ static bool reconstruct_retrieve_libmv_tracks(MovieReconstructContext *context,
reconstruction->camnr = 0;
reconstruction->cameras = nullptr;
MovieReconstructedCamera *reconstructed_cameras = MEM_cnew_array<MovieReconstructedCamera>(
MovieReconstructedCamera *reconstructed_cameras = MEM_calloc_arrayN<MovieReconstructedCamera>(
(efra - sfra + 1), "temp reconstructed camera");
for (int a = sfra; a <= efra; a++) {
@ -213,8 +213,8 @@ static bool reconstruct_retrieve_libmv_tracks(MovieReconstructContext *context,
if (reconstruction->camnr) {
const size_t size = reconstruction->camnr * sizeof(MovieReconstructedCamera);
reconstruction->cameras = MEM_cnew_array<MovieReconstructedCamera>(reconstruction->camnr,
"reconstructed camera");
reconstruction->cameras = MEM_calloc_arrayN<MovieReconstructedCamera>(reconstruction->camnr,
"reconstructed camera");
memcpy(reconstruction->cameras, reconstructed_cameras, size);
}
@ -324,7 +324,7 @@ MovieReconstructContext *BKE_tracking_reconstruction_context_new(
int height)
{
MovieTracking *tracking = &clip->tracking;
MovieReconstructContext *context = MEM_cnew<MovieReconstructContext>(
MovieReconstructContext *context = MEM_callocN<MovieReconstructContext>(
"MovieReconstructContext data");
const float aspy = 1.0f / tracking->camera.pixel_aspect;
const int num_tracks = BLI_listbase_count(&tracking_object->tracks);

View file

@ -202,7 +202,7 @@ static void use_values_from_fcurves(StabContext *ctx, bool toggle)
*/
static StabContext *init_stabilization_working_context(MovieClip *clip)
{
StabContext *ctx = MEM_cnew<StabContext>("2D stabilization animation runtime data");
StabContext *ctx = MEM_callocN<StabContext>("2D stabilization animation runtime data");
ctx->clip = clip;
ctx->tracking = &clip->tracking;
ctx->stab = &clip->tracking.stabilization;
@ -869,7 +869,7 @@ static void init_all_tracks(StabContext *ctx, float aspect)
LISTBASE_FOREACH (MovieTrackingTrack *, track, &tracking_camera_object->tracks) {
TrackStabilizationBase *local_data = access_stabilization_baseline_data(ctx, track);
if (!local_data) {
local_data = MEM_cnew<TrackStabilizationBase>("2D stabilization per track baseline data");
local_data = MEM_callocN<TrackStabilizationBase>("2D stabilization per track baseline data");
attach_stabilization_baseline_data(ctx, track, local_data);
}
BLI_assert(local_data != nullptr);
@ -882,7 +882,7 @@ static void init_all_tracks(StabContext *ctx, float aspect)
return;
}
order = MEM_cnew_array<TrackInitOrder>(track_len, "stabilization track order");
order = MEM_calloc_arrayN<TrackInitOrder>(track_len, "stabilization track order");
if (!order) {
return;
}

View file

@ -50,13 +50,13 @@
TracksMap *tracks_map_new(const char *object_name, int num_tracks)
{
TracksMap *map = MEM_cnew<TracksMap>("TrackingsMap");
TracksMap *map = MEM_callocN<TracksMap>("TrackingsMap");
STRNCPY(map->object_name, object_name);
map->num_tracks = num_tracks;
map->tracks = MEM_cnew_array<MovieTrackingTrack>(num_tracks, "TrackingsMap tracks");
map->tracks = MEM_calloc_arrayN<MovieTrackingTrack>(num_tracks, "TrackingsMap tracks");
map->hash = BLI_ghash_ptr_new("TracksMap hash");
@ -625,7 +625,7 @@ static ImBuf *make_grayscale_ibuf_copy(ImBuf *ibuf)
*/
const size_t num_pixels = size_t(grayscale->x) * size_t(grayscale->y);
grayscale->channels = 1;
float *rect_float = MEM_cnew_array<float>(num_pixels, "tracking grayscale image");
float *rect_float = MEM_calloc_arrayN<float>(num_pixels, "tracking grayscale image");
if (rect_float != nullptr) {
IMB_assign_float_buffer(grayscale, rect_float, IB_TAKE_OWNERSHIP);
@ -653,7 +653,7 @@ static ImBuf *float_image_to_ibuf(libmv_FloatImage *float_image)
ImBuf *ibuf = IMB_allocImBuf(float_image->width, float_image->height, 32, 0);
size_t num_total_channels = size_t(ibuf->x) * size_t(ibuf->y) * float_image->channels;
ibuf->channels = float_image->channels;
float *rect_float = MEM_cnew_array<float>(num_total_channels, "tracking grayscale image");
float *rect_float = MEM_calloc_arrayN<float>(num_total_channels, "tracking grayscale image");
if (rect_float != nullptr) {
IMB_assign_float_buffer(ibuf, rect_float, IB_TAKE_OWNERSHIP);
@ -885,14 +885,14 @@ TrackingImageAccessor *tracking_image_accessor_new(MovieClip *clips[MAX_ACCESSOR
MovieTrackingTrack **tracks,
int num_tracks)
{
TrackingImageAccessor *accessor = MEM_cnew<TrackingImageAccessor>("tracking image accessor");
TrackingImageAccessor *accessor = MEM_callocN<TrackingImageAccessor>("tracking image accessor");
BLI_assert(num_clips <= MAX_ACCESSOR_CLIP);
memcpy(accessor->clips, clips, num_clips * sizeof(MovieClip *));
accessor->num_clips = num_clips;
accessor->tracks = MEM_cnew_array<MovieTrackingTrack *>(num_tracks, "image accessor tracks");
accessor->tracks = MEM_calloc_arrayN<MovieTrackingTrack *>(num_tracks, "image accessor tracks");
memcpy(accessor->tracks, tracks, num_tracks * sizeof(MovieTrackingTrack *));
accessor->num_tracks = num_tracks;

View file

@ -269,7 +269,7 @@ static void undosys_stack_validate(UndoStack * /*ustack*/, bool /*expect_non_emp
UndoStack *BKE_undosys_stack_create()
{
UndoStack *ustack = MEM_cnew<UndoStack>(__func__);
UndoStack *ustack = MEM_callocN<UndoStack>(__func__);
return ustack;
}
@ -907,7 +907,7 @@ bool BKE_undosys_step_redo(UndoStack *ustack, bContext *C)
UndoType *BKE_undosys_type_append(void (*undosys_fn)(UndoType *))
{
UndoType *ut = MEM_cnew<UndoType>(__func__);
UndoType *ut = MEM_callocN<UndoType>(__func__);
undosys_fn(ut);

View file

@ -174,7 +174,7 @@ void BKE_viewer_path_id_remap(ViewerPath *viewer_path,
template<typename T> static T *make_elem(const ViewerPathElemType type)
{
T *elem = MEM_cnew<T>(__func__);
T *elem = MEM_callocN<T>(__func__);
elem->base.type = type;
return elem;
}

View file

@ -239,7 +239,7 @@ static void workspace_relation_add(ListBase *relation_list,
const int parentid,
void *data)
{
WorkSpaceDataRelation *relation = MEM_cnew<WorkSpaceDataRelation>(__func__);
WorkSpaceDataRelation *relation = MEM_callocN<WorkSpaceDataRelation>(__func__);
relation->parent = parent;
relation->parentid = parentid;
relation->value = data;
@ -336,7 +336,7 @@ void BKE_workspace_remove(Main *bmain, WorkSpace *workspace)
WorkSpaceInstanceHook *BKE_workspace_instance_hook_create(const Main *bmain, const int winid)
{
WorkSpaceInstanceHook *hook = MEM_cnew<WorkSpaceInstanceHook>(__func__);
WorkSpaceInstanceHook *hook = MEM_callocN<WorkSpaceInstanceHook>(__func__);
/* set an active screen-layout for each possible window/workspace combination */
for (WorkSpace *workspace = static_cast<WorkSpace *>(bmain->workspaces.first); workspace;
@ -380,7 +380,7 @@ WorkSpaceLayout *BKE_workspace_layout_add(Main *bmain,
bScreen *screen,
const char *name)
{
WorkSpaceLayout *layout = MEM_cnew<WorkSpaceLayout>(__func__);
WorkSpaceLayout *layout = MEM_callocN<WorkSpaceLayout>(__func__);
BLI_assert(!workspaces_is_screen_used(bmain, screen));
#ifdef NDEBUG

View file

@ -108,8 +108,8 @@ static void args_print_wrapper(void * /*user_data*/, const char *format, va_list
bArgs *BLI_args_create(int argc, const char **argv)
{
bArgs *ba = MEM_cnew<bArgs>("bArgs");
ba->passes = MEM_cnew_array<int>(argc, "bArgs passes");
bArgs *ba = MEM_callocN<bArgs>("bArgs");
ba->passes = MEM_calloc_arrayN<int>(argc, "bArgs passes");
ba->items = BLI_ghash_new(keyhash, keycmp, "bArgs passes gh");
BLI_listbase_clear(&ba->docs);
ba->argc = argc;
@ -166,7 +166,7 @@ static bArgDoc *internalDocs(bArgs *ba,
{
bArgDoc *d;
d = MEM_cnew<bArgDoc>("bArgDoc");
d = MEM_callocN<bArgDoc>("bArgDoc");
if (doc == nullptr) {
doc = NO_DOCS;
@ -202,8 +202,8 @@ static void internalAdd(
a->key->case_str == 1 ? "not " : "");
}
a = MEM_cnew<bArgument>("bArgument");
key = MEM_cnew<bAKey>("bAKey");
a = MEM_callocN<bArgument>("bArgument");
key = MEM_callocN<bAKey>("bAKey");
key->arg = arg;
key->pass = pass;

View file

@ -36,7 +36,7 @@ struct Dial {
Dial *BLI_dial_init(const float start_position[2], float threshold)
{
Dial *dial = MEM_cnew<Dial>("dial");
Dial *dial = MEM_callocN<Dial>("dial");
copy_v2_v2(dial->center, start_position);
dial->threshold_squared = threshold * threshold;

View file

@ -35,12 +35,12 @@ struct DynStr {
DynStr *BLI_dynstr_new()
{
return MEM_cnew<DynStr>("DynStr");
return MEM_callocN<DynStr>("DynStr");
}
DynStr *BLI_dynstr_new_memarena()
{
DynStr *ds = MEM_cnew<DynStr>("DynStr");
DynStr *ds = MEM_callocN<DynStr>("DynStr");
ds->memarena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
return ds;

View file

@ -416,7 +416,7 @@ static GHash *ghash_new(GHashHashFP hashfp,
const uint nentries_reserve,
const uint flag)
{
GHash *gh = MEM_cnew<GHash>(info);
GHash *gh = MEM_callocN<GHash>(info);
gh->hashfp = hashfp;
gh->cmpfp = cmpfp;
@ -887,7 +887,7 @@ void BLI_ghash_flag_clear(GHash *gh, uint flag)
GHashIterator *BLI_ghashIterator_new(GHash *gh)
{
GHashIterator *ghi = MEM_cnew<GHashIterator>("ghash iterator");
GHashIterator *ghi = MEM_callocN<GHashIterator>("ghash iterator");
BLI_ghashIterator_init(ghi, gh);
return ghi;
}

View file

@ -170,11 +170,11 @@ static void heap_node_free(Heap *heap, HeapNode *node)
Heap *BLI_heap_new_ex(uint reserve_num)
{
Heap *heap = MEM_cnew<Heap>(__func__);
Heap *heap = MEM_callocN<Heap>(__func__);
/* ensure we have at least one so we can keep doubling it */
heap->size = 0;
heap->bufsize = std::max(1u, reserve_num);
heap->tree = MEM_cnew_array<HeapNode *>(heap->bufsize, "BLIHeapTree");
heap->tree = MEM_calloc_arrayN<HeapNode *>(heap->bufsize, "BLIHeapTree");
heap->nodes.chunk = heap_node_alloc_chunk(
(reserve_num > 1) ? reserve_num : HEAP_CHUNK_DEFAULT_NUM, nullptr);

View file

@ -138,11 +138,11 @@ static void heapsimple_up(HeapSimple *heap, uint i, float active_val, void *acti
HeapSimple *BLI_heapsimple_new_ex(uint reserve_num)
{
HeapSimple *heap = MEM_cnew<HeapSimple>(__func__);
HeapSimple *heap = MEM_callocN<HeapSimple>(__func__);
/* ensure we have at least one so we can keep doubling it */
heap->size = 0;
heap->bufsize = std::max(1u, reserve_num);
heap->tree = MEM_cnew_array<HeapSimpleNode>(heap->bufsize, "BLIHeapSimpleTree");
heap->tree = MEM_calloc_arrayN<HeapSimpleNode>(heap->bufsize, "BLIHeapSimpleTree");
return heap;
}

View file

@ -856,7 +856,7 @@ BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis)
BLI_assert(tree_type >= 2 && tree_type <= MAX_TREETYPE);
BVHTree *tree = MEM_cnew<BVHTree>(__func__);
BVHTree *tree = MEM_callocN<BVHTree>(__func__);
/* tree epsilon must be >= FLT_EPSILON
* so that tangent rays can still hit a bounding volume..
@ -899,10 +899,10 @@ BVHTree *BLI_bvhtree_new(int maxsize, float epsilon, char tree_type, char axis)
/* Allocate arrays */
numnodes = maxsize + implicit_needed_branches(tree_type, maxsize) + tree_type;
tree->nodes = MEM_cnew_array<BVHNode *>(size_t(numnodes), "BVHNodes");
tree->nodebv = MEM_cnew_array<float>(axis * size_t(numnodes), "BVHNodeBV");
tree->nodechild = MEM_cnew_array<BVHNode *>(tree_type * size_t(numnodes), "BVHNodeBV");
tree->nodearray = MEM_cnew_array<BVHNode>(size_t(numnodes), "BVHNodeArray");
tree->nodes = MEM_calloc_arrayN<BVHNode *>(size_t(numnodes), "BVHNodes");
tree->nodebv = MEM_calloc_arrayN<float>(axis * size_t(numnodes), "BVHNodeBV");
tree->nodechild = MEM_calloc_arrayN<BVHNode *>(tree_type * size_t(numnodes), "BVHNodeBV");
tree->nodearray = MEM_calloc_arrayN<BVHNode>(size_t(numnodes), "BVHNodeArray");
if (UNLIKELY((!tree->nodes) || (!tree->nodebv) || (!tree->nodechild) || (!tree->nodearray))) {
goto fail;

View file

@ -237,7 +237,7 @@ void *BLI_linklist_pop_pool(LinkNode **listp, BLI_mempool *mempool)
void BLI_linklist_insert_after(LinkNode **listp, void *ptr)
{
LinkNode *nlink = MEM_cnew<LinkNode>(__func__);
LinkNode *nlink = MEM_callocN<LinkNode>(__func__);
LinkNode *node = *listp;
nlink->link = ptr;

View file

@ -65,7 +65,7 @@ static void memarena_buf_free_all(MemBuf *mb)
MemArena *BLI_memarena_new(const size_t bufsize, const char *name)
{
MemArena *ma = MEM_cnew<MemArena>("memarena");
MemArena *ma = MEM_callocN<MemArena>("memarena");
ma->bufsize = bufsize;
ma->align = 8;
ma->name = name;
@ -130,8 +130,13 @@ void *BLI_memarena_alloc(MemArena *ma, size_t size)
ma->cursize = ma->bufsize;
}
MemBuf *mb = static_cast<MemBuf *>(
(ma->use_calloc ? MEM_callocN : MEM_mallocN)(sizeof(*mb) + ma->cursize, ma->name));
MemBuf *mb;
if (ma->use_calloc) {
mb = static_cast<MemBuf *>(MEM_callocN(sizeof(*mb) + ma->cursize, ma->name));
}
else {
mb = static_cast<MemBuf *>(MEM_mallocN(sizeof(*mb) + ma->cursize, ma->name));
}
ma->curbuf = mb->data;
mb->next = ma->bufs;
ma->bufs = mb;

View file

@ -47,13 +47,13 @@ BLI_memblock *BLI_memblock_create_ex(uint elem_size, uint chunk_size)
{
BLI_assert(elem_size < chunk_size);
BLI_memblock *mblk = MEM_cnew<BLI_memblock>("BLI_memblock");
BLI_memblock *mblk = MEM_callocN<BLI_memblock>("BLI_memblock");
mblk->elem_size = int(elem_size);
mblk->elem_next = 0;
mblk->elem_last = -1;
mblk->chunk_size = int(chunk_size);
mblk->chunk_len = CHUNK_LIST_SIZE;
mblk->chunk_list = MEM_cnew_array<void *>(size_t(mblk->chunk_len), "chunk list");
mblk->chunk_list = MEM_calloc_arrayN<void *>(size_t(mblk->chunk_len), "chunk list");
mblk->chunk_list[0] = MEM_mallocN_aligned(size_t(mblk->chunk_size), 32, "BLI_memblock chunk");
memset(mblk->chunk_list[0], 0x0, uint(mblk->chunk_size));
mblk->chunk_max_ofs = (mblk->chunk_size / mblk->elem_size) * mblk->elem_size;

View file

@ -115,7 +115,7 @@ static void memiter_init(BLI_memiter *mi)
BLI_memiter *BLI_memiter_create(uint chunk_size_min)
{
BLI_memiter *mi = MEM_cnew<BLI_memiter>("BLI_memiter");
BLI_memiter *mi = MEM_callocN<BLI_memiter>("BLI_memiter");
memiter_init(mi);
/* Small values are used for tests to check for correctness,

View file

@ -340,7 +340,7 @@ BLI_mempool *BLI_mempool_create(uint esize, uint elem_num, uint pchunk, uint fla
uint i, maxchunks;
/* allocate the pool structure */
pool = MEM_cnew<BLI_mempool>("memory pool");
pool = MEM_callocN<BLI_mempool>("memory pool");
#ifdef WITH_ASAN
BLI_mutex_init(&pool->mutex);
@ -618,8 +618,9 @@ ParallelMempoolTaskData *mempool_iter_threadsafe_create(BLI_mempool *pool, const
{
BLI_assert(pool->flag & BLI_MEMPOOL_ALLOW_ITER);
ParallelMempoolTaskData *iter_arr = MEM_cnew_array<ParallelMempoolTaskData>(iter_num, __func__);
BLI_mempool_chunk **curchunk_threaded_shared = MEM_cnew<BLI_mempool_chunk *>(__func__);
ParallelMempoolTaskData *iter_arr = MEM_calloc_arrayN<ParallelMempoolTaskData>(iter_num,
__func__);
BLI_mempool_chunk **curchunk_threaded_shared = MEM_callocN<BLI_mempool_chunk *>(__func__);
mempool_threadsafe_iternew(pool, &iter_arr->ts_iter);

View file

@ -167,7 +167,7 @@ BLI_mmap_file *BLI_mmap_open(int fd)
#endif
/* Now that the mapping was successful, allocate memory and set up the BLI_mmap_file. */
BLI_mmap_file *file = MEM_cnew<BLI_mmap_file>(__func__);
BLI_mmap_file *file = MEM_callocN<BLI_mmap_file>(__func__);
file->memory = static_cast<char *>(memory);
file->handle = handle;
file->length = length;

View file

@ -38,7 +38,7 @@ void BLI_timer_register(uintptr_t uuid,
double first_interval,
bool persistent)
{
TimedFunction *timed_func = MEM_cnew<TimedFunction>(__func__);
TimedFunction *timed_func = MEM_callocN<TimedFunction>(__func__);
timed_func->func = func;
timed_func->user_data_free = user_data_free;
timed_func->user_data = user_data;

View file

@ -1497,7 +1497,7 @@ BArrayStore *BLI_array_store_create(uint stride, uint chunk_count)
{
BLI_assert(stride > 0 && chunk_count > 0);
BArrayStore *bs = MEM_cnew<BArrayStore>(__func__);
BArrayStore *bs = MEM_callocN<BArrayStore>(__func__);
bs->info.chunk_stride = stride;
// bs->info.chunk_count = chunk_count;
@ -1656,7 +1656,7 @@ BArrayState *BLI_array_store_state_add(BArrayStore *bs,
chunk_list->users += 1;
BArrayState *state = MEM_cnew<BArrayState>(__func__);
BArrayState *state = MEM_callocN<BArrayState>(__func__);
state->chunk_list = chunk_list;
BLI_addtail(&bs->states, state);

View file

@ -655,7 +655,7 @@ void BLI_box_pack_2d(
void BLI_box_pack_2d_fixedarea(ListBase *boxes, int width, int height, ListBase *packed)
{
ListBase spaces = {nullptr};
FixedSizeBoxPack *full_rect = MEM_cnew<FixedSizeBoxPack>(__func__);
FixedSizeBoxPack *full_rect = MEM_callocN<FixedSizeBoxPack>(__func__);
full_rect->w = width;
full_rect->h = height;
@ -717,7 +717,7 @@ void BLI_box_pack_2d_fixedarea(ListBase *boxes, int width, int height, ListBase
/* Perform split. This space becomes the larger space,
* while the new smaller space is inserted _before_ it. */
FixedSizeBoxPack *new_space = MEM_cnew<FixedSizeBoxPack>(__func__);
FixedSizeBoxPack *new_space = MEM_callocN<FixedSizeBoxPack>(__func__);
if (area_hsplit_large > area_vsplit_large) {
new_space->x = space->x + box->w;
new_space->y = space->y;

View file

@ -403,7 +403,7 @@ bool BLI_dir_create_recursive(const char *dirname)
size_t len = strlen(dirname);
if (len >= sizeof(dirname_static_buf)) {
dirname_mut = MEM_cnew_array<char>(len + 1, __func__);
dirname_mut = MEM_calloc_arrayN<char>(len + 1, __func__);
}
memcpy(dirname_mut, dirname, len + 1);
@ -786,7 +786,7 @@ static const char *path_destination_ensure_filename(const char *path_src,
size_t buf_size_needed = path_dst_len + strlen(filename_src) + 1;
char *path_dst_with_filename = (buf_size_needed <= buf_size) ?
buf :
MEM_cnew_array<char>(buf_size_needed, __func__);
MEM_calloc_arrayN<char>(buf_size_needed, __func__);
BLI_string_join(path_dst_with_filename, buf_size_needed, path_dst, filename_src);
return path_dst_with_filename;
}
@ -1389,7 +1389,7 @@ static int copy_single_file(const char *from, const char *to)
need_free = 0;
}
else {
link_buffer = MEM_cnew_array<char>(st.st_size + 2, "copy_single_file link_buffer");
link_buffer = MEM_calloc_arrayN<char>(st.st_size + 2, "copy_single_file link_buffer");
need_free = 1;
}
@ -1512,7 +1512,7 @@ static const char *path_destination_ensure_filename(const char *path_src,
const size_t buf_size_needed = strlen(path_dst) + 1 + strlen(filename_src) + 1;
char *path_dst_with_filename = (buf_size_needed <= buf_size) ?
buf :
MEM_cnew_array<char>(buf_size_needed, __func__);
MEM_calloc_arrayN<char>(buf_size_needed, __func__);
BLI_path_join(path_dst_with_filename, buf_size_needed, path_dst, filename_src);
path_dst = path_dst_with_filename;
}

View file

@ -53,7 +53,7 @@ static void file_close(FileReader *reader)
FileReader *BLI_filereader_new_file(int filedes)
{
RawFileReader *rawfile = MEM_cnew<RawFileReader>(__func__);
RawFileReader *rawfile = MEM_callocN<RawFileReader>(__func__);
rawfile->filedes = filedes;

View file

@ -74,7 +74,7 @@ static void gzip_close(FileReader *reader)
FileReader *BLI_filereader_new_gzip(FileReader *base)
{
GzipReader *gzip = MEM_cnew<GzipReader>(__func__);
GzipReader *gzip = MEM_callocN<GzipReader>(__func__);
gzip->base = base;
if (inflateInit2(&gzip->strm, 16 + MAX_WBITS) != Z_OK) {

View file

@ -70,7 +70,7 @@ static void memory_close_raw(FileReader *reader)
FileReader *BLI_filereader_new_memory(const void *data, size_t len)
{
MemoryReader *mem = MEM_cnew<MemoryReader>(__func__);
MemoryReader *mem = MEM_callocN<MemoryReader>(__func__);
mem->data = (const char *)data;
mem->length = len;
@ -118,7 +118,7 @@ FileReader *BLI_filereader_new_mmap(int filedes)
return nullptr;
}
MemoryReader *mem = MEM_cnew<MemoryReader>(__func__);
MemoryReader *mem = MEM_callocN<MemoryReader>(__func__);
mem->mmap = mmap;
mem->length = BLI_mmap_get_length(mmap);

View file

@ -303,7 +303,7 @@ static void zstd_close(FileReader *reader)
FileReader *BLI_filereader_new_zstd(FileReader *base)
{
ZstdReader *zstd = MEM_cnew<ZstdReader>(__func__);
ZstdReader *zstd = MEM_callocN<ZstdReader>(__func__);
zstd->ctx = ZSTD_createDCtx();
zstd->base = base;

View file

@ -71,7 +71,7 @@ static size_t queue_chunk_elem_max_calc(const size_t elem_size, size_t chunk_siz
GSQueue *BLI_gsqueue_new(const size_t elem_size)
{
GSQueue *queue = MEM_cnew<GSQueue>("BLI_gsqueue_new");
GSQueue *queue = MEM_callocN<GSQueue>("BLI_gsqueue_new");
queue->chunk_elem_max = queue_chunk_elem_max_calc(elem_size, CHUNK_SIZE_DEFAULT);
queue->elem_size = elem_size;

View file

@ -94,7 +94,7 @@ KDTree *BLI_kdtree_nd_(new)(uint nodes_len_capacity)
{
KDTree *tree;
tree = MEM_cnew<KDTree>("KDTree");
tree = MEM_callocN<KDTree>("KDTree");
tree->nodes = static_cast<KDTreeNode *>(
MEM_mallocN(sizeof(KDTreeNode) * nodes_len_capacity, "KDTreeNode"));
tree->nodes_len = 0;

View file

@ -916,7 +916,7 @@ LinkData *BLI_genericNodeN(void *data)
}
/* create new link, and make it hold the given data */
ld = MEM_cnew<LinkData>(__func__);
ld = MEM_callocN<LinkData>(__func__);
ld->data = data;
return ld;

View file

@ -1988,9 +1988,9 @@ int BLI_path_cmp_normalized(const char *p1, const char *p2)
const size_t p2_size = strlen(p2) + 1;
char *norm_p1 = (p1_size <= sizeof(norm_p1_buf)) ? norm_p1_buf :
MEM_cnew_array<char>(p1_size, __func__);
MEM_calloc_arrayN<char>(p1_size, __func__);
char *norm_p2 = (p2_size <= sizeof(norm_p2_buf)) ? norm_p2_buf :
MEM_cnew_array<char>(p2_size, __func__);
MEM_calloc_arrayN<char>(p2_size, __func__);
memcpy(norm_p1, p1, p1_size);
memcpy(norm_p2, p2, p2_size);

View file

@ -1067,7 +1067,7 @@ uint BLI_scanfill_calc_ex(ScanFillContext *sf_ctx, const int flag, const float n
}
#endif
uint *target_map = MEM_cnew_array<uint>(poly, "polycache");
uint *target_map = MEM_calloc_arrayN<uint>(poly, "polycache");
range_vn_u(target_map, poly, 0);
for (a = 0; a < poly; a++) {

Some files were not shown because too many files have changed in this diff Show more