This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
Re: [PATCH] Move nested functions in dwfl_module.c and dwfl_module_getsrc_file.c.
- From: Mark Wielaard <mjw at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Tue, 03 Nov 2015 15:58:10 +0100
- Subject: Re: [PATCH] Move nested functions in dwfl_module.c and dwfl_module_getsrc_file.c.
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
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