To be compiled without gnu99 extension.
Signed-off-by: Chih-Hung Hsieh <chh(a)google.com>
---
libelf/ChangeLog | 6 ++++++
libelf/elf32_updatefile.c | 36 +++++++++++++++++-------------------
libelf/elf_begin.c | 23 +++++++++++------------
3 files changed, 34 insertions(+), 31 deletions(-)
diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index bb56e5b..6d3313d 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,9 @@
+2015-09-14 Chih-Hung Hsieh <chh(a)google.com>
+
+ * elf32_updatefile.c (__elfw2(LIBELFBITS,updatemmap)): Replace simple
+ nested functions with macros.
+ * elf_begin.c (elf_begin): Likewise.
+
2015-06-18 Mark Wielaard <mjw(a)redhat.com>
* elf32_updatefile.c (updatefile): Always free shdr_data and scns
diff --git a/libelf/elf32_updatefile.c b/libelf/elf32_updatefile.c
index 832f852..df6d74b 100644
--- a/libelf/elf32_updatefile.c
+++ b/libelf/elf32_updatefile.c
@@ -303,25 +303,23 @@ __elfw2(LIBELFBITS,updatemmap) (Elf *elf, int change_bo, size_t
shnum)
Elf_Data_List *dl = &scn->data_list;
bool scn_changed = false;
- void fill_mmap (size_t offset)
- {
- size_t written = 0;
-
- if (last_position < shdr_start)
- {
- written = MIN (scn_start + offset - last_position,
- shdr_start - last_position);
-
- memset (last_position, __libelf_fill_byte, written);
- }
-
- if (last_position + written != scn_start + offset
- && shdr_end < scn_start + offset)
- {
- char *fill_start = MAX (shdr_end, scn_start);
- memset (fill_start, __libelf_fill_byte,
- scn_start + offset - fill_start);
- }
+ #define fill_mmap(_offset) \
+ { \
+ size_t offset = _offset; \
+ size_t written = 0; \
+ if (last_position < shdr_start) \
+ { \
+ written = MIN (scn_start + offset - last_position, \
+ shdr_start - last_position); \
+ memset (last_position, __libelf_fill_byte, written); \
+ } \
+ if (last_position + written != scn_start + offset \
+ && shdr_end < scn_start + offset) \
+ { \
+ char *fill_start = MAX (shdr_end, scn_start); \
+ memset (fill_start, __libelf_fill_byte, \
+ scn_start + offset - fill_start); \
+ } \
}
if (scn->data_list_rear != NULL)
diff --git a/libelf/elf_begin.c b/libelf/elf_begin.c
index f002ebf..710f643 100644
--- a/libelf/elf_begin.c
+++ b/libelf/elf_begin.c
@@ -1067,18 +1067,17 @@ elf_begin (fildes, cmd, ref)
return NULL;
}
- Elf *lock_dup_elf ()
- {
- /* We need wrlock to dup an archive. */
- if (ref->kind == ELF_K_AR)
- {
- rwlock_unlock (ref->lock);
- rwlock_wrlock (ref->lock);
- }
-
- /* Duplicate the descriptor. */
- return dup_elf (fildes, cmd, ref);
- }
+ #define lock_dup_elf() \
+ ( { \
+ /* We need wrlock to dup an archive. */ \
+ if (ref->kind == ELF_K_AR) \
+ { \
+ rwlock_unlock (ref->lock); \
+ rwlock_wrlock (ref->lock); \
+ } \
+ /* Duplicate the descriptor. */ \
+ dup_elf (fildes, cmd, ref); \
+ } )
switch (cmd)
{
--
2.6.0.rc0.131.gf624c3d
Show replies by date