diff --git a/historic/jam/src/builtins.c b/historic/jam/src/builtins.c index 20d413b7c..30aa649ad 100644 --- a/historic/jam/src/builtins.c +++ b/historic/jam/src/builtins.c @@ -937,6 +937,17 @@ static void add_hash_key( void* np, void* result_ ) *result = list_new( *result, copystr( *(char**)np ) ); } +static struct hash *get_running_module_vars() +{ + struct hash *dummy, *vars = NULL; + /* Get the global variables pointer (that of the currently running module) */ + var_hash_swap(&vars); + dummy = vars; + /* Put the global variables pointer in its right place */ + var_hash_swap(&dummy); + return vars; +} + LIST * builtin_varnames( PARSE *parse, @@ -946,8 +957,14 @@ builtin_varnames( LIST *result = L0; module_t* source_module = bindmodule( arg0 ? arg0->string : 0 ); - if ( source_module->variables ) - hashenumerate( source_module->variables, add_hash_key, &result ); + /* The running module _always_ has its 'variables' member set to NULL + * due to the way enter_module and var_hash_swap work */ + struct hash *vars = + source_module == frame->module ? + get_running_module_vars() : source_module->variables; + + if ( vars ) + hashenumerate( vars, add_hash_key, &result ); return result; }