diff --git a/event.cpp b/event.cpp index 69d7f83fa..c6d31b031 100644 --- a/event.cpp +++ b/event.cpp @@ -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 *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; + parser.current_block->state1() = event; parser.eval( buffer.c_str(), 0, TOP ); parser.pop_block(); proc_pop_interactive(); diff --git a/event.h b/event.h index 647e6553b..a32c2b3c2 100644 --- a/event.h +++ b/event.h @@ -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 diff --git a/function.cpp b/function.cpp index 926865e5a..06a284d50 100644 --- a/function.cpp +++ b/function.cpp @@ -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; diff --git a/parser.cpp b/parser.cpp index e5cc65c2e..2453a37be 100644 --- a/parser.cpp +++ b/parser.cpp @@ -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() ); + wcstring description = event_get_desc( b->state1() ); sb_printf( buff, _(L"in event handler: %ls\n"), description.c_str()); sb_printf( buff, L"\n" );