From a52b90c771f39af8bbcee8441db5c831a79c9cb1 Mon Sep 17 00:00:00 2001 From: "elias.bachaalany" Date: Mon, 9 May 2011 10:29:08 +0000 Subject: [PATCH] bugfix: Previous implementation set_script_timeout() was causing the script wait dialog box to open and never close upon the invocation of callbacks (add_menu_item callback or other callbacks) that take longer than the timeout value. --- python.cpp | 34 ++++++++++++++++++++++------------ python/idc.py | 4 ++-- swig/idaapi.i | 15 ++++++++++++++- 3 files changed, 38 insertions(+), 15 deletions(-) diff --git a/python.cpp b/python.cpp index 6c44f79..ebc0dd3 100644 --- a/python.cpp +++ b/python.cpp @@ -128,8 +128,8 @@ static bool g_ui_ready = false; static bool g_alert_auto_scripts = true; static bool g_remove_cwd_sys_path = false; -void end_execution(); -void begin_execution(); +static void end_execution(); +static void begin_execution(); //------------------------------------------------------------------------ // This callback is called on various interpreter events @@ -159,29 +159,36 @@ static int break_check(PyObject *obj, _frame *frame, int what, PyObject *arg) } //------------------------------------------------------------------------ +static void reset_execution_time() +{ + start_time = time(NULL); + ninsns = 0; +} // Prepare for Python execution -void begin_execution() +static void begin_execution() { if ( !g_ui_ready || script_timeout == 0 ) return; - ninsns = 0; end_execution(); - box_displayed = false; - start_time = time(NULL); + reset_execution_time(); PyEval_SetTrace(break_check, NULL); } //------------------------------------------------------------------------ // Called after Python execution finishes -void end_execution() +static void hide_script_waitbox() { if ( box_displayed ) { hide_wait_box(); box_displayed = false; } +} +static void end_execution() +{ + hide_script_waitbox(); #ifdef ENABLE_PYTHON_PROFILING PyEval_SetTrace(tracefunc, NULL); #else @@ -191,15 +198,18 @@ void end_execution() //------------------------------------------------------------------------- // Exported to the Python environment +void disable_script_timeout() +{ + script_timeout = 0; + end_execution(); +} + int set_script_timeout(int timeout) { - if ( timeout == 0 ) - end_execution(); - qswap(timeout, script_timeout); - if ( script_timeout != 0 ) - begin_execution(); + reset_execution_time(); + hide_script_waitbox(); return timeout; } diff --git a/python/idc.py b/python/idc.py index 59bf15c..6df1f1a 100644 --- a/python/idc.py +++ b/python/idc.py @@ -2911,7 +2911,7 @@ def AskAddr(defval, prompt): """ Ask the user to enter an address - @param defval: the default address value. This value + @param defval: a string designating the default address value. This value will appear in the dialog box. @param prompt: the prompt to display in the dialog box @@ -2924,7 +2924,7 @@ def AskLong(defval, prompt): """ Ask the user to enter a number - @param defval: the default value. This value + @param defval: a number designating the default value. This value will appear in the dialog box. @param prompt: the prompt to display in the dialog box diff --git a/swig/idaapi.i b/swig/idaapi.i index 78ffed4..d73936c 100644 --- a/swig/idaapi.i +++ b/swig/idaapi.i @@ -2320,7 +2320,8 @@ idainfo *get_inf_structure(void) # def set_script_timeout(timeout): """ - Changes the script timeout value. + Changes the script timeout value. The script wait box dialog will be hidden and shown again when the timeout elapses. + See also L{disable_script_timeout}. @param timeout: This value is in seconds. If this value is set to zero then the script will never timeout. @return: returns the old timeout value @@ -2331,6 +2332,18 @@ def set_script_timeout(timeout): int set_script_timeout(int timeout); /* # +def disable_script_timeout(): + """ + Disables the script timeout and hides the script wait box. + Calling L{set_script_timeout} will not have any effects until the script is compiled and executed again + @return: None + """ + pass +# +*/ +void disable_script_timeout(); +/* +# def enable_extlang_python(enable): """ Enables or disables Python extlang.