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:
authorJoseph Eagar <joeedh@gmail.com>2006-12-01 06:04:36 +0300
committerJoseph Eagar <joeedh@gmail.com>2006-12-01 06:04:36 +0300
commit71da111613758d289209a5df64f722f8c0926767 (patch)
treebbd8775f4f68cb9d8c22babf16637bfdc4f44a3e /source/blender
parentb36b940807011e0d85a0030933617ac6d0ec02bb (diff)
=IDProperties bugfix=
Another bug from the tracker, reported by Mike Stramba. A duplicated Py_XDECREF in the wrong place made assigning arrays from Vector objects not work. Also, fixed nasty bug in C API of idproperties (the function to look up a property from a group was broken). Fixed a memory leak too. In addition, made "del group['property']" delete properties from group; previously this would just crash (or at least it should have). Added a small addition to the example in the epydocs for IDGroup.
Diffstat (limited to 'source/blender')
-rw-r--r--source/blender/blenkernel/BKE_idprop.h10
-rw-r--r--source/blender/blenkernel/intern/idprop.c2
-rw-r--r--source/blender/python/api2_2x/IDProp.c20
-rw-r--r--source/blender/python/api2_2x/doc/IDProp.py4
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=""):