fix for memory leak, use Key Errors for pyrna getitem access & idprops
authorCampbell Barton <ideasman42@gmail.com>
Wed, 18 Nov 2009 13:02:09 +0000 (13:02 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 18 Nov 2009 13:02:09 +0000 (13:02 +0000)
source/blender/makesrna/intern/rna_access.c
source/blender/python/generic/IDProp.c
source/blender/python/intern/bpy_rna.c

index 355b61a0c49bea1dacd9e42674895aa61e97d556..3e30827fad221d41f57fbf1250f72efa92cadd8d 100644 (file)
@@ -2344,13 +2344,8 @@ int RNA_path_resolve(PointerRNA *ptr, const char *path, PointerRNA *r_ptr, Prope
 
                if(use_id_prop) { /* look up property name in current struct */
                        IDProperty *group= RNA_struct_idproperties(ptr, 0);
-                       if(!group)
-                               return 0;
-
-                       if(rna_token_strip_quotes(token))
+                       if(group && rna_token_strip_quotes(token))
                                prop= (PropertyRNA *)IDP_GetPropertyFromGroup(group, token+1);
-                       else
-                               prop= NULL;
                }
                else {
                        prop= RNA_struct_find_property(&curptr, token);
index 6d71332b9ec1eaee76455fb3695cbf859b8a5651..2339350823d3bf5a65c1b61ecf0ecb1f7a5a7b05 100644 (file)
@@ -322,7 +322,7 @@ int BPy_Wrap_SetMapItem(IDProperty *prop, PyObject *key, PyObject *val)
                        MEM_freeN(pkey);
                        return 0;
                } else {
-                       PyErr_SetString( PyExc_RuntimeError, "property not found in group" );
+                       PyErr_SetString( PyExc_KeyError, "property not found in group" );
                        return -1;
                }
        }
@@ -336,7 +336,7 @@ int BPy_Wrap_SetMapItem(IDProperty *prop, PyObject *key, PyObject *val)
 
                err = BPy_IDProperty_Map_ValidateAndCreate(_PyUnicode_AsString(key), prop, val);
                if (err) {
-                       PyErr_SetString( PyExc_RuntimeError, err );
+                       PyErr_SetString( PyExc_KeyError, err );
                        return -1;
                }
 
index 024473f596a5b6753a42fcbc51d67745e14e9d22..ba268201b814982a196eb9a4e6530bced9a1478f 100644 (file)
@@ -1218,14 +1218,14 @@ static PyObject *pyrna_struct_subscript( BPy_StructRNA *self, PyObject *key )
        group= RNA_struct_idproperties(&self->ptr, 0);
 
        if(group==NULL) {
-               PyErr_Format( PyExc_TypeError, "key \"%s\" not found", name);
+               PyErr_Format( PyExc_KeyError, "key \"%s\" not found", name);
                return NULL;
        }
 
        idprop= IDP_GetPropertyFromGroup(group, name);
 
        if(idprop==NULL) {
-               PyErr_Format( PyExc_TypeError, "key \"%s\" not found", name);
+               PyErr_Format( PyExc_KeyError, "key \"%s\" not found", name);
                return NULL;
        }