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.

This commit is contained in:
elias.bachaalany 2011-05-09 10:29:08 +00:00
parent 7179b2c654
commit a52b90c771
3 changed files with 38 additions and 15 deletions

View File

@ -128,8 +128,8 @@ static bool g_ui_ready = false;
static bool g_alert_auto_scripts = true; static bool g_alert_auto_scripts = true;
static bool g_remove_cwd_sys_path = false; static bool g_remove_cwd_sys_path = false;
void end_execution(); static void end_execution();
void begin_execution(); static void begin_execution();
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// This callback is called on various interpreter events // 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 // Prepare for Python execution
void begin_execution() static void begin_execution()
{ {
if ( !g_ui_ready || script_timeout == 0 ) if ( !g_ui_ready || script_timeout == 0 )
return; return;
ninsns = 0;
end_execution(); end_execution();
box_displayed = false; reset_execution_time();
start_time = time(NULL);
PyEval_SetTrace(break_check, NULL); PyEval_SetTrace(break_check, NULL);
} }
//------------------------------------------------------------------------ //------------------------------------------------------------------------
// Called after Python execution finishes // Called after Python execution finishes
void end_execution() static void hide_script_waitbox()
{ {
if ( box_displayed ) if ( box_displayed )
{ {
hide_wait_box(); hide_wait_box();
box_displayed = false; box_displayed = false;
} }
}
static void end_execution()
{
hide_script_waitbox();
#ifdef ENABLE_PYTHON_PROFILING #ifdef ENABLE_PYTHON_PROFILING
PyEval_SetTrace(tracefunc, NULL); PyEval_SetTrace(tracefunc, NULL);
#else #else
@ -191,15 +198,18 @@ void end_execution()
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Exported to the Python environment // Exported to the Python environment
void disable_script_timeout()
{
script_timeout = 0;
end_execution();
}
int set_script_timeout(int timeout) int set_script_timeout(int timeout)
{ {
if ( timeout == 0 )
end_execution();
qswap(timeout, script_timeout); qswap(timeout, script_timeout);
if ( script_timeout != 0 ) reset_execution_time();
begin_execution(); hide_script_waitbox();
return timeout; return timeout;
} }

View File

@ -2911,7 +2911,7 @@ def AskAddr(defval, prompt):
""" """
Ask the user to enter an address 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. will appear in the dialog box.
@param prompt: the prompt to display 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 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. will appear in the dialog box.
@param prompt: the prompt to display in the dialog box @param prompt: the prompt to display in the dialog box

View File

@ -2320,7 +2320,8 @@ idainfo *get_inf_structure(void)
#<pydoc> #<pydoc>
def set_script_timeout(timeout): 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. @param timeout: This value is in seconds.
If this value is set to zero then the script will never timeout. If this value is set to zero then the script will never timeout.
@return: returns the old timeout value @return: returns the old timeout value
@ -2331,6 +2332,18 @@ def set_script_timeout(timeout):
int set_script_timeout(int timeout); int set_script_timeout(int timeout);
/* /*
#<pydoc> #<pydoc>
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
#</pydoc>
*/
void disable_script_timeout();
/*
#<pydoc>
def enable_extlang_python(enable): def enable_extlang_python(enable):
""" """
Enables or disables Python extlang. Enables or disables Python extlang.