RFC: Short circuit bfd_map_over_sections

H. J. Lu hjl@lucon.org
Fri Apr 30 01:36:00 GMT 2004


On Thu, Apr 29, 2004 at 08:29:01PM -0400, Ian Lance Taylor wrote:
> "H. J. Lu" <hjl@lucon.org> writes:
> 
> > That is fine. What should we call it? bfd_run_over_sections,
> > bfd_call_over_sections, bfd_call_on_sections, ...
> 
> By analogy with C++, it should be bfd_sections_find_if, and it should
> return the first section for which the function returns true.
> 

I like bfd_sections_find_if. Here is a patch.

> bfd_for_each_section is another possibility.
> 
> Or bfd_traverse_sections.
> 

H.J.
-------------- next part --------------
2004-04-29  H.J. Lu  <hongjiu.lu@intel.com>

	* section.c (bfd_sections_find_if): New.
	* bfd-in2.h: Regenerated.

--- bfd/section.c.short	2003-12-04 10:43:20.000000000 -0800
+++ bfd/section.c	2004-04-29 18:30:25.000000000 -0700
@@ -1090,6 +1090,41 @@ bfd_map_over_sections (bfd *abfd,
 
 /*
 FUNCTION
+	bfd_sections_find_if
+
+SYNOPSIS
+	asection *bfd_sections_find_if
+	  (bfd *abfd,
+	   bfd_boolean (*func) (bfd *abfd, asection *sect, void *obj),
+	   void *obj);
+
+DESCRIPTION
+	Call the provided function @var{func} for each section
+	attached to the BFD @var{abfd}, passing @var{obj} as an
+	argument. The function will be called as if by
+
+|	func (abfd, the_section, obj);
+
+	It returns the first section for which @var{func} returns true.
+
+*/
+
+asection *
+bfd_sections_find_if (bfd *abfd,
+		      bfd_boolean (*operation) (bfd *, asection *, void *),
+		      void *user_storage)
+{
+  asection *sect;
+
+  for (sect = abfd->sections; sect != NULL; sect = sect->next)
+    if ((*operation) (abfd, sect, user_storage))
+      break;
+
+  return sect;
+}
+
+/*
+FUNCTION
 	bfd_set_section_size
 
 SYNOPSIS


More information about the Binutils mailing list