public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mjw@redhat.com>
To: elfutils-devel@lists.fedorahosted.org
Subject: Re: [PATCH] Move nested functions in dwfl_module.c and dwfl_module_getsrc_file.c.
Date: Tue, 03 Nov 2015 23:58:06 +0100	[thread overview]
Message-ID: <20151103225806.GE26991@blokker.redhat.com> (raw)
In-Reply-To: 1446562690.12265.66.camel@bordewijk.wildebeest.org

[-- 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


             reply	other threads:[~2015-11-03 22:58 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-03 22:58 Mark Wielaard [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-11-04 10:25 Mark Wielaard
2015-11-04  0:05 Chih-Hung Hsieh
2015-11-03 14:58 Mark Wielaard
2015-10-21 23:11 Chih-Hung Hsieh
2015-10-21 22:50 Chih-Hung Hsieh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20151103225806.GE26991@blokker.redhat.com \
    --to=mjw@redhat.com \
    --cc=elfutils-devel@lists.fedorahosted.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).