Refactor: Simplify ID Property freeing

This also makes `IDP_CopyProperty` the "opposite"
of `IDP_FreeProperty`, which is what I'd expect.

Two refactoring steps:
* rename IDP_FreeProperty to IDP_FreePropertyContent
* new IDP_FreeProperty function that actually frees the property

Reviewers: brecht

Differential Revision: https://developer.blender.org/D4872
This commit is contained in:
Jacques Lucke 2019-05-16 14:11:11 +02:00
parent c0d743238d
commit db5120603f
Notes: blender-bot 2023-02-13 23:16:02 +01:00
Referenced by commit e60890075b, Cleanup: rename IDP_FreeProperty_ex to IDP_FreePropertyContent_ex
37 changed files with 23 additions and 75 deletions

View File

@ -135,6 +135,7 @@ struct IDProperty *IDP_New(const char type,
const char *name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
void IDP_FreeProperty_ex(struct IDProperty *prop, const bool do_id_user);
void IDP_FreePropertyContent(struct IDProperty *prop);
void IDP_FreeProperty(struct IDProperty *prop);
void IDP_ClearProperty(IDProperty *prop);

View File

@ -822,7 +822,6 @@ void BKE_pose_channel_free_ex(bPoseChannel *pchan, bool do_id_user)
if (pchan->prop) {
IDP_FreeProperty(pchan->prop);
MEM_freeN(pchan->prop);
}
/* Cached data, for new draw manager rendering code. */
@ -964,7 +963,6 @@ void BKE_pose_channel_copy_data(bPoseChannel *pchan, const bPoseChannel *pchan_f
if (pchan->prop) {
/* unlikely but possible it exists */
IDP_FreeProperty(pchan->prop);
MEM_freeN(pchan->prop);
pchan->prop = NULL;
}
if (pchan_from->prop) {

View File

@ -81,7 +81,6 @@ void BKE_addon_free(bAddon *addon)
{
if (addon->prop) {
IDP_FreeProperty(addon->prop);
MEM_freeN(addon->prop);
}
MEM_freeN(addon);
}

View File

@ -112,7 +112,6 @@ void BKE_armature_bonelist_free(ListBase *lb)
for (bone = lb->first; bone; bone = bone->next) {
if (bone->prop) {
IDP_FreeProperty(bone->prop);
MEM_freeN(bone->prop);
}
BKE_armature_bonelist_free(&bone->childbase);
}
@ -2430,7 +2429,6 @@ static void pose_proxy_synchronize(Object *ob, Object *from, int layer_protected
}
if (prop_orig) {
IDP_FreeProperty(prop_orig);
MEM_freeN(prop_orig);
}
}
}

View File

@ -155,7 +155,6 @@ static void keymap_item_free(wmKeyMapItem *kmi)
{
if (kmi->properties) {
IDP_FreeProperty(kmi->properties);
MEM_freeN(kmi->properties);
}
if (kmi->ptr) {
MEM_freeN(kmi->ptr);
@ -212,7 +211,6 @@ static void userdef_free_keyconfig_prefs(UserDef *userdef)
kpt = kpt_next) {
kpt_next = kpt->next;
IDP_FreeProperty(kpt->prop);
MEM_freeN(kpt->prop);
MEM_freeN(kpt);
}
BLI_listbase_clear(&userdef->user_keyconfig_prefs);

View File

@ -97,7 +97,6 @@ void BKE_blender_user_menu_item_free(bUserMenuItem *umi)
bUserMenuItem_Op *umi_op = (bUserMenuItem_Op *)umi;
if (umi_op->prop) {
IDP_FreeProperty(umi_op->prop);
MEM_freeN(umi_op->prop);
}
}
MEM_freeN(umi);

View File

@ -2113,7 +2113,6 @@ static void pycon_free(bConstraint *con)
/* id-properties */
IDP_FreeProperty(data->prop);
MEM_freeN(data->prop);
/* multiple targets */
BLI_freelistN(&data->targets);

View File

@ -867,7 +867,6 @@ static void fcm_python_free(FModifier *fcm)
/* id-properties */
IDP_FreeProperty(data->prop);
MEM_freeN(data->prop);
}
static void fcm_python_new_data(void *mdata)

View File

@ -142,7 +142,7 @@ void IDP_SetIndexArray(IDProperty *prop, int index, IDProperty *item)
old = GETPROP(prop, index);
if (item != old) {
IDP_FreeProperty(old);
IDP_FreePropertyContent(old);
memcpy(old, item, sizeof(IDProperty));
}
@ -175,7 +175,7 @@ void IDP_ResizeIDPArray(IDProperty *prop, int newlen)
int i;
for (i = newlen; i < prop->len; i++) {
IDP_FreeProperty(GETPROP(prop, i));
IDP_FreePropertyContent(GETPROP(prop, i));
}
prop->len = newlen;
@ -192,7 +192,7 @@ void IDP_ResizeIDPArray(IDProperty *prop, int newlen)
/* newlen is smaller */
int i;
for (i = newlen; i < prop->len; i++) {
IDP_FreeProperty(GETPROP(prop, i));
IDP_FreePropertyContent(GETPROP(prop, i));
}
}
@ -236,7 +236,6 @@ static void idp_resize_group_array(IDProperty *prop, int newlen, void *newarr)
for (a = newlen; a < prop->len; a++) {
IDP_FreeProperty(array[a]);
MEM_freeN(array[a]);
}
}
}
@ -513,7 +512,6 @@ void IDP_SyncGroupValues(IDProperty *dest, const IDProperty *src)
default: {
BLI_insertlinkreplace(&dest->data.group, other, IDP_CopyProperty(prop));
IDP_FreeProperty(other);
MEM_freeN(other);
break;
}
}
@ -535,7 +533,6 @@ void IDP_SyncGroupTypes(IDProperty *dst, const IDProperty *src, const bool do_ar
(prop_src->len != prop_dst->len))) {
BLI_insertlinkreplace(&dst->data.group, prop_dst, IDP_CopyProperty(prop_src));
IDP_FreeProperty(prop_dst);
MEM_freeN(prop_dst);
}
else if (prop_dst->type == IDP_GROUP) {
IDP_SyncGroupTypes(prop_dst, prop_src, do_arraylen);
@ -562,7 +559,6 @@ void IDP_ReplaceGroupInGroup(IDProperty *dest, const IDProperty *src)
if (STREQ(loop->name, prop->name)) {
BLI_insertlinkreplace(&dest->data.group, loop, IDP_CopyProperty(prop));
IDP_FreeProperty(loop);
MEM_freeN(loop);
break;
}
}
@ -588,7 +584,6 @@ void IDP_ReplaceInGroup_ex(IDProperty *group, IDProperty *prop, IDProperty *prop
if (prop_exist != NULL) {
BLI_insertlinkreplace(&group->data.group, prop_exist, prop);
IDP_FreeProperty(prop_exist);
MEM_freeN(prop_exist);
}
else {
group->len++;
@ -668,12 +663,6 @@ void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, const bool do_overw
* (the function that adds new properties to groups, #IDP_AddToGroup,
* returns false if a property can't be added to the group, and true if it can)
* and free the property.
*
* Currently the code to free ID properties is designed to leave the actual struct
* you pass it un-freed, this is needed for how the system works. This means
* to free an ID property, you first call #IDP_FreeProperty then #MEM_freeN the struct.
* In the future this will just be #IDP_FreeProperty and the code will
* be reorganized to work properly.
*/
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop)
{
@ -709,8 +698,7 @@ bool IDP_InsertToGroup(IDProperty *group, IDProperty *previous, IDProperty *pnew
* \note this does not free the property!!
*
* To free the property, you have to do:
* IDP_FreeProperty(prop); //free all subdata
* MEM_freeN(prop); //free property struct itself
* IDP_FreeProperty(prop);
*/
void IDP_RemoveFromGroup(IDProperty *group, IDProperty *prop)
{
@ -727,7 +715,6 @@ void IDP_FreeFromGroup(IDProperty *group, IDProperty *prop)
{
IDP_RemoveFromGroup(group, prop);
IDP_FreeProperty(prop);
MEM_freeN(prop);
}
IDProperty *IDP_GetPropertyFromGroup(IDProperty *prop, const char *name)
@ -1093,14 +1080,20 @@ void IDP_FreeProperty_ex(IDProperty *prop, const bool do_id_user)
}
}
void IDP_FreeProperty(IDProperty *prop)
void IDP_FreePropertyContent(IDProperty *prop)
{
IDP_FreeProperty_ex(prop, true);
}
void IDP_FreeProperty(IDProperty *prop)
{
IDP_FreePropertyContent(prop);
MEM_freeN(prop);
}
void IDP_ClearProperty(IDProperty *prop)
{
IDP_FreeProperty(prop);
IDP_FreePropertyContent(prop);
prop->data.pointer = NULL;
prop->len = prop->totallen = 0;
}

View File

@ -235,7 +235,6 @@ void BKE_view_layer_free_ex(ViewLayer *view_layer, const bool do_id_user)
if (view_layer->id_properties) {
IDP_FreeProperty(view_layer->id_properties);
MEM_freeN(view_layer->id_properties);
}
MEM_SAFE_FREE(view_layer->object_bases_array);

View File

@ -1910,7 +1910,6 @@ static void node_socket_interface_free(bNodeTree *UNUSED(ntree), bNodeSocket *so
{
if (sock->prop) {
IDP_FreeProperty(sock->prop);
MEM_freeN(sock->prop);
}
if (sock->default_value) {

View File

@ -1951,7 +1951,6 @@ void BKE_object_make_proxy(Main *bmain, Object *ob, Object *target, Object *cob)
/* copy IDProperties */
if (ob->id.properties) {
IDP_FreeProperty(ob->id.properties);
MEM_freeN(ob->id.properties);
ob->id.properties = NULL;
}
if (target->id.properties) {
@ -4497,4 +4496,4 @@ void BKE_object_update_select_id(struct Main *bmain)
ob->runtime.select_id = select_id++;
ob = ob->id.next;
}
}
}

View File

@ -497,7 +497,6 @@ void BKE_scene_free_ex(Scene *sce, const bool do_id_user)
}
if (sce->r.ffcodecdata.properties) {
IDP_FreeProperty(sce->r.ffcodecdata.properties);
MEM_freeN(sce->r.ffcodecdata.properties);
sce->r.ffcodecdata.properties = NULL;
}

View File

@ -427,7 +427,6 @@ void BKE_area_region_free(SpaceType *st, ARegion *ar)
}
if (uilst->properties) {
IDP_FreeProperty(uilst->properties);
MEM_freeN(uilst->properties);
}
}

View File

@ -356,7 +356,6 @@ void BKE_workspace_tool_remove(struct WorkSpace *workspace, struct bToolRef *tre
}
if (tref->properties) {
IDP_FreeProperty(tref->properties);
MEM_freeN(tref->properties);
}
BLI_remlink(&workspace->tools, tref);
MEM_freeN(tref);

View File

@ -1616,7 +1616,7 @@ static void ffmpeg_set_expert_options(RenderData *rd)
int codec_id = rd->ffcodecdata.codec;
if (rd->ffcodecdata.properties) {
IDP_FreeProperty(rd->ffcodecdata.properties);
IDP_FreePropertyContent(rd->ffcodecdata.properties);
}
if (codec_id == AV_CODEC_ID_H264) {
@ -1680,7 +1680,7 @@ void BKE_ffmpeg_preset_set(RenderData *rd, int preset)
int isntsc = (rd->frs_sec != 25);
if (rd->ffcodecdata.properties) {
IDP_FreeProperty(rd->ffcodecdata.properties);
IDP_FreePropertyContent(rd->ffcodecdata.properties);
}
switch (preset) {

View File

@ -2537,7 +2537,7 @@ static void _IDP_DirectLinkGroup_OrFree(IDProperty **prop,
/* corrupt file! */
printf("%s: found non group data, freeing type %d!\n", caller_func_id, (*prop)->type);
/* don't risk id, data's likely corrupt. */
// IDP_FreeProperty(*prop);
// IDP_FreePropertyContent(*prop);
*prop = NULL;
}
}

View File

@ -850,7 +850,6 @@ void do_versions_after_linking_280(Main *bmain)
for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
if (srl->prop) {
IDP_FreeProperty(srl->prop);
MEM_freeN(srl->prop);
}
BKE_freestyle_config_free(&srl->freestyleConfig, true);
}
@ -1739,7 +1738,6 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
/* Cleanup. */
IDP_FreeProperty(scene->layer_properties);
MEM_freeN(scene->layer_properties);
scene->layer_properties = NULL;
#undef EEVEE_GET_FLOAT_ARRAY

View File

@ -79,7 +79,6 @@ void BLO_update_defaults_userpref_blend(void)
if (addon->prop) {
IDP_FreeProperty(addon->prop);
MEM_freeN(addon->prop);
addon->prop = NULL;
}
}

View File

@ -94,7 +94,6 @@ void verify_id_properties_freed(DEGObjectIterData *data)
// Free memory which is owned by temporary storage which is about to
// get overwritten.
IDP_FreeProperty(temp_dupli_object->id.properties);
MEM_freeN(temp_dupli_object->id.properties);
temp_dupli_object->id.properties = NULL;
}

View File

@ -127,7 +127,6 @@ void bone_free(bArmature *arm, EditBone *bone)
if (bone->prop) {
IDP_FreeProperty(bone->prop);
MEM_freeN(bone->prop);
}
/* Clear references from other edit bones. */
@ -777,7 +776,6 @@ void ED_armature_edit_free(struct bArmature *arm)
for (eBone = arm->edbo->first; eBone; eBone = eBone->next) {
if (eBone->prop) {
IDP_FreeProperty(eBone->prop);
MEM_freeN(eBone->prop);
}
}
@ -811,7 +809,6 @@ void ED_armature_ebone_listbase_free(ListBase *lb)
if (ebone->prop) {
IDP_FreeProperty(ebone->prop);
MEM_freeN(ebone->prop);
}
MEM_freeN(ebone);

View File

@ -1018,7 +1018,6 @@ static void poselib_backup_free_data(tPoseLib_PreviewData *pld)
/* free custom data */
if (plb->oldprops) {
IDP_FreeProperty(plb->oldprops);
MEM_freeN(plb->oldprops);
}
/* free backup element now */

View File

@ -1225,7 +1225,6 @@ static int pose_clear_user_transforms_exec(bContext *C, wmOperator *op)
for (pchan = dummyPose->chanbase.first; pchan; pchan = pchan->next) {
if (pchan->prop) {
IDP_FreeProperty(pchan->prop);
MEM_freeN(pchan->prop);
}
}

View File

@ -203,7 +203,6 @@ void poseAnim_mapping_free(ListBase *pfLinks)
/* free custom properties */
if (pfl->oldprops) {
IDP_FreeProperty(pfl->oldprops);
MEM_freeN(pfl->oldprops);
}
/* free list of F-Curve reference links */

View File

@ -1086,7 +1086,6 @@ static bool ui_but_event_operator_string_from_menu(const bContext *C,
}
IDP_FreeProperty(prop_menu);
MEM_freeN(prop_menu);
return found;
}
@ -1135,7 +1134,6 @@ static bool ui_but_event_operator_string_from_panel(const bContext *C,
}
IDP_FreeProperty(prop_panel);
MEM_freeN(prop_panel);
return found;
}
@ -1356,7 +1354,6 @@ static bool ui_but_event_property_operator_string(const bContext *C,
/* cleanup */
IDP_FreeProperty(prop_path);
MEM_freeN(prop_path);
if (data_path) {
MEM_freeN(data_path);
}

View File

@ -116,7 +116,6 @@ static void shortcut_free_operator_property(IDProperty *prop)
{
if (prop) {
IDP_FreeProperty(prop);
MEM_freeN(prop);
}
}

View File

@ -1455,7 +1455,6 @@ void uiItemsFullEnumO_items(uiLayout *layout,
if (properties) {
if (tptr.data) {
IDP_FreeProperty(tptr.data);
MEM_freeN(tptr.data);
}
tptr.data = IDP_CopyProperty(properties);
}

View File

@ -55,7 +55,6 @@ void IMB_metadata_free(struct IDProperty *metadata)
}
IDP_FreeProperty(metadata);
MEM_freeN(metadata);
}
bool IMB_metadata_get_field(struct IDProperty *metadata,

View File

@ -302,7 +302,7 @@ static IDProperty *rna_idproperty_ui_ensure(PointerRNA *ptr, PropertyRNA *prop,
idprop = IDP_New(IDP_GROUP, &dummy, RNA_IDP_UI);
if (!IDP_AddToGroup(props, idprop)) {
IDP_FreeProperty(idprop);
IDP_FreePropertyContent(idprop);
return NULL;
}
}
@ -316,7 +316,7 @@ static IDProperty *rna_idproperty_ui_ensure(PointerRNA *ptr, PropertyRNA *prop,
rv = IDP_New(IDP_GROUP, &dummy, name);
if (!IDP_AddToGroup(idprop, rv)) {
IDP_FreeProperty(rv);
IDP_FreePropertyContent(rv);
return NULL;
}
}
@ -370,7 +370,7 @@ static bool rna_idproperty_ui_set_default(PointerRNA *ptr,
item = IDP_New(type, value, "default");
if (!IDP_AddToGroup(idp_ui, item)) {
IDP_FreeProperty(item);
IDP_FreePropertyContent(item);
return false;
}
}
@ -3961,7 +3961,7 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA
item = IDP_New(IDP_GROUP, &val, "");
IDP_AppendArray(idprop, item);
/* IDP_AppendArray does a shallow copy (memcpy), only free memory */
/* IDP_FreeProperty(item); */
/* IDP_FreePropertyContent(item); */
MEM_freeN(item);
rna_idproperty_touch(idprop);
}
@ -3977,7 +3977,7 @@ void RNA_property_collection_add(PointerRNA *ptr, PropertyRNA *prop, PointerRNA
item = IDP_New(IDP_GROUP, &val, "");
IDP_AppendArray(idprop, item);
/* IDP_AppendArray does a shallow copy (memcpy), only free memory */
/* IDP_FreeProperty(item); */
/* IDP_FreePropertyContent(item); */
MEM_freeN(item);
}
}

View File

@ -601,7 +601,6 @@ static IDProperty *idp_from_PyMapping(const char *name, PyObject *ob)
pval = PySequence_GetItem(vals, i);
if (BPy_IDProperty_Map_ValidateAndCreate(key, prop, pval) == false) {
IDP_FreeProperty(prop);
MEM_freeN(prop);
Py_XDECREF(keys);
Py_XDECREF(vals);
Py_XDECREF(key);
@ -690,7 +689,7 @@ bool BPy_IDProperty_Map_ValidateAndCreate(PyObject *name_obj, IDProperty *group,
prop->prev = prop_exist->prev;
prop->next = prop_exist->next;
IDP_FreeProperty(prop_exist);
IDP_FreePropertyContent(prop_exist);
*prop_exist = *prop;
MEM_freeN(prop);
}

View File

@ -1122,7 +1122,6 @@ static void pyrna_struct_dealloc(BPy_StructRNA *self)
#ifdef PYRNA_FREE_SUPPORT
if (self->freeptr && self->ptr.data) {
IDP_FreeProperty(self->ptr.data);
MEM_freeN(self->ptr.data);
self->ptr.data = NULL;
}
#endif /* PYRNA_FREE_SUPPORT */

View File

@ -754,7 +754,6 @@ void WM_gizmo_properties_free(PointerRNA *ptr)
if (properties) {
IDP_FreeProperty(properties);
MEM_freeN(properties);
ptr->data = NULL; /* just in case */
}
}

View File

@ -82,7 +82,6 @@ void WM_operator_free(wmOperator *op)
if (op->properties) {
IDP_FreeProperty(op->properties);
MEM_freeN(op->properties);
}
if (op->reports && (op->reports->flag & RPT_FREE)) {

View File

@ -1293,7 +1293,6 @@ static bool operator_last_properties_init_impl(wmOperator *op, IDProperty *last_
IDP_MergeGroup(op->properties, replaceprops, true);
IDP_FreeProperty(replaceprops);
MEM_freeN(replaceprops);
return changed;
}
@ -1316,7 +1315,6 @@ bool WM_operator_last_properties_store(wmOperator *op)
{
if (op->type->last_properties) {
IDP_FreeProperty(op->type->last_properties);
MEM_freeN(op->type->last_properties);
op->type->last_properties = NULL;
}

View File

@ -1412,7 +1412,6 @@ static wmKeyMapItem *wm_keymap_item_find_in_keymap(wmKeyMap *keymap,
}
IDP_FreeProperty(properties_default);
MEM_freeN(properties_default);
}
}
}
@ -1586,7 +1585,6 @@ static wmKeyMapItem *wm_keymap_item_find(const bContext *C,
}
IDP_FreeProperty(properties_temp);
MEM_freeN(properties_temp);
}
}
@ -1625,7 +1623,6 @@ static wmKeyMapItem *wm_keymap_item_find(const bContext *C,
}
IDP_FreeProperty(properties_default);
MEM_freeN(properties_default);
}
}
}
@ -2022,7 +2019,6 @@ void WM_keymap_item_restore_to_default(bContext *C, wmKeyMap *keymap, wmKeyMapIt
if (orig->properties) {
if (kmi->properties) {
IDP_FreeProperty(kmi->properties);
MEM_freeN(kmi->properties);
kmi->properties = NULL;
}

View File

@ -156,7 +156,6 @@ void WM_operatortype_remove_ptr(wmOperatorType *ot)
if (ot->last_properties) {
IDP_FreeProperty(ot->last_properties);
MEM_freeN(ot->last_properties);
}
if (ot->macro.first) {
@ -194,7 +193,6 @@ static void operatortype_ghash_free_cb(wmOperatorType *ot)
{
if (ot->last_properties) {
IDP_FreeProperty(ot->last_properties);
MEM_freeN(ot->last_properties);
}
if (ot->macro.first) {
@ -279,7 +277,6 @@ void WM_operatortype_last_properties_clear_all(void)
if (ot->last_properties) {
IDP_FreeProperty(ot->last_properties);
MEM_freeN(ot->last_properties);
ot->last_properties = NULL;
}
}

View File

@ -691,7 +691,6 @@ void WM_operator_properties_free(PointerRNA *ptr)
if (properties) {
IDP_FreeProperty(properties);
MEM_freeN(properties);
ptr->data = NULL; /* just in case */
}
}