when importing sys failed blender could crash on startup. Blender will now exit with an error rather then crashing.

This commit is contained in:
2007-09-17 04:46:58 +00:00
parent 90daa8f811
commit 976a0424e1

View File

@@ -273,25 +273,32 @@ void BPY_end_python( void )
void syspath_append( char *dirname ) 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( ); PyErr_Clear( );
dir = Py_BuildValue( "s", dirname ); dir = Py_BuildValue( "s", dirname );
mod_sys = PyImport_ImportModule( "sys" ); /* new ref */ 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 ) ) if (mod_sys) {
return; 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( ) ) if( (ok==0) || PyErr_Occurred( ) )
Py_FatalError( "could not build sys.path" ); 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 ) void init_syspath( int first_time )