Fix event_block_t list from ad-hoc linked list to std::dequeue

This commit is contained in:
ridiculousfish 2012-02-07 21:04:51 -08:00
parent a0a43046b3
commit 399c78fbf7
4 changed files with 30 additions and 50 deletions

View file

@ -798,25 +798,19 @@ static int builtin_block( parser_t &parser, wchar_t **argv )
return STATUS_BUILTIN_ERROR; return STATUS_BUILTIN_ERROR;
} }
event_block_t *eb = parser.global_event_block; if (parser.global_event_blocks.empty())
if( ! eb )
{ {
sb_printf( sb_err, _( L"%ls: No blocks defined\n" ), argv[0] ); sb_printf( sb_err, _( L"%ls: No blocks defined\n" ), argv[0] );
return STATUS_BUILTIN_ERROR; return STATUS_BUILTIN_ERROR;
} }
parser.global_event_block = eb->next; parser.global_event_blocks.pop_front();
free( eb );
} }
else else
{ {
block_t *block=parser.current_block; block_t *block=parser.current_block;
event_block_t *eb = (event_block_t *)malloc( sizeof( event_block_t ) ); event_block_t eb = {};
eb.typemask = type;
if( !eb )
DIE_MEM();
eb->type = type;
switch( scope ) switch( scope )
{ {
@ -840,14 +834,11 @@ static int builtin_block( parser_t &parser, wchar_t **argv )
} }
if( block ) if( block )
{ {
eb->next = block->first_event_block; block->event_blocks.push_front(eb);
block->first_event_block = eb;
halloc_register( block, eb );
} }
else else
{ {
eb->next = parser.global_event_block; parser.global_event_blocks.push_front(eb);
parser.global_event_block=eb;
} }
} }

View file

@ -172,29 +172,13 @@ static event_t *event_copy( event_t *event, int copy_arguments )
static int event_is_blocked( event_t *e ) static int event_is_blocked( event_t *e )
{ {
block_t *block; block_t *block;
event_block_t *eb;
parser_t &parser = parser_t::principal_parser(); parser_t &parser = parser_t::principal_parser();
for( block = parser.current_block; block; block = block->outer ) for( block = parser.current_block; block; block = block->outer )
{ {
for( eb = block->first_event_block; eb; eb=eb->next ) if (event_block_list_blocks_type(block->event_blocks, e->type))
{ return true;
if( eb->type & (1<<EVENT_ANY ) )
return 1;
if( eb->type & (1<<e->type) )
return 1;
}
} }
for( eb = parser.global_event_block; eb; eb=eb->next ) return event_block_list_blocks_type(parser.global_event_blocks, e->type);
{
if( eb->type & (1<<EVENT_ANY ) )
return 1;
if( eb->type & (1<<e->type) )
return 1;
return 1;
}
return 0;
} }
const wchar_t *event_get_desc( event_t *e ) const wchar_t *event_get_desc( event_t *e )

View file

@ -368,7 +368,6 @@ parser_t::parser_t(enum parser_type_t type) :
job_start_pos(0), job_start_pos(0),
eval_level(-1), eval_level(-1),
current_block(NULL), current_block(NULL),
global_event_block(NULL),
block_io(NULL) block_io(NULL)
{ {

View file

@ -12,6 +12,7 @@
#include "parser.h" #include "parser.h"
#include "event.h" #include "event.h"
#include <vector> #include <vector>
#include <deque>
#define PARSER_TEST_ERROR 1 #define PARSER_TEST_ERROR 1
#define PARSER_TEST_INCOMPLETE 2 #define PARSER_TEST_INCOMPLETE 2
@ -19,7 +20,7 @@
/** /**
event_block_t represents a block on events of the specified type event_block_t represents a block on events of the specified type
*/ */
typedef struct event_block struct event_block_t
{ {
/** /**
The types of events to block. This is interpreted as a bitset The types of events to block. This is interpreted as a bitset
@ -29,13 +30,20 @@ typedef struct event_block
Note that EVENT_ANY can be used to specify any event. Note that EVENT_ANY can be used to specify any event.
*/ */
int type; unsigned int typemask;
};
/** typedef std::deque<event_block_t> event_block_list_t;
The next event_block struct
*/ inline bool event_block_list_blocks_type(const event_block_list_t &ebls, int type) {
struct event_block *next; for (event_block_list_t::const_iterator iter = ebls.begin(); iter != ebls.end(); iter++) {
} event_block_t; if( iter->typemask & (1<<EVENT_ANY ) )
return true;
if( iter->typemask & (1<<type) )
return true;
}
return false;
}
/** Block state template, to replace the discriminated union */ /** Block state template, to replace the discriminated union */
@ -144,13 +152,11 @@ typedef struct block
*/ */
int src_lineno; int src_lineno;
/** Whether we should pop the environment variable stack when we're popped */ /** Whether we should pop the environment variable stack when we're popped off of the block stack */
bool wants_pop_env; bool wants_pop_env;
/** /** List of event blocks. */
Some naming confusion. This is a pointer to the first element in the list of all event blocks. event_block_list_t event_blocks;
*/
event_block_t *first_event_block;
/** /**
Next outer block Next outer block
@ -338,7 +344,7 @@ class parser_t {
block_t *current_block; block_t *current_block;
/** Global event blocks */ /** Global event blocks */
event_block_t *global_event_block; event_block_list_t global_event_blocks;
/** Current block level io redirections */ /** Current block level io redirections */
io_data_t *block_io; io_data_t *block_io;