Revision: 34483
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34483
Author:   campbellbarton
Date:     2011-01-25 06:54:57 +0000 (Tue, 25 Jan 2011)
Log Message:
-----------
fix [#25748] Addons register parameters/functions more than once
- values were added to both the classes __dict__ as well as the internal 
StructRNA.
- made properties available from the type since this is where the python api 
assigns them:
>>> bpy.types.Scene.frame_start
<bpy_struct, IntProperty("frame_start")>
- rename RNA_struct_type_properties() -> RNA_struct_type_properties(), added 
RNA_struct_type_find_property()

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/node.c
    trunk/blender/source/blender/makesrna/RNA_access.h
    trunk/blender/source/blender/makesrna/intern/rna_access.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/blenkernel/intern/node.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/node.c       2011-01-25 
05:45:21 UTC (rev 34482)
+++ trunk/blender/source/blender/blenkernel/intern/node.c       2011-01-25 
06:54:57 UTC (rev 34483)
@@ -3119,7 +3119,7 @@
        
        /* check to see if any of the node's properties have fcurves */
        RNA_pointer_create((ID *)ntree, &RNA_Node, node, &ptr);
-       lb = RNA_struct_defined_properties(ptr.type);
+       lb = RNA_struct_type_properties(ptr.type);
        
        for (link=lb->first; link; link=link->next) {
                int driven, len=1, index;

Modified: trunk/blender/source/blender/makesrna/RNA_access.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_access.h  2011-01-25 05:45:21 UTC 
(rev 34482)
+++ trunk/blender/source/blender/makesrna/RNA_access.h  2011-01-25 06:54:57 UTC 
(rev 34483)
@@ -617,8 +617,11 @@
 
 
 PropertyRNA *RNA_struct_find_property(PointerRNA *ptr, const char *identifier);
-const struct ListBase *RNA_struct_defined_properties(StructRNA *srna);
 
+/* lower level functions for access to type properties */
+const struct ListBase *RNA_struct_type_properties(StructRNA *srna);
+PropertyRNA *RNA_struct_type_find_property(StructRNA *srna, const char 
*identifier);
+
 FunctionRNA *RNA_struct_find_function(PointerRNA *ptr, const char *identifier);
 const struct ListBase *RNA_struct_defined_functions(StructRNA *srna);
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_access.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_access.c   2011-01-25 
05:45:21 UTC (rev 34482)
+++ trunk/blender/source/blender/makesrna/intern/rna_access.c   2011-01-25 
06:54:57 UTC (rev 34483)
@@ -569,11 +569,17 @@
        return prop;
 }
 
-const struct ListBase *RNA_struct_defined_properties(StructRNA *srna)
+/* low level direct access to type->properties, note this ignores parent 
classes so should be used with care */
+const struct ListBase *RNA_struct_type_properties(StructRNA *srna)
 {
        return &srna->cont.properties;
 }
 
+PropertyRNA *RNA_struct_type_find_property(StructRNA *srna, const char 
*identifier)
+{
+       return BLI_findstring_ptr(&srna->cont.properties, identifier, 
offsetof(PropertyRNA, identifier));
+}
+
 FunctionRNA *RNA_struct_find_function(PointerRNA *ptr, const char *identifier)
 {
 #if 1

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c        2011-01-25 
05:45:21 UTC (rev 34482)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c        2011-01-25 
06:54:57 UTC (rev 34483)
@@ -2831,14 +2831,29 @@
        return PyTuple_CheckExact(value) && PyTuple_GET_SIZE(value)==2 && 
PyCallable_Check(PyTuple_GET_ITEM(value, 0)) && 
PyDict_CheckExact(PyTuple_GET_ITEM(value, 1));
 }
 
-static PyObject *pyrna_struct_meta_idprop_getattro(PyObject *cls, PyObject 
*pyname)
+static PyObject *pyrna_struct_meta_idprop_getattro(PyObject *cls, PyObject 
*attr)
 {
-       return PyType_Type.tp_getattro(cls, pyname);    
+       PyObject *ret= PyType_Type.tp_getattro(cls, attr);
+
+       if(ret == NULL) {
+               StructRNA *srna= srna_from_self(cls, "StructRNA.__getattr__");
+               if(srna) {
+                       PropertyRNA *prop= RNA_struct_type_find_property(srna, 
_PyUnicode_AsString(attr));
+                       if(prop) {
+                               PointerRNA tptr;
+                               PyErr_Clear(); /* clear error from tp_getattro 
*/
+                               RNA_pointer_create(NULL, &RNA_Property, prop, 
&tptr);
+                               ret= pyrna_struct_CreatePyObject(&tptr);
+                       }
+               }
+       }
+
+       return ret;
 }
 
 static int pyrna_struct_meta_idprop_setattro(PyObject *cls, PyObject *attr, 
PyObject *value)
 {
-       StructRNA *srna= srna_from_self(cls, "");
+       StructRNA *srna= srna_from_self(cls, "StructRNA.__setattr__");
 
        if(srna == NULL) {
                if(value && pyrna_is_deferred_prop(value)) {
@@ -2854,10 +2869,8 @@
        if(value) {
                /* check if the value is a property */
                if(pyrna_is_deferred_prop(value)) {
-                       int ret= deferred_register_prop(srna, attr, value);
-                       if(ret < 0)
-                               return ret;
-                       /* pass through, when the value isn't assigned it still 
works but gets confusing from script writers POV */
+                       /* dont add this to the __dict__, getattr deals with 
returning the newly created RNA_Property type */
+                       return deferred_register_prop(srna, attr, value);
                }
                else {
                        /* remove existing property if its set or we also end 
up with confusement */
@@ -2874,7 +2887,7 @@
                        return -1;
                }
        }
-       
+
        /* fallback to standard py, delattr/setattr */
        return PyType_Type.tp_setattro(cls, attr, value);
 }
@@ -4951,12 +4964,10 @@
 
 /* Orphan functions, not sure where they should go */
 /* get the srna for methods attached to types */
-/* */
+/*
+ * Caller needs to raise error.*/
 StructRNA *srna_from_self(PyObject *self, const char *error_prefix)
 {
-       /* a bit sloppy but would cause a very confusing bug if
-        * an error happened to be set here */
-       PyErr_Clear();
 
        if(self==NULL) {
                return NULL;
@@ -4967,10 +4978,24 @@
        else if (PyType_Check(self)==0) {
                return NULL;
        }
-       /* These cases above not errors, they just mean the type was not 
compatible
-        * After this any errors will be raised in the script */
+       else {
+               /* These cases above not errors, they just mean the type was 
not compatible
+                * After this any errors will be raised in the script */
 
-       return pyrna_struct_as_srna(self, 0, error_prefix);
+               PyObject *error_type, *error_value, *error_traceback;
+               StructRNA *srna;
+
+               PyErr_Fetch(&error_type, &error_value, &error_traceback);
+               PyErr_Clear();
+
+               srna= pyrna_struct_as_srna(self, 0, error_prefix);
+
+               if(!PyErr_Occurred()) {
+                       PyErr_Restore(error_type, error_value, error_traceback);
+               }
+
+               return srna;
+       }
 }
 
 static int deferred_register_prop(StructRNA *srna, PyObject *key, PyObject 
*item)
@@ -5200,7 +5225,7 @@
        }
 
        /* verify properties */
-       lb= RNA_struct_defined_properties(srna);
+       lb= RNA_struct_type_properties(srna);
        for(link=lb->first; link; link=link->next) {
                const char *identifier;
                prop= (PropertyRNA*)link;

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to