[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20093] trunk/blender/source: python3 compatibility for the BGE api, this only works with scons when WITH_BF_NOBLENDER is enabled.

Campbell Barton ideasman42 at gmail.com
Thu May 7 07:23:16 CEST 2009


Revision: 20093
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20093
Author:   campbellbarton
Date:     2009-05-07 07:23:15 +0200 (Thu, 07 May 2009)

Log Message:
-----------
python3 compatibility for the BGE api, this only works with scons when WITH_BF_NOBLENDER is enabled.
Mathutils, Geometry and BGL modules are currently disabled with python3

Modified Paths:
--------------
    trunk/blender/source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c
    trunk/blender/source/blender/python/SConscript
    trunk/blender/source/gameengine/Expressions/PyObjectPlus.h
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
    trunk/blender/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
    trunk/blender/source/gameengine/Ketsji/SConscript
    trunk/blender/source/gameengine/VideoTexture/Texture.cpp

Modified: trunk/blender/source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c
===================================================================
--- trunk/blender/source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c	2009-05-07 01:27:58 UTC (rev 20092)
+++ trunk/blender/source/blender/nodes/intern/SHD_nodes/SHD_dynamic.c	2009-05-07 05:23:15 UTC (rev 20093)
@@ -33,6 +33,11 @@
 #include <eval.h>
 #endif
 
+/* TODO, support python3.x */
+#if PY_VERSION_HEX >= 0x03000000
+#define DISABLE_PYTHON 1
+#endif
+
 #include "DNA_text_types.h"
 #include "BKE_text.h"
 #include "BKE_utildefines.h"

Modified: trunk/blender/source/blender/python/SConscript
===================================================================
--- trunk/blender/source/blender/python/SConscript	2009-05-07 01:27:58 UTC (rev 20092)
+++ trunk/blender/source/blender/python/SConscript	2009-05-07 05:23:15 UTC (rev 20093)
@@ -30,4 +30,6 @@
 if env['BF_BUILDINFO']:
 	defs.append('NAN_BUILDINFO')
 
-env.BlenderLib ( libname='blender_python', sources = Split(sources), includes = Split(incs), defines = defs, libtype=['core','game2'], priority = [60,115] )
+# A bit dodgy but disable building with python3
+if not env['BF_PYTHON_VERSION'].startswith('3'):
+	env.BlenderLib ( libname='blender_python', sources = Split(sources), includes = Split(incs), defines = defs, libtype=['core','game2'], priority = [60,115] )

Modified: trunk/blender/source/gameengine/Expressions/PyObjectPlus.h
===================================================================
--- trunk/blender/source/gameengine/Expressions/PyObjectPlus.h	2009-05-07 01:27:58 UTC (rev 20092)
+++ trunk/blender/source/gameengine/Expressions/PyObjectPlus.h	2009-05-07 05:23:15 UTC (rev 20093)
@@ -43,6 +43,23 @@
  * Python defines
 ------------------------------*/
 
+
+
+#if PY_VERSION_HEX > 0x03000000
+#define PyString_FromString PyUnicode_FromString
+#define PyString_FromFormat PyUnicode_FromFormat
+#define PyString_Check PyUnicode_Check
+#define PyString_Size PyUnicode_GetSize
+
+#define PyInt_FromLong PyLong_FromSsize_t
+#define PyInt_AsLong PyLong_AsSsize_t
+#define PyString_AsString _PyUnicode_AsString
+#define PyInt_Check PyLong_Check
+#define PyInt_AS_LONG PyLong_AsLong // TODO - check this one
+#endif
+
+
+
 /*
    Py_RETURN_NONE
    Python 2.4 macro.

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2009-05-07 01:27:58 UTC (rev 20092)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp	2009-05-07 05:23:15 UTC (rev 20093)
@@ -88,10 +88,12 @@
 #include "BKE_main.h"
 
 extern "C" {
+	#include "bpy_internal_import.h"  /* from the blender python api, but we want to import text too! */
+#if PY_VERSION_HEX < 0x03000000
 	#include "Mathutils.h" // Blender.Mathutils module copied here so the blenderlayer can use.
 	#include "Geometry.h" // Blender.Geometry module copied here so the blenderlayer can use.
-	#include "bpy_internal_import.h"  /* from the blender python api, but we want to import text too! */
 	#include "BGL.h"
+#endif
 }
 
 #include "marshal.h" /* python header for loading/saving dicts */
@@ -1770,7 +1772,7 @@
 	clearModule(modules, "GameLogic");	
 	clearModule(modules, "Rasterizer");	
 	clearModule(modules, "GameKeys");	
-	clearModule(modules, "VideoTexture");	
+	clearModule(modules, "VideoTexture");
 	clearModule(modules, "Mathutils");	
 	clearModule(modules, "Geometry");	
 	clearModule(modules, "BGL");	
@@ -2095,6 +2097,7 @@
 	return d;
 }
 
+#if PY_VERSION_HEX < 0x03000000
 PyObject* initMathutils()
 {
 	return Mathutils_Init("Mathutils"); // Use as a top level module in BGE
@@ -2109,6 +2112,11 @@
 {
 	return BGL_Init("BGL"); // Use as a top level module in BGE
 }
+#else // TODO Py3k conversion
+PyObject* initMathutils() {Py_INCREF(Py_None);return Py_None;}
+PyObject* initGeometry() {Py_INCREF(Py_None);return Py_None;}
+PyObject* initBGL() {Py_INCREF(Py_None);return Py_None;}
+#endif
 
 void KX_SetActiveScene(class KX_Scene* scene)
 {

Modified: trunk/blender/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_VehicleWrapper.cpp	2009-05-07 01:27:58 UTC (rev 20092)
+++ trunk/blender/source/gameengine/Ketsji/KX_VehicleWrapper.cpp	2009-05-07 05:23:15 UTC (rev 20093)
@@ -312,32 +312,9 @@
 	py_getattro_dict_up(PyObjectPlus);
 }
 
-int	KX_VehicleWrapper::py_setattro(PyObject *attr,PyObject* pyobj)
+int	KX_VehicleWrapper::py_setattro(PyObject *attr,PyObject* value)
 {
-	/* TODO - strange setattr, needs updating */
-	PyTypeObject* type = pyobj->ob_type;
-	int result = 1;
-
-	if (type == &PyList_Type)
-	{
-		result = 0;
-	}
-	if (type == &PyFloat_Type)
-	{
-		result = 0;
-
-	}
-	if (type == &PyInt_Type)
-	{
-		result = 0;
-	}
-	if (type == &PyString_Type)
-	{
-		result = 0;
-	}
-	if (result)
-		result = PyObjectPlus::py_setattro(attr,pyobj);
-	return result;
+	py_setattro_up(PyObjectPlus);
 };
 
 

Modified: trunk/blender/source/gameengine/Ketsji/SConscript
===================================================================
--- trunk/blender/source/gameengine/Ketsji/SConscript	2009-05-07 01:27:58 UTC (rev 20092)
+++ trunk/blender/source/gameengine/Ketsji/SConscript	2009-05-07 05:23:15 UTC (rev 20093)
@@ -7,25 +7,27 @@
 defs = ''
 
 # Mathutils C files.
-sources.extend([\
-	'#source/blender/python/api2_2x/Mathutils.c',\
-	'#source/blender/python/api2_2x/Geometry.c',\
-	'#source/blender/python/api2_2x/constant.c',\
-	'#source/blender/python/api2_2x/euler.c',\
-	'#source/blender/python/api2_2x/matrix.c',\
-	'#source/blender/python/api2_2x/quat.c',\
-	'#source/blender/python/api2_2x/vector.c',\
-])
+if not env['BF_PYTHON_VERSION'].startswith('3'):
+	# TODO - py3 support
+	sources.extend([\
+		'#source/blender/python/api2_2x/Mathutils.c',\
+		'#source/blender/python/api2_2x/Geometry.c',\
+		'#source/blender/python/api2_2x/euler.c',\
+		'#source/blender/python/api2_2x/matrix.c',\
+		'#source/blender/python/api2_2x/quat.c',\
+		'#source/blender/python/api2_2x/vector.c',\
+		'#source/blender/python/api2_2x/constant.c',\
+	])
+	
+	sources.extend([\
+		'#source/blender/python/api2_2x/BGL.c'
+	])
 
 sources.extend([\
 	'#source/blender/python/api2_2x/bpy_internal_import.c'
 ])
 
 
-sources.extend([\
-	'#source/blender/python/api2_2x/BGL.c'
-])
-
 incs = '. #source/blender/python/api2_2x' # Only for Mathutils! and bpy_internal_import.h, be very careful
 
 incs += ' #source/kernel/gen_system #intern/string #intern/guardedalloc'

Modified: trunk/blender/source/gameengine/VideoTexture/Texture.cpp
===================================================================
--- trunk/blender/source/gameengine/VideoTexture/Texture.cpp	2009-05-07 01:27:58 UTC (rev 20092)
+++ trunk/blender/source/gameengine/VideoTexture/Texture.cpp	2009-05-07 05:23:15 UTC (rev 20093)
@@ -168,7 +168,7 @@
 	// release scaled image buffer
 	delete [] self->m_scaledImg;
 	// release object
-	self->ob_type->tp_free((PyObject*)self);
+	((PyObject *)self)->ob_type->tp_free((PyObject*)self);
 }
 
 





More information about the Bf-blender-cvs mailing list