This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix for [Bug preprocessor/16366] Preprocessor option -remap causes memory corruption


On Friday 16 July 2004 07:42, Zack Weinberg wrote:
> Andris Pavenis <pavenis@latnet.lv> writes:
> > On Friday 09 July 2004 19:14, Zack Weinberg wrote:
> >>> I think, the best could be to reimplement remap_filename() to
> >>> avoid use of pfile->file_hash in it.
> >>
> >> Yes, that would also be an acceptable solution.
> >
> > It seems that fix is very simple: using a different hash table for
> > directories.
>
> Yes, that looks like a correct fix.  This is also something I wanted
> to do anyway, since it will allow simplifying this data structure a
> little.
>
> Please write a change log, check the patch in to the 3.5 and 3.4
> branches, and close the bug report.

I don't have CVS write access, so I cannot check it in myself.

Also: is an assignment to FSF needed in this case? At this moment I don't have 
it.

I'm attaching patches for both HEAD and 3.4 branches with changelog entries.

Andris
2004-07-15  Andris Pavenis <pavenis@latnet.lv>

	PR preprocessor/16366
	* internal.h, files.c: Use separate hash table for directories


Index: libcpp/files.c
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/files.c,v
retrieving revision 1.4
diff -p -r1.4 files.c
*** libcpp/files.c	26 Jun 2004 17:39:40 -0000	1.4
--- libcpp/files.c	15 Jul 2004 06:40:27 -0000
*************** make_cpp_dir (cpp_reader *pfile, const c
*** 884,890 ****
    cpp_dir *dir;
  
    hash_slot = (struct file_hash_entry **)
!     htab_find_slot_with_hash (pfile->file_hash, dir_name,
  			      htab_hash_string (dir_name),
  			      INSERT);
  
--- 884,890 ----
    cpp_dir *dir;
  
    hash_slot = (struct file_hash_entry **)
!     htab_find_slot_with_hash (pfile->dir_hash, dir_name,
  			      htab_hash_string (dir_name),
  			      INSERT);
  
*************** _cpp_init_files (cpp_reader *pfile)
*** 984,989 ****
--- 984,991 ----
  {
    pfile->file_hash = htab_create_alloc (127, file_hash_hash, file_hash_eq,
  					NULL, xcalloc, free);
+   pfile->dir_hash = htab_create_alloc (127, file_hash_hash, file_hash_eq,
+ 					NULL, xcalloc, free);
    allocate_file_hash_entries (pfile);
  }
  
*************** void
*** 992,997 ****
--- 994,1000 ----
  _cpp_cleanup_files (cpp_reader *pfile)
  {
    htab_delete (pfile->file_hash);
+   htab_delete (pfile->dir_hash);
  }
  
  /* Enter a file name in the hash for the sake of cpp_included.  */
Index: libcpp/internal.h
===================================================================
RCS file: /cvs/gcc/gcc/libcpp/internal.h,v
retrieving revision 1.4
diff -p -r1.4 internal.h
*** libcpp/internal.h	30 Jun 2004 18:35:17 -0000	1.4
--- libcpp/internal.h	15 Jul 2004 06:40:27 -0000
*************** struct cpp_reader
*** 334,339 ****
--- 334,340 ----
  
    /* File and directory hash table.  */
    struct htab *file_hash;
+   struct htab *dir_hash;
    struct file_hash_entry *file_hash_entries;
    unsigned int file_hash_entries_allocated, file_hash_entries_used;
  
2004-07-15  Andris Pavenis <pavenis@latnet.lv>

	PR preprocessor/16366
	* cpphash.h, cppfiles.c: Use separate hash table for directories


Index: gcc/cppfiles.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/cppfiles.c,v
retrieving revision 1.198.4.2
diff -p -r1.198.4.2 cppfiles.c
*** gcc/cppfiles.c	7 Feb 2004 14:33:08 -0000	1.198.4.2
--- gcc/cppfiles.c	16 Jul 2004 07:25:05 -0000
*************** make_cpp_dir (cpp_reader *pfile, const c
*** 795,801 ****
    cpp_dir *dir;
  
    hash_slot = (struct file_hash_entry **)
!     htab_find_slot_with_hash (pfile->file_hash, dir_name,
  			      htab_hash_string (dir_name),
  			      INSERT);
  
--- 795,801 ----
    cpp_dir *dir;
  
    hash_slot = (struct file_hash_entry **)
!     htab_find_slot_with_hash (pfile->dir_hash, dir_name,
  			      htab_hash_string (dir_name),
  			      INSERT);
  
*************** _cpp_init_files (cpp_reader *pfile)
*** 894,899 ****
--- 894,901 ----
  {
    pfile->file_hash = htab_create_alloc (127, file_hash_hash, file_hash_eq,
  					NULL, xcalloc, free);
+   pfile->dir_hash = htab_create_alloc (127, file_hash_hash, file_hash_eq,
+ 					NULL, xcalloc, free);
    allocate_file_hash_entries (pfile);
  }
  
*************** void
*** 902,907 ****
--- 904,910 ----
  _cpp_cleanup_files (cpp_reader *pfile)
  {
    htab_delete (pfile->file_hash);
+   htab_delete (pfile->dir_hash);
  }
  
  /* Enter a file name in the hash for the sake of cpp_included.  */
Index: gcc/cpphash.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/cpphash.h,v
retrieving revision 1.203.4.3
diff -p -r1.203.4.3 cpphash.h
*** gcc/cpphash.h	18 Feb 2004 22:10:13 -0000	1.203.4.3
--- gcc/cpphash.h	16 Jul 2004 07:25:06 -0000
*************** struct cpp_reader
*** 362,367 ****
--- 362,368 ----
  
    /* File and directory hash table.  */
    struct htab *file_hash;
+   struct htab *dir_hash;
    struct file_hash_entry *file_hash_entries;
    unsigned int file_hash_entries_allocated, file_hash_entries_used;
  

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]