From 1f6a98ecb8d03e05b1ce58aa96275de3b4166706 Mon Sep 17 00:00:00 2001 From: axel Date: Sun, 26 Nov 2006 23:09:43 +1000 Subject: [PATCH] Make sure that non-exporeted variables can shadow exported ones. This problem was reported by David Bitseff. darcs-hash:20061126130943-ac50b-b99cddc9a042545d5555b281d7e0aa8f667131d6.gz --- env.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/env.c b/env.c index 2911273fb..66bf1185c 100644 --- a/env.c +++ b/env.c @@ -1314,16 +1314,31 @@ void env_get_names( array_list_t *l, int flags ) static void export_func1( void *k, void *v, void *aux ) { var_entry_t *val_entry = (var_entry_t *)v; + hash_table_t *h = (hash_table_t *)aux; + + hash_remove( h, k, 0, 0 ); + if( val_entry->export ) - { - hash_table_t *h = (hash_table_t *)aux; - - if( !hash_get( h, k ) ) - hash_put( h, k, val_entry->val ); + { + hash_put( h, k, val_entry->val ); } } +static void get_exported( env_node_t *n, hash_table_t *h ) +{ + if( !n ) + return; + + if( n->new_scope ) + get_exported( global_env, h ); + else + get_exported( n->next, h ); + + hash_foreach2( &n->env, &export_func1, h ); +} + + /** Function used by env_export_arr to iterate over hashtable of variables */ @@ -1376,7 +1391,6 @@ char **env_export_arr( int recalc ) { array_list_t uni; hash_table_t vals; - env_node_t *n=top; int prev_was_null=1; int pos=0; int i; @@ -1385,15 +1399,7 @@ char **env_export_arr( int recalc ) hash_init( &vals, &hash_wcs_func, &hash_wcs_cmp ); - while( n ) - { - hash_foreach2( &n->env, &export_func1, &vals ); - - if( n->new_scope ) - n = global_env; - else - n = n->next; - } + get_exported( top, &vals ); al_init( &uni ); env_universal_get_names( &uni, 1, 0 );