Alexandre Julliard : winebuild: Open the output file only when needed.
Alexandre Julliard
julliard at winehq.org
Mon Mar 4 15:08:25 CST 2019
Module: wine
Branch: master
Commit: aa0572f0a27d5dd5981835aa5bd198061964df97
URL: https://source.winehq.org/git/wine.git/?a=commit;h=aa0572f0a27d5dd5981835aa5bd198061964df97
Author: Alexandre Julliard <julliard at winehq.org>
Date: Mon Mar 4 14:31:48 2019 +0100
winebuild: Open the output file only when needed.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
tools/winebuild/build.h | 2 ++
tools/winebuild/import.c | 3 ---
tools/winebuild/main.c | 34 +++++++---------------------------
tools/winebuild/res32.c | 2 --
tools/winebuild/spec16.c | 2 ++
tools/winebuild/spec32.c | 2 ++
tools/winebuild/utils.c | 38 ++++++++++++++++++++++++++++++++++++++
7 files changed, 51 insertions(+), 32 deletions(-)
diff --git a/tools/winebuild/build.h b/tools/winebuild/build.h
index eee98eb..d65af7b 100644
--- a/tools/winebuild/build.h
+++ b/tools/winebuild/build.h
@@ -258,6 +258,8 @@ extern char *get_temp_file_name( const char *prefix, const char *suffix );
extern void output_standard_file_header(void);
extern FILE *open_input_file( const char *srcdir, const char *name );
extern void close_input_file( FILE *file );
+extern void open_output_file(void);
+extern void close_output_file(void);
extern void dump_bytes( const void *buffer, unsigned int size );
extern int remove_stdcall_decoration( char *name );
extern void assemble_file( const char *src_file, const char *obj_file );
diff --git a/tools/winebuild/import.c b/tools/winebuild/import.c
index 893691e..b3c7121 100644
--- a/tools/winebuild/import.c
+++ b/tools/winebuild/import.c
@@ -1382,12 +1382,10 @@ static void build_windows_import_lib( DLLSPEC *spec )
const char *as_flags, *m_flag;
def_file = get_temp_file_name( output_file_name, ".def" );
- fclose( output_file );
if (!(output_file = fopen( def_file, "w" )))
fatal_error( "Unable to create output file '%s'\n", def_file );
output_def_file( spec, 0 );
fclose( output_file );
- output_file = NULL;
args = find_tool( "dlltool", NULL );
switch (target_cpu)
@@ -1484,5 +1482,4 @@ void output_import_lib( DLLSPEC *spec, char **argv )
build_unix_import_lib( spec );
build_library( output_file_name, argv, 1 );
}
- output_file_name = NULL;
}
diff --git a/tools/winebuild/main.c b/tools/winebuild/main.c
index b2f5c95..7769641 100644
--- a/tools/winebuild/main.c
+++ b/tools/winebuild/main.c
@@ -79,7 +79,6 @@ char *input_file_name = NULL;
char *spec_file_name = NULL;
FILE *output_file = NULL;
const char *output_file_name = NULL;
-static const char *output_file_source_name;
static int fake_module;
struct strarray lib_path = { 0 };
@@ -450,25 +449,9 @@ static char **parse_options( int argc, char **argv, DLLSPEC *spec )
add_import_dll( optarg, NULL );
break;
case 'o':
- {
- char *ext = strrchr( optarg, '.' );
-
- if (unlink( optarg ) == -1 && errno != ENOENT)
- fatal_error( "Unable to create output file '%s'\n", optarg );
- if (ext && !strcmp( ext, ".o" ))
- {
- output_file_source_name = get_temp_file_name( optarg, ".s" );
- if (!(output_file = fopen( output_file_source_name, "w" )))
- fatal_error( "Unable to create output file '%s'\n", optarg );
- }
- else
- {
- if (!(output_file = fopen( optarg, "w" )))
- fatal_error( "Unable to create output file '%s'\n", optarg );
- }
- output_file_name = xstrdup(optarg);
- atexit( cleanup ); /* make sure we remove the output file on exit */
- }
+ if (unlink( optarg ) == -1 && errno != ENOENT)
+ fatal_error( "Unable to create output file '%s'\n", optarg );
+ output_file_name = xstrdup( optarg );
break;
case 'r':
strarray_add( &res_files, xstrdup( optarg ), NULL );
@@ -636,8 +619,8 @@ int main(int argc, char **argv)
signal( SIGTERM, exit_on_signal );
signal( SIGINT, exit_on_signal );
- output_file = stdout;
argv = parse_options( argc, argv, spec );
+ atexit( cleanup ); /* make sure we remove the output file on exit */
switch(exec_mode)
{
@@ -671,7 +654,9 @@ int main(int argc, char **argv)
if (argv[0]) fatal_error( "file argument '%s' not allowed in this mode\n", argv[0] );
if (!spec_file_name) fatal_error( "missing .spec file\n" );
if (!parse_input_file( spec )) break;
+ open_output_file();
output_def_file( spec, 1 );
+ close_output_file();
break;
case MODE_IMPLIB:
if (!spec_file_name) fatal_error( "missing .spec file\n" );
@@ -687,11 +672,6 @@ int main(int argc, char **argv)
break;
}
if (nb_errors) exit(1);
- if (output_file_name)
- {
- if (fclose( output_file ) < 0) fatal_perror( "fclose" );
- if (output_file_source_name) assemble_file( output_file_source_name, output_file_name );
- output_file_name = NULL;
- }
+ output_file_name = NULL;
return 0;
}
diff --git a/tools/winebuild/res32.c b/tools/winebuild/res32.c
index d237782..b20dfb4 100644
--- a/tools/winebuild/res32.c
+++ b/tools/winebuild/res32.c
@@ -698,6 +698,4 @@ void output_res_o_file( DLLSPEC *spec )
if (format)
strarray_add( &args, "-F", format, NULL );
spawn( args );
-
- output_file_name = NULL; /* so we don't try to assemble it */
}
diff --git a/tools/winebuild/spec16.c b/tools/winebuild/spec16.c
index 85bcf09..027580b 100644
--- a/tools/winebuild/spec16.c
+++ b/tools/winebuild/spec16.c
@@ -816,6 +816,7 @@ void output_spec16_file( DLLSPEC *spec16 )
add_16bit_exports( spec32, spec16 );
needs_get_pc_thunk = 0;
+ open_output_file();
output_standard_file_header();
output_module( spec32 );
output_module16( spec16 );
@@ -831,6 +832,7 @@ void output_spec16_file( DLLSPEC *spec16 )
output( "\t%s \"%s\"\n", get_asm_string_keyword(), spec16->main_module );
}
output_gnu_stack_note();
+ close_output_file();
free_dll_spec( spec32 );
}
diff --git a/tools/winebuild/spec32.c b/tools/winebuild/spec32.c
index 132ab88..89f33c8 100644
--- a/tools/winebuild/spec32.c
+++ b/tools/winebuild/spec32.c
@@ -703,6 +703,7 @@ void BuildSpec32File( DLLSPEC *spec )
{
needs_get_pc_thunk = 0;
resolve_imports( spec );
+ open_output_file();
output_standard_file_header();
output_module( spec );
output_stubs( spec );
@@ -711,6 +712,7 @@ void BuildSpec32File( DLLSPEC *spec )
if (needs_get_pc_thunk) output_get_pc_thunk();
output_resources( spec );
output_gnu_stack_note();
+ close_output_file();
}
diff --git a/tools/winebuild/utils.c b/tools/winebuild/utils.c
index 78e9645..09b01fa 100644
--- a/tools/winebuild/utils.c
+++ b/tools/winebuild/utils.c
@@ -47,6 +47,7 @@
static struct strarray tmp_files;
static struct strarray empty_strarray;
+static const char *output_file_source_name;
static const struct
{
@@ -564,8 +565,10 @@ void init_output_buffer(void)
void flush_output_buffer(void)
{
+ open_output_file();
if (fwrite( output_buffer, 1, output_buffer_pos, output_file ) != output_buffer_pos)
fatal_error( "Error writing to %s\n", output_file_name );
+ close_output_file();
free( output_buffer );
}
@@ -724,6 +727,41 @@ void close_input_file( FILE *file )
/*******************************************************************
+ * open_output_file
+ */
+void open_output_file(void)
+{
+ if (output_file_name)
+ {
+ if (strendswith( output_file_name, ".o" ))
+ {
+ output_file_source_name = get_temp_file_name( output_file_name, ".s" );
+ if (!(output_file = fopen( output_file_source_name, "w" )))
+ fatal_error( "Unable to create output file '%s'\n", output_file_name );
+ }
+ else
+ {
+ if (!(output_file = fopen( output_file_name, "w" )))
+ fatal_error( "Unable to create output file '%s'\n", output_file_name );
+ }
+ }
+ else output_file = stdout;
+}
+
+
+/*******************************************************************
+ * close_output_file
+ */
+void close_output_file(void)
+{
+ if (!output_file || !output_file_name) return;
+ if (fclose( output_file ) < 0) fatal_perror( "fclose" );
+ if (output_file_source_name) assemble_file( output_file_source_name, output_file_name );
+ output_file = NULL;
+}
+
+
+/*******************************************************************
* remove_stdcall_decoration
*
* Remove a possible @xx suffix from a function name.
More information about the wine-cvs
mailing list