[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19867] trunk/blender/source/gameengine: BGE Python API
Campbell Barton
ideasman42 at gmail.com
Wed Apr 22 11:47:57 CEST 2009
Revision: 19867
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19867
Author: campbellbarton
Date: 2009-04-22 11:47:57 +0200 (Wed, 22 Apr 2009)
Log Message:
-----------
BGE Python API
improved how attribute errors are set so each classes py_getattro function dosnt need to set an error if the attribute doesn't exist.
Now py_base_getattro sets an error on a NULL return value when no errors are set to avoid setting errors at multiple levels.
Modified Paths:
--------------
trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp
trunk/blender/source/gameengine/Expressions/PyObjectPlus.h
trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
Modified: trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp
===================================================================
--- trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp 2009-04-22 09:08:57 UTC (rev 19866)
+++ trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp 2009-04-22 09:47:57 UTC (rev 19867)
@@ -146,9 +146,23 @@
PyObject *ret= self_plus->py_getattro(attr);
- if(ret==NULL && (strcmp(PyString_AsString(attr), "__dict__")==0))
- ret= self_plus->py_getattro_dict();
-
+ /* Attribute not found, was this a __dict__ lookup?, otherwise set an error if none is set */
+ if(ret==NULL) {
+ char *attr_str= PyString_AsString(attr);
+
+ if (strcmp(attr_str, "__dict__")==0)
+ {
+ /* the error string will probably not
+ * be set but just incase clear it */
+ PyErr_Clear();
+ ret= self_plus->py_getattro_dict();
+ }
+ else if (!PyErr_Occurred()) {
+ /* We looked for an attribute but it wasnt found
+ * since py_getattro didnt set the error, set it here */
+ PyErr_Format(PyExc_AttributeError, "'%s' object has no attribute '%s'", self->ob_type->tp_name, attr_str);
+ }
+ }
return ret;
}
@@ -183,8 +197,7 @@
{
PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \
if (descr == NULL) {
- PyErr_Format(PyExc_AttributeError, "attribute \"%s\" not found", PyString_AsString(attr));
- return NULL;
+ return NULL; /* py_base_getattro sets the error, this way we can avoid setting the error at many levels */
} else {
/* Copied from py_getattro_up */
if (PyCObject_Check(descr)) {
@@ -192,8 +205,7 @@
} else if (descr->ob_type->tp_descr_get) {
return PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, this->m_proxy);
} else {
- fprintf(stderr, "Unknown attribute type (PyObjectPlus::py_getattro)");
- return descr;
+ return NULL;
}
/* end py_getattro_up copy */
}
Modified: trunk/blender/source/gameengine/Expressions/PyObjectPlus.h
===================================================================
--- trunk/blender/source/gameengine/Expressions/PyObjectPlus.h 2009-04-22 09:08:57 UTC (rev 19866)
+++ trunk/blender/source/gameengine/Expressions/PyObjectPlus.h 2009-04-22 09:47:57 UTC (rev 19867)
@@ -114,6 +114,9 @@
// This defines the py_getattro_up macro
// which allows attribute and method calls
// to be properly passed up the hierarchy.
+ //
+ // Note, PyDict_GetItem() WONT set an exception!
+ // let the py_base_getattro function do this.
#define py_getattro_up(Parent) \
\
@@ -125,14 +128,11 @@
} else if (descr->ob_type->tp_descr_get) { \
return PyCFunction_New(((PyMethodDescrObject *)descr)->d_method, this->m_proxy); \
} else { \
- fprintf(stderr, "unknown attribute type"); \
- return descr; \
+ return NULL; \
} \
} else { \
- PyErr_Clear(); \
return Parent::py_getattro(attr); \
- } \
- return NULL;
+ }
#define py_getattro_dict_up(Parent) \
return py_getattr_dict(Parent::py_getattro_dict(), Type.tp_dict);
Modified: trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-04-22 09:08:57 UTC (rev 19866)
+++ trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp 2009-04-22 09:47:57 UTC (rev 19867)
@@ -1655,7 +1655,7 @@
PyObject *meshes= PyList_New(self->m_meshes.size());
int i;
- for(i=0; i < self->m_meshes.size(); i++)
+ for(i=0; i < (int)self->m_meshes.size(); i++)
{
KX_MeshProxy* meshproxy = new KX_MeshProxy(self->m_meshes[i]);
PyList_SET_ITEM(meshes, i, meshproxy->GetProxy());
More information about the Bf-blender-cvs
mailing list