From ecddfb399a37328230ff87e70a98407586fe752f Mon Sep 17 00:00:00 2001 From: Mike Stump Date: Wed, 9 Feb 2005 01:23:56 +0000 Subject: [PATCH] files.c (pchf_adder): Remove. * files.c (pchf_adder): Remove. (struct pchf_adder_info): Likewise. (_cpp_save_file_entries): Write out all files so that #import works. From-SVN: r94755 --- gcc/testsuite/ChangeLog | 7 ++ gcc/testsuite/gcc.dg/pch/import-2.c | 8 ++ gcc/testsuite/gcc.dg/pch/import-2.hs | 4 + gcc/testsuite/gcc.dg/pch/include/import-2a.h | 1 + gcc/testsuite/gcc.dg/pch/include/import-2b.h | 1 + libcpp/ChangeLog | 6 ++ libcpp/files.c | 103 ++++++++----------- 7 files changed, 70 insertions(+), 60 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pch/import-2.c create mode 100644 gcc/testsuite/gcc.dg/pch/import-2.hs create mode 100644 gcc/testsuite/gcc.dg/pch/include/import-2a.h create mode 100644 gcc/testsuite/gcc.dg/pch/include/import-2b.h diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5e44b2d0202e..952c0a74142f 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2005-02-08 Mike Stump + + * g++.dg/pch/import-2.c: New test. + * g++.dg/pch/import-2.hs: New. + * g++.dg/pch/include/import-2a.h: New. + * g++.dg/pch/include/import-2b.h: New. + 2005-02-08 Janis Johnson * gcc.dg/uninit-4.c: XFAIL bogus warning for powerpc64. diff --git a/gcc/testsuite/gcc.dg/pch/import-2.c b/gcc/testsuite/gcc.dg/pch/import-2.c new file mode 100644 index 000000000000..f95356881821 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pch/import-2.c @@ -0,0 +1,8 @@ +/* { dg-options "-I. -I $srcdir/gcc.dg/pch/include" } */ + +#include "import-2.h" +#import "import-2b.h" + +int main(int argc, char **argv) { + return 0; +} diff --git a/gcc/testsuite/gcc.dg/pch/import-2.hs b/gcc/testsuite/gcc.dg/pch/import-2.hs new file mode 100644 index 000000000000..f9798c122665 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pch/import-2.hs @@ -0,0 +1,4 @@ +/* { dg-options "-I $srcdir/gcc.dg/pch/include" } */ + +#import "import-2b.h" +#import "import-2a.h" diff --git a/gcc/testsuite/gcc.dg/pch/include/import-2a.h b/gcc/testsuite/gcc.dg/pch/include/import-2a.h new file mode 100644 index 000000000000..bb3250cf6ae8 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pch/include/import-2a.h @@ -0,0 +1 @@ +#import "import-2b.h" diff --git a/gcc/testsuite/gcc.dg/pch/include/import-2b.h b/gcc/testsuite/gcc.dg/pch/include/import-2b.h new file mode 100644 index 000000000000..ad10c62717c9 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pch/include/import-2b.h @@ -0,0 +1 @@ +int dup = 9; diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 49055bd51bd3..35e5369137dd 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,9 @@ +2005-02-08 Mike Stump + + * files.c (pchf_adder): Remove. + (struct pchf_adder_info): Likewise. + (_cpp_save_file_entries): Write out all files so that #import works. + 2005-01-23 Joseph S. Myers * configure: Regenerate. diff --git a/libcpp/files.c b/libcpp/files.c index df5d9d7c9727..4ef72cd6111c 100644 --- a/libcpp/files.c +++ b/libcpp/files.c @@ -173,7 +173,6 @@ static void read_name_map (cpp_dir *dir); static char *remap_filename (cpp_reader *pfile, _cpp_file *file); static char *append_file_to_dir (const char *fname, cpp_dir *dir); static bool validate_pch (cpp_reader *, _cpp_file *file, const char *pchname); -static int pchf_adder (void **slot, void *data); static int pchf_save_compare (const void *e1, const void *e2); static int pchf_compare (const void *d_p, const void *e_p); static bool check_file_against_entries (cpp_reader *, _cpp_file *, bool); @@ -1448,58 +1447,6 @@ struct pchf_data { static struct pchf_data *pchf; -/* Data for pchf_addr. */ -struct pchf_adder_info -{ - cpp_reader *pfile; - struct pchf_data *d; -}; - -/* A hash traversal function to add entries into DATA->D. */ - -static int -pchf_adder (void **slot, void *data) -{ - struct file_hash_entry *h = (struct file_hash_entry *) *slot; - struct pchf_adder_info *i = (struct pchf_adder_info *) data; - - if (h->start_dir != NULL && h->u.file->stack_count != 0) - { - struct pchf_data *d = i->d; - _cpp_file *f = h->u.file; - size_t count = d->count++; - - /* This should probably never happen, since if a read error occurred - the PCH file shouldn't be written... */ - if (f->dont_read || f->err_no) - return 1; - - d->entries[count].once_only = f->once_only; - /* |= is avoided in the next line because of an HP C compiler bug */ - d->have_once_only = d->have_once_only | f->once_only; - if (f->buffer_valid) - md5_buffer ((const char *)f->buffer, - f->st.st_size, d->entries[count].sum); - else - { - FILE *ff; - int oldfd = f->fd; - - if (!open_file (f)) - { - open_file_failed (i->pfile, f); - return 0; - } - ff = fdopen (f->fd, "rb"); - md5_stream (ff, d->entries[count].sum); - fclose (ff); - f->fd = oldfd; - } - d->entries[count].size = f->st.st_size; - } - return 1; -} - /* A qsort ordering function for pchf_entry structures. */ static int @@ -1511,14 +1458,16 @@ pchf_save_compare (const void *e1, const void *e2) /* Create and write to F a pchf_data structure. */ bool -_cpp_save_file_entries (cpp_reader *pfile, FILE *f) +_cpp_save_file_entries (cpp_reader *pfile, FILE *fp) { size_t count = 0; struct pchf_data *result; size_t result_size; - struct pchf_adder_info pai; + _cpp_file *f; + + for (f = pfile->all_files; f; f = f->next_file) + ++count; - count = htab_elements (pfile->file_hash); result_size = (sizeof (struct pchf_data) + sizeof (struct pchf_entry) * (count - 1)); result = xcalloc (result_size, 1); @@ -1526,9 +1475,43 @@ _cpp_save_file_entries (cpp_reader *pfile, FILE *f) result->count = 0; result->have_once_only = false; - pai.pfile = pfile; - pai.d = result; - htab_traverse (pfile->file_hash, pchf_adder, &pai); + for (f = pfile->all_files; f; f = f->next_file) + { + size_t count; + + /* This should probably never happen, since if a read error occurred + the PCH file shouldn't be written... */ + if (f->dont_read || f->err_no) + continue; + + if (f->stack_count == 0) + continue; + + count = result->count++; + + result->entries[count].once_only = f->once_only; + /* |= is avoided in the next line because of an HP C compiler bug */ + result->have_once_only = result->have_once_only | f->once_only; + if (f->buffer_valid) + md5_buffer ((const char *)f->buffer, + f->st.st_size, result->entries[count].sum); + else + { + FILE *ff; + int oldfd = f->fd; + + if (!open_file (f)) + { + open_file_failed (pfile, f); + return false; + } + ff = fdopen (f->fd, "rb"); + md5_stream (ff, result->entries[count].sum); + fclose (ff); + f->fd = oldfd; + } + result->entries[count].size = f->st.st_size; + } result_size = (sizeof (struct pchf_data) + sizeof (struct pchf_entry) * (result->count - 1)); @@ -1536,7 +1519,7 @@ _cpp_save_file_entries (cpp_reader *pfile, FILE *f) qsort (result->entries, result->count, sizeof (struct pchf_entry), pchf_save_compare); - return fwrite (result, result_size, 1, f) == 1; + return fwrite (result, result_size, 1, fp) == 1; } /* Read the pchf_data structure from F. */