public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Move nested functions in elf_compress.c and elf_strptr.c.
@ 2016-01-22 18:04 Chih-Hung Hsieh
  0 siblings, 0 replies; 2+ messages in thread
From: Chih-Hung Hsieh @ 2016-01-22 18:04 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 3876 bytes --]

* elf_compress.c (__libelf_compress): do_deflate_cleanup
* elf_strptr.c (elf_strptr): get_zdata

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
---
 libelf/ChangeLog      |  7 +++++++
 libelf/elf_compress.c | 25 +++++++++++++++----------
 libelf/elf_strptr.c   | 33 +++++++++++++++++----------------
 3 files changed, 39 insertions(+), 26 deletions(-)

diff --git a/libelf/ChangeLog b/libelf/ChangeLog
index aabf6f6..afe6a6a 100644
--- a/libelf/ChangeLog
+++ b/libelf/ChangeLog
@@ -1,3 +1,10 @@
+2016-01-22  Chih-Hung Hsieh <chh@google.com>
+
+	* elf_compress.c (__libelf_compress): Move nested function
+	'do_deflate_cleanup' to file scope to compile with clang.
+	* elf_strptr.c (elf_strptr): Move nested function 'get_zdata'
+	to file scope to compile with clang.
+
 2016-01-13  Mark Wielaard  <mjw@redhat.com>
 
 	* libelf.h: Check SHF_COMPRESSED is defined. If not define it and the
diff --git a/libelf/elf_compress.c b/libelf/elf_compress.c
index ec5b717..4c7c35e 100644
--- a/libelf/elf_compress.c
+++ b/libelf/elf_compress.c
@@ -45,6 +45,21 @@
 # define MAX(a, b) ((a) > (b) ? (a) : (b))
 #endif
 
+/* Cleanup and return result.  Don't leak memory.  */
+static void *
+do_deflate_cleanup (void *result, z_stream *z, void *out_buf,
+                    int ei_data, Elf_Data *cdatap)
+{
+  deflateEnd (z);
+  free (out_buf);
+  if (ei_data != MY_ELFDATA)
+    free (cdatap->d_buf);
+  return result;
+}
+
+#define deflate_cleanup(result) \
+    do_deflate_cleanup(result, &z, out_buf, ei_data, &cdata)
+
 /* Given a section, uses the (in-memory) Elf_Data to extract the
    original data size (including the given header size) and data
    alignment.  Returns a buffer that has at least hsize bytes (for the
@@ -109,16 +124,6 @@ __libelf_compress (Elf_Scn *scn, size_t hsize, int ei_data,
   Elf_Data cdata;
   cdata.d_buf = NULL;
 
-  /* Cleanup and return result.  Don't leak memory.  */
-  void *deflate_cleanup (void *result)
-  {
-    deflateEnd (&z);
-    free (out_buf);
-    if (ei_data != MY_ELFDATA)
-      free (cdata.d_buf);
-    return result;
-  }
-
   /* Loop over data buffers.  */
   int flush = Z_NO_FLUSH;
   do
diff --git a/libelf/elf_strptr.c b/libelf/elf_strptr.c
index e3b5876..ea21045 100644
--- a/libelf/elf_strptr.c
+++ b/libelf/elf_strptr.c
@@ -37,6 +37,21 @@
 #include "libelfP.h"
 
 
+static void *
+get_zdata (Elf_Scn *strscn)
+{
+  size_t zsize, zalign;
+  void *zdata = __libelf_decompress_elf (strscn, &zsize, &zalign);
+  if (zdata == NULL)
+    return NULL;
+
+  strscn->zdata_base = zdata;
+  strscn->zdata_size = zsize;
+  strscn->zdata_align = zalign;
+
+  return zdata;
+}
+
 char *
 elf_strptr (Elf *elf, size_t idx, size_t offset)
 {
@@ -83,20 +98,6 @@ elf_strptr (Elf *elf, size_t idx, size_t offset)
 	}
     }
 
-  void *get_zdata (void)
-  {
-    size_t zsize, zalign;
-    void *zdata = __libelf_decompress_elf (strscn, &zsize, &zalign);
-    if (zdata == NULL)
-      return NULL;
-
-    strscn->zdata_base = zdata;
-    strscn->zdata_size = zsize;
-    strscn->zdata_align = zalign;
-
-    return zdata;
-  }
-
   size_t sh_size = 0;
   if (elf->class == ELFCLASS32)
     {
@@ -112,7 +113,7 @@ elf_strptr (Elf *elf, size_t idx, size_t offset)
 	sh_size = shdr->sh_size;
       else
 	{
-	  if (strscn->zdata_base == NULL && get_zdata () == NULL)
+	  if (strscn->zdata_base == NULL && get_zdata (strscn) == NULL)
 	    goto out;
 	  sh_size = strscn->zdata_size;
 	}
@@ -138,7 +139,7 @@ elf_strptr (Elf *elf, size_t idx, size_t offset)
 	sh_size = shdr->sh_size;
       else
 	{
-	  if (strscn->zdata_base == NULL && get_zdata () == NULL)
+	  if (strscn->zdata_base == NULL && get_zdata (strscn) == NULL)
 	    goto out;
 	  sh_size = strscn->zdata_size;
 	}
-- 
2.7.0.rc3.207.g0ac5344

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

* Re: [PATCH] Move nested functions in elf_compress.c and elf_strptr.c.
@ 2016-01-23 19:05 Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2016-01-23 19:05 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 195 bytes --]

On Fri, Jan 22, 2016 at 10:04:33AM -0800, Chih-Hung Hsieh wrote:
> * elf_compress.c (__libelf_compress): do_deflate_cleanup
> * elf_strptr.c (elf_strptr): get_zdata

Thanks, pushed to master.

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

end of thread, other threads:[~2016-01-23 19:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-22 18:04 [PATCH] Move nested functions in elf_compress.c and elf_strptr.c Chih-Hung Hsieh
2016-01-23 19:05 Mark Wielaard

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).