This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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]

Commit: Replace BFD set macros with static inline functions


Hi Guys,

  Following up on Tom's suggestion I am checking in the patch below to
  replace the various bfd_xxx_set macros with static inline functions,
  so that we can avoid compile time warnings about comma expressions
  with unused values.

Cheers
  Nick

bfd/ChangeLog
2014-01-29  Nick Clifton  <nickc@redhat.com>

	* bfd-in.h (bfd_set_section_vma): Delete.
	(bfd_set_section_alignment): Delete.
	(bfd_set_section_userdata): Delete.
	(bfd_set_cacheable): Delete.
	* bfd.c (bfd_set_cacheable): New static inline function.
	* section.c (bfd_set_section_userdata): Likewise.
	(bfd_set_section_vma): Likewise.
	(bfd_set_section_alignment): Likewise.
	* bfd-in2.h: Regenerate.

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index 3afd71b..c7c5a7d 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -292,9 +292,6 @@ typedef struct bfd_section *sec_ptr;
 
 #define bfd_is_com_section(ptr) (((ptr)->flags & SEC_IS_COMMON) != 0)
 
-#define bfd_set_section_vma(bfd, ptr, val) (((ptr)->vma = (ptr)->lma = (val)), ((ptr)->user_set_vma = TRUE), TRUE)
-#define bfd_set_section_alignment(bfd, ptr, val) (((ptr)->alignment_power = (val)),TRUE)
-#define bfd_set_section_userdata(bfd, ptr, val) (((ptr)->userdata = (val)),TRUE)
 /* Find the address one past the end of SEC.  */
 #define bfd_get_section_limit(bfd, sec) \
   (((bfd)->direction != write_direction && (sec)->rawsize != 0	\
@@ -517,8 +514,6 @@ extern void warn_deprecated (const char *, const char *, int, const char *);
 
 #define bfd_get_symbol_leading_char(abfd) ((abfd)->xvec->symbol_leading_char)
 
-#define bfd_set_cacheable(abfd,bool) (((abfd)->cacheable = bool), TRUE)
-
 extern bfd_boolean bfd_cache_close
   (bfd *abfd);
 /* NB: This declaration should match the autogenerated one in libbfd.h.  */
diff --git a/bfd/bfd.c b/bfd/bfd.c
index 8d0580c..2d174f3 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -311,6 +311,14 @@ CODE_FRAGMENT
 .  unsigned int selective_search : 1;
 .};
 .
+.{* See note beside bfd_set_section_userdata.  *}
+.static inline bfd_boolean
+.bfd_set_cacheable (bfd * abfd, bfd_boolean val)
+.{
+.  abfd->cacheable = val;
+.  return TRUE;
+.}
+.
 */
 
 #include "sysdep.h"
diff --git a/bfd/section.c b/bfd/section.c
index fb19d8c..a661228 100644
--- a/bfd/section.c
+++ b/bfd/section.c
@@ -542,6 +542,32 @@ CODE_FRAGMENT
 .  int size;
 .};
 .
+.{* Note: the following are provided as inline functions rather than macros
+.   because not all callers use the return value.  A macro implementation
+.   would use a comma expression, eg: "((ptr)->foo = val, TRUE)" and some
+.   compilers will complain about comma expressions that have no effect.  *}
+.static inline bfd_boolean
+.bfd_set_section_userdata (bfd * abfd ATTRIBUTE_UNUSED, asection * ptr, void * val)
+.{
+.  ptr->userdata = val;
+.  return TRUE;
+.}
+.
+.static inline bfd_boolean
+.bfd_set_section_vma (bfd * abfd ATTRIBUTE_UNUSED, asection * ptr, bfd_vma val)
+.{
+.  ptr->vma = ptr->lma = val;
+.  ptr->user_set_vma = TRUE;
+.  return TRUE;
+.}
+.
+.static inline bfd_boolean
+.bfd_set_section_alignment (bfd * abfd ATTRIBUTE_UNUSED, asection * ptr, unsigned int val)
+.{
+.  ptr->alignment_power = val;
+.  return TRUE;
+.}
+.
 .{* These sections are global, and are managed by BFD.  The application
 .   and target back end are not permitted to change the values in
 .   these sections.  *}


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