[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [19790] trunk/blender/source/gameengine: BGE Python API cleanup - no functionality changes

Campbell Barton ideasman42 at gmail.com
Sun Apr 19 16:57:52 CEST 2009


Revision: 19790
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=19790
Author:   campbellbarton
Date:     2009-04-19 16:57:52 +0200 (Sun, 19 Apr 2009)

Log Message:
-----------
BGE Python API cleanup - no functionality changes
- comments to PyObjectPlus.h
- remove unused/commented junk.
- renamed PyDestructor to py_base_dealloc for consistency
- all the PyTypeObject's were still using the sizeof() their class, can use sizeof(PyObjectPlus_Proxy) now which is smaller too.

Modified Paths:
--------------
    trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp
    trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.cpp
    trunk/blender/source/gameengine/Expressions/ListValue.cpp
    trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp
    trunk/blender/source/gameengine/Expressions/PyObjectPlus.h
    trunk/blender/source/gameengine/Expressions/Value.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_ANDController.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_DelaySensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_ILogicBrick.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_IObject.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_ISensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_MouseSensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_NANDController.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_NORController.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_ORController.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_PropertyActuator.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_PropertySensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_RandomActuator.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_RandomSensor.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_XNORController.cpp
    trunk/blender/source/gameengine/GameLogic/SCA_XORController.cpp
    trunk/blender/source/gameengine/Ketsji/BL_Shader.cpp
    trunk/blender/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
    trunk/blender/source/gameengine/Ketsji/KX_CDActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Camera.cpp
    trunk/blender/source/gameengine/Ketsji/KX_CameraActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_ConstraintActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_GameObject.cpp
    trunk/blender/source/gameengine/Ketsji/KX_IpoActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Light.cpp
    trunk/blender/source/gameengine/Ketsji/KX_MeshProxy.cpp
    trunk/blender/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_NearSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_ObjectActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_ParentActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_PhysicsObjectWrapper.cpp
    trunk/blender/source/gameengine/Ketsji/KX_PolyProxy.cpp
    trunk/blender/source/gameengine/Ketsji/KX_PolygonMaterial.cpp
    trunk/blender/source/gameengine/Ketsji/KX_RadarSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_RaySensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_Scene.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SceneActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_SoundActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_StateActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_TouchSensor.cpp
    trunk/blender/source/gameengine/Ketsji/KX_TrackToActuator.cpp
    trunk/blender/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
    trunk/blender/source/gameengine/Ketsji/KX_VertexProxy.cpp
    trunk/blender/source/gameengine/Ketsji/KX_VisibilityActuator.cpp

Modified: trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp	2009-04-19 13:37:59 UTC (rev 19789)
+++ trunk/blender/source/gameengine/Converter/BL_ActionActuator.cpp	2009-04-19 14:57:52 UTC (rev 19790)
@@ -968,9 +968,9 @@
 	PyObject_HEAD_INIT(NULL)
 		0,
 		"BL_ActionActuator",
-		sizeof(BL_ActionActuator),
+		sizeof(PyObjectPlus_Proxy),
 		0,
-		PyDestructor,
+		py_base_dealloc,
 		0,
 		0,
 		0,

Modified: trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.cpp
===================================================================
--- trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.cpp	2009-04-19 13:37:59 UTC (rev 19789)
+++ trunk/blender/source/gameengine/Converter/BL_ShapeActionActuator.cpp	2009-04-19 14:57:52 UTC (rev 19790)
@@ -423,9 +423,9 @@
 	PyObject_HEAD_INIT(NULL)
 		0,
 		"BL_ShapeActionActuator",
-		sizeof(BL_ShapeActionActuator),
+		sizeof(PyObjectPlus_Proxy),
 		0,
-		PyDestructor,
+		py_base_dealloc,
 		0,
 		0,
 		0,

Modified: trunk/blender/source/gameengine/Expressions/ListValue.cpp
===================================================================
--- trunk/blender/source/gameengine/Expressions/ListValue.cpp	2009-04-19 13:37:59 UTC (rev 19789)
+++ trunk/blender/source/gameengine/Expressions/ListValue.cpp	2009-04-19 14:57:52 UTC (rev 19790)
@@ -223,10 +223,10 @@
 	PyObject_HEAD_INIT(NULL)
 	0,				/*ob_size*/
 	"CListValue",			/*tp_name*/
-	sizeof(CListValue),		/*tp_basicsize*/
+	sizeof(PyObjectPlus_Proxy), /*tp_basicsize*/
 	0,				/*tp_itemsize*/
 	/* methods */
-	PyDestructor,	  		/*tp_dealloc*/
+	py_base_dealloc,	  		/*tp_dealloc*/
 	0,			 	/*tp_print*/
 	0, 			/*tp_getattr*/
 	0, 			/*tp_setattr*/

Modified: trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp
===================================================================
--- trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp	2009-04-19 13:37:59 UTC (rev 19789)
+++ trunk/blender/source/gameengine/Expressions/PyObjectPlus.cpp	2009-04-19 14:57:52 UTC (rev 19790)
@@ -59,10 +59,10 @@
 	PyObject_HEAD_INIT(NULL)
 	0,				/*ob_size*/
 	"PyObjectPlus",			/*tp_name*/
-	sizeof(PyObjectPlus),		/*tp_basicsize*/
+	sizeof(PyObjectPlus_Proxy),		/*tp_basicsize*/
 	0,				/*tp_itemsize*/
 	/* methods */
-	PyDestructor,
+	py_base_dealloc,
 	0,
 	0,
 	0,
@@ -85,7 +85,7 @@
 //	assert(ob_refcnt==0);
 }
 
-void PyObjectPlus::PyDestructor(PyObject *self)				// python wrapper
+void PyObjectPlus::py_base_dealloc(PyObject *self)				// python wrapper
 {
 	PyObjectPlus *self_plus= BGE_PROXY_REF(self);
 	if(self_plus) {
@@ -108,7 +108,7 @@
  * PyObjectPlus Methods 	-- Every class, even the abstract one should have a Methods
 ------------------------------*/
 PyMethodDef PyObjectPlus::Methods[] = {
-  {"isA",		 (PyCFunction) sPy_isA,			METH_O},
+  {"isA",		 (PyCFunction) sPyisA,			METH_O},
   {NULL, NULL}		/* Sentinel */
 };
 
@@ -130,6 +130,49 @@
 /*------------------------------
  * PyObjectPlus attributes	-- attributes
 ------------------------------*/
+
+
+/* This should be the entry in Type since it takes the C++ class from PyObjectPlus_Proxy */
+PyObject *PyObjectPlus::py_base_getattro(PyObject * self, PyObject *attr)
+{
+	PyObjectPlus *self_plus= BGE_PROXY_REF(self);
+	if(self_plus==NULL) {
+		if(!strcmp("isValid", PyString_AsString(attr))) {
+			Py_RETURN_TRUE;
+		}
+		PyErr_SetString(PyExc_RuntimeError, BGE_PROXY_ERROR_MSG);
+		return NULL;
+	}
+	return self_plus->py_getattro(attr); 
+}
+
+/* This should be the entry in Type since it takes the C++ class from PyObjectPlus_Proxy */
+int PyObjectPlus::py_base_setattro(PyObject *self, PyObject *attr, PyObject *value)
+{
+	PyObjectPlus *self_plus= BGE_PROXY_REF(self);
+	if(self_plus==NULL) {
+		PyErr_SetString(PyExc_RuntimeError, BGE_PROXY_ERROR_MSG);
+		return -1;
+	}
+	
+	if (value==NULL)
+		return self_plus->py_delattro(attr);
+	
+	return self_plus->py_setattro(attr, value); 
+}
+
+PyObject *PyObjectPlus::py_base_repr(PyObject *self)			// This should be the entry in Type.
+{
+	
+	PyObjectPlus *self_plus= BGE_PROXY_REF(self);
+	if(self_plus==NULL) {
+		PyErr_SetString(PyExc_RuntimeError, BGE_PROXY_ERROR_MSG);
+		return NULL;
+	}
+	
+	return self_plus->py_repr();  
+}
+
 PyObject *PyObjectPlus::py_getattro(PyObject* attr)
 {
 	PyObject *descr = PyDict_GetItem(Type.tp_dict, attr); \
@@ -151,8 +194,6 @@
 		}
 		/* end py_getattro_up copy */
 	}
-  //if (streq(attr, "type"))
-  //  return Py_BuildValue("s", (*(GetParents()))->tp_name);
 }
 
 int PyObjectPlus::py_delattro(PyObject* attr)
@@ -163,8 +204,6 @@
 
 int PyObjectPlus::py_setattro(PyObject *attr, PyObject* value)
 {
-	//return PyObject::py_setattro(attr,value);
-	//cerr << "Unknown attribute" << endl;
 	PyErr_SetString(PyExc_AttributeError, "attribute cant be set");
 	return PY_SET_ATTR_MISSING;
 }
@@ -275,20 +314,6 @@
 	}
 }
 
-#if 0
-PyObject *PyObjectPlus::py_getattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr)
-{
-	char *attr_str= PyString_AsString(attr);
-	const PyAttributeDef *attrdef;
-	
-	for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++)
-		if (!strcmp(attr_str, attrdef->m_name))
-			return py_get_attrdef(self, attrdef);
-	
-	return NULL;
-}
-#endif
-
 int PyObjectPlus::py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyObject *value)
 {
 	void *undoBuffer = NULL;
@@ -714,29 +739,7 @@
 	return 0;	
 }
 
-#if 0
-int PyObjectPlus::py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value)
-{
-	const PyAttributeDef *attrdef;
-	char *attr_str= PyString_AsString(attr);
 
-	for (attrdef=attrlist; attrdef->m_name != NULL; attrdef++)
-	{
-		if (!strcmp(attr_str, attrdef->m_name))
-		{
-			if (attrdef->m_access == KX_PYATTRIBUTE_RO ||
-				attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY)
-			{
-				PyErr_SetString(PyExc_AttributeError, "property is read-only");
-				return PY_SET_ATTR_FAIL;
-			}
-			
-			return py_set_attrdef(self, attrdef, value);
-		}
-	}
-	return PY_SET_ATTR_MISSING;			
-}
-#endif
 
 /*------------------------------
  * PyObjectPlus repr		-- representations
@@ -777,7 +780,7 @@
 	return false;
 }
 
-PyObject *PyObjectPlus::Py_isA(PyObject *value)		// Python wrapper for isA
+PyObject *PyObjectPlus::PyisA(PyObject *self, PyObject *value)		// Python wrapper for isA
 {
 	if (PyType_Check(value)) {
 		return PyBool_FromLong(isA((PyTypeObject *)value));

Modified: trunk/blender/source/gameengine/Expressions/PyObjectPlus.h
===================================================================
--- trunk/blender/source/gameengine/Expressions/PyObjectPlus.h	2009-04-19 13:37:59 UTC (rev 19789)
+++ trunk/blender/source/gameengine/Expressions/PyObjectPlus.h	2009-04-19 14:57:52 UTC (rev 19790)
@@ -50,13 +50,13 @@
    also in api2_2x/gen_utils.h 
 */
 #ifndef Py_RETURN_NONE
-#define Py_RETURN_NONE  return Py_BuildValue("O", Py_None)
+#define Py_RETURN_NONE  return Py_INCREF(Py_None), Py_None
 #endif
 #ifndef Py_RETURN_FALSE
-#define Py_RETURN_FALSE  return PyBool_FromLong(0)
+#define Py_RETURN_FALSE  return Py_INCREF(Py_False), Py_False
 #endif
 #ifndef Py_RETURN_TRUE
-#define Py_RETURN_TRUE  return PyBool_FromLong(1)
+#define Py_RETURN_TRUE  return Py_INCREF(Py_True), Py_True
 #endif
 
 /*  for pre Py 2.5 */
@@ -92,7 +92,7 @@
 #define BGE_PROXY_PYOWNS(_self) (((PyObjectPlus_Proxy *)_self)->py_owns)
 
 /* Note, sometimes we dont care what BGE type this is as long as its a proxy */
-#define BGE_PROXY_CHECK_TYPE(_self) ((_self)->ob_type->tp_dealloc == PyDestructor)
+#define BGE_PROXY_CHECK_TYPE(_self) ((_self)->ob_type->tp_dealloc == py_base_dealloc)
 
 
 								// This must be the first line of each 
@@ -429,81 +429,35 @@
 	PyObject *m_proxy; /* actually a PyObjectPlus_Proxy */
 	
 	virtual ~PyObjectPlus();					// destructor
-	static void PyDestructor(PyObject *self);				// python wrapper
 	
-//	void INCREF(void) {
-//		  Py_INCREF(this);
-//	  };				// incref method
-//	void DECREF(void) {
-//		  Py_DECREF(this);
-//	  };				// decref method
+	/* These static functions are referenced by ALL PyObjectPlus_Proxy types
+	 * they take the C++ reference from the PyObjectPlus_Proxy and call
+	 * its own virtual py_getattro, py_setattro etc. functions.
+	 */
+	static void			py_base_dealloc(PyObject *self);
+	static  PyObject*		py_base_getattro(PyObject * self, PyObject *attr);
+	static  int			py_base_setattro(PyObject *self, PyObject *attr, PyObject *value);
+	static PyObject*		py_base_repr(PyObject *self);
+
+	/* 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 int			py_delattro(PyObject *attr);
+	virtual int			py_setattro(PyObject *attr, PyObject *value);
+	virtual PyObject*		py_repr(void);
+
+	static PyObject*		py_get_attrdef(void *self, const PyAttributeDef *attrdef);
+	static int				py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyObject *value);
 	
-	virtual PyObject *py_getattro(PyObject *attr);			// py_getattro method
-	static  PyObject *py_base_getattro(PyObject * self, PyObject *attr) 	// This should be the entry in Type. 
-	{
-		PyObjectPlus *self_plus= BGE_PROXY_REF(self);
-		if(self_plus==NULL) {
-			if(!strcmp("isValid", PyString_AsString(attr))) {
-				Py_RETURN_TRUE;
-			}
-			PyErr_SetString(PyExc_RuntimeError, "data has been removed");
-			return NULL;
-		}
-		return self_plus->py_getattro(attr); 
-	}
-	
-	static PyObject*	py_get_attrdef(void *self, const PyAttributeDef *attrdef);
-	static int			py_set_attrdef(void *self, const PyAttributeDef *attrdef, PyObject *value);
-	
-#if 0
-	static PyObject *py_getattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr);
-	static int py_setattro_self(const PyAttributeDef attrlist[], void *self, PyObject *attr, PyObject *value);
-#endif
-	
-	virtual int py_delattro(PyObject *attr);
-	virtual int py_setattro(PyObject *attr, PyObject *value);		// py_setattro method
-	static  int py_base_setattro(PyObject *self, PyObject *attr, PyObject *value) // the PyType should reference this
-	{
-		PyObjectPlus *self_plus= BGE_PROXY_REF(self);
-		if(self_plus==NULL) {
-			PyErr_SetString(PyExc_RuntimeError, "data has been removed");
-			return -1;
-		}
-		
-		if (value==NULL)
-			return self_plus->py_delattro(attr);
-		
-		return self_plus->py_setattro(attr, value); 
-	}
-	

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list