mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-11 07:34:32 +00:00
Fix bug where recursive function loading crashed fish
darcs-hash:20060208184437-ac50b-c6b2001fbab07ac9561ba7aa941fbab0d93d7cd7.gz
This commit is contained in:
parent
cbf1dbaa2e
commit
47373c4f68
2 changed files with 43 additions and 11 deletions
42
parse_util.c
42
parse_util.c
|
@ -28,7 +28,7 @@
|
|||
/**
|
||||
Set of files which have been autoloaded
|
||||
*/
|
||||
static hash_table_t *loaded=0;
|
||||
static hash_table_t *all_loaded=0;
|
||||
|
||||
int parse_util_lineno( const wchar_t *str, int len )
|
||||
{
|
||||
|
@ -438,6 +438,8 @@ int parse_util_load( const wchar_t *cmd,
|
|||
string_buffer_t path;
|
||||
time_t *tm;
|
||||
int reloaded = 0;
|
||||
hash_table_t *loaded;
|
||||
|
||||
|
||||
/*
|
||||
Do we know where to look
|
||||
|
@ -445,6 +447,18 @@ int parse_util_load( const wchar_t *cmd,
|
|||
|
||||
if( !path_var )
|
||||
return 0;
|
||||
|
||||
if( !all_loaded )
|
||||
{
|
||||
all_loaded = malloc( sizeof( hash_table_t ) );
|
||||
if( !all_loaded )
|
||||
{
|
||||
die_mem();
|
||||
}
|
||||
hash_init( all_loaded, &hash_wcs_func, &hash_wcs_cmp );
|
||||
}
|
||||
|
||||
loaded = hash_get( all_loaded, path_var );
|
||||
|
||||
if( !loaded )
|
||||
{
|
||||
|
@ -454,8 +468,8 @@ int parse_util_load( const wchar_t *cmd,
|
|||
die_mem();
|
||||
}
|
||||
hash_init( loaded, &hash_wcs_func, &hash_wcs_cmp );
|
||||
hash_put( all_loaded, wcsdup(path_var), loaded );
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Get modification time of file
|
||||
|
@ -514,7 +528,7 @@ int parse_util_load( const wchar_t *cmd,
|
|||
free( esc );
|
||||
|
||||
on_load(cmd );
|
||||
|
||||
|
||||
/*
|
||||
Source the completion file for the specified completion
|
||||
*/
|
||||
|
@ -562,16 +576,26 @@ static void clear_hash_value( const void *key, const void *data )
|
|||
free( (void *)data );
|
||||
}
|
||||
|
||||
static void clear_loaded_entry( const void *key, const void *data )
|
||||
{
|
||||
hash_table_t *loaded = (hash_table_t *)data;
|
||||
hash_foreach( loaded,
|
||||
&clear_hash_value );
|
||||
hash_destroy( loaded );
|
||||
free( loaded );
|
||||
free( (void *)key );
|
||||
}
|
||||
|
||||
void parse_util_destroy()
|
||||
{
|
||||
if( loaded )
|
||||
if( all_loaded )
|
||||
{
|
||||
hash_foreach( loaded,
|
||||
&clear_hash_value );
|
||||
hash_destroy( loaded );
|
||||
free( loaded );
|
||||
loaded = 0;
|
||||
hash_foreach( all_loaded,
|
||||
&clear_loaded_entry );
|
||||
|
||||
hash_destroy( all_loaded );
|
||||
free( all_loaded );
|
||||
all_loaded = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
12
parser.c
12
parser.c
|
@ -1169,7 +1169,7 @@ wchar_t *parser_current_line()
|
|||
/*
|
||||
Calculate line number, line offset, etc.
|
||||
*/
|
||||
for( i=0; i<current_tokenizer_pos; i++ )
|
||||
for( i=0; i<current_tokenizer_pos && whole_str[i]; i++ )
|
||||
{
|
||||
if( whole_str[i] == L'\n' )
|
||||
{
|
||||
|
@ -1640,6 +1640,7 @@ static int parse_job( process_t *p,
|
|||
int is_new_block=0; // Does this command create a new block?
|
||||
|
||||
block_t *prev_block = current_block;
|
||||
int prev_tokenizer_pos = current_tokenizer_pos;
|
||||
|
||||
al_init( &args );
|
||||
|
||||
|
@ -1663,6 +1664,7 @@ static int parse_job( process_t *p,
|
|||
tok_last( tok ) );
|
||||
|
||||
al_destroy( &args );
|
||||
current_tokenizer_pos = prev_tokenizer_pos;
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
|
@ -1676,6 +1678,7 @@ static int parse_job( process_t *p,
|
|||
tok_last(tok) );
|
||||
|
||||
al_destroy( &args );
|
||||
current_tokenizer_pos = prev_tokenizer_pos;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1698,6 +1701,7 @@ static int parse_job( process_t *p,
|
|||
}
|
||||
|
||||
al_destroy( &args );
|
||||
current_tokenizer_pos = prev_tokenizer_pos;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1709,6 +1713,7 @@ static int parse_job( process_t *p,
|
|||
tok_get_desc( tok_last_type(tok) ) );
|
||||
|
||||
al_destroy( &args );
|
||||
current_tokenizer_pos = prev_tokenizer_pos;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
@ -1795,6 +1800,7 @@ static int parse_job( process_t *p,
|
|||
EXEC_ERR_MSG );
|
||||
al_destroy( &args );
|
||||
free(nxt);
|
||||
current_tokenizer_pos = prev_tokenizer_pos;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1809,6 +1815,7 @@ static int parse_job( process_t *p,
|
|||
use_builtin=0;
|
||||
p->type=INTERNAL_EXEC;
|
||||
free( nxt );
|
||||
current_tokenizer_pos = prev_tokenizer_pos;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -1972,6 +1979,7 @@ static int parse_job( process_t *p,
|
|||
|
||||
if( is_new_block )
|
||||
{
|
||||
|
||||
const wchar_t *end=parser_find_end( tok_string( tok ) +
|
||||
current_tokenizer_pos );
|
||||
tokenizer subtok;
|
||||
|
@ -2065,7 +2073,7 @@ static int parse_job( process_t *p,
|
|||
|
||||
}
|
||||
al_destroy( &args );
|
||||
|
||||
current_tokenizer_pos = prev_tokenizer_pos;
|
||||
return !error_code;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue