diff --git a/parser.cpp b/parser.cpp index 340267701..7ed65bc82 100644 --- a/parser.cpp +++ b/parser.cpp @@ -1012,6 +1012,10 @@ int parser_t::get_lineno() const const wchar_t *parser_t::current_filename() const { + /* We query a global array for the current file name, so it only makes sense to ask this on the principal parser. */ + ASSERT_IS_MAIN_THREAD(); + assert(this == &principal_parser()); + block_t *b = current_block; while( 1 ) diff --git a/reader.cpp b/reader.cpp index 10f020043..2e67c89f4 100644 --- a/reader.cpp +++ b/reader.cpp @@ -44,6 +44,7 @@ commence. #include #include #include +#include #if HAVE_NCURSES_H #include @@ -103,6 +104,7 @@ commence. #include "halloc.h" #include "halloc_util.h" #include "iothread.h" +#include "intern.h" #include "parse_util.h" @@ -325,9 +327,9 @@ static int is_interactive_read; static int end_loop = 0; /** - The list containing names of files that are being parsed + The stack containing names of files that are being parsed */ -static array_list_t current_filename; +static std::stack current_filename; /** @@ -498,21 +500,24 @@ void reader_handle_int( int sig ) } -wchar_t *reader_current_filename() +const wchar_t *reader_current_filename() { - return al_get_count( ¤t_filename )?(wchar_t *)al_peek( ¤t_filename ):0; + ASSERT_IS_MAIN_THREAD(); + return current_filename.empty() ? NULL : current_filename.top(); } void reader_push_current_filename( const wchar_t *fn ) { - al_push( ¤t_filename, fn ); + ASSERT_IS_MAIN_THREAD(); + current_filename.push(intern(fn)); } -wchar_t *reader_pop_current_filename() +void reader_pop_current_filename() { - return (wchar_t *)al_pop( ¤t_filename ); + ASSERT_IS_MAIN_THREAD(); + current_filename.pop(); } @@ -730,14 +735,11 @@ void reader_init() shell_modes.c_lflag &= ~ECHO; /* turn off echo mode */ shell_modes.c_cc[VMIN]=1; shell_modes.c_cc[VTIME]=0; - - al_init( ¤t_filename); } void reader_destroy() { - al_destroy( ¤t_filename); tcsetattr(0, TCSANOW, &saved_modes); } diff --git a/reader.h b/reader.h index e9ac22799..593a816db 100644 --- a/reader.h +++ b/reader.h @@ -46,7 +46,7 @@ void reader_destroy(); /** Returns the filename of the file currently read */ -wchar_t *reader_current_filename(); +const wchar_t *reader_current_filename(); /** Push a new filename on the stack of read files @@ -57,7 +57,7 @@ void reader_push_current_filename( const wchar_t *fn ); /** Pop the current filename from the stack of read files */ -wchar_t *reader_pop_current_filename(); +void reader_pop_current_filename(); /** Write the title to the titlebar. This function is called just