Fixes a regression from 9d537999e315a7, which removed closing the file. This causes Windows widl build to be to remove the temporary file on exit.
-- v2: widl: Always close parsed input file.
From: Jacek Caban jacek@codeweavers.com
Fixes a regression from 9d537999e315a7, which removed closing the file. This causes Windows widl build to be to remove the temporary file on exit. --- tools/widl/parser.h | 1 + tools/widl/parser.l | 12 ++++++++++-- tools/widl/parser.y | 4 ++-- tools/widl/widl.c | 6 ++---- 4 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/tools/widl/parser.h b/tools/widl/parser.h index 7fef1e755bd..8db115dd03f 100644 --- a/tools/widl/parser.h +++ b/tools/widl/parser.h @@ -42,5 +42,6 @@ int is_warning_enabled(int warning);
extern char *find_input_file( const char *name, const char *parent ); extern FILE *open_input_file( const char *path ); +extern void close_all_inputs(void);
#endif diff --git a/tools/widl/parser.l b/tools/widl/parser.l index 61266efb9e3..7a1ae18abdc 100644 --- a/tools/widl/parser.l +++ b/tools/widl/parser.l @@ -481,10 +481,11 @@ static void print_imports(void) fprintf( stderr, "%s:%d:\n", state->input_name, state->where.first_line ); }
-void pop_import( struct location *where ) +struct location pop_import(void) { struct list *entry = list_head( &import_stack ); struct import_state *state; + struct location where; assert( entry );
state = LIST_ENTRY( entry, struct import_state, entry ); @@ -496,8 +497,9 @@ void pop_import( struct location *where ) yy_switch_to_buffer( state->buffer );
input_name = state->input_name; - *where = state->where; + where = state->where; free( state ); + return where; }
void push_import( const char *import_name, struct location *where ) @@ -547,6 +549,12 @@ static void switch_to_acf(void) yy_switch_to_buffer( yy_create_buffer( file, YY_BUF_SIZE ) ); }
+void close_all_inputs(void) +{ + while (!list_empty( &import_stack )) pop_import(); + if (yyin) fclose( yyin ); +} + static void reset_location( struct location *where, const char *input_name ) { where->first_line = 1; diff --git a/tools/widl/parser.y b/tools/widl/parser.y index bfd41aa9807..9b6a4c36732 100644 --- a/tools/widl/parser.y +++ b/tools/widl/parser.y @@ -118,7 +118,7 @@ static typelib_t *current_typelib;
int parser_lex( PARSER_STYPE *yylval, PARSER_LTYPE *yylloc ); void push_import( const char *fname, PARSER_LTYPE *yylloc ); -void pop_import( PARSER_LTYPE *yylloc ); +PARSER_LTYPE pop_import(void);
# define YYLLOC_DEFAULT( cur, rhs, n ) \ do { if (n) init_location( &(cur), &YYRHSLOC( rhs, 1 ), &YYRHSLOC( rhs, n ) ); \ @@ -515,7 +515,7 @@ cppquote: tCPPQUOTE '(' aSTRING ')' { $$ = $3; }
import_start: tIMPORT aSTRING ';' { $$ = $2; push_import( $2, &yylloc ); } ; -import: import_start imp_statements aEOF { pop_import( &yylloc ); } +import: import_start imp_statements aEOF { yyloc = pop_import(); } ;
importlib: tIMPORTLIB '(' aSTRING ')' diff --git a/tools/widl/widl.c b/tools/widl/widl.c index 9d3ea0c36bf..8a887d667ae 100644 --- a/tools/widl/widl.c +++ b/tools/widl/widl.c @@ -835,10 +835,8 @@ int main(int argc,char *argv[])
init_types(); ret = parser_parse(); - - if(ret) { - exit(1); - } + close_all_inputs(); + if (ret) exit(1);
/* Everything has been done successfully, don't delete any files. */ set_everything(FALSE);
On Wed Mar 20 20:56:37 2024 +0000, Rémi Bernon wrote:
This causes Windows widl build to be to remove the temporary file on exit.
Do you mean "to fail to remove"? Shouldn't we then also make sure that all the imports are popped (and closed) on exit, or can we somehow assume they are?
Right, it's not enough for errors in imported files. I pushed a more complete version.
This merge request was approved by Rémi Bernon.