From a5d31fc28e7737b9e6ef3d56986cb2e2f0493047 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Sat, 15 Mar 2008 18:53:42 +0000 Subject: fix for [#8559] Python script that uses FIleSelector and has an error in it segfaults Blender --- source/blender/blenkernel/intern/script.c | 9 +-------- source/blender/python/BPY_extern.h | 4 +++- source/blender/python/BPY_interface.c | 22 +++++++++++----------- source/blender/python/api2_2x/Draw.c | 7 ++++--- source/blender/src/drawtext.c | 2 +- 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/source/blender/blenkernel/intern/script.c b/source/blender/blenkernel/intern/script.c index 099fedf460a..2836f5fd507 100644 --- a/source/blender/blenkernel/intern/script.c +++ b/source/blender/blenkernel/intern/script.c @@ -60,12 +60,5 @@ 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); } diff --git a/source/blender/python/BPY_extern.h b/source/blender/python/BPY_extern.h index d7bd4f22fc6..bf7c4d7ad62 100644 --- a/source/blender/python/BPY_extern.h +++ b/source/blender/python/BPY_extern.h @@ -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); */ diff --git a/source/blender/python/BPY_interface.c b/source/blender/python/BPY_interface.c index f99a804d75f..d4a894e7661 100644 --- a/source/blender/python/BPY_interface.c +++ b/source/blender/python/BPY_interface.c @@ -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"); +} diff --git a/source/blender/python/api2_2x/Draw.c b/source/blender/python/api2_2x/Draw.c index a4bbeba65ac..76e33a1bcb7 100644 --- a/source/blender/python/api2_2x/Draw.c +++ b/source/blender/python/api2_2x/Draw.c @@ -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 */ diff --git a/source/blender/src/drawtext.c b/source/blender/src/drawtext.c index 73b1aa9856c..327fcb341c7 100644 --- a/source/blender/src/drawtext.c +++ b/source/blender/src/drawtext.c @@ -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); -- cgit v1.2.3