make sure BPY_Err_Handle clears python errors, even if the exception cant be printed. Added PyErr_Clear() incase there are other references to exception data (sys.exc_info() from python)

This commit is contained in:
Campbell Barton 2008-10-22 07:09:15 +00:00
parent 5987488fd0
commit 69c6bd604c
2 changed files with 18 additions and 7 deletions

@ -532,6 +532,16 @@ static PyObject *traceback_getFilename( PyObject * tb )
else return PyString_FromString("unknown");
}
static void BPY_Err_Clear(void)
{
/* Added in 2.48a, the last_traceback can reference Objects for example, increasing
* their user count. Not to mention holding references to wrapped data.
* This is especially bad when the PyObject for the wrapped data is free'd, after blender
* has alredy dealocated the pointer */
PySys_SetObject( "last_traceback", Py_None);
PyErr_Clear();
}
/****************************************************************************
* Description: Blender Python error handler. This catches the error and
* stores filename and line number in a global
@ -542,6 +552,7 @@ static void BPY_Err_Handle( char *script_name )
if( !script_name ) {
printf( "Error: script has NULL name\n" );
BPY_Err_Clear();
return;
}
@ -568,8 +579,9 @@ static void BPY_Err_Handle( char *script_name )
} else {
g_script_error.lineno = -1;
}
/* this avoids an abort in Python 2.3's garbage collecting: */
PyErr_Clear( );
/* this avoids an abort in Python 2.3's garbage collecting:
PyErr_Clear() */
BPY_Err_Clear(); /* Calls PyErr_Clear as well */
return;
} else {
PyErr_NormalizeException( &exception, &err, &tb );
@ -579,6 +591,7 @@ static void BPY_Err_Handle( char *script_name )
if( !tb ) {
printf( "\nCan't get traceback\n" );
BPY_Err_Clear(); /* incase there is still some data hanging about */
return;
}
@ -617,11 +630,7 @@ static void BPY_Err_Handle( char *script_name )
Py_DECREF( tb );
}
/* Added in 2.48a, the last_traceback can reference Objects for example, increasing
* their user count. Not to mention holding references to wrapped data.
* This is especially bad when the PyObject for the wrapped data is free'd, after blender
* has alredy dealocated the pointer */
PySys_SetObject( "last_traceback", Py_None);
BPY_Err_Clear();
return;
}

@ -268,6 +268,7 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
* This is especially bad when the PyObject for the wrapped data is free'd, after blender
* has alredy dealocated the pointer */
PySys_SetObject( "last_traceback", Py_None);
PyErr_Clear(); /* just to be sure */
return;
}
@ -311,6 +312,7 @@ void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
* This is especially bad when the PyObject for the wrapped data is free'd, after blender
* has alredy dealocated the pointer */
PySys_SetObject( "last_traceback", Py_None);
PyErr_Clear(); /* just to be sure */
//PyRun_SimpleString(m_scriptText.Ptr());
}