This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Always pass an open file descriptor to c_common_read_pch
Zack Weinberg schrieb:
> Ritzert@t-online.de writes:
>
> > * c-pch.c (c_common_read_pch): Assert that an
> invalid file descriptor
> > will never get here.
> > * cppfiles.c (should_stack_file): Make sure
> that the file descriptor
> > passed to read_pch is valid.
> ...
>
> > !
> > ! my_friendly_assert( fd != -1, 20030818 );
>
> my_friendly_assert is not to be used in new code. Write
>
> if (fd == -1)
> abort ();
>
> instead. Actually, I don't think this assertion is
> necessary; the
> fatal error after fdopen fails is good enough.
It was convinient for me to have this. I stripped out this very small
testcase from a rather big one that produced loads of warnings after
the fdopen error and somewhat obscured my view.
> > Index: cppfiles.c
> >
> ===================================================================
> > RCS file: /cvs/gcc/gcc/gcc/cppfiles.c,v
> > retrieving revision 1.186
> > diff -u -3 -p -f -r1.186 cppfiles.c
> > *** cppfiles.c 9 Aug 2003 22:14:07 -0000 1.186
> > --- cppfiles.c 18 Aug 2003 19:39:42 -0000
> > *************** should_stack_file (cpp_reader *pfile,
> _c
> > *** 551,556 ****
> > --- 551,563 ----
> > /* Handle PCH files immediately; don't stack them.
> */
> > if (include_pch_p (file))
> > {
> > + /* Make sure the file is open. */
> > + if (file->fd == -1)
> > + {
> > + if (!pch_open_file (pfile, file))
> > + return false;
> > + }
> > +
> > pfile->cb.read_pch (pfile, file->path,
> file->fd,
> > file->pchname);
> > close (file->fd);
> > file->fd = -1;
>
> I don't think this is right either. Your test case does
> not involve
> PCH; we should not be going through this code path at
> all.
I couldn't reproduce the error without using PCH, i.e. omitting the g++
-c x.h step.
Michael