winebuild: Use strarray objects instead of pointers where possible.
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
parent
6bc0ce26a8
commit
8baaf5349f
|
@ -229,10 +229,9 @@ extern char *xstrdup( const char *str );
|
|||
extern char *strupper(char *s);
|
||||
extern int strendswith(const char* str, const char* end);
|
||||
extern char *strmake(const char* fmt, ...) __attribute__((__format__ (__printf__, 1, 2 )));
|
||||
extern struct strarray *strarray_fromstring( const char *str, const char *delim );
|
||||
extern struct strarray strarray_fromstring( const char *str, const char *delim );
|
||||
extern void strarray_add( struct strarray *array, ... );
|
||||
extern void strarray_addv( struct strarray *array, char * const *argv );
|
||||
extern void strarray_free( struct strarray *array );
|
||||
extern DECLSPEC_NORETURN void fatal_error( const char *msg, ... )
|
||||
__attribute__ ((__format__ (__printf__, 1, 2)));
|
||||
extern DECLSPEC_NORETURN void fatal_perror( const char *msg, ... )
|
||||
|
@ -245,10 +244,10 @@ extern int output( const char *format, ... )
|
|||
__attribute__ ((__format__ (__printf__, 1, 2)));
|
||||
extern void output_cfi( const char *format, ... )
|
||||
__attribute__ ((__format__ (__printf__, 1, 2)));
|
||||
extern void spawn( struct strarray *array );
|
||||
extern struct strarray *find_tool( const char *name, const char * const *names );
|
||||
extern struct strarray *get_as_command(void);
|
||||
extern struct strarray *get_ld_command(void);
|
||||
extern void spawn( struct strarray array );
|
||||
extern struct strarray find_tool( const char *name, const char * const *names );
|
||||
extern struct strarray get_as_command(void);
|
||||
extern struct strarray get_ld_command(void);
|
||||
extern const char *get_nm_command(void);
|
||||
extern void cleanup_tmp_files(void);
|
||||
extern char *get_temp_file_name( const char *prefix, const char *suffix );
|
||||
|
@ -357,10 +356,10 @@ extern FILE *output_file;
|
|||
extern const char *output_file_name;
|
||||
extern char **lib_path;
|
||||
|
||||
extern struct strarray *as_command;
|
||||
extern struct strarray *cc_command;
|
||||
extern struct strarray *ld_command;
|
||||
extern struct strarray *nm_command;
|
||||
extern struct strarray as_command;
|
||||
extern struct strarray cc_command;
|
||||
extern struct strarray ld_command;
|
||||
extern struct strarray nm_command;
|
||||
extern char *cpu_option;
|
||||
extern char *arch_option;
|
||||
extern int thumb_mode;
|
||||
|
|
|
@ -500,15 +500,14 @@ static char *create_undef_symbols_file( DLLSPEC *spec )
|
|||
static const char *ldcombine_files( DLLSPEC *spec, char **argv )
|
||||
{
|
||||
char *ld_tmp_file, *undef_file;
|
||||
struct strarray *args = get_ld_command();
|
||||
struct strarray args = get_ld_command();
|
||||
|
||||
undef_file = create_undef_symbols_file( spec );
|
||||
ld_tmp_file = get_temp_file_name( output_file_name, ".o" );
|
||||
|
||||
strarray_add( args, "-r", "-o", ld_tmp_file, undef_file, NULL );
|
||||
strarray_addv( args, argv );
|
||||
strarray_add( &args, "-r", "-o", ld_tmp_file, undef_file, NULL );
|
||||
strarray_addv( &args, argv );
|
||||
spawn( args );
|
||||
strarray_free( args );
|
||||
return ld_tmp_file;
|
||||
}
|
||||
|
||||
|
@ -1327,7 +1326,7 @@ void output_imports( DLLSPEC *spec )
|
|||
/* output an import library for a Win32 module and additional object files */
|
||||
void output_import_lib( DLLSPEC *spec, char **argv )
|
||||
{
|
||||
struct strarray *args;
|
||||
struct strarray args;
|
||||
char *def_file;
|
||||
const char *as_flags, *m_flag;
|
||||
|
||||
|
@ -1357,19 +1356,17 @@ void output_import_lib( DLLSPEC *spec, char **argv )
|
|||
m_flag = NULL;
|
||||
break;
|
||||
}
|
||||
strarray_add( args, "-k", "-l", output_file_name, "-d", def_file, NULL );
|
||||
strarray_add( &args, "-k", "-l", output_file_name, "-d", def_file, NULL );
|
||||
if (m_flag)
|
||||
strarray_add( args, "-m", m_flag, as_flags, NULL );
|
||||
strarray_add( &args, "-m", m_flag, as_flags, NULL );
|
||||
spawn( args );
|
||||
strarray_free( args );
|
||||
|
||||
if (argv[0])
|
||||
{
|
||||
args = find_tool( "ar", NULL );
|
||||
strarray_add( args, "rs", output_file_name, NULL );
|
||||
strarray_addv( args, argv );
|
||||
strarray_add( &args, "rs", output_file_name, NULL );
|
||||
strarray_addv( &args, argv );
|
||||
spawn( args );
|
||||
strarray_free( args );
|
||||
}
|
||||
output_file_name = NULL;
|
||||
}
|
||||
|
|
|
@ -84,10 +84,10 @@ const char *output_file_name = NULL;
|
|||
static const char *output_file_source_name;
|
||||
static int fake_module;
|
||||
|
||||
struct strarray *as_command = NULL;
|
||||
struct strarray *cc_command = NULL;
|
||||
struct strarray *ld_command = NULL;
|
||||
struct strarray *nm_command = NULL;
|
||||
struct strarray as_command = { 0 };
|
||||
struct strarray cc_command = { 0 };
|
||||
struct strarray ld_command = { 0 };
|
||||
struct strarray nm_command = { 0 };
|
||||
char *cpu_option = NULL;
|
||||
char *arch_option = NULL;
|
||||
|
||||
|
|
|
@ -625,7 +625,7 @@ void output_res_o_file( DLLSPEC *spec )
|
|||
char *res_file = NULL;
|
||||
const char *format;
|
||||
int fd;
|
||||
struct strarray *args;
|
||||
struct strarray args;
|
||||
|
||||
if (!spec->nb_resources) fatal_error( "--resources mode needs at least one resource file as input\n" );
|
||||
if (!output_file_name) fatal_error( "No output file name specified\n" );
|
||||
|
@ -694,11 +694,10 @@ void output_res_o_file( DLLSPEC *spec )
|
|||
format = NULL;
|
||||
break;
|
||||
}
|
||||
strarray_add( args, "-i", res_file, "-o", output_file_name, NULL );
|
||||
strarray_add( &args, "-i", res_file, "-o", output_file_name, NULL );
|
||||
if (format)
|
||||
strarray_add( args, "-F", format, NULL );
|
||||
strarray_add( &args, "-F", format, NULL );
|
||||
spawn( args );
|
||||
strarray_free( args );
|
||||
|
||||
output_file_name = NULL; /* so we don't try to assemble it */
|
||||
}
|
||||
|
|
|
@ -49,6 +49,8 @@ static const char **tmp_files;
|
|||
static unsigned int nb_tmp_files;
|
||||
static unsigned int max_tmp_files;
|
||||
|
||||
static struct strarray empty_strarray;
|
||||
|
||||
static const struct
|
||||
{
|
||||
const char *name;
|
||||
|
@ -147,23 +149,13 @@ char *strmake( const char* fmt, ... )
|
|||
}
|
||||
}
|
||||
|
||||
static struct strarray *strarray_init( const char *str )
|
||||
static struct strarray strarray_copy( struct strarray src )
|
||||
{
|
||||
struct strarray *array = xmalloc( sizeof(*array) );
|
||||
array->count = 0;
|
||||
array->max = 16;
|
||||
array->str = xmalloc( array->max * sizeof(*array->str) );
|
||||
if (str) array->str[array->count++] = str;
|
||||
return array;
|
||||
}
|
||||
|
||||
static struct strarray *strarray_copy( const struct strarray *src )
|
||||
{
|
||||
struct strarray *array = xmalloc( sizeof(*array) );
|
||||
array->count = src->count;
|
||||
array->max = src->max;
|
||||
array->str = xmalloc( array->max * sizeof(*array->str) );
|
||||
memcpy( array->str, src->str, array->count * sizeof(*array->str) );
|
||||
struct strarray array;
|
||||
array.count = src.count;
|
||||
array.max = src.max;
|
||||
array.str = xmalloc( array.max * sizeof(*array.str) );
|
||||
memcpy( array.str, src.str, array.count * sizeof(*array.str) );
|
||||
return array;
|
||||
}
|
||||
|
||||
|
@ -172,6 +164,7 @@ static void strarray_add_one( struct strarray *array, const char *str )
|
|||
if (array->count == array->max)
|
||||
{
|
||||
array->max *= 2;
|
||||
if (array->max < 16) array->max = 16;
|
||||
array->str = xrealloc( array->str, array->max * sizeof(*array->str) );
|
||||
}
|
||||
array->str[array->count++] = str;
|
||||
|
@ -192,25 +185,19 @@ void strarray_addv( struct strarray *array, char * const *argv )
|
|||
while (*argv) strarray_add_one( array, *argv++ );
|
||||
}
|
||||
|
||||
struct strarray *strarray_fromstring( const char *str, const char *delim )
|
||||
struct strarray strarray_fromstring( const char *str, const char *delim )
|
||||
{
|
||||
const char *tok;
|
||||
struct strarray *array = strarray_init( NULL );
|
||||
char *buf = strdup( str );
|
||||
struct strarray array = empty_strarray;
|
||||
char *buf = xstrdup( str );
|
||||
|
||||
for (tok = strtok( buf, delim ); tok; tok = strtok( NULL, delim ))
|
||||
strarray_add_one( array, strdup( tok ));
|
||||
strarray_add_one( &array, strdup( tok ));
|
||||
|
||||
free( buf );
|
||||
return array;
|
||||
}
|
||||
|
||||
void strarray_free( struct strarray *array )
|
||||
{
|
||||
free( array->str );
|
||||
free( array );
|
||||
}
|
||||
|
||||
void fatal_error( const char *msg, ... )
|
||||
{
|
||||
va_list valist;
|
||||
|
@ -291,26 +278,26 @@ int output( const char *format, ... )
|
|||
return ret;
|
||||
}
|
||||
|
||||
void spawn( struct strarray *args )
|
||||
void spawn( struct strarray args )
|
||||
{
|
||||
unsigned int i;
|
||||
int status;
|
||||
|
||||
strarray_add_one( args, NULL );
|
||||
strarray_add_one( &args, NULL );
|
||||
if (verbose)
|
||||
for (i = 0; args->str[i]; i++)
|
||||
fprintf( stderr, "%s%c", args->str[i], args->str[i+1] ? ' ' : '\n' );
|
||||
for (i = 0; args.str[i]; i++)
|
||||
fprintf( stderr, "%s%c", args.str[i], args.str[i+1] ? ' ' : '\n' );
|
||||
|
||||
if ((status = _spawnvp( _P_WAIT, args->str[0], args->str )))
|
||||
if ((status = _spawnvp( _P_WAIT, args.str[0], args.str )))
|
||||
{
|
||||
if (status > 0) fatal_error( "%s failed with status %u\n", args->str[0], status );
|
||||
if (status > 0) fatal_error( "%s failed with status %u\n", args.str[0], status );
|
||||
else fatal_perror( "winebuild" );
|
||||
exit( 1 );
|
||||
}
|
||||
}
|
||||
|
||||
/* find a build tool in the path, trying the various names */
|
||||
struct strarray *find_tool( const char *name, const char * const *names )
|
||||
struct strarray find_tool( const char *name, const char * const *names )
|
||||
{
|
||||
static char **dirs;
|
||||
static unsigned int count, maxlen;
|
||||
|
@ -372,7 +359,11 @@ struct strarray *find_tool( const char *name, const char * const *names )
|
|||
strcat( p, EXEEXT );
|
||||
|
||||
if (!stat( file, &st ) && S_ISREG(st.st_mode) && (st.st_mode & 0111))
|
||||
return strarray_init( file );
|
||||
{
|
||||
struct strarray ret = empty_strarray;
|
||||
strarray_add_one( &ret, file );
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
free( file );
|
||||
names++;
|
||||
|
@ -380,22 +371,22 @@ struct strarray *find_tool( const char *name, const char * const *names )
|
|||
fatal_error( "cannot find the '%s' tool\n", name );
|
||||
}
|
||||
|
||||
struct strarray *get_as_command(void)
|
||||
struct strarray get_as_command(void)
|
||||
{
|
||||
struct strarray *args;
|
||||
struct strarray args;
|
||||
|
||||
if (cc_command)
|
||||
if (cc_command.count)
|
||||
{
|
||||
args = strarray_copy( cc_command );
|
||||
strarray_add( args, "-xassembler", "-c", NULL );
|
||||
strarray_add( &args, "-xassembler", "-c", NULL );
|
||||
if (force_pointer_size)
|
||||
strarray_add_one( args, (force_pointer_size == 8) ? "-m64" : "-m32" );
|
||||
if (cpu_option) strarray_add_one( args, strmake("-mcpu=%s", cpu_option) );
|
||||
if (arch_option) strarray_add_one( args, strmake("-march=%s", arch_option) );
|
||||
strarray_add_one( &args, (force_pointer_size == 8) ? "-m64" : "-m32" );
|
||||
if (cpu_option) strarray_add_one( &args, strmake("-mcpu=%s", cpu_option) );
|
||||
if (arch_option) strarray_add_one( &args, strmake("-march=%s", arch_option) );
|
||||
return args;
|
||||
}
|
||||
|
||||
if (!as_command)
|
||||
if (!as_command.count)
|
||||
{
|
||||
static const char * const commands[] = { "gas", "as", NULL };
|
||||
as_command = find_tool( "as", commands );
|
||||
|
@ -408,31 +399,31 @@ struct strarray *get_as_command(void)
|
|||
switch (target_platform)
|
||||
{
|
||||
case PLATFORM_APPLE:
|
||||
strarray_add( args, "-arch", (force_pointer_size == 8) ? "x86_64" : "i386", NULL );
|
||||
strarray_add( &args, "-arch", (force_pointer_size == 8) ? "x86_64" : "i386", NULL );
|
||||
break;
|
||||
default:
|
||||
switch(target_cpu)
|
||||
{
|
||||
case CPU_POWERPC:
|
||||
strarray_add_one( args, (force_pointer_size == 8) ? "-a64" : "-a32" );
|
||||
strarray_add_one( &args, (force_pointer_size == 8) ? "-a64" : "-a32" );
|
||||
break;
|
||||
default:
|
||||
strarray_add_one( args, (force_pointer_size == 8) ? "--64" : "--32" );
|
||||
strarray_add_one( &args, (force_pointer_size == 8) ? "--64" : "--32" );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (cpu_option) strarray_add_one( args, strmake("-mcpu=%s", cpu_option) );
|
||||
if (cpu_option) strarray_add_one( &args, strmake("-mcpu=%s", cpu_option) );
|
||||
return args;
|
||||
}
|
||||
|
||||
struct strarray *get_ld_command(void)
|
||||
struct strarray get_ld_command(void)
|
||||
{
|
||||
struct strarray *args;
|
||||
struct strarray args;
|
||||
|
||||
if (!ld_command)
|
||||
if (!ld_command.count)
|
||||
{
|
||||
static const char * const commands[] = { "ld", "gld", NULL };
|
||||
ld_command = find_tool( "ld", commands );
|
||||
|
@ -445,19 +436,19 @@ struct strarray *get_ld_command(void)
|
|||
switch (target_platform)
|
||||
{
|
||||
case PLATFORM_APPLE:
|
||||
strarray_add( args, "-arch", (force_pointer_size == 8) ? "x86_64" : "i386", NULL );
|
||||
strarray_add( &args, "-arch", (force_pointer_size == 8) ? "x86_64" : "i386", NULL );
|
||||
break;
|
||||
case PLATFORM_FREEBSD:
|
||||
strarray_add( args, "-m", (force_pointer_size == 8) ? "elf_x86_64_fbsd" : "elf_i386_fbsd", NULL );
|
||||
strarray_add( &args, "-m", (force_pointer_size == 8) ? "elf_x86_64_fbsd" : "elf_i386_fbsd", NULL );
|
||||
break;
|
||||
default:
|
||||
switch(target_cpu)
|
||||
{
|
||||
case CPU_POWERPC:
|
||||
strarray_add( args, "-m", (force_pointer_size == 8) ? "elf64ppc" : "elf32ppc", NULL );
|
||||
strarray_add( &args, "-m", (force_pointer_size == 8) ? "elf64ppc" : "elf32ppc", NULL );
|
||||
break;
|
||||
default:
|
||||
strarray_add( args, "-m", (force_pointer_size == 8) ? "elf_x86_64" : "elf_i386", NULL );
|
||||
strarray_add( &args, "-m", (force_pointer_size == 8) ? "elf_x86_64" : "elf_i386", NULL );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -468,14 +459,14 @@ struct strarray *get_ld_command(void)
|
|||
|
||||
const char *get_nm_command(void)
|
||||
{
|
||||
if (!nm_command)
|
||||
if (!nm_command.count)
|
||||
{
|
||||
static const char * const commands[] = { "nm", "gnm", NULL };
|
||||
nm_command = find_tool( "nm", commands );
|
||||
}
|
||||
if (nm_command->count > 1)
|
||||
if (nm_command.count > 1)
|
||||
fatal_error( "multiple arguments in nm command not supported yet\n" );
|
||||
return nm_command->str[0];
|
||||
return nm_command.str[0];
|
||||
}
|
||||
|
||||
/* get a name for a temp file, automatically cleaned up on exit */
|
||||
|
@ -755,10 +746,9 @@ int remove_stdcall_decoration( char *name )
|
|||
*/
|
||||
void assemble_file( const char *src_file, const char *obj_file )
|
||||
{
|
||||
struct strarray *args = get_as_command();
|
||||
strarray_add( args, "-o", obj_file, src_file, NULL );
|
||||
struct strarray args = get_as_command();
|
||||
strarray_add( &args, "-o", obj_file, src_file, NULL );
|
||||
spawn( args );
|
||||
strarray_free( args );
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue