Revision: 16894
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16894
Author:   campbellbarton
Date:     2008-10-03 08:27:41 +0200 (Fri, 03 Oct 2008)

Log Message:
-----------
Blender works with python 2.6, our own import functions that replace pythons 
internal function needed updating for an extra in argument in 2.6.

if importing is not working blender should not crash (was crashing on exit)

Modified Paths:
--------------
    trunk/blender/source/blender/python/BPY_interface.c
    trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp

Modified: trunk/blender/source/blender/python/BPY_interface.c
===================================================================
--- trunk/blender/source/blender/python/BPY_interface.c 2008-10-03 06:10:57 UTC 
(rev 16893)
+++ trunk/blender/source/blender/python/BPY_interface.c 2008-10-03 06:27:41 UTC 
(rev 16894)
@@ -95,6 +95,7 @@
 PyObject *bpy_pydriver_Dict = NULL;
 PyObject *bpy_orig_syspath_List = NULL;
 
+
 /*
  * set up a weakref list for Armatures
  *    creates list in __main__ module dict 
@@ -194,7 +195,7 @@
        //stuff for Registry module
        bpy_registryDict = PyDict_New(  );/* check comment at start of this 
file */
        if( !bpy_registryDict )
-               printf( "Error: Couldn't create the Registry Python 
Dictionary!" );
+               printf( "Warning: Couldn't create the Registry Python 
Dictionary!" );
        Py_SetProgramName( "blender" );
 
        /* Py_Initialize() will attempt to import the site module and
@@ -222,11 +223,11 @@
        
        //Start the interpreter
        Py_Initialize(  );
+       
        PySys_SetArgv( argc_copy, argv_copy );
-
        /* Initialize thread support (also acquires lock) */
        PyEval_InitThreads();
-
+       
        //Overrides __import__
        init_ourImport(  );
        init_ourReload(  );
@@ -236,7 +237,6 @@
 
        //Look for a python installation
        init_syspath( first_time ); /* not first_time: some msgs are suppressed 
*/
-
        py_tstate = PyGILState_GetThisThreadState();
        PyEval_ReleaseThread(py_tstate);
 
@@ -289,10 +289,7 @@
 {
        PyObject *mod_sys= NULL, *dict= NULL, *path= NULL, *dir= NULL;
        short ok=1;
-       PyErr_Clear(  );
 
-       dir = PyString_FromString( dirname );
-
        mod_sys = PyImport_ImportModule( "sys" );       /* new ref */
        
        if (mod_sys) {
@@ -303,16 +300,19 @@
                }
        } else {
                /* cant get the sys module */
+               /* PyErr_Clear(); is called below */
                ok = 0;
        }
        
+       dir = PyString_FromString( dirname );
+       
        if (ok && PySequence_Contains(path, dir)==0) { /* Only add if we need 
to */
-               if (ok && PyList_Append( path, dir ) != 0) /* decref below */
+               if (PyList_Append( path, dir ) != 0) /* decref below */
                        ok = 0; /* append failed */
        }
        
        if( (ok==0) || PyErr_Occurred(  ) )
-               fprintf(stderr, "could import or build sys.path\n" );
+               fprintf(stderr, "Warning: could import or build sys.path\n" );
        
        PyErr_Clear();
        Py_DECREF( dir );
@@ -333,8 +333,10 @@
                d = PyModule_GetDict( mod );
                EXPP_dict_set_item_str( d, "progname", PyString_FromString( 
bprogname ) );
                Py_DECREF( mod );
-       } else
-               printf( "Warning: could not set Blender.sys.progname\n" );
+       } else {
+               printf( "Warning: could not set Blender.sys\n" );
+               PyErr_Clear();
+       }
 
        progname = BLI_last_slash( bprogname ); /* looks for the last dir 
separator */
 
@@ -393,7 +395,8 @@
                
                Py_DECREF( mod );
        } else{
-               printf("import of sys module failed\n");
+               PyErr_Clear( );
+               printf("Warning: import of sys module failed\n");
        }
 }
 
@@ -406,13 +409,14 @@
 
        mod = PyImport_ImportModule( "sys" );   
        if (!mod) {
-               printf("error: could not import python sys module. some modules 
may not import.\n");
+               printf("Warning: could not import python sys module. some 
modules may not import.\n");
+               PyErr_Clear(  );
                PyGILState_Release(gilstate);
                return;
        }
        
        if (!bpy_orig_syspath_List) { /* should never happen */
-               printf("error refershing python path\n");
+               printf("Warning: cant refresh python path, 
bpy_orig_syspath_List is NULL\n");
                Py_DECREF(mod);
                PyGILState_Release(gilstate);
                return;
@@ -1228,6 +1232,8 @@
                PyDict_SetItemString(d, "Blender", mod);
                PyDict_SetItemString(d, "b", mod);
                Py_DECREF(mod);
+       } else {
+               PyErr_Clear();
        }
 
        mod = PyImport_ImportModule("math");
@@ -1245,6 +1251,8 @@
                PyDict_SetItemString(d, "noise", mod);
                PyDict_SetItemString(d, "n", mod);
                Py_DECREF(mod);
+       } else {
+               PyErr_Clear();
        }
 
        /* If there's a Blender text called pydrivers.py, import it.
@@ -1270,6 +1278,8 @@
                        PyDict_SetItemString(d, "ob", fcn);
                        Py_DECREF(fcn);
                }
+       } else {
+               PyErr_Clear();
        }
        
        /* TODO - change these */
@@ -1282,6 +1292,8 @@
                        PyDict_SetItemString(d, "me", fcn);
                        Py_DECREF(fcn);
                }
+       } else {
+               PyErr_Clear();
        }
 
        /* ma(matname) == Blender.Material.Get(matname) */
@@ -1293,6 +1305,8 @@
                        PyDict_SetItemString(d, "ma", fcn);
                        Py_DECREF(fcn);
                }
+       } else {
+               PyErr_Clear();
        }
 
        return 0;
@@ -2828,11 +2842,18 @@
        char *name;
        PyObject *globals = NULL, *locals = NULL, *fromlist = NULL;
        PyObject *m;
-
+       //PyObject_Print(args, stderr, 0);
+#if (PY_VERSION_HEX >= 0x02060000)
+       int dummy_val; /* what does this do?*/
+       
+       if( !PyArg_ParseTuple( args, "s|OOOi:bimport",
+                              &name, &globals, &locals, &fromlist, &dummy_val) 
)
+               return NULL;
+#else
        if( !PyArg_ParseTuple( args, "s|OOO:bimport",
                               &name, &globals, &locals, &fromlist ) )
                return NULL;
-
+#endif
        m = PyImport_ImportModuleEx( name, globals, locals, fromlist );
 
        if( m )

Modified: trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp
===================================================================
--- trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp    2008-10-03 
06:10:57 UTC (rev 16893)
+++ trunk/blender/source/gameengine/Ketsji/KX_PythonInit.cpp    2008-10-03 
06:27:41 UTC (rev 16894)
@@ -1077,9 +1077,17 @@
        PyObject *fromlist = NULL;
        PyObject *l, *m, *n;
 
+#if (PY_VERSION_HEX >= 0x02060000)
+       int dummy_val; /* what does this do?*/
+       
+       if (!PyArg_ParseTuple(args, "s|OOOi:m_import",
+               &name, &globals, &locals, &fromlist, &dummy_val))
+           return NULL;
+#else
        if (!PyArg_ParseTuple(args, "s|OOO:m_import",
                &name, &globals, &locals, &fromlist))
            return NULL;
+#endif
 
        /* check for builtin modules */
        m = PyImport_AddModule("sys");
@@ -1492,6 +1500,7 @@
                }
                Py_DECREF(gameLogic);
        } else {
+               PyErr_Clear();
                printf("Error, GameLogic failed to import GameLogic.globalDict 
will be lost\n");
        }
        return marshal_length;
@@ -1523,6 +1532,7 @@
                                printf("Error could not marshall string\n");
                        }
                } else {
+                       PyErr_Clear();
                        printf("Error, GameLogic failed to import 
GameLogic.globalDict will be lost\n");
                }       
        }


_______________________________________________
Bf-blender-cvs mailing list
[email protected]
http://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to