Commit d65446af authored by Alexandre Julliard's avatar Alexandre Julliard

winebuild: Use strarray objects for a few more string arrays.

parent 8baaf534
......@@ -341,7 +341,6 @@ extern void align_output( unsigned int align );
extern int current_line;
extern int UsePIC;
extern int nb_lib_paths;
extern int nb_errors;
extern int display_warnings;
extern int kill_at;
......@@ -354,8 +353,8 @@ extern char *input_file_name;
extern char *spec_file_name;
extern FILE *output_file;
extern const char *output_file_name;
extern char **lib_path;
extern struct strarray lib_path;
extern struct strarray as_command;
extern struct strarray cc_command;
extern struct strarray ld_command;
......
......@@ -50,16 +50,10 @@ struct import
int nb_imports; /* number of imported functions */
};
struct name_table
{
char **names;
unsigned int count, size;
};
static struct name_table undef_symbols; /* list of undefined symbols */
static struct name_table extra_ld_symbols; /* list of extra symbols that ld should resolve */
static struct name_table delayed_imports; /* list of delayed import dlls */
static struct name_table ext_link_imports; /* list of external symbols to link to */
static struct strarray undef_symbols; /* list of undefined symbols */
static struct strarray extra_ld_symbols; /* list of extra symbols that ld should resolve */
static struct strarray delayed_imports; /* list of delayed import dlls */
static struct strarray ext_link_imports; /* list of external symbols to link to */
static struct import **dll_imports = NULL;
static int nb_imports = 0; /* number of imported dlls (delayed or not) */
......@@ -93,41 +87,28 @@ static int func_cmp( const void *func1, const void *func2 )
odp2->name ? odp2->name : odp2->export_name );
}
/* add a name to a name table */
static inline void add_name( struct name_table *table, const char *name )
{
if (table->count == table->size)
{
table->size += (table->size / 2);
if (table->size < 32) table->size = 32;
table->names = xrealloc( table->names, table->size * sizeof(*table->names) );
}
table->names[table->count++] = xstrdup( name );
}
/* remove a name from a name table */
static inline void remove_name( struct name_table *table, unsigned int idx )
static inline void remove_name( struct strarray *table, unsigned int idx )
{
assert( idx < table->count );
free( table->names[idx] );
memmove( table->names + idx, table->names + idx + 1,
(table->count - idx - 1) * sizeof(*table->names) );
memmove( table->str + idx, table->str + idx + 1,
(table->count - idx - 1) * sizeof(*table->str) );
table->count--;
}
/* locate a name in a (sorted) list */
static inline const char *find_name( const char *name, const struct name_table *table )
static inline const char *find_name( const char *name, const struct strarray *table )
{
char **res = NULL;
if (table->count) res = bsearch( &name, table->names, table->count, sizeof(*table->names), name_cmp );
if (table->count) res = bsearch( &name, table->str, table->count, sizeof(*table->str), name_cmp );
return res ? *res : NULL;
}
/* sort a name table */
static inline void sort_names( struct name_table *table )
static inline void sort_names( struct strarray *table )
{
if (table->count) qsort( table->names, table->count, sizeof(*table->names), name_cmp );
if (table->count) qsort( table->str, table->count, sizeof(*table->str), name_cmp );
}
/* locate an export in a (sorted) export list */
......@@ -160,7 +141,7 @@ static int is_delayed_import( const char *name )
for (i = 0; i < delayed_imports.count; i++)
{
if (!strcmp( delayed_imports.names[i], name )) return 1;
if (!strcmp( delayed_imports.str[i], name )) return 1;
}
return 0;
}
......@@ -199,11 +180,11 @@ static char *try_library_path( const char *path, const char *name )
static char *find_library( const char *name )
{
char *fullname;
int i;
unsigned int i;
for (i = 0; i < nb_lib_paths; i++)
for (i = 0; i < lib_path.count; i++)
{
if ((fullname = try_library_path( lib_path[i], name ))) return fullname;
if ((fullname = try_library_path( lib_path.str[i], name ))) return fullname;
}
fatal_error( "could not open .def file for %s\n", name );
return NULL;
......@@ -310,13 +291,12 @@ void add_delayed_import( const char *name )
struct import *imp;
char *fullname = get_dll_name( name, NULL );
add_name( &delayed_imports, fullname );
strarray_add( &delayed_imports, fullname, NULL );
if ((imp = is_already_imported( fullname )) && !imp->delay)
{
imp->delay = 1;
nb_delayed++;
}
free( fullname );
}
/* remove an imported dll, based on its index in the dll_imports array */
......@@ -333,7 +313,7 @@ static void remove_import_dll( int index )
/* add a symbol to the list of extra symbols that ld must resolve */
void add_extra_ld_symbol( const char *name )
{
add_name( &extra_ld_symbols, name );
strarray_add( &extra_ld_symbols, name, NULL );
}
/* add a function to the list of imports from a given dll */
......@@ -453,7 +433,7 @@ static void check_undefined_exports( DLLSPEC *spec )
if (link_ext_symbols)
{
odp->flags |= FLAG_EXT_LINK;
add_name( &ext_link_imports, odp->link_name );
strarray_add( &ext_link_imports, odp->link_name, NULL );
}
else error( "%s:%d: function '%s' not defined\n",
spec->src_name, odp->lineno, odp->link_name );
......@@ -487,7 +467,7 @@ static char *create_undef_symbols_file( DLLSPEC *spec )
fprintf( f, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(odp->link_name) );
}
for (j = 0; j < extra_ld_symbols.count; j++)
fprintf( f, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(extra_ld_symbols.names[j]) );
fprintf( f, "\t%s %s\n", get_asm_ptr_keyword(), asm_name(extra_ld_symbols.str[j]) );
fclose( f );
obj_file = get_temp_file_name( output_file_name, ".o" );
......@@ -543,7 +523,7 @@ void read_undef_symbols( DLLSPEC *spec, char **argv )
while (*p == ' ') p++;
if (p[0] == 'U' && p[1] == ' ' && p[2]) p += 2;
if (prefix_len && !strncmp( p, name_prefix, prefix_len )) p += prefix_len;
add_name( &undef_symbols, p );
strarray_add( &undef_symbols, xstrdup( p ), NULL );
}
if ((err = pclose( f ))) warning( "%s failed with status %d\n", cmd, err );
free( cmd );
......@@ -564,7 +544,7 @@ void resolve_imports( DLLSPEC *spec )
for (j = removed = 0; j < undef_symbols.count; j++)
{
odp = find_export( undef_symbols.names[j], imp->exports, imp->nb_exports );
odp = find_export( undef_symbols.str[j], imp->exports, imp->nb_exports );
if (odp)
{
if (odp->flags & FLAG_PRIVATE) continue;
......@@ -1145,7 +1125,7 @@ static void output_external_link_imports( DLLSPEC *spec )
/* get rid of duplicate names */
for (i = 1; i < ext_link_imports.count; i++)
{
if (!strcmp( ext_link_imports.names[i-1], ext_link_imports.names[i] ))
if (!strcmp( ext_link_imports.str[i-1], ext_link_imports.str[i] ))
remove_name( &ext_link_imports, i-- );
}
......@@ -1154,7 +1134,7 @@ static void output_external_link_imports( DLLSPEC *spec )
output( "\t.align %d\n", get_alignment(get_ptr_size()) );
output( ".L__wine_spec_external_links:\n" );
for (i = 0; i < ext_link_imports.count; i++)
output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(ext_link_imports.names[i]) );
output( "\t%s %s\n", get_asm_ptr_keyword(), asm_name(ext_link_imports.str[i]) );
output( "\n\t.text\n" );
output( "\t.align %d\n", get_alignment(get_ptr_size()) );
......@@ -1162,7 +1142,7 @@ static void output_external_link_imports( DLLSPEC *spec )
for (i = pos = 0; i < ext_link_imports.count; i++)
{
char *buffer = strmake( "__wine_spec_ext_link_%s", ext_link_imports.names[i] );
char *buffer = strmake( "__wine_spec_ext_link_%s", ext_link_imports.str[i] );
output_import_thunk( buffer, ".L__wine_spec_external_links", pos );
free( buffer );
pos += get_ptr_size();
......
......@@ -39,7 +39,6 @@
#include "build.h"
int UsePIC = 0;
int nb_lib_paths = 0;
int nb_errors = 0;
int display_warnings = 0;
int kill_at = 0;
......@@ -75,7 +74,6 @@ enum target_platform target_platform = PLATFORM_UNSPECIFIED;
#endif
char *target_alias = NULL;
char **lib_path = NULL;
char *input_file_name = NULL;
char *spec_file_name = NULL;
......@@ -84,6 +82,7 @@ const char *output_file_name = NULL;
static const char *output_file_source_name;
static int fake_module;
struct strarray lib_path = { 0 };
struct strarray as_command = { 0 };
struct strarray cc_command = { 0 };
struct strarray ld_command = { 0 };
......@@ -97,8 +96,7 @@ int thumb_mode = 1;
int thumb_mode = 0;
#endif
static int nb_res_files;
static char **res_files;
static struct strarray res_files;
/* execution mode */
enum exec_mode_values
......@@ -399,8 +397,7 @@ static char **parse_options( int argc, char **argv, DLLSPEC *spec )
/* ignored, because cc generates correct code. */
break;
case 'L':
lib_path = xrealloc( lib_path, (nb_lib_paths+1) * sizeof(*lib_path) );
lib_path[nb_lib_paths++] = xstrdup( optarg );
strarray_add( &lib_path, xstrdup( optarg ), NULL );
break;
case 'm':
if (!strcmp( optarg, "16" )) spec->type = SPEC_WIN16;
......@@ -465,8 +462,7 @@ static char **parse_options( int argc, char **argv, DLLSPEC *spec )
}
break;
case 'r':
res_files = xrealloc( res_files, (nb_res_files+1) * sizeof(*res_files) );
res_files[nb_res_files++] = xstrdup( optarg );
strarray_add( &res_files, xstrdup( optarg ), NULL );
break;
case 'u':
add_extra_ld_symbol( optarg );
......@@ -566,14 +562,14 @@ static void load_resources( char *argv[], DLLSPEC *spec )
switch (spec->type)
{
case SPEC_WIN16:
for (i = 0; i < nb_res_files; i++) load_res16_file( res_files[i], spec );
for (i = 0; i < res_files.count; i++) load_res16_file( res_files.str[i], spec );
break;
case SPEC_WIN32:
for (i = 0; i < nb_res_files; i++)
for (i = 0; i < res_files.count; i++)
{
if (!load_res32_file( res_files[i], spec ))
fatal_error( "%s is not a valid Win32 resource file\n", res_files[i] );
if (!load_res32_file( res_files.str[i], spec ))
fatal_error( "%s is not a valid Win32 resource file\n", res_files.str[i] );
}
/* load any resource file found in the remaining arguments */
......
......@@ -45,10 +45,7 @@
# define PATH_SEPARATOR ':'
#endif
static const char **tmp_files;
static unsigned int nb_tmp_files;
static unsigned int max_tmp_files;
static struct strarray tmp_files;
static struct strarray empty_strarray;
static const struct
......@@ -77,7 +74,7 @@ static const struct
void cleanup_tmp_files(void)
{
unsigned int i;
for (i = 0; i < nb_tmp_files; i++) if (tmp_files[i]) unlink( tmp_files[i] );
for (i = 0; i < tmp_files.count; i++) if (tmp_files.str[i]) unlink( tmp_files.str[i] );
}
......@@ -497,12 +494,7 @@ char *get_temp_file_name( const char *prefix, const char *suffix )
}
close( fd );
if (nb_tmp_files >= max_tmp_files)
{
max_tmp_files = max( 2 * max_tmp_files, 8 );
tmp_files = xrealloc( tmp_files, max_tmp_files * sizeof(tmp_files[0]) );
}
tmp_files[nb_tmp_files++] = name;
strarray_add_one( &tmp_files, name );
return name;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment