Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-04-21 03:17:52 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-04-21 03:17:52 +0400
commit217bbb7800679899302ddb058f9ceea1d00c7ce1 (patch)
tree05cef2f2d94dc0af0cbf027c233f5d35ff782eee /source/gameengine/Expressions
parent2d0d06f642b661b084657c05ebb0c664f998a937 (diff)
BGE Python API
Separate getting a normal attribute and getting __dict__, was having to do too a check for __dict__ on each class (multiple times per getattro call from python) when its not used that often.
Diffstat (limited to 'source/gameengine/Expressions')
-rw-r--r--source/gameengine/Expressions/ListValue.cpp4
-rw-r--r--source/gameengine/Expressions/ListValue.h1
-rw-r--r--source/gameengine/Expressions/PyObjectPlus.cpp15
-rw-r--r--source/gameengine/Expressions/PyObjectPlus.h11
-rw-r--r--source/gameengine/Expressions/Value.cpp4
-rw-r--r--source/gameengine/Expressions/Value.h1
6 files changed, 25 insertions, 11 deletions
diff --git a/source/gameengine/Expressions/ListValue.cpp b/source/gameengine/Expressions/ListValue.cpp
index dd9b296dce1..7c31a29f4ac 100644
--- a/source/gameengine/Expressions/ListValue.cpp
+++ b/source/gameengine/Expressions/ListValue.cpp
@@ -273,6 +273,10 @@ PyObject* CListValue::py_getattro(PyObject* attr) {
py_getattro_up(CValue);
}
+PyObject* CListValue::py_getattro_dict() {
+ py_getattro_dict_up(CValue);
+}
+
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
diff --git a/source/gameengine/Expressions/ListValue.h b/source/gameengine/Expressions/ListValue.h
index 2af5a330c43..3d88b5aea9c 100644
--- a/source/gameengine/Expressions/ListValue.h
+++ b/source/gameengine/Expressions/ListValue.h
@@ -60,6 +60,7 @@ public:
bool CheckEqual(CValue* first,CValue* second);
virtual PyObject* py_getattro(PyObject* attr);
+ virtual PyObject* py_getattro_dict();
virtual PyObject* py_repr(void) {
PyObject *py_proxy= this->GetProxy();
PyObject *py_list= PySequence_List(py_proxy);
diff --git a/source/gameengine/Expressions/PyObjectPlus.cpp b/source/gameengine/Expressions/PyObjectPlus.cpp
index 6cfa14ddc80..c4daaff2dd1 100644
--- a/source/gameengine/Expressions/PyObjectPlus.cpp
+++ b/source/gameengine/Expressions/PyObjectPlus.cpp
@@ -143,7 +143,13 @@ PyObject *PyObjectPlus::py_base_getattro(PyObject * self, PyObject *attr)
PyErr_SetString(PyExc_RuntimeError, BGE_PROXY_ERROR_MSG);
return NULL;
}
- return self_plus->py_getattro(attr);
+
+ PyObject *ret= self_plus->py_getattro(attr);
+
+ if(ret==NULL && (strcmp(PyString_AsString(attr), "__dict__")==0))
+ ret= self_plus->py_getattro_dict();
+
+ return ret;
}
/* This should be the entry in Type since it takes the C++ class from PyObjectPlus_Proxy */
@@ -177,9 +183,6 @@ PyObject *PyObjectPlus::py_getattro(PyObject* attr)
{
PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \
if (descr == NULL) {
- if (strcmp(PyString_AsString(attr), "__dict__")==0) {
- return py_getattr_dict(NULL, Type.tp_dict); /* no Attributes yet */
- }
PyErr_Format(PyExc_AttributeError, "attribute \"%s\" not found", PyString_AsString(attr));
return NULL;
} else {
@@ -196,6 +199,10 @@ PyObject *PyObjectPlus::py_getattro(PyObject* attr)
}
}
+PyObject* PyObjectPlus::py_getattro_dict() {
+ return py_getattr_dict(NULL, Type.tp_dict);
+}
+
int PyObjectPlus::py_delattro(PyObject* attr)
{
PyErr_SetString(PyExc_AttributeError, "attribute cant be deleted");
diff --git a/source/gameengine/Expressions/PyObjectPlus.h b/source/gameengine/Expressions/PyObjectPlus.h
index 370717a919b..b0ddfa04e32 100644
--- a/source/gameengine/Expressions/PyObjectPlus.h
+++ b/source/gameengine/Expressions/PyObjectPlus.h
@@ -130,16 +130,12 @@ typedef struct {
} \
} else { \
PyErr_Clear(); \
- PyObject *rvalue= Parent::py_getattro(attr); \
- \
- if (strcmp(PyString_AsString(attr), "__dict__")==0) { \
- return py_getattr_dict(rvalue, Type.tp_dict); \
- } \
- \
- return rvalue; \
+ return Parent::py_getattro(attr); \
} \
return NULL;
+#define py_getattro_dict_up(Parent) \
+ return py_getattr_dict(Parent::py_getattro_dict(), Type.tp_dict);
/*
* nonzero values are an error for setattr
@@ -434,6 +430,7 @@ public:
/* These are all virtual python methods that are defined in each class
* Our own fake subclassing calls these on each class, then calls the parent */
virtual PyObject* py_getattro(PyObject *attr);
+ virtual PyObject* py_getattro_dict();
virtual int py_delattro(PyObject *attr);
virtual int py_setattro(PyObject *attr, PyObject *value);
virtual PyObject* py_repr(void);
diff --git a/source/gameengine/Expressions/Value.cpp b/source/gameengine/Expressions/Value.cpp
index 7cb97909119..106bd1256a6 100644
--- a/source/gameengine/Expressions/Value.cpp
+++ b/source/gameengine/Expressions/Value.cpp
@@ -612,6 +612,10 @@ PyObject* CValue::py_getattro(PyObject *attr)
py_getattro_up(PyObjectPlus);
}
+PyObject* CValue::py_getattro_dict() {
+ py_getattro_dict_up(PyObjectPlus);
+}
+
CValue* CValue::ConvertPythonToValue(PyObject* pyobj)
{
diff --git a/source/gameengine/Expressions/Value.h b/source/gameengine/Expressions/Value.h
index a687e1a493c..88186fa95c0 100644
--- a/source/gameengine/Expressions/Value.h
+++ b/source/gameengine/Expressions/Value.h
@@ -225,6 +225,7 @@ public:
virtual PyObject* py_getattro(PyObject *attr);
+ virtual PyObject* py_getattro_dict();
virtual PyObject* ConvertValueToPython() {
return NULL;
}