diff options
author | 2006-02-09 04:44:37 +1000 | |
---|---|---|
committer | 2006-02-09 04:44:37 +1000 | |
commit | 47373c4f68a9c8386ee70545e731c901491ccfd0 (patch) | |
tree | e289ca971d770799aa97f919e33d4421fdb00c46 /parse_util.c | |
parent | cbf1dbaa2e40c427ee97276167348d4af3caf770 (diff) |
Fix bug where recursive function loading crashed fish
darcs-hash:20060208184437-ac50b-c6b2001fbab07ac9561ba7aa941fbab0d93d7cd7.gz
Diffstat (limited to 'parse_util.c')
-rw-r--r-- | parse_util.c | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/parse_util.c b/parse_util.c index 216a1a03..e9eb1d03 100644 --- a/parse_util.c +++ b/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; } } |