Revision: 17170
          
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17170
Author:   campbellbarton
Date:     2008-10-22 09:09:15 +0200 (Wed, 22 Oct 2008)

Log Message:
-----------
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)

Modified Paths:
--------------
    trunk/blender/source/blender/python/BPY_interface.c
    trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp

Modified: trunk/blender/source/blender/python/BPY_interface.c
===================================================================
--- trunk/blender/source/blender/python/BPY_interface.c 2008-10-22 07:02:30 UTC 
(rev 17169)
+++ trunk/blender/source/blender/python/BPY_interface.c 2008-10-22 07:09:15 UTC 
(rev 17170)
@@ -532,6 +532,16 @@
        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 @@
 
        if( !script_name ) {
                printf( "Error: script has NULL name\n" );
+               BPY_Err_Clear();
                return;
        }
 
@@ -568,8 +579,9 @@
                } 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 @@
 
                if( !tb ) {
                        printf( "\nCan't get traceback\n" );
+                       BPY_Err_Clear(); /* incase there is still some data 
hanging about */
                        return;
                }
 
@@ -617,11 +630,7 @@
                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;
 }
 

Modified: trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp
===================================================================
--- trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp  
2008-10-22 07:02:30 UTC (rev 17169)
+++ trunk/blender/source/gameengine/GameLogic/SCA_PythonController.cpp  
2008-10-22 07:09:15 UTC (rev 17170)
@@ -268,6 +268,7 @@
                         * 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 @@
                 * 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());
        }


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

Reply via email to