mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-26 10:43:47 +08:00
Fix event_block_t list from ad-hoc linked list to std::dequeue
This commit is contained in:
parent
a0a43046b3
commit
399c78fbf7
23
builtin.cpp
23
builtin.cpp
|
@ -797,26 +797,20 @@ static int builtin_block( parser_t &parser, wchar_t **argv )
|
|||
sb_printf( sb_err, _( L"%ls: Can not specify scope when removing block\n" ), argv[0] );
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
|
||||
event_block_t *eb = parser.global_event_block;
|
||||
if( ! eb )
|
||||
|
||||
if (parser.global_event_blocks.empty())
|
||||
{
|
||||
sb_printf( sb_err, _( L"%ls: No blocks defined\n" ), argv[0] );
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
}
|
||||
parser.global_event_block = eb->next;
|
||||
free( eb );
|
||||
parser.global_event_blocks.pop_front();
|
||||
}
|
||||
else
|
||||
{
|
||||
block_t *block=parser.current_block;
|
||||
|
||||
event_block_t *eb = (event_block_t *)malloc( sizeof( event_block_t ) );
|
||||
|
||||
if( !eb )
|
||||
DIE_MEM();
|
||||
|
||||
eb->type = type;
|
||||
event_block_t eb = {};
|
||||
eb.typemask = type;
|
||||
|
||||
switch( scope )
|
||||
{
|
||||
|
@ -840,14 +834,11 @@ static int builtin_block( parser_t &parser, wchar_t **argv )
|
|||
}
|
||||
if( block )
|
||||
{
|
||||
eb->next = block->first_event_block;
|
||||
block->first_event_block = eb;
|
||||
halloc_register( block, eb );
|
||||
block->event_blocks.push_front(eb);
|
||||
}
|
||||
else
|
||||
{
|
||||
eb->next = parser.global_event_block;
|
||||
parser.global_event_block=eb;
|
||||
parser.global_event_blocks.push_front(eb);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
22
event.cpp
22
event.cpp
|
@ -172,29 +172,13 @@ static event_t *event_copy( event_t *event, int copy_arguments )
|
|||
static int event_is_blocked( event_t *e )
|
||||
{
|
||||
block_t *block;
|
||||
event_block_t *eb;
|
||||
parser_t &parser = parser_t::principal_parser();
|
||||
for( block = parser.current_block; block; block = block->outer )
|
||||
{
|
||||
for( eb = block->first_event_block; eb; eb=eb->next )
|
||||
{
|
||||
if( eb->type & (1<<EVENT_ANY ) )
|
||||
return 1;
|
||||
if( eb->type & (1<<e->type) )
|
||||
return 1;
|
||||
}
|
||||
if (event_block_list_blocks_type(block->event_blocks, e->type))
|
||||
return true;
|
||||
}
|
||||
for( eb = parser.global_event_block; eb; eb=eb->next )
|
||||
{
|
||||
if( eb->type & (1<<EVENT_ANY ) )
|
||||
return 1;
|
||||
if( eb->type & (1<<e->type) )
|
||||
return 1;
|
||||
return 1;
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
return event_block_list_blocks_type(parser.global_event_blocks, e->type);
|
||||
}
|
||||
|
||||
const wchar_t *event_get_desc( event_t *e )
|
||||
|
|
|
@ -368,7 +368,6 @@ parser_t::parser_t(enum parser_type_t type) :
|
|||
job_start_pos(0),
|
||||
eval_level(-1),
|
||||
current_block(NULL),
|
||||
global_event_block(NULL),
|
||||
block_io(NULL)
|
||||
{
|
||||
|
||||
|
|
34
parser.h
34
parser.h
|
@ -12,6 +12,7 @@
|
|||
#include "parser.h"
|
||||
#include "event.h"
|
||||
#include <vector>
|
||||
#include <deque>
|
||||
|
||||
#define PARSER_TEST_ERROR 1
|
||||
#define PARSER_TEST_INCOMPLETE 2
|
||||
|
@ -19,7 +20,7 @@
|
|||
/**
|
||||
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
|
||||
|
@ -29,13 +30,20 @@ typedef struct event_block
|
|||
|
||||
Note that EVENT_ANY can be used to specify any event.
|
||||
*/
|
||||
int type;
|
||||
|
||||
/**
|
||||
The next event_block struct
|
||||
*/
|
||||
struct event_block *next;
|
||||
} event_block_t;
|
||||
unsigned int typemask;
|
||||
};
|
||||
|
||||
typedef std::deque<event_block_t> event_block_list_t;
|
||||
|
||||
inline bool event_block_list_blocks_type(const event_block_list_t &ebls, int type) {
|
||||
for (event_block_list_t::const_iterator iter = ebls.begin(); iter != ebls.end(); iter++) {
|
||||
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 */
|
||||
|
@ -144,13 +152,11 @@ typedef struct block
|
|||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
Some naming confusion. This is a pointer to the first element in the list of all event blocks.
|
||||
*/
|
||||
event_block_t *first_event_block;
|
||||
/** List of event blocks. */
|
||||
event_block_list_t event_blocks;
|
||||
|
||||
/**
|
||||
Next outer block
|
||||
|
@ -338,7 +344,7 @@ class parser_t {
|
|||
block_t *current_block;
|
||||
|
||||
/** Global event blocks */
|
||||
event_block_t *global_event_block;
|
||||
event_block_list_t global_event_blocks;
|
||||
|
||||
/** Current block level io redirections */
|
||||
io_data_t *block_io;
|
||||
|
|
Loading…
Reference in New Issue
Block a user