public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Move nested functions in dwfl_module.c and dwfl_module_getsrc_file.c.
@ 2015-10-21 22:50 Chih-Hung Hsieh
  0 siblings, 0 replies; 6+ messages in thread
From: Chih-Hung Hsieh @ 2015-10-21 22:50 UTC (permalink / raw)
  To: elfutils-devel

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

* Nested functions in these two files are moved to file scope
  to compile with clang. Extra parameters are added to pass
  local variables.

Signed-off-by: Chih-Hung Hsieh
---
 libdwfl/ChangeLog                 |  7 +++++++
 libdwfl/dwfl_module.c             | 33 +++++++++++++++++----------------
 libdwfl/dwfl_module_getsrc_file.c | 31 ++++++++++++++++++-------------
 3 files changed, 42 insertions(+), 29 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 5cae434..0374e5a 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,10 @@
+2015-10-21  Chih-Hung Hsieh <chh@google.com>
+
+	* dwfl_module.c (dwfl_report_module): Move nested function 'use' to file
+	scope.
+	* dwfl_module_getsrc_file.c (dwfl_module_getsrc_file): Move nested functions
+	'dwarf_line_file', 'dwfl_line', and 'dwfl_line_file' to file scope.
+
 2015-10-09  Josh Stone  <jistone@redhat.com>
 
 	* core-file.c (elf_begin_rand): Replace loff_t with off_t.
diff --git a/libdwfl/dwfl_module.c b/libdwfl/dwfl_module.c
index 8efcfaa..76d45a8 100644
--- a/libdwfl/dwfl_module.c
+++ b/libdwfl/dwfl_module.c
@@ -125,6 +125,21 @@ dwfl_report_begin (Dwfl *dwfl)
 }
 INTDEF (dwfl_report_begin)
 
+static inline Dwfl_Module *
+use (Dwfl_Module *mod, Dwfl_Module **tailp, Dwfl *dwfl)
+{
+  mod->next = *tailp;
+  *tailp = mod;
+
+  if (unlikely (dwfl->lookup_module != NULL))
+    {
+      free (dwfl->lookup_module);
+      dwfl->lookup_module = NULL;
+    }
+
+  return mod;
+}
+
 /* Report that a module called NAME spans addresses [START, END).
    Returns the module handle, either existing or newly allocated,
    or returns a null pointer for an allocation error.  */
@@ -134,20 +149,6 @@ dwfl_report_module (Dwfl *dwfl, const char *name,
 {
   Dwfl_Module **tailp = &dwfl->modulelist, **prevp = tailp;
 
-  inline Dwfl_Module *use (Dwfl_Module *mod)
-  {
-    mod->next = *tailp;
-    *tailp = mod;
-
-    if (unlikely (dwfl->lookup_module != NULL))
-      {
-	free (dwfl->lookup_module);
-	dwfl->lookup_module = NULL;
-      }
-
-    return mod;
-  }
-
   for (Dwfl_Module *m = *prevp; m != NULL; m = *(prevp = &m->next))
     {
       if (m->low_addr == start && m->high_addr == end
@@ -157,7 +158,7 @@ dwfl_report_module (Dwfl *dwfl, const char *name,
 	     after the last module already reported.  */
 	  *prevp = m->next;
 	  m->gc = false;
-	  return use (m);
+	  return use (m, tailp, dwfl);
 	}
 
       if (! m->gc)
@@ -181,7 +182,7 @@ dwfl_report_module (Dwfl *dwfl, const char *name,
   mod->high_addr = end;
   mod->dwfl = dwfl;
 
-  return use (mod);
+  return use (mod, tailp, dwfl);
 }
 INTDEF (dwfl_report_module)
 
diff --git a/libdwfl/dwfl_module_getsrc_file.c b/libdwfl/dwfl_module_getsrc_file.c
index 20aa8a5..75ba68e 100644
--- a/libdwfl/dwfl_module_getsrc_file.c
+++ b/libdwfl/dwfl_module_getsrc_file.c
@@ -30,6 +30,24 @@
 #include "../libdw/libdwP.h"
 
 
+static inline const char *
+INTUSE(dwarf_line_file) (const Dwarf_Line *line)
+{
+  return line->files->info[line->file].name;
+}
+
+static inline Dwarf_Line *
+dwfl_line (const Dwfl_Line *line)
+{
+  return &dwfl_linecu (line)->die.cu->lines->info[line->idx];
+}
+
+static inline const char *
+dwfl_line_file (const Dwfl_Line *line)
+{
+  return INTUSE(dwarf_line_file) (dwfl_line (line));
+}
+
 int
 dwfl_module_getsrc_file (Dwfl_Module *mod,
 			 const char *fname, int lineno, int column,
@@ -58,19 +76,6 @@ dwfl_module_getsrc_file (Dwfl_Module *mod,
 	 && cu != NULL
 	 && (error = __libdwfl_cu_getsrclines (cu)) == DWFL_E_NOERROR)
     {
-      inline const char *INTUSE(dwarf_line_file) (const Dwarf_Line *line)
-	{
-	  return line->files->info[line->file].name;
-	}
-      inline Dwarf_Line *dwfl_line (const Dwfl_Line *line)
-	{
-	  return &dwfl_linecu (line)->die.cu->lines->info[line->idx];
-	}
-      inline const char *dwfl_line_file (const Dwfl_Line *line)
-	{
-	  return INTUSE(dwarf_line_file) (dwfl_line (line));
-	}
-
       /* Search through all the line number records for a matching
 	 file and line/column number.  If any of the numbers is zero,
 	 no match is performed.  */
-- 
2.6.0.rc2.230.g3dd15c0


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

* Re: [PATCH] Move nested functions in dwfl_module.c and dwfl_module_getsrc_file.c.
@ 2015-11-04 10:25 Mark Wielaard
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Wielaard @ 2015-11-04 10:25 UTC (permalink / raw)
  To: elfutils-devel

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

On Tue, Nov 03, 2015 at 04:05:28PM -0800, Chih-hung Hsieh wrote:
> Mark, your new changed patch looked good to me.
> It does not matter to me if INTUSE is changed now or later.

Lets change it now. It really is a strange usage. Pushed to master.
Sorry to have hijacked your patch to clean this up at the same time.
It wasn't as bad as I thought it was at first.

Cheers,

Mark

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

* Re: [PATCH] Move nested functions in dwfl_module.c and dwfl_module_getsrc_file.c.
@ 2015-11-04  0:05 Chih-Hung Hsieh
  0 siblings, 0 replies; 6+ messages in thread
From: Chih-Hung Hsieh @ 2015-11-04  0:05 UTC (permalink / raw)
  To: elfutils-devel

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

Mark, your new changed patch looked good to me.
It does not matter to me if INTUSE is changed now or later.
Thanks.


On Tue, Nov 3, 2015 at 2:58 PM, Mark Wielaard <mjw@redhat.com> wrote:

> On Tue, Nov 03, 2015 at 03:58:10PM +0100, Mark Wielaard wrote:
> > Although the dwfl_module_getsrc_file.c change itself is good, the abuse
> > of INTUSE to define and use a "not really" libdw dwarf_line_file
> > function (which really is just dwarf_linesrc with the two unused return
> > values dropped) was just too ugly. Sorry, I know you didn't introduce
> > this (it looks like it has been this way forever). I'll propose
> > something that doesn't hurt my eyes so much.
>
> At first I thought we should introduce a new libdw line function or
> make an exiting one easier for what dwfl_module_getsrc_file needs.
> But this seems a little too specific. It might be better to wait till
> we start supporting the the new DWARFv5 line tables which will need
> new functions to support anyway.
>
> So lets just use what you came up with, but just rename the function
> and drop the strange INTUSE usage. Attached your patch with just that
> change.
>
> Cheers,
>
> Mark
>

[-- Attachment #2: attachment.html --]
[-- Type: text/html, Size: 1590 bytes --]

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

* Re: [PATCH] Move nested functions in dwfl_module.c and dwfl_module_getsrc_file.c.
@ 2015-11-03 22:58 Mark Wielaard
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Wielaard @ 2015-11-03 22:58 UTC (permalink / raw)
  To: elfutils-devel

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

On Tue, Nov 03, 2015 at 03:58:10PM +0100, Mark Wielaard wrote:
> Although the dwfl_module_getsrc_file.c change itself is good, the abuse
> of INTUSE to define and use a "not really" libdw dwarf_line_file
> function (which really is just dwarf_linesrc with the two unused return
> values dropped) was just too ugly. Sorry, I know you didn't introduce
> this (it looks like it has been this way forever). I'll propose
> something that doesn't hurt my eyes so much.

At first I thought we should introduce a new libdw line function or
make an exiting one easier for what dwfl_module_getsrc_file needs.
But this seems a little too specific. It might be better to wait till
we start supporting the the new DWARFv5 line tables which will need
new functions to support anyway.

So lets just use what you came up with, but just rename the function
and drop the strange INTUSE usage. Attached your patch with just that
change.

Cheers,

Mark

[-- Attachment #2: 0001-Move-nested-functions-in-dwfl_module_getsrc_file.c.patch --]
[-- Type: text/plain, Size: 3352 bytes --]

>From 3148f5cd3dafdce78a30b609901fc9b27cceb983 Mon Sep 17 00:00:00 2001
From: Chih-Hung Hsieh <chh@google.com>
Date: Wed, 21 Oct 2015 15:44:56 -0700
Subject: [PATCH] Move nested functions in dwfl_module_getsrc_file.c.

* Nested functions in this file are moved to file scope
  to compile with clang. Extra parameters are added to pass
  local variables.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 libdwfl/ChangeLog                 |  8 ++++++++
 libdwfl/dwfl_module_getsrc_file.c | 35 ++++++++++++++++++++---------------
 2 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index e7c373e..27250a9 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,4 +1,12 @@
 2015-10-21  Chih-Hung Hsieh <chh@google.com>
+	    Mark Wielaard  <mjw@redhat.com>
+
+	* dwfl_module_getsrc_file.c (dwfl_module_getsrc_file): Move nested
+	functions 'dwarf_line_file', 'dwfl_line', and 'dwfl_line_file' to
+	file scope. Rename dwarf_line_file to dwfl_dwarf_line_file. Don't
+	use INTUSE.
+
+2015-10-21  Chih-Hung Hsieh <chh@google.com>
 
 	* frame_unwind.c (expr_eval): Move nested function 'push' and 'pop'
 	to file scope. Pass used local variables in struct eval_stack.
diff --git a/libdwfl/dwfl_module_getsrc_file.c b/libdwfl/dwfl_module_getsrc_file.c
index 20aa8a5..21a5915 100644
--- a/libdwfl/dwfl_module_getsrc_file.c
+++ b/libdwfl/dwfl_module_getsrc_file.c
@@ -30,6 +30,24 @@
 #include "../libdw/libdwP.h"
 
 
+static inline const char *
+dwfl_dwarf_line_file (const Dwarf_Line *line)
+{
+  return line->files->info[line->file].name;
+}
+
+static inline Dwarf_Line *
+dwfl_line (const Dwfl_Line *line)
+{
+  return &dwfl_linecu (line)->die.cu->lines->info[line->idx];
+}
+
+static inline const char *
+dwfl_line_file (const Dwfl_Line *line)
+{
+  return dwfl_dwarf_line_file (dwfl_line (line));
+}
+
 int
 dwfl_module_getsrc_file (Dwfl_Module *mod,
 			 const char *fname, int lineno, int column,
@@ -58,19 +76,6 @@ dwfl_module_getsrc_file (Dwfl_Module *mod,
 	 && cu != NULL
 	 && (error = __libdwfl_cu_getsrclines (cu)) == DWFL_E_NOERROR)
     {
-      inline const char *INTUSE(dwarf_line_file) (const Dwarf_Line *line)
-	{
-	  return line->files->info[line->file].name;
-	}
-      inline Dwarf_Line *dwfl_line (const Dwfl_Line *line)
-	{
-	  return &dwfl_linecu (line)->die.cu->lines->info[line->idx];
-	}
-      inline const char *dwfl_line_file (const Dwfl_Line *line)
-	{
-	  return INTUSE(dwarf_line_file) (dwfl_line (line));
-	}
-
       /* Search through all the line number records for a matching
 	 file and line/column number.  If any of the numbers is zero,
 	 no match is performed.  */
@@ -87,7 +92,7 @@ dwfl_module_getsrc_file (Dwfl_Module *mod,
 	    }
 	  else
 	    {
-	      const char *file = INTUSE(dwarf_line_file) (line);
+	      const char *file = dwfl_dwarf_line_file (line);
 	      if (file != lastfile)
 		{
 		  /* Match the name with the name the user provided.  */
@@ -110,7 +115,7 @@ dwfl_module_getsrc_file (Dwfl_Module *mod,
 	  size_t inner;
 	  for (inner = 0; inner < cur_match; ++inner)
 	    if (dwfl_line_file (match[inner])
-		== INTUSE(dwarf_line_file) (line))
+		== dwfl_dwarf_line_file (line))
 	      break;
 	  if (inner < cur_match
 	      && (dwfl_line (match[inner])->line != line->line
-- 
2.4.3


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

* Re: [PATCH] Move nested functions in dwfl_module.c and dwfl_module_getsrc_file.c.
@ 2015-11-03 14:58 Mark Wielaard
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Wielaard @ 2015-11-03 14:58 UTC (permalink / raw)
  To: elfutils-devel

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

On Wed, 2015-10-21 at 16:11 -0700, Chih-hung Hsieh wrote:
> +2015-10-21  Chih-Hung Hsieh <chh@google.com>
> +
> +	* dwfl_module.c (dwfl_report_module): Move nested function 'use' to file
> +	scope.
> +	* dwfl_module_getsrc_file.c (dwfl_module_getsrc_file): Move nested functions
> +	'dwarf_line_file', 'dwfl_line', and 'dwfl_line_file' to file scope.

I pushed only the dwfl_module.c change (as attached) to master.

Although the dwfl_module_getsrc_file.c change itself is good, the abuse
of INTUSE to define and use a "not really" libdw dwarf_line_file
function (which really is just dwarf_linesrc with the two unused return
values dropped) was just too ugly. Sorry, I know you didn't introduce
this (it looks like it has been this way forever). I'll propose
something that doesn't hurt my eyes so much.

Thanks,

Mark

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Move-nested-functions-in-dwfl_module.c.patch --]
[-- Type: text/x-patch, Size: 2712 bytes --]

From 1ac2041156c3ecda5932069f1e295cc0b9727f7c Mon Sep 17 00:00:00 2001
From: Chih-Hung Hsieh <chh@google.com>
Date: Wed, 21 Oct 2015 15:44:56 -0700
Subject: [PATCH] Move nested functions in dwfl_module.c

* Nested functions in this file are moved to file scope
  to compile with clang. Extra parameters are added to pass
  local variables.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
---
 libdwfl/ChangeLog     |  5 +++++
 libdwfl/dwfl_module.c | 33 +++++++++++++++++----------------
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 5cae434..d30fd3c 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,8 @@
+2015-10-21  Chih-Hung Hsieh <chh@google.com>
+
+	* dwfl_module.c (dwfl_report_module): Move nested function 'use' to
+	file scope.
+
 2015-10-09  Josh Stone  <jistone@redhat.com>
 
 	* core-file.c (elf_begin_rand): Replace loff_t with off_t.
diff --git a/libdwfl/dwfl_module.c b/libdwfl/dwfl_module.c
index 8efcfaa..76d45a8 100644
--- a/libdwfl/dwfl_module.c
+++ b/libdwfl/dwfl_module.c
@@ -125,6 +125,21 @@ dwfl_report_begin (Dwfl *dwfl)
 }
 INTDEF (dwfl_report_begin)
 
+static inline Dwfl_Module *
+use (Dwfl_Module *mod, Dwfl_Module **tailp, Dwfl *dwfl)
+{
+  mod->next = *tailp;
+  *tailp = mod;
+
+  if (unlikely (dwfl->lookup_module != NULL))
+    {
+      free (dwfl->lookup_module);
+      dwfl->lookup_module = NULL;
+    }
+
+  return mod;
+}
+
 /* Report that a module called NAME spans addresses [START, END).
    Returns the module handle, either existing or newly allocated,
    or returns a null pointer for an allocation error.  */
@@ -134,20 +149,6 @@ dwfl_report_module (Dwfl *dwfl, const char *name,
 {
   Dwfl_Module **tailp = &dwfl->modulelist, **prevp = tailp;
 
-  inline Dwfl_Module *use (Dwfl_Module *mod)
-  {
-    mod->next = *tailp;
-    *tailp = mod;
-
-    if (unlikely (dwfl->lookup_module != NULL))
-      {
-	free (dwfl->lookup_module);
-	dwfl->lookup_module = NULL;
-      }
-
-    return mod;
-  }
-
   for (Dwfl_Module *m = *prevp; m != NULL; m = *(prevp = &m->next))
     {
       if (m->low_addr == start && m->high_addr == end
@@ -157,7 +158,7 @@ dwfl_report_module (Dwfl *dwfl, const char *name,
 	     after the last module already reported.  */
 	  *prevp = m->next;
 	  m->gc = false;
-	  return use (m);
+	  return use (m, tailp, dwfl);
 	}
 
       if (! m->gc)
@@ -181,7 +182,7 @@ dwfl_report_module (Dwfl *dwfl, const char *name,
   mod->high_addr = end;
   mod->dwfl = dwfl;
 
-  return use (mod);
+  return use (mod, tailp, dwfl);
 }
 INTDEF (dwfl_report_module)
 
-- 
1.8.3.1


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

* Re: [PATCH] Move nested functions in dwfl_module.c and dwfl_module_getsrc_file.c.
@ 2015-10-21 23:11 Chih-Hung Hsieh
  0 siblings, 0 replies; 6+ messages in thread
From: Chih-Hung Hsieh @ 2015-10-21 23:11 UTC (permalink / raw)
  To: elfutils-devel

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

Please use attached 0002*patch file,
which added my missing email address in the signed-off line.
Thanks.



On Wed, Oct 21, 2015 at 3:50 PM, Chih-Hung Hsieh <chh@google.com> wrote:

> * Nested functions in these two files are moved to file scope
>   to compile with clang. Extra parameters are added to pass
>   local variables.
>
> Signed-off-by: Chih-Hung Hsieh
> ---
>  libdwfl/ChangeLog                 |  7 +++++++
>  libdwfl/dwfl_module.c             | 33 +++++++++++++++++----------------
>  libdwfl/dwfl_module_getsrc_file.c | 31 ++++++++++++++++++-------------
>  3 files changed, 42 insertions(+), 29 deletions(-)
>
> diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
> index 5cae434..0374e5a 100644
> --- a/libdwfl/ChangeLog
> +++ b/libdwfl/ChangeLog
> @@ -1,3 +1,10 @@
> +2015-10-21  Chih-Hung Hsieh <chh@google.com>
> +
> +       * dwfl_module.c (dwfl_report_module): Move nested function 'use'
> to file
> +       scope.
> +       * dwfl_module_getsrc_file.c (dwfl_module_getsrc_file): Move nested
> functions
> +       'dwarf_line_file', 'dwfl_line', and 'dwfl_line_file' to file scope.
> +
>  2015-10-09  Josh Stone  <jistone@redhat.com>
>
>         * core-file.c (elf_begin_rand): Replace loff_t with off_t.
> diff --git a/libdwfl/dwfl_module.c b/libdwfl/dwfl_module.c
> index 8efcfaa..76d45a8 100644
> --- a/libdwfl/dwfl_module.c
> +++ b/libdwfl/dwfl_module.c
> @@ -125,6 +125,21 @@ dwfl_report_begin (Dwfl *dwfl)
>  }
>  INTDEF (dwfl_report_begin)
>
> +static inline Dwfl_Module *
> +use (Dwfl_Module *mod, Dwfl_Module **tailp, Dwfl *dwfl)
> +{
> +  mod->next = *tailp;
> +  *tailp = mod;
> +
> +  if (unlikely (dwfl->lookup_module != NULL))
> +    {
> +      free (dwfl->lookup_module);
> +      dwfl->lookup_module = NULL;
> +    }
> +
> +  return mod;
> +}
> +
>  /* Report that a module called NAME spans addresses [START, END).
>     Returns the module handle, either existing or newly allocated,
>     or returns a null pointer for an allocation error.  */
> @@ -134,20 +149,6 @@ dwfl_report_module (Dwfl *dwfl, const char *name,
>  {
>    Dwfl_Module **tailp = &dwfl->modulelist, **prevp = tailp;
>
> -  inline Dwfl_Module *use (Dwfl_Module *mod)
> -  {
> -    mod->next = *tailp;
> -    *tailp = mod;
> -
> -    if (unlikely (dwfl->lookup_module != NULL))
> -      {
> -       free (dwfl->lookup_module);
> -       dwfl->lookup_module = NULL;
> -      }
> -
> -    return mod;
> -  }
> -
>    for (Dwfl_Module *m = *prevp; m != NULL; m = *(prevp = &m->next))
>      {
>        if (m->low_addr == start && m->high_addr == end
> @@ -157,7 +158,7 @@ dwfl_report_module (Dwfl *dwfl, const char *name,
>              after the last module already reported.  */
>           *prevp = m->next;
>           m->gc = false;
> -         return use (m);
> +         return use (m, tailp, dwfl);
>         }
>
>        if (! m->gc)
> @@ -181,7 +182,7 @@ dwfl_report_module (Dwfl *dwfl, const char *name,
>    mod->high_addr = end;
>    mod->dwfl = dwfl;
>
> -  return use (mod);
> +  return use (mod, tailp, dwfl);
>  }
>  INTDEF (dwfl_report_module)
>
> diff --git a/libdwfl/dwfl_module_getsrc_file.c
> b/libdwfl/dwfl_module_getsrc_file.c
> index 20aa8a5..75ba68e 100644
> --- a/libdwfl/dwfl_module_getsrc_file.c
> +++ b/libdwfl/dwfl_module_getsrc_file.c
> @@ -30,6 +30,24 @@
>  #include "../libdw/libdwP.h"
>
>
> +static inline const char *
> +INTUSE(dwarf_line_file) (const Dwarf_Line *line)
> +{
> +  return line->files->info[line->file].name;
> +}
> +
> +static inline Dwarf_Line *
> +dwfl_line (const Dwfl_Line *line)
> +{
> +  return &dwfl_linecu (line)->die.cu->lines->info[line->idx];
> +}
> +
> +static inline const char *
> +dwfl_line_file (const Dwfl_Line *line)
> +{
> +  return INTUSE(dwarf_line_file) (dwfl_line (line));
> +}
> +
>  int
>  dwfl_module_getsrc_file (Dwfl_Module *mod,
>                          const char *fname, int lineno, int column,
> @@ -58,19 +76,6 @@ dwfl_module_getsrc_file (Dwfl_Module *mod,
>          && cu != NULL
>          && (error = __libdwfl_cu_getsrclines (cu)) == DWFL_E_NOERROR)
>      {
> -      inline const char *INTUSE(dwarf_line_file) (const Dwarf_Line *line)
> -       {
> -         return line->files->info[line->file].name;
> -       }
> -      inline Dwarf_Line *dwfl_line (const Dwfl_Line *line)
> -       {
> -         return &dwfl_linecu (line)->die.cu->lines->info[line->idx];
> -       }
> -      inline const char *dwfl_line_file (const Dwfl_Line *line)
> -       {
> -         return INTUSE(dwarf_line_file) (dwfl_line (line));
> -       }
> -
>        /* Search through all the line number records for a matching
>          file and line/column number.  If any of the numbers is zero,
>          no match is performed.  */
> --
> 2.6.0.rc2.230.g3dd15c0
>
>

[-- Attachment #2: attachment.html --]
[-- Type: text/html, Size: 5931 bytes --]

[-- Attachment #3: 0002-Move-nested-functions-in-dwfl_module.c-and-dwfl_modu.patch --]
[-- Type: application/octet-stream, Size: 4361 bytes --]

From 4a380a1aaf7695a2f5c6ceb118dbeed01f57cb26 Mon Sep 17 00:00:00 2001
From: Chih-Hung Hsieh <chh@google.com>
Date: Wed, 21 Oct 2015 15:44:56 -0700
Subject: [PATCH] Move nested functions in dwfl_module.c and
 dwfl_module_getsrc_file.c.

* Nested functions in these two files are moved to file scope
  to compile with clang. Extra parameters are added to pass
  local variables.

Signed-off-by: Chih-Hung Hsieh <chh@google.com>
---
 libdwfl/ChangeLog                 |  7 +++++++
 libdwfl/dwfl_module.c             | 33 +++++++++++++++++----------------
 libdwfl/dwfl_module_getsrc_file.c | 31 ++++++++++++++++++-------------
 3 files changed, 42 insertions(+), 29 deletions(-)

diff --git a/libdwfl/ChangeLog b/libdwfl/ChangeLog
index 5cae434..0374e5a 100644
--- a/libdwfl/ChangeLog
+++ b/libdwfl/ChangeLog
@@ -1,3 +1,10 @@
+2015-10-21  Chih-Hung Hsieh <chh@google.com>
+
+	* dwfl_module.c (dwfl_report_module): Move nested function 'use' to file
+	scope.
+	* dwfl_module_getsrc_file.c (dwfl_module_getsrc_file): Move nested functions
+	'dwarf_line_file', 'dwfl_line', and 'dwfl_line_file' to file scope.
+
 2015-10-09  Josh Stone  <jistone@redhat.com>
 
 	* core-file.c (elf_begin_rand): Replace loff_t with off_t.
diff --git a/libdwfl/dwfl_module.c b/libdwfl/dwfl_module.c
index 8efcfaa..76d45a8 100644
--- a/libdwfl/dwfl_module.c
+++ b/libdwfl/dwfl_module.c
@@ -125,6 +125,21 @@ dwfl_report_begin (Dwfl *dwfl)
 }
 INTDEF (dwfl_report_begin)
 
+static inline Dwfl_Module *
+use (Dwfl_Module *mod, Dwfl_Module **tailp, Dwfl *dwfl)
+{
+  mod->next = *tailp;
+  *tailp = mod;
+
+  if (unlikely (dwfl->lookup_module != NULL))
+    {
+      free (dwfl->lookup_module);
+      dwfl->lookup_module = NULL;
+    }
+
+  return mod;
+}
+
 /* Report that a module called NAME spans addresses [START, END).
    Returns the module handle, either existing or newly allocated,
    or returns a null pointer for an allocation error.  */
@@ -134,20 +149,6 @@ dwfl_report_module (Dwfl *dwfl, const char *name,
 {
   Dwfl_Module **tailp = &dwfl->modulelist, **prevp = tailp;
 
-  inline Dwfl_Module *use (Dwfl_Module *mod)
-  {
-    mod->next = *tailp;
-    *tailp = mod;
-
-    if (unlikely (dwfl->lookup_module != NULL))
-      {
-	free (dwfl->lookup_module);
-	dwfl->lookup_module = NULL;
-      }
-
-    return mod;
-  }
-
   for (Dwfl_Module *m = *prevp; m != NULL; m = *(prevp = &m->next))
     {
       if (m->low_addr == start && m->high_addr == end
@@ -157,7 +158,7 @@ dwfl_report_module (Dwfl *dwfl, const char *name,
 	     after the last module already reported.  */
 	  *prevp = m->next;
 	  m->gc = false;
-	  return use (m);
+	  return use (m, tailp, dwfl);
 	}
 
       if (! m->gc)
@@ -181,7 +182,7 @@ dwfl_report_module (Dwfl *dwfl, const char *name,
   mod->high_addr = end;
   mod->dwfl = dwfl;
 
-  return use (mod);
+  return use (mod, tailp, dwfl);
 }
 INTDEF (dwfl_report_module)
 
diff --git a/libdwfl/dwfl_module_getsrc_file.c b/libdwfl/dwfl_module_getsrc_file.c
index 20aa8a5..75ba68e 100644
--- a/libdwfl/dwfl_module_getsrc_file.c
+++ b/libdwfl/dwfl_module_getsrc_file.c
@@ -30,6 +30,24 @@
 #include "../libdw/libdwP.h"
 
 
+static inline const char *
+INTUSE(dwarf_line_file) (const Dwarf_Line *line)
+{
+  return line->files->info[line->file].name;
+}
+
+static inline Dwarf_Line *
+dwfl_line (const Dwfl_Line *line)
+{
+  return &dwfl_linecu (line)->die.cu->lines->info[line->idx];
+}
+
+static inline const char *
+dwfl_line_file (const Dwfl_Line *line)
+{
+  return INTUSE(dwarf_line_file) (dwfl_line (line));
+}
+
 int
 dwfl_module_getsrc_file (Dwfl_Module *mod,
 			 const char *fname, int lineno, int column,
@@ -58,19 +76,6 @@ dwfl_module_getsrc_file (Dwfl_Module *mod,
 	 && cu != NULL
 	 && (error = __libdwfl_cu_getsrclines (cu)) == DWFL_E_NOERROR)
     {
-      inline const char *INTUSE(dwarf_line_file) (const Dwarf_Line *line)
-	{
-	  return line->files->info[line->file].name;
-	}
-      inline Dwarf_Line *dwfl_line (const Dwfl_Line *line)
-	{
-	  return &dwfl_linecu (line)->die.cu->lines->info[line->idx];
-	}
-      inline const char *dwfl_line_file (const Dwfl_Line *line)
-	{
-	  return INTUSE(dwarf_line_file) (dwfl_line (line));
-	}
-
       /* Search through all the line number records for a matching
 	 file and line/column number.  If any of the numbers is zero,
 	 no match is performed.  */
-- 
2.6.0.rc2.230.g3dd15c0


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

end of thread, other threads:[~2015-11-04 10:25 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-21 22:50 [PATCH] Move nested functions in dwfl_module.c and dwfl_module_getsrc_file.c Chih-Hung Hsieh
2015-10-21 23:11 Chih-Hung Hsieh
2015-11-03 14:58 Mark Wielaard
2015-11-03 22:58 Mark Wielaard
2015-11-04  0:05 Chih-Hung Hsieh
2015-11-04 10:25 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).