Fix for removing too many event handlers (that's why "Goodbye" never got printed")

This commit is contained in:
ridiculousfish 2012-02-17 11:36:49 -08:00
parent 6e58c9f7c8
commit 9787901ddb
4 changed files with 22 additions and 9 deletions

View File

@ -85,12 +85,12 @@ static event_list_t blocked;
they must name the same function.
*/
static int event_match( event_t *classv, event_t *instance )
static int event_match( const event_t *classv, const event_t *instance )
{
if( ! classv->function_name.empty() && ! instance->function_name.empty() )
{
if( classv->function_name == instance->function_name )
if( classv->function_name != instance->function_name )
return 0;
}
@ -164,7 +164,7 @@ static int event_is_blocked( event_t *e )
return event_block_list_blocks_type(parser.global_event_blocks, e->type);
}
wcstring event_get_desc( event_t *e )
wcstring event_get_desc( const event_t *e )
{
CHECK( e, 0 );
@ -221,6 +221,14 @@ wcstring event_get_desc( event_t *e )
return result;
}
static void show_all_handlers(void) {
puts("event handlers:");
for (event_list_t::const_iterator iter = events.begin(); iter != events.end(); iter++) {
const event_t *foo = *iter;
wcstring tmp = event_get_desc(foo);
printf(" handler now %ls\n", tmp.c_str());
}
}
void event_add_handler( event_t *event )
{
@ -234,12 +242,15 @@ void event_add_handler( event_t *event )
{
signal_handle( e->param1.signal, 1 );
}
events.push_back(e);
show_all_handlers();
}
void event_remove( event_t *criterion )
{
size_t i;
event_list_t new_list;
@ -284,6 +295,7 @@ void event_remove( event_t *criterion )
}
}
events.swap(new_list);
show_all_handlers();
}
int event_get( event_t *criterion, std::vector<event_t *> *out )
@ -332,8 +344,9 @@ static int event_is_killed( event_t *e )
optimize the 'no matches' path. This means that nothing is
allocated/initialized unless needed.
*/
static void event_fire_internal( event_t *event )
static void event_fire_internal( const event_t *event )
{
size_t i, j;
event_list_t fire;
@ -411,7 +424,7 @@ static void event_fire_internal( event_t *event )
prev_status = proc_get_last_status();
parser_t &parser = parser_t::principal_parser();
parser.push_block( EVENT );
parser.current_block->state1<event_t *>() = event;
parser.current_block->state1<const event_t *>() = event;
parser.eval( buffer.c_str(), 0, TOP );
parser.pop_block();
proc_pop_interactive();

View File

@ -158,7 +158,7 @@ void event_free( event_t *e );
/**
Returns a string describing the specified event.
*/
wcstring event_get_desc( event_t *e );
wcstring event_get_desc( const event_t *e );
/**
Fire a generic event with the specified name

View File

@ -214,7 +214,7 @@ static bool function_remove_ignore_autoload(const wcstring &name)
if (erased) {
event_t ev(EVENT_ANY);
ev.function_name=name.c_str();
ev.function_name=name;
event_remove( &ev );
}
return erased;

View File

@ -868,7 +868,7 @@ void parser_t::stack_trace( block_t *b, string_buffer_t *buff)
/*
This is an event handler
*/
wcstring description = event_get_desc( b->state1<event_t *>() );
wcstring description = event_get_desc( b->state1<const event_t *>() );
sb_printf( buff, _(L"in event handler: %ls\n"), description.c_str());
sb_printf( buff,
L"\n" );