08a0a12
2008-04-01  Jakub Jelinek  <jakub@redhat.com>
08a0a12
08a0a12
	PR pch/13675
08a0a12
	* files.c (struct _cpp_file): Remove pch field.
08a0a12
	(pch_open_file): Don't set file->pch, just file->pchname.
08a0a12
	(should_stack_file): After pfile->cb.read_pch call
08a0a12
	free pchname and clear pchname, don't close file->fd.
08a0a12
	Test file->pchname instead of file->pch.  Don't close fd after cb.
08a0a12
	(_cpp_stack_include): Test file->pchname instead of file->pch.
08a0a12
08a0a12
	* c-pch.c (c_common_read_pch): On error close (fd) resp. fclose (f).
08a0a12
08a0a12
--- libcpp/files.c.jj	2008-02-18 23:50:17.000000000 +0100
08a0a12
+++ libcpp/files.c	2008-03-31 15:59:01.000000000 +0200
08a0a12
@@ -106,9 +106,6 @@ struct _cpp_file
08a0a12
 
08a0a12
   /* If BUFFER above contains the true contents of the file.  */
08a0a12
   bool buffer_valid;
08a0a12
-
08a0a12
-  /* File is a PCH (on return from find_include_file).  */
08a0a12
-  bool pch;
08a0a12
 };
08a0a12
 
08a0a12
 /* A singly-linked list for all searches for a given file name, with
08a0a12
@@ -322,9 +319,7 @@ pch_open_file (cpp_reader *pfile, _cpp_f
08a0a12
 	    }
08a0a12
 	  closedir (pchdir);
08a0a12
 	}
08a0a12
-      if (valid)
08a0a12
-	file->pch = true;
08a0a12
-      else
08a0a12
+      if (!valid)
08a0a12
 	*invalid_pch = true;
08a0a12
     }
08a0a12
 
08a0a12
@@ -703,11 +698,12 @@ should_stack_file (cpp_reader *pfile, _c
08a0a12
     return false;
08a0a12
 
08a0a12
   /* Handle PCH files immediately; don't stack them.  */
08a0a12
-  if (file->pch)
08a0a12
+  if (file->pchname)
08a0a12
     {
08a0a12
       pfile->cb.read_pch (pfile, file->pchname, file->fd, file->path);
08a0a12
-      close (file->fd);
08a0a12
       file->fd = -1;
08a0a12
+      free ((void *) file->pchname);
08a0a12
+      file->pchname = NULL;
08a0a12
       return false;
08a0a12
     }
08a0a12
 
08a0a12
@@ -916,7 +912,7 @@ _cpp_stack_include (cpp_reader *pfile, c
08a0a12
      complicates LAST_SOURCE_LINE_LOCATION.  This does not apply if we
08a0a12
      found a PCH file (in which case linemap_add is not called) or we
08a0a12
      were included from the command-line.  */
08a0a12
-  if (! file->pch && file->err_no == 0 && type != IT_CMDLINE)
08a0a12
+  if (file->pchname == NULL && file->err_no == 0 && type != IT_CMDLINE)
08a0a12
     pfile->line_table->highest_location--;
08a0a12
 
08a0a12
   return _cpp_stack_file (pfile, file, type == IT_IMPORT);
08a0a12
--- gcc/c-pch.c.jj	2008-02-18 23:46:08.000000000 +0100
08a0a12
+++ gcc/c-pch.c	2008-03-31 15:56:00.000000000 +0200
08a0a12
@@ -372,6 +372,7 @@ c_common_read_pch (cpp_reader *pfile, co
08a0a12
   if (f == NULL)
08a0a12
     {
08a0a12
       cpp_errno (pfile, CPP_DL_ERROR, "calling fdopen");
08a0a12
+      close (fd);
08a0a12
       return;
08a0a12
     }
08a0a12
 
08a0a12
@@ -380,6 +381,7 @@ c_common_read_pch (cpp_reader *pfile, co
08a0a12
   if (fread (&h, sizeof (h), 1, f) != 1)
08a0a12
     {
08a0a12
       cpp_errno (pfile, CPP_DL_ERROR, "reading");
08a0a12
+      fclose (f);
08a0a12
       return;
08a0a12
     }
08a0a12
 
08a0a12
@@ -425,7 +427,10 @@ c_common_read_pch (cpp_reader *pfile, co
08a0a12
   gt_pch_restore (f);
08a0a12
 
08a0a12
   if (cpp_read_state (pfile, name, f, smd) != 0)
08a0a12
-    return;
08a0a12
+    {
08a0a12
+      fclose (f);
08a0a12
+      return;
08a0a12
+    }
08a0a12
 
08a0a12
   fclose (f);
08a0a12