diff options
-rw-r--r-- | source/blender/blenkernel/BKE_idprop.h | 10 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/idprop.c | 2 | ||||
-rw-r--r-- | source/blender/python/api2_2x/IDProp.c | 20 | ||||
-rw-r--r-- | source/blender/python/api2_2x/doc/IDProp.py | 4 |
4 files changed, 31 insertions, 5 deletions
diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h index 0a3e0634411..3a5e84b490e 100644 --- a/source/blender/blenkernel/BKE_idprop.h +++ b/source/blender/blenkernel/BKE_idprop.h @@ -94,7 +94,17 @@ struct. In the future this will just be IDP_FreeProperty and the code will be reorganized to work properly. */ int IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop); + + +/*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 + +*/ void IDP_RemFromGroup(struct IDProperty *group, struct IDProperty *prop); + IDProperty *IDP_GetPropertyFromGroup(struct IDProperty *prop, char *name); /*Get an iterator to iterate over the members of an id property group. diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c index 90de7edc7bc..0bcb6a87ba3 100644 --- a/source/blender/blenkernel/intern/idprop.c +++ b/source/blender/blenkernel/intern/idprop.c @@ -192,7 +192,7 @@ IDProperty *IDP_GetPropertyFromGroup(IDProperty *prop, char *name) { IDProperty *loop; for (loop=prop->data.group.first; loop; loop=loop->next) { - if (strcmp(prop->name, name)==0) return prop; + if (strcmp(loop->name, name)==0) return loop; } return NULL; } diff --git a/source/blender/python/api2_2x/IDProp.c b/source/blender/python/api2_2x/IDProp.c index 120a4b2b76b..df4e1a009ec 100644 --- a/source/blender/python/api2_2x/IDProp.c +++ b/source/blender/python/api2_2x/IDProp.c @@ -249,7 +249,6 @@ char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObje prop = IDP_New(IDP_ARRAY, val, name); for (i=0; i<val.array.len; i++) { item = PySequence_GetItem(ob, i); - Py_XDECREF(item); if (val.array.type == IDP_INT) { item = PyNumber_Int(item); ((int*)prop->data.pointer)[i] = (int)PyInt_AsLong(item); @@ -292,10 +291,13 @@ char *BPy_IDProperty_Map_ValidateAndCreate(char *name, IDProperty *group, PyObje } Py_XDECREF(keys); Py_XDECREF(vals); - } + } else return "invalid property value"; - if (IDP_GetPropertyFromGroup(group, prop->name) == NULL) { - IDP_RemFromGroup(group, IDP_GetPropertyFromGroup(group, prop->name)); + if (IDP_GetPropertyFromGroup(group, prop->name) != NULL) { + IDProperty *prop2 = IDP_GetPropertyFromGroup(group, prop->name); + IDP_RemFromGroup(group, prop2); + IDP_FreeProperty(prop2); + MEM_freeN(prop2); } IDP_AddToGroup(group, prop); @@ -313,6 +315,16 @@ int BPy_IDProperty_Map_SetItem(BPy_IDProperty *self, PyObject *key, PyObject *va if (!PyString_Check(key)) return EXPP_ReturnIntError( PyExc_TypeError, "only strings are allowed as subgroup keys" ); + + if (val == NULL) { + IDProperty *pkey = IDP_GetPropertyFromGroup(self->prop, PyString_AsString(key)); + if (pkey) { + IDP_RemFromGroup(self->prop, pkey); + IDP_FreeProperty(pkey); + MEM_freeN(pkey); + return 0; + } else return EXPP_ReturnIntError( PyExc_RuntimeError, "property not found in group" ); + } err = BPy_IDProperty_Map_ValidateAndCreate(PyString_AsString(key), self->prop, val); if (err) return EXPP_ReturnIntError( PyExc_RuntimeError, err ); diff --git a/source/blender/python/api2_2x/doc/IDProp.py b/source/blender/python/api2_2x/doc/IDProp.py index 1061fd1be4a..d4cf59a6424 100644 --- a/source/blender/python/api2_2x/doc/IDProp.py +++ b/source/blender/python/api2_2x/doc/IDProp.py @@ -37,6 +37,10 @@ class IDGroup: Note that for arrays, the array type defaults to int unless a float is found while scanning the template list; if any floats are found, then the whole array is float. + + You can also delete properties with the del operator. For example: + + del group['property'] """ def newProperty(type, name, array_type="Float", val=""): |