when importing sys failed blender could crash on startup. Blender will now exit with...
authorCampbell Barton <ideasman42@gmail.com>
Mon, 17 Sep 2007 04:46:58 +0000 (04:46 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 17 Sep 2007 04:46:58 +0000 (04:46 +0000)
source/blender/python/BPY_interface.c

index 2b723f2444d6ca82c407c063e9eb7a4d74a98332..97d9f221ab99ee35bde0fdbf19c6c246420bdbe8 100644 (file)
@@ -273,25 +273,32 @@ void BPY_end_python( void )
 
 void syspath_append( char *dirname )
 {
-       PyObject *mod_sys, *dict, *path, *dir;
-
+       PyObject *mod_sys= NULL, *dict= NULL, *path= NULL, *dir= NULL;
+       short ok=1;
        PyErr_Clear(  );
 
        dir = Py_BuildValue( "s", dirname );
 
        mod_sys = PyImport_ImportModule( "sys" );       /* new ref */
-       dict = PyModule_GetDict( mod_sys );     /* borrowed ref */
-       path = PyDict_GetItemString( dict, "path" );    /* borrowed ref */
-
-       if( !PyList_Check( path ) )
-               return;
+       
+       if (mod_sys) {
+               dict = PyModule_GetDict( mod_sys );     /* borrowed ref */
+               path = PyDict_GetItemString( dict, "path" );    /* borrowed ref */
+               if ( !PyList_Check( path ) ) {
+                       ok = 0;
+               }
+       } else {
+               /* cant get the sys module */
+               ok = 0;
+       }
 
-       PyList_Append( path, dir );
+       if (ok && PyList_Append( path, dir ) != 0)
+               ok = 0; /* append failed */
 
-       if( PyErr_Occurred(  ) )
-               Py_FatalError( "could not build sys.path" );
+       if( (ok==0) || PyErr_Occurred(  ) )
+               Py_FatalError( "could import or build sys.path, can't continue" );
 
-       Py_DECREF( mod_sys );
+       Py_XDECREF( mod_sys );
 }
 
 void init_syspath( int first_time )