Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Montagne <montagne29@wanadoo.fr>2017-03-29 17:21:40 +0300
committerBastien Montagne <montagne29@wanadoo.fr>2017-03-29 17:21:40 +0300
commitaae70f182b1477dc9f4091cc92582ba21d4679cd (patch)
tree67837f1dd403b761a0a320f0b32391b47265ab8c
parent603aafc9dc82b18b9f1e70d6e025f3d593dc8622 (diff)
Cleanup, minor fixes and serious simplification of idprops.c
Mostly, get rid of id_(un)register, we can just use mere id_us_plus/min as anywhere else in code now. Also, unlink function was not actually used.
-rw-r--r--source/blender/blenkernel/BKE_idprop.h5
-rw-r--r--source/blender/blenkernel/intern/idprop.c122
-rw-r--r--source/blender/blenloader/intern/readfile.c8
-rw-r--r--source/blender/makesrna/intern/rna_access.c10
4 files changed, 39 insertions, 106 deletions
diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h
index a338ee266d5..d86075c1317 100644
--- a/source/blender/blenkernel/BKE_idprop.h
+++ b/source/blender/blenkernel/BKE_idprop.h
@@ -82,9 +82,6 @@ void IDP_FreeString(struct IDProperty *prop) ATTR_NONNULL();
/*-------- ID Type -------*/
-/* Registers the creation of a new ID Property */
-void IDP_id_register(struct IDProperty *prop);
-
typedef void(*IDPWalkFunc)(void *userData, IDProperty *idp);
/*-------- Group Functions -------*/
@@ -119,8 +116,6 @@ void IDP_FreeProperty(struct IDProperty *prop);
void IDP_ClearProperty(IDProperty *prop);
-void IDP_UnlinkProperty(struct IDProperty *prop);
-
void IDP_RelinkProperty(struct IDProperty *prop);
#define IDP_Int(prop) ((prop)->data.val)
diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c
index ff999bcf494..e0cf0c686ff 100644
--- a/source/blender/blenkernel/intern/idprop.c
+++ b/source/blender/blenkernel/intern/idprop.c
@@ -129,19 +129,26 @@ void IDP_FreeIDPArray(IDProperty *prop)
MEM_freeN(prop->data.pointer);
}
-/*shallow copies item*/
+/* shallow copies item */
void IDP_SetIndexArray(IDProperty *prop, int index, IDProperty *item)
{
IDProperty *old;
BLI_assert(prop->type == IDP_IDPARRAY);
+ if (index >= prop->len || index < 0)
+ return;
+
old = GETPROP(prop, index);
- if (index >= prop->len || index < 0) return;
- if (item != old) IDP_FreeProperty(old);
-
- memcpy(GETPROP(prop, index), item, sizeof(IDProperty));
- IDP_id_register(prop);
+ if (item != old) {
+ IDP_FreeProperty(old);
+
+ memcpy(old, item, sizeof(IDProperty));
+
+ if (old->type == IDP_ID) {
+ id_us_plus(IDP_Id(old));
+ }
+ }
}
IDProperty *IDP_GetIndexArray(IDProperty *prop, int index)
@@ -375,20 +382,6 @@ static IDProperty *IDP_CopyString(const IDProperty *prop)
return newp;
}
-static IDProperty *IDP_CopyID(const IDProperty *prop)
-{
- IDProperty *newp;
-
- BLI_assert(prop->type == IDP_ID);
- newp = idp_generic_copy(prop);
-
- if (IDP_Id(prop)) {
- newp->data.pointer = (ID *)IDP_Id(prop);
- IDP_id_register(newp);
- }
- return newp;
-}
-
void IDP_AssignString(IDProperty *prop, const char *st, int maxlen)
{
int stlen;
@@ -451,41 +444,17 @@ void IDP_FreeString(IDProperty *prop)
/** \name IDProperty ID API
* \{ */
-void IDP_id_register(IDProperty *prop)
+static IDProperty *IDP_CopyID(const IDProperty *prop)
{
- switch (prop->type)
- {
- case IDP_ID:
- IDP_Id(prop);
- if (!IDP_Id(prop))
- break;
- id_us_plus(IDP_Id(prop));
- break;
- case IDP_IDPARRAY:
- for (int i = 0; i < prop->len; i++) {
- IDProperty *inner = GETPROP(prop, i);
- if (inner->type != IDP_ID) continue;
- id_us_plus(IDP_Id(inner));
- }
- break;
- }
-}
+ IDProperty *newp;
-static void IDP_id_unregister(IDProperty *prop)
-{
- switch(prop->type) {
- case IDP_ID:
- if (IDP_Id(prop)) {
- id_us_min(IDP_Id(prop));
- }
- break;
- case IDP_IDPARRAY:
- for (int i = 0; i < prop->len; i++) {
- IDProperty *inner = GETPROP(prop, i);
- if (inner->type == IDP_ID)
- id_us_min(IDP_Id(inner));
- }
- }
+ BLI_assert(prop->type == IDP_ID);
+ newp = idp_generic_copy(prop);
+
+ newp->data.pointer = prop->data.pointer;
+ id_us_plus(IDP_Id(newp));
+
+ return newp;
}
/** \} */
@@ -815,9 +784,9 @@ void IDP_RelinkProperty(struct IDProperty *prop)
{
ID *id = IDP_Id(prop);
if (id && id->newid) {
- IDP_id_unregister(prop);
+ id_us_min(IDP_Id(prop));
prop->data.pointer = id->newid;
- IDP_id_register(prop);
+ id_us_plus(IDP_Id(prop));
}
break;
}
@@ -923,7 +892,7 @@ bool IDP_EqualsProperties_ex(IDProperty *prop1, IDProperty *prop2, const bool is
return true;
}
case IDP_ID:
- return IDP_Id(prop1) == IDP_Id(prop2) ? true : false;
+ return (IDP_Id(prop1) == IDP_Id(prop2));
default:
/* should never get here */
BLI_assert(0);
@@ -1047,9 +1016,9 @@ IDProperty *IDP_New(const char type, const IDPropertyTemplate *val, const char *
case IDP_ID:
{
prop = MEM_callocN(sizeof(IDProperty), "IDProperty datablock");
- prop->data.pointer = (void*)val->id;
+ prop->data.pointer = (void *)val->id;
prop->type = IDP_ID;
- IDP_id_register(prop);
+ id_us_plus(IDP_Id(prop));
break;
}
default:
@@ -1066,9 +1035,8 @@ IDProperty *IDP_New(const char type, const IDPropertyTemplate *val, const char *
}
/**
- * \note this will free all child properties of list arrays and groups!
- * Also, note that this does NOT unlink anything! Plus it doesn't free
- * the actual struct IDProperty struct either.
+ * \note This will free allocated data, all child properties of arrays and groups, and unlink IDs!
+ * But it does not free the actual IDProperty struct itself.
*/
void IDP_FreeProperty(IDProperty *prop)
{
@@ -1086,46 +1054,16 @@ void IDP_FreeProperty(IDProperty *prop)
IDP_FreeIDPArray(prop);
break;
case IDP_ID:
- IDP_id_unregister(prop);
+ id_us_min(IDP_Id(prop));
break;
}
}
void IDP_ClearProperty(IDProperty *prop)
{
- IDP_UnlinkProperty(prop);
IDP_FreeProperty(prop);
prop->data.pointer = NULL;
prop->len = prop->totallen = 0;
}
-/**
- * Unlinks any struct IDProperty<->ID linkage that might be going on.
- */
-void IDP_UnlinkProperty(IDProperty *prop)
-{
- int i;
- IDProperty *idp_loop;
-
- if (!prop) return;
-
- switch (prop->type) {
- case IDP_ID:
- IDP_id_unregister(prop);
- prop->data.pointer = NULL;
- break;
- case IDP_IDPARRAY:
- idp_loop = IDP_Array(prop);
- for (i = 0; i < prop->len; i++) {
- IDP_UnlinkProperty(&(idp_loop[i]));
- }
- break;
- case IDP_GROUP:
- for (idp_loop = prop->data.group.first; idp_loop; idp_loop = idp_loop->next) {
- IDP_UnlinkProperty(idp_loop);
- }
- break;
- }
-}
-
/** \} */
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index a3eea276478..ef3f6b82cf9 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2141,13 +2141,11 @@ static void IDP_LibLinkProperty(IDProperty *prop, FileData *fd)
switch (prop->type) {
case IDP_ID: /* PointerProperty */
{
- void *newaddr = newlibadr(fd, NULL, IDP_Id(prop));
- if (IDP_Id(prop) && !newaddr) {
- if (G.debug)
- printf("Error while loading \"%s\". Data not found in file!\n", prop->name);
+ void *newaddr = newlibadr_us(fd, NULL, IDP_Id(prop));
+ if (IDP_Id(prop) && !newaddr && G.debug) {
+ printf("Error while loading \"%s\". Data not found in file!\n", prop->name);
}
prop->data.pointer = newaddr;
- IDP_id_register(prop);
break;
}
case IDP_IDPARRAY: /* CollectionProperty */
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 4f4df44b73e..7c7e7d3c7c3 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -3021,12 +3021,14 @@ void RNA_property_pointer_set(PointerRNA *ptr, PropertyRNA *prop, PointerRNA ptr
return;
}
- // RNA
- if (pprop->set && !((prop->flag & PROP_NEVER_NULL) && ptr_value.data == NULL) &&
- !((prop->flag & PROP_ID_SELF_CHECK) && ptr->id.data == ptr_value.id.data)) {
+ /* RNA */
+ if (pprop->set &&
+ !((prop->flag & PROP_NEVER_NULL) && ptr_value.data == NULL) &&
+ !((prop->flag & PROP_ID_SELF_CHECK) && ptr->id.data == ptr_value.id.data))
+ {
pprop->set(ptr, ptr_value);
}
- // IDProperty
+ /* IDProperty */
else if (prop->flag & PROP_EDITABLE) {
IDPropertyTemplate val = { 0 };
IDProperty *group;