saving globalDict didnt work with python3.x
authorCampbell Barton <ideasman42@gmail.com>
Mon, 15 Jun 2009 20:22:50 +0000 (20:22 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 15 Jun 2009 20:22:50 +0000 (20:22 +0000)
source/gameengine/Ketsji/KX_PythonInit.cpp

index 20009b7b8461894bdf123404ac1afbec6837ebe6..b10ea7e1ab587a8c213e82ee4fdefd8285c304f7 100644 (file)
@@ -1986,6 +1986,8 @@ 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)
 {
        gp_KetsjiScene = scene;
@@ -2017,11 +2019,17 @@ int saveGamePythonConfig( char **marshal_buffer)
                        if (pyGlobalDictMarshal) {
                                // for testing only
                                // PyObject_Print(pyGlobalDictMarshal, stderr, 0);
-
+                               char *marshal_cstring;
+                               
+#if PY_VERSION_HEX < 0x03000000
+                               marshal_cstring = PyString_AsString(pyGlobalDictMarshal);
                                marshal_length= PyString_Size(pyGlobalDictMarshal);
+#else                  // py3 uses byte arrays
+                               marshal_cstring = PyBytes_AsString(pyGlobalDictMarshal);
+                               marshal_length= PyBytes_Size(pyGlobalDictMarshal);
+#endif
                                *marshal_buffer = new char[marshal_length + 1];
-                               memcpy(*marshal_buffer, PyString_AsString(pyGlobalDictMarshal), marshal_length);
-
+                               memcpy(*marshal_buffer, marshal_cstring, marshal_length);
                                Py_DECREF(pyGlobalDictMarshal);
                        } else {
                                printf("Error, GameLogic.globalDict could not be marshal'd\n");