fix for [#8559] Python script that uses FIleSelector and has an error in it segfaults...
authorCampbell Barton <ideasman42@gmail.com>
Sat, 15 Mar 2008 18:53:42 +0000 (18:53 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 15 Mar 2008 18:53:42 +0000 (18:53 +0000)
source/blender/blenkernel/intern/script.c
source/blender/python/BPY_extern.h
source/blender/python/BPY_interface.c
source/blender/python/api2_2x/Draw.c
source/blender/src/drawtext.c

index 099fedf460af34cc748af46b7b0bc2652d72156c..2836f5fd507d584fbea8800e4411bcf9860139b7 100644 (file)
 void free_script (Script *script)
 {
        if (!script) return;
-
-       if (script->py_globaldict || script->py_button ||
-                       script->py_event || script->py_draw)
-       {
-               BPY_clear_script(script);
-       }
-
-       return;
+       BPY_clear_script(script);
 }
index d7bd4f22fc6ccd990f0c2d332a9f792b57738472..bf7c4d7ad62fc2e5fb125ae03575987468caddcf 100644 (file)
@@ -128,7 +128,9 @@ extern "C" {
        void BPY_clear_script( struct Script *script );
        void BPY_free_finished_script( struct Script *script );
        void BPY_scripts_clear_pyobjects( void );
-
+       
+       void error_pyscript( void );
+       
 /* void BPY_Err_Handle(struct Text *text); */
 /* void BPY_clear_bad_scriptlink(struct ID *id, struct Text *byebye); */
 /* void BPY_clear_bad_scriptlist(struct ListBase *, struct Text *byebye); */
index f99a804d75f4fcafcc2abefd83c9a19c78681595..d4a894e76616e3e530fb68f1c207e97ce6bb8d60 100644 (file)
@@ -284,7 +284,6 @@ void BPY_end_python( void )
         * Python is finalized and G.main is freed in exit_usiblender() */
        for (script = G.main->script.first; script; script = next_script) {
                next_script = script->id.next;
-               BPY_clear_script(script);
                free_libblock( &G.main->script, script );
        }
 
@@ -693,8 +692,7 @@ int BPY_txt_do_python_Text( struct Text *text )
                BPY_Err_Handle( textname );
                ReleaseGlobalDictionary( py_dict );
                script->py_globaldict = NULL;
-               if( G.main->script.first )
-                       free_libblock( &G.main->script, script );
+               free_libblock( &G.main->script, script );
                PyGILState_Release(gilstate);
                return 0;
        } else {
@@ -817,8 +815,7 @@ int BPY_run_script(Script *script)
                fp = fopen( script->scriptname, "rb" );
                if( !fp ) {
                        printf( "Error loading script: couldn't open file %s\n", script->scriptname );
-                       if( G.main->script.first )
-                               free_libblock( &G.main->script, script );
+                       free_libblock( &G.main->script, script );
                        PyGILState_Release(gilstate);
                        return 0;
                }
@@ -844,8 +841,7 @@ int BPY_run_script(Script *script)
 
        if( !setup_armature_weakrefs()){
                printf("Oops - weakref dict\n");
-               if( G.main->script.first )
-                       free_libblock( &G.main->script, script );
+               free_libblock( &G.main->script, script );
                ReleaseGlobalDictionary( py_dict );
                MEM_freeN( buffer );
                PyGILState_Release(gilstate);
@@ -912,9 +908,8 @@ int BPY_run_script(Script *script)
                BPY_Err_Handle( script->id.name + 2 );
                ReleaseGlobalDictionary( py_dict );
                script->py_globaldict = NULL;
-               if( G.main->script.first )
-                       free_libblock( &G.main->script, script );
-               error( "Python script error: check console" );
+               free_libblock( &G.main->script, script );
+               error_pyscript(  );
 
                PyGILState_Release(gilstate);
                return 0;
@@ -1112,7 +1107,7 @@ void BPY_free_finished_script( Script * script )
 
        if( PyErr_Occurred(  ) ) {      /* if script ended after filesel */
                PyErr_Print(  );        /* eventual errors are handled now */
-               error( "Python script error: check console" );
+               error_pyscript(  );
        }
 
        PyGILState_Release(gilstate);
@@ -1148,6 +1143,7 @@ static void unlink_script( Script * script )
        }
 }
 
+/* This is called from free_libblock( &G.main->script, script ); */
 void BPY_clear_script( Script * script )
 {
        PyObject *dict;
@@ -2963,3 +2959,7 @@ void BPY_scripts_clear_pyobjects( void )
                SCRIPT_SET_NULL(script)
        }
 }
+void error_pyscript( void )
+{
+       error("Python script error: check console");
+}
index a4bbeba65ac31be3e7a0d25b2f63db7ad83fa8d7..76e33a1bcb726b93f1cac1778daa615b22ef88e7 100644 (file)
@@ -617,7 +617,8 @@ static void exit_pydraw( SpaceScript * sc, short err )
        if( err ) {
                PyErr_Print(  );
                script->flags = 0;      /* mark script struct for deletion */
-               error( "Python script error: check console" );
+               SCRIPT_SET_NULL(script);
+               error_pyscript();
                scrarea_queue_redraw( sc->area );
        }
 
@@ -837,7 +838,7 @@ static void exec_but_callback(void *pyobj, void *data)
        if (!result) {
                Py_DECREF(pyvalue);
                PyErr_Print(  );
-               error( "Python script error: check console" );
+               error_pyscript(  );
        }
        Py_XDECREF( result );
 }
@@ -1109,7 +1110,7 @@ static PyObject *Method_UIBlock( PyObject * self, PyObject * args )
        
        if (!result) {
                PyErr_Print(  );
-               error( "Python script error: check console" );
+               error_pyscript(  );
        } else {
                /* copied from do_clever_numbuts in toolbox.c */
                
index 73b1aa9856c1f5ba9674c4d3efa7f603ae710bca..327fcb341c7b16521a7f2773c6e17f3ddd1fc770 100644 (file)
@@ -1442,7 +1442,7 @@ void run_python_script(SpaceText *st)
                if (!st->text) return;
 
                if (!strcmp(py_filename, st->text->id.name+2)) {
-                       error("Python script error, check console");
+                       error_pyscript(  );
                        if (lineno >= 0) {
                                txt_move_toline(text, lineno-1, 0);
                                txt_sel_line(text);