public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 3/5] remove deleted BFDs from the archive cache
@ 2012-08-03 14:55 Tom Tromey
  2012-08-03 16:12 ` Alan Modra
  0 siblings, 1 reply; 48+ messages in thread
From: Tom Tromey @ 2012-08-03 14:55 UTC (permalink / raw)
  To: Binutils Development

Right now if you bfd_close a member BFD, the pointer to the BFD
remains in the parent archive's cache.  This means that if you try to
re-open that member, BFD will return a stale pointer.

This patch fixes the problem by deleting the entry from the hash.

I could not find a way to look up the member BFD in its parent cache
directly, hence the iteration.

	* archive.c (delete_bfd_from_htab): New function.
	(_bfd_delete_archive_data): Iterate over the parent archive's
	hash table.
---
 bfd/archive.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/bfd/archive.c b/bfd/archive.c
index 8d02257..f84a8fc 100644
--- a/bfd/archive.c
+++ b/bfd/archive.c
@@ -293,6 +293,24 @@ bfd_set_archive_head (bfd *output_archive, bfd *new_head)
   return TRUE;
 }
 
+/* A callback for htab_traverse that finds and clears an entry
+   corresponding to a given BFD.  */
+
+static int
+delete_bfd_from_htab (void **slot, void *arg)
+{
+  struct ar_cache *cache = *slot;
+  bfd *abfd = arg;
+
+  if (cache->arbfd == abfd)
+    {
+      *slot = HTAB_DELETED_ENTRY;
+      return 0;
+    }
+
+  return 1;
+}
+
 /* Free the archive hash table, if it exists.  */
 
 void
@@ -302,6 +320,17 @@ _bfd_delete_archive_data (bfd *abfd)
 
   if (ardata && ardata->cache)
     htab_delete (ardata->cache);
+
+  if (abfd->my_archive)
+    {
+      ardata = bfd_ardata (abfd->my_archive);
+      if (ardata && ardata->cache)
+	{
+	  /* We have to traverse the hash table because there is no
+	     way to find ABFD in it directly.  */
+	  htab_traverse_noresize (ardata->cache, delete_bfd_from_htab, abfd);
+	}
+    }
 }
 
 bfd *
-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 48+ messages in thread

end of thread, other threads:[~2012-08-20 14:32 UTC | newest]

Thread overview: 48+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-03 14:55 [PATCH 3/5] remove deleted BFDs from the archive cache Tom Tromey
2012-08-03 16:12 ` Alan Modra
2012-08-03 20:56   ` Tom Tromey
2012-08-08 22:47   ` Tom Tromey
2012-08-09 10:35     ` Alan Modra
2012-08-15 20:14       ` H.J. Lu
2012-08-15 21:30         ` Tom Tromey
2012-08-16 14:47           ` Alan Modra
2012-08-16 16:31             ` H.J. Lu
2012-08-16 18:14               ` Tom Tromey
2012-08-16 18:33                 ` H.J. Lu
2012-08-16 18:45                   ` Tom Tromey
2012-08-16 18:49                     ` H.J. Lu
2012-08-16 18:55                       ` Tom Tromey
2012-08-16 20:33                         ` Tom Tromey
2012-08-16 20:38                         ` H.J. Lu
2012-08-16 21:11                 ` H.J. Lu
2012-08-16 21:35                 ` H.J. Lu
2012-08-17  1:01                 ` Alan Modra
2012-08-17  1:06                   ` H.J. Lu
2012-08-17  2:44                     ` Alan Modra
2012-08-17  4:56                       ` Hans-Peter Nilsson
2012-08-17  5:04                         ` Alan Modra
2012-08-17  5:08                         ` H.J. Lu
2012-08-17  5:30                           ` H.J. Lu
2012-08-17  5:42                             ` H.J. Lu
2012-08-17  5:45                               ` H.J. Lu
2012-08-17  6:01                                 ` H.J. Lu
2012-08-17 13:10                                   ` H.J. Lu
2012-08-17 16:50                                     ` Hans-Peter Nilsson
2012-08-17 16:01                           ` Hans-Peter Nilsson
2012-08-17 16:10                             ` H.J. Lu
2012-08-17 16:14                               ` Hans-Peter Nilsson
2012-08-17 16:13                       ` Tom Tromey
2012-08-17 16:26                         ` H.J. Lu
2012-08-17 16:51                           ` Tom Tromey
2012-08-17 17:11                             ` H.J. Lu
2012-08-17 17:22                               ` Tom Tromey
2012-08-17 17:22                                 ` H.J. Lu
2012-08-17 19:03                                   ` Tom Tromey
2012-08-17 19:13                                     ` H.J. Lu
2012-08-18  4:37                         ` Alan Modra
2012-08-21  9:55                           ` Tom Tromey
2012-08-17  1:17                   ` Alan Modra
2012-08-17 15:36                   ` Tom Tromey
2012-08-17 15:38                     ` H.J. Lu
2012-08-17 15:43                       ` Tom Tromey
2012-08-17  0:48           ` H.J. Lu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).