Skip to content

Commit

Permalink
include fixes and suggestions from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
JanKanis committed Dec 22, 2012
1 parent 30392bf commit 8a446f4
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 25 deletions.
10 changes: 5 additions & 5 deletions builtin.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1010,12 +1010,12 @@ static int builtin_emit(parser_t &parser, wchar_t **argv)


} }


wcstring_list_t args; if(!argv[woptind]) {
wchar_t *eventname = argv[woptind]; append_format(stderr_buffer, L"%ls: expected event name\n", argv[0]);
for (woptind++; woptind < argc; woptind++) return STATUS_BUILTIN_ERROR;
{
args.push_back(argv[woptind]);
} }
wchar_t *eventname = argv[woptind];
wcstring_list_t args(argv + woptind + 1, argv + argc);
event_fire_generic(eventname, &args); event_fire_generic(eventname, &args);


return STATUS_BUILTIN_OK; return STATUS_BUILTIN_OK;
Expand Down
24 changes: 16 additions & 8 deletions event.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -221,8 +221,11 @@ static void show_all_handlers(void)
} }
#endif #endif



/*
wcstring event_type_str(const event_t &event) { Give a more condensed description of \c event compared to \c event_get_desc.
It includes what function will fire if the \c event is an event handler.
*/
static wcstring event_desc_compact(const event_t &event) {
wcstring res; wcstring res;
wchar_t const *temp; wchar_t const *temp;
int sig; int sig;
Expand Down Expand Up @@ -288,8 +291,10 @@ void event_add_handler(const event_t &event)
{ {
event_t *e; event_t *e;


if(debug_level >= 3) if(debug_level >= 3) {
debug(3, "register: %ls\n", event_type_str(event).c_str()); wcstring desc = event_desc_compact(event);
debug(3, "register: %ls\n", desc.c_str());
}


e = new event_t(event); e = new event_t(event);


Expand All @@ -304,14 +309,16 @@ void event_add_handler(const event_t &event)
signal_unblock(); signal_unblock();
} }


void event_remove(event_t &criterion) void event_remove(const event_t &criterion)
{ {


size_t i; size_t i;
event_list_t new_list; event_list_t new_list;


if(debug_level >= 3) if(debug_level >= 3) {
debug(3, "unregister: %ls\n", event_type_str(criterion).c_str()); wcstring desc = event_desc_compact(criterion);
debug(3, "unregister: %ls\n", desc.c_str());
}


/* /*
Because of concurrency issues (env_remove could remove an event Because of concurrency issues (env_remove could remove an event
Expand Down Expand Up @@ -504,7 +511,7 @@ static void event_fire_internal(const event_t &event)
prev_status = proc_get_last_status(); prev_status = proc_get_last_status();
parser_t &parser = parser_t::principal_parser(); parser_t &parser = parser_t::principal_parser();


block_t *block = new event_block_t((const event_t*)&event); block_t *block = new event_block_t(event);
parser.push_block(block); parser.push_block(block);
parser.eval(buffer, io_chain_t(), TOP); parser.eval(buffer, io_chain_t(), TOP);
parser.pop_block(); parser.pop_block();
Expand Down Expand Up @@ -570,6 +577,7 @@ static void event_fire_delayed()
Set up Set up
*/ */
event_t e = event_t::signal_event(0); event_t e = event_t::signal_event(0);
e.arguments.resize(1);
lst = &sig_list[1-active_list]; lst = &sig_list[1-active_list];


if (lst->overflow) if (lst->overflow)
Expand Down
8 changes: 1 addition & 7 deletions event.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void event_add_handler(const event_t &event);
May not be called by a signal handler, since it may free allocated memory. May not be called by a signal handler, since it may free allocated memory.
*/ */
void event_remove(event_t &event); void event_remove(const event_t &event);


/** /**
Return all events which match the specified event class Return all events which match the specified event class
Expand Down Expand Up @@ -171,12 +171,6 @@ void event_free(event_t *e);
*/ */
wcstring event_get_desc(const event_t &e); wcstring event_get_desc(const event_t &e);


/**
Returns a string describing the event. This version is more concise and
more detailed than event_get_desc.
*/
wcstring event_type_str(const event_t &e);

/** /**
Fire a generic event with the specified name Fire a generic event with the specified name
*/ */
Expand Down
4 changes: 2 additions & 2 deletions parser.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ void parser_t::stack_trace(block_t *b, wcstring &buff)
This is an event handler This is an event handler
*/ */
const event_block_t *eb = static_cast<const event_block_t *>(b); const event_block_t *eb = static_cast<const event_block_t *>(b);
wcstring description = event_get_desc(*eb->event); wcstring description = event_get_desc(eb->event);
append_format(buff, _(L"in event handler: %ls\n"), description.c_str()); append_format(buff, _(L"in event handler: %ls\n"), description.c_str());
buff.append(L"\n"); buff.append(L"\n");


Expand Down Expand Up @@ -3798,7 +3798,7 @@ if_block_t::if_block_t() :
{ {
} }


event_block_t::event_block_t(const event_t *evt) : event_block_t::event_block_t(const event_t &evt) :
block_t(EVENT), block_t(EVENT),
event(evt) event(evt)
{ {
Expand Down
4 changes: 2 additions & 2 deletions parser.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ struct if_block_t : public block_t


struct event_block_t : public block_t struct event_block_t : public block_t
{ {
const event_t * const event; event_t const &event;
event_block_t(const event_t *evt); event_block_t(const event_t &evt);
}; };


struct function_block_t : public block_t struct function_block_t : public block_t
Expand Down
1 change: 1 addition & 0 deletions tests/test9.err
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
emit: expected event name
3 changes: 3 additions & 0 deletions tests/test9.in
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ function test3 --on-event test3
end end


emit test3 foo bar emit test3 foo bar

# test empty argument
emit
2 changes: 1 addition & 1 deletion tests/test9.status
Original file line number Original file line Diff line number Diff line change
@@ -1 +1 @@
0 1

0 comments on commit 8a446f4

Please sign in to comment.