bpy's __rna__ attribute doesnt work as it should, since the parent classes __rna__...
authorCampbell Barton <ideasman42@gmail.com>
Sat, 22 Aug 2009 17:06:10 +0000 (17:06 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 22 Aug 2009 17:06:10 +0000 (17:06 +0000)
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__']

source/blender/python/intern/bpy_rna.c

index bece114d8bd8daa4f52a7b4dd4b1494b8cf085f4..316480373461811de40ae10563e572339b740cfd 100644 (file)
@@ -2655,8 +2655,17 @@ PyObject *BPY_rna_props( void )
 
 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.");