fix for crash when using a NULL context from python

This commit is contained in:
2010-01-27 10:54:11 +00:00
parent 2cb23d03ef
commit 49abcd49f1

View File

@@ -1898,43 +1898,49 @@ static PyObject *pyrna_struct_getattro( BPy_StructRNA *self, PyObject *pyname )
ret = pyrna_func_to_py((BPy_DummyPointerRNA *)self, func); ret = pyrna_func_to_py((BPy_DummyPointerRNA *)self, func);
} }
else if (self->ptr.type == &RNA_Context) { else if (self->ptr.type == &RNA_Context) {
PointerRNA newptr; bContext *C = self->ptr.data;
ListBase newlb; if(C==NULL) {
int done; PyErr_Format( PyExc_AttributeError, "StructRNA Context is 'NULL', can't get \"%.200s\" from context", name);
ret= NULL;
}
else {
PointerRNA newptr;
ListBase newlb;
done= CTX_data_get(self->ptr.data, name, &newptr, &newlb); int done= CTX_data_get(C, name, &newptr, &newlb);
if(done==1) { /* found */ if(done==1) { /* found */
if (newptr.data) { if (newptr.data) {
ret = pyrna_struct_CreatePyObject(&newptr); ret = pyrna_struct_CreatePyObject(&newptr);
} }
else if (newlb.first) { else if (newlb.first) {
CollectionPointerLink *link; CollectionPointerLink *link;
PyObject *linkptr; PyObject *linkptr;
ret = PyList_New(0); ret = PyList_New(0);
for(link=newlb.first; link; link=link->next) { for(link=newlb.first; link; link=link->next) {
linkptr= pyrna_struct_CreatePyObject(&link->ptr); linkptr= pyrna_struct_CreatePyObject(&link->ptr);
PyList_Append(ret, linkptr); PyList_Append(ret, linkptr);
Py_DECREF(linkptr); Py_DECREF(linkptr);
}
}
else {
ret = Py_None;
Py_INCREF(ret);
} }
} }
else { else if (done==-1) { /* found but not set */
ret = Py_None; ret = Py_None;
Py_INCREF(ret); Py_INCREF(ret);
} }
} else { /* not found in the context */
else if (done==-1) { /* found but not set */ /* lookup the subclass. raise an error if its not found */
ret = Py_None; ret = PyObject_GenericGetAttr((PyObject *)self, pyname);
Py_INCREF(ret); }
}
else { /* not found in the context */
/* lookup the subclass. raise an error if its not found */
ret = PyObject_GenericGetAttr((PyObject *)self, pyname);
}
BLI_freelistN(&newlb); BLI_freelistN(&newlb);
}
} }
else { else {
#if 0 #if 0