public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] libdwfl: Move nested functions in parse_opt to file scope.
@ 2017-07-27 15:42 Yunlian Jiang via elfutils-devel
  2017-07-27 16:12 ` Mark Wielaard
  0 siblings, 1 reply; 4+ messages in thread
From: Yunlian Jiang via elfutils-devel @ 2017-07-27 15:42 UTC (permalink / raw)
  To: elfutils-devel

* Move nested function 'failure' to file scope to compile with clang.
* Move nested function 'fail' to file scope to compile with clang.

Signed-off-by: Yunlian Jiang <yunlian@google.com>
---
 libdwfl/argp-std.c | 55 ++++++++++++++++++++++++++++--------------------------
 1 file changed, 29 insertions(+), 26 deletions(-)

index 9bce6b1e..83f03a8f 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,7 @@
+2017-07-27  Yunlian Jiang <yunlian@google.com>
+       * Move nested function 'failure' to file scope to compile with clang.
+       * Move nested function 'fail' to file scope to compile with clang.
+
 2017-04-20  Ulf Hermann  <ulf.hermann@qt.io>
            Mark Wielaard  <mark@klomp.org>

diff --git a/libdwfl/argp-std.c b/libdwfl/argp-std.c
index 347a05b4..498ace21 100644
--- a/libdwfl/argp-std.c
+++ b/libdwfl/argp-std.c
@@ -104,25 +104,28 @@ struct parse_opt
   const char *core;
 };

+static inline void
+failure (Dwfl *dwfl, int errnum, const char *msg, struct argp_state *state)
+{
+  if (dwfl != NULL)
+    dwfl_end (dwfl);
+  if (errnum == -1)
+    argp_failure (state, EXIT_FAILURE, 0, "%s: %s",
+                  msg, INTUSE(dwfl_errmsg) (-1));
+  else
+    argp_failure (state, EXIT_FAILURE, errnum, "%s", msg);
+}
+
+static inline error_t
+fail (Dwfl *dwfl, int errnum, const char *msg, struct argp_state *state)
+{
+  failure (dwfl, errnum, msg, state);
+  return errnum == -1 ? EIO : errnum;
+}
+
 static error_t
 parse_opt (int key, char *arg, struct argp_state *state)
 {
-  inline void failure (Dwfl *dwfl, int errnum, const char *msg)
-    {
-      if (dwfl != NULL)
- dwfl_end (dwfl);
-      if (errnum == -1)
- argp_failure (state, EXIT_FAILURE, 0, "%s: %s",
-      msg, INTUSE(dwfl_errmsg) (-1));
-      else
- argp_failure (state, EXIT_FAILURE, errnum, "%s", msg);
-    }
-  inline error_t fail (Dwfl *dwfl, int errnum, const char *msg)
-    {
-      failure (dwfl, errnum, msg);
-      return errnum == -1 ? EIO : errnum;
-    }
-
   switch (key)
     {
     case ARGP_KEY_INIT:
@@ -130,7 +133,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
  assert (state->hook == NULL);
  struct parse_opt *opt = calloc (1, sizeof (*opt));
  if (opt == NULL)
-  failure (NULL, DWFL_E_ERRNO, "calloc");
+  failure (NULL, DWFL_E_ERRNO, "calloc", state);
  state->hook = opt;
       }
       break;
@@ -147,7 +150,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
   {
     dwfl = INTUSE(dwfl_begin) (&offline_callbacks);
     if (dwfl == NULL)
-      return fail (dwfl, -1, arg);
+      return fail (dwfl, -1, arg, state);
     opt->dwfl = dwfl;

     /* Start at zero so if there is just one -e foo.so,
@@ -173,7 +176,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
     Dwfl *dwfl = INTUSE(dwfl_begin) (&proc_callbacks);
     int result = INTUSE(dwfl_linux_proc_report) (dwfl, atoi (arg));
     if (result != 0)
-      return fail (dwfl, result, arg);
+      return fail (dwfl, result, arg, state);

     /* Non-fatal to not be able to attach to process, ignore error.  */
     INTUSE(dwfl_linux_proc_attach) (dwfl, atoi (arg), false);
@@ -202,7 +205,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
     int result = INTUSE(dwfl_linux_proc_maps_report) (dwfl, f);
     fclose (f);
     if (result != 0)
-      return fail (dwfl, result, arg);
+      return fail (dwfl, result, arg, state);
     opt->dwfl = dwfl;
   }
  else
@@ -231,11 +234,11 @@ parse_opt (int key, char *arg, struct argp_state *state)
     Dwfl *dwfl = INTUSE(dwfl_begin) (&kernel_callbacks);
     int result = INTUSE(dwfl_linux_kernel_report_kernel) (dwfl);
     if (result != 0)
-      return fail (dwfl, result, _("cannot load kernel symbols"));
+      return fail (dwfl, result, _("cannot load kernel symbols"), state);
     result = INTUSE(dwfl_linux_kernel_report_modules) (dwfl);
     if (result != 0)
       /* Non-fatal to have no modules since we do have the kernel.  */
-      failure (dwfl, result, _("cannot find kernel modules"));
+      failure (dwfl, result, _("cannot find kernel modules"), state);
     opt->dwfl = dwfl;
   }
  else
@@ -252,7 +255,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
     int result = INTUSE(dwfl_linux_kernel_report_offline) (dwfl, arg,
    NULL);
     if (result != 0)
-      return fail (dwfl, result, _("cannot find kernel or modules"));
+      return fail (dwfl, result, _("cannot find kernel or modules"), state);
     opt->dwfl = dwfl;
   }
  else
@@ -271,7 +274,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
     arg = "a.out";
     dwfl = INTUSE(dwfl_begin) (&offline_callbacks);
     if (INTUSE(dwfl_report_offline) (dwfl, "", arg, -1) == NULL)
-      return fail (dwfl, -1, arg);
+      return fail (dwfl, -1, arg, state);
     opt->dwfl = dwfl;
   }

@@ -301,7 +304,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
       {
  elf_end (core);
  close (fd);
- return fail (dwfl, result, opt->core);
+ return fail (dwfl, result, opt->core, state);
       }

     /* Non-fatal to not be able to attach to core, ignore error.  */
@@ -331,7 +334,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
  else if (opt->e)
   {
     if (INTUSE(dwfl_report_offline) (dwfl, "", opt->e, -1) == NULL)
-      return fail (dwfl, -1, opt->e);
+      return fail (dwfl, -1, opt->e, state);
   }

  /* One of the three flavors has done dwfl_begin and some reporting
-- 
2.14.0.rc0.400.g1c36432dff-goog

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

* Re: [PATCH] libdwfl: Move nested functions in parse_opt to file scope.
  2017-07-27 15:42 [PATCH] libdwfl: Move nested functions in parse_opt to file scope Yunlian Jiang via elfutils-devel
@ 2017-07-27 16:12 ` Mark Wielaard
  2017-07-27 16:35   ` Yunlian Jiang via elfutils-devel
  0 siblings, 1 reply; 4+ messages in thread
From: Mark Wielaard @ 2017-07-27 16:12 UTC (permalink / raw)
  To: Yunlian Jiang; +Cc: elfutils-devel

On Thu, 2017-07-27 at 08:42 -0700, Yunlian Jiang via elfutils-devel
wrote:
> * Move nested function 'failure' to file scope to compile with clang.
> * Move nested function 'fail' to file scope to compile with clang.

The patch seems fine but doesn't apply because of whitespace issues
(looks like tab versus space issues?) Could you sent again.

Thanks,

Mark

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

* Re: [PATCH] libdwfl: Move nested functions in parse_opt to file scope.
  2017-07-27 16:12 ` Mark Wielaard
@ 2017-07-27 16:35   ` Yunlian Jiang via elfutils-devel
  2017-07-27 17:04     ` Mark Wielaard
  0 siblings, 1 reply; 4+ messages in thread
From: Yunlian Jiang via elfutils-devel @ 2017-07-27 16:35 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: elfutils-devel

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

I attach the output of git format-patch and this should work.

On Thu, Jul 27, 2017 at 9:12 AM, Mark Wielaard <mark@klomp.org> wrote:
> On Thu, 2017-07-27 at 08:42 -0700, Yunlian Jiang via elfutils-devel
> wrote:
>> * Move nested function 'failure' to file scope to compile with clang.
>> * Move nested function 'fail' to file scope to compile with clang.
>
> The patch seems fine but doesn't apply because of whitespace issues
> (looks like tab versus space issues?) Could you sent again.
>
> Thanks,
>
> Mark

[-- Attachment #2: 0001-libdwfl-Move-nested-functions-in-parse_opt-to-file-s.patch --]
[-- Type: text/x-patch, Size: 5367 bytes --]

From bc1df8629c98785789444b5ec836f3bbc61bdf7d Mon Sep 17 00:00:00 2001
From: Yunlian Jiang <yunlian@google.com>
Date: Wed, 26 Jul 2017 16:25:43 -0700
Subject: [PATCH] libdwfl: Move nested functions in parse_opt to file scope.

* Move nested function 'failure' to file scope to compile with clang.
* Move nested function 'fail' to file scope to compile with clang.

Signed-off-by: Yunlian Jiang <yunlian@google.com>
---
 libdwfl/argp-std.c | 55 ++++++++++++++++++++++++++++--------------------------
 1 file changed, 29 insertions(+), 26 deletions(-)

diff --git a/libdwfl/argp-std.c b/libdwfl/argp-std.c
index 347a05b4..498ace21 100644
--- a/libdwfl/argp-std.c
+++ b/libdwfl/argp-std.c
@@ -104,25 +104,28 @@ struct parse_opt
   const char *core;
 };
 
+static inline void
+failure (Dwfl *dwfl, int errnum, const char *msg, struct argp_state *state)
+{
+  if (dwfl != NULL)
+    dwfl_end (dwfl);
+  if (errnum == -1)
+    argp_failure (state, EXIT_FAILURE, 0, "%s: %s",
+                  msg, INTUSE(dwfl_errmsg) (-1));
+  else
+    argp_failure (state, EXIT_FAILURE, errnum, "%s", msg);
+}
+
+static inline error_t
+fail (Dwfl *dwfl, int errnum, const char *msg, struct argp_state *state)
+{
+  failure (dwfl, errnum, msg, state);
+  return errnum == -1 ? EIO : errnum;
+}
+
 static error_t
 parse_opt (int key, char *arg, struct argp_state *state)
 {
-  inline void failure (Dwfl *dwfl, int errnum, const char *msg)
-    {
-      if (dwfl != NULL)
-	dwfl_end (dwfl);
-      if (errnum == -1)
-	argp_failure (state, EXIT_FAILURE, 0, "%s: %s",
-		      msg, INTUSE(dwfl_errmsg) (-1));
-      else
-	argp_failure (state, EXIT_FAILURE, errnum, "%s", msg);
-    }
-  inline error_t fail (Dwfl *dwfl, int errnum, const char *msg)
-    {
-      failure (dwfl, errnum, msg);
-      return errnum == -1 ? EIO : errnum;
-    }
-
   switch (key)
     {
     case ARGP_KEY_INIT:
@@ -130,7 +133,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
 	assert (state->hook == NULL);
 	struct parse_opt *opt = calloc (1, sizeof (*opt));
 	if (opt == NULL)
-	  failure (NULL, DWFL_E_ERRNO, "calloc");
+	  failure (NULL, DWFL_E_ERRNO, "calloc", state);
 	state->hook = opt;
       }
       break;
@@ -147,7 +150,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
 	  {
 	    dwfl = INTUSE(dwfl_begin) (&offline_callbacks);
 	    if (dwfl == NULL)
-	      return fail (dwfl, -1, arg);
+	      return fail (dwfl, -1, arg, state);
 	    opt->dwfl = dwfl;
 
 	    /* Start at zero so if there is just one -e foo.so,
@@ -173,7 +176,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
 	    Dwfl *dwfl = INTUSE(dwfl_begin) (&proc_callbacks);
 	    int result = INTUSE(dwfl_linux_proc_report) (dwfl, atoi (arg));
 	    if (result != 0)
-	      return fail (dwfl, result, arg);
+	      return fail (dwfl, result, arg, state);
 
 	    /* Non-fatal to not be able to attach to process, ignore error.  */
 	    INTUSE(dwfl_linux_proc_attach) (dwfl, atoi (arg), false);
@@ -202,7 +205,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
 	    int result = INTUSE(dwfl_linux_proc_maps_report) (dwfl, f);
 	    fclose (f);
 	    if (result != 0)
-	      return fail (dwfl, result, arg);
+	      return fail (dwfl, result, arg, state);
 	    opt->dwfl = dwfl;
 	  }
 	else
@@ -231,11 +234,11 @@ parse_opt (int key, char *arg, struct argp_state *state)
 	    Dwfl *dwfl = INTUSE(dwfl_begin) (&kernel_callbacks);
 	    int result = INTUSE(dwfl_linux_kernel_report_kernel) (dwfl);
 	    if (result != 0)
-	      return fail (dwfl, result, _("cannot load kernel symbols"));
+	      return fail (dwfl, result, _("cannot load kernel symbols"), state);
 	    result = INTUSE(dwfl_linux_kernel_report_modules) (dwfl);
 	    if (result != 0)
 	      /* Non-fatal to have no modules since we do have the kernel.  */
-	      failure (dwfl, result, _("cannot find kernel modules"));
+	      failure (dwfl, result, _("cannot find kernel modules"), state);
 	    opt->dwfl = dwfl;
 	  }
 	else
@@ -252,7 +255,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
 	    int result = INTUSE(dwfl_linux_kernel_report_offline) (dwfl, arg,
 								   NULL);
 	    if (result != 0)
-	      return fail (dwfl, result, _("cannot find kernel or modules"));
+	      return fail (dwfl, result, _("cannot find kernel or modules"), state);
 	    opt->dwfl = dwfl;
 	  }
 	else
@@ -271,7 +274,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
 	    arg = "a.out";
 	    dwfl = INTUSE(dwfl_begin) (&offline_callbacks);
 	    if (INTUSE(dwfl_report_offline) (dwfl, "", arg, -1) == NULL)
-	      return fail (dwfl, -1, arg);
+	      return fail (dwfl, -1, arg, state);
 	    opt->dwfl = dwfl;
 	  }
 
@@ -301,7 +304,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
 	      {
 		elf_end (core);
 		close (fd);
-		return fail (dwfl, result, opt->core);
+		return fail (dwfl, result, opt->core, state);
 	      }
 
 	    /* Non-fatal to not be able to attach to core, ignore error.  */
@@ -331,7 +334,7 @@ parse_opt (int key, char *arg, struct argp_state *state)
 	else if (opt->e)
 	  {
 	    if (INTUSE(dwfl_report_offline) (dwfl, "", opt->e, -1) == NULL)
-	      return fail (dwfl, -1, opt->e);
+	      return fail (dwfl, -1, opt->e, state);
 	  }
 
 	/* One of the three flavors has done dwfl_begin and some reporting
-- 
2.14.0.rc0.400.g1c36432dff-goog


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

* Re: [PATCH] libdwfl: Move nested functions in parse_opt to file scope.
  2017-07-27 16:35   ` Yunlian Jiang via elfutils-devel
@ 2017-07-27 17:04     ` Mark Wielaard
  0 siblings, 0 replies; 4+ messages in thread
From: Mark Wielaard @ 2017-07-27 17:04 UTC (permalink / raw)
  To: Yunlian Jiang; +Cc: elfutils-devel

On Thu, Jul 27, 2017 at 09:35:29AM -0700, Yunlian Jiang wrote:
> I attach the output of git format-patch and this should work.

It does. Applied to master (with ChangeLog entry).

Thanks,

Mark

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

end of thread, other threads:[~2017-07-27 17:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-27 15:42 [PATCH] libdwfl: Move nested functions in parse_opt to file scope Yunlian Jiang via elfutils-devel
2017-07-27 16:12 ` Mark Wielaard
2017-07-27 16:35   ` Yunlian Jiang via elfutils-devel
2017-07-27 17:04     ` 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).