public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: Yunlian Jiang <yunlian@google.com>
Cc: elfutils-devel@sourceware.org
Subject: Re: [PATCH] libdwfl: Move nested function in dwfl_segment_report_module.c
Date: Mon, 31 Jul 2017 09:22:00 -0000	[thread overview]
Message-ID: <1501492925.3741.59.camel@klomp.org> (raw)
In-Reply-To: <CAMsPy2s_W-pcx2zrTfmzpz-Osh26e7v76024HVkEB0Nh7KoHqQ@mail.gmail.com>

On Fri, 2017-07-28 at 09:36 -0700, Yunlian Jiang via elfutils-devel
wrote:
> This moves part of nested functions in dwfl_segment_report_module.c to file
> scope.

Note that your email provides two variants of the patch, the first
having whitespace issues making it a bit hard to read and apply.

I am not a fan of replacing nested functions with variants that take
long argument lists, some of which aren't even used or are only used to
then pass through another function in a different order.

> +static inline bool
> +segment_read (int segndx, void **buffer, size_t *buffer_available,
> +      GElf_Addr addr, size_t minread, Dwfl *dwfl,
> +      Dwfl_Memory_Callback *memory_callback,
> +      void *memory_callback_arg)
> +{
> +  return ! (*memory_callback) (dwfl, segndx, buffer, buffer_available,
> +               addr, minread, memory_callback_arg);
> +}

For example in this case it would make more sense to just directly call
the memory_callback.

> +static inline void
> +release_buffer (void **buffer, size_t *buffer_available,
> + Dwfl *dwfl,
> + Dwfl_Memory_Callback *memory_callback,
> + void *memory_callback_arg)
> +{
> +  if (*buffer != NULL)
> +    (void) segment_read (-1, buffer, buffer_available, 0, 0, dwfl,
> +         memory_callback, memory_callback_arg);
> +}

Likewise, just include the if guard in the code directly. Especially
since this function only exists as helper function in two other helper
functions.

> +#define DO_REAL_FINISH finish(phdrsp, buffer, buffer_available, elf, fd, ndx, \
> + dwfl, memory_callback, memory_callback_arg)

I rather see this as a real functions. If the issue is passing all the
arguments (which I agree is somewhat ugly) then just put those that form
the relevant state in struct (Elf, fd, Dwfl, Dwfl_Memory_Callback,
callback_arg, buffer, buffer_available) that you pass by reference to
the new static functions.

Cheers,

Mark

      reply	other threads:[~2017-07-31  9:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-28 16:36 Yunlian Jiang via elfutils-devel
2017-07-31  9:22 ` Mark Wielaard [this message]

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=1501492925.3741.59.camel@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    --cc=yunlian@google.com \
    /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).