[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22707] branches/blender2.5/blender/source /blender/python/intern/bpy_rna.c: bpy' s __rna__ attribute doesnt work as it should, since the parent classes __rna__ overrides the subtypes.

Campbell Barton ideasman42 at gmail.com
Sat Aug 22 19:06:10 CEST 2009


Revision: 22707
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22707
Author:   campbellbarton
Date:     2009-08-22 19:06:10 +0200 (Sat, 22 Aug 2009)

Log Message:
-----------
bpy's __rna__ attribute doesnt work as it should, since the parent classes __rna__ overrides the subtypes.

For now have pyrna_struct_as_srna look in the dict first for __rna__ before using PyDict_GetItemString.
Somehow __rna__ is not calling the pyrna_struct_getattro function, python find it first.

The only relyable way to get the rna from python currently is.
bpy.types.SomeType.__dict__['__rna__']

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c

Modified: branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c	2009-08-22 16:54:18 UTC (rev 22706)
+++ branches/blender2.5/blender/source/blender/python/intern/bpy_rna.c	2009-08-22 17:06:10 UTC (rev 22707)
@@ -2655,8 +2655,17 @@
 
 static StructRNA *pyrna_struct_as_srna(PyObject *self)
 {
-	BPy_StructRNA *py_srna= (BPy_StructRNA*)PyObject_GetAttrString(self, "__rna__");
+	BPy_StructRNA *py_srna;
 	StructRNA *srna;
+	
+	/* ack, PyObject_GetAttrString wont look up this types tp_dict first :/ */
+	if(PyType_Check(self)) {
+		py_srna = (BPy_StructRNA *)PyDict_GetItemString(((PyTypeObject *)self)->tp_dict, "__rna__");
+		Py_XINCREF(py_srna);
+	}
+	
+	if(py_srna==NULL)
+		py_srna = (BPy_StructRNA*)PyObject_GetAttrString(self, "__rna__");
 
 	if(py_srna==NULL) {
 	 	PyErr_SetString(PyExc_SystemError, "internal error, self had no __rna__ attribute, should never happen.");





More information about the Bf-blender-cvs mailing list