public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
From: Mark Wielaard <mark@klomp.org>
To: tbaeder@redhat.com, elfutils-devel@sourceware.org
Subject: Re: [PATCH 1/3] link_map: Pull release_buffer() into file scope
Date: Sun, 06 Dec 2020 14:20:11 +0100	[thread overview]
Message-ID: <633e97a4293852732af8a9edba9b383a5f9cfeb1.camel@klomp.org> (raw)
In-Reply-To: <20201201083854.1870943-2-tbaeder@redhat.com>

Hi Timm,

On Tue, 2020-12-01 at 09:38 +0100, Timm Bäder via Elfutils-devel wrote:
> From: Timm Bäder <tbaeder@redhat.com>
> 
> Get rid of another nested function

It is missing a ChangeLog entry.

> diff --git a/libdwfl/link_map.c b/libdwfl/link_map.c
> index 29307c74..5c39c631 100644
> --- a/libdwfl/link_map.c
> +++ b/libdwfl/link_map.c
> @@ -225,6 +225,18 @@ addrsize (uint_fast8_t elfclass)
>    return elfclass * 4;
>  }
>  
> +static inline int
> +release_buffer (Dwfl *dwfl,
> +                Dwfl_Memory_Callback *memory_callback, void *memory_callback_arg,
> +                void **buffer, size_t *buffer_available,
> +                int result)
> +{
> +  if (buffer != NULL)
> +    (void) (*memory_callback) (dwfl, -1, buffer, buffer_available, 0, 0,
> +                               memory_callback_arg);
> +  return result;
> +}

Note that this changes the semantics slightly. Because you now take the
address of the buffer variable before checking it is NULL (it now never
is). Also note that the result is not always used, so it might be
cleaner to not pass it around. It is IMHO better to fully inline it.

> @@ -249,13 +261,6 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
>  
>    void *buffer = NULL;
>    size_t buffer_available = 0;
> -  inline int release_buffer (int result)
> -  {
> -    if (buffer != NULL)
> -      (void) (*memory_callback) (dwfl, -1, &buffer, &buffer_available, 0, 0,
> -                                memory_callback_arg);
> -    return result;
> -  }
>  
>    GElf_Addr addrs[4];
>    inline bool read_addrs (GElf_Addr vaddr, size_t n)
> [...]
> @@ -304,7 +310,9 @@ report_r_debug (uint_fast8_t elfclass, uint_fast8_t elfdata,
>    }
>  
>    if (unlikely (read_addrs (read_vaddr, 1)))
> -    return release_buffer (-1);
> +    release_buffer (dwfl, memory_callback, memory_callback_arg,
> +                    &buffer, &buffer_available, -1);
> +

Note that here the result is used, but the change doesn't use it
anymore and so doesn't return early but just tries to carry on after an
error occurred.

Cheers,

Mark

  reply	other threads:[~2020-12-06 13:20 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-01  8:38 link_map: Remove nested functions tbaeder
2020-12-01  8:38 ` [PATCH 1/3] link_map: Pull release_buffer() into file scope tbaeder
2020-12-06 13:20   ` Mark Wielaard [this message]
2020-12-01  8:38 ` [PATCH 2/3] link_map: Pull read_addrs() in " tbaeder
2020-12-01  8:38 ` [PATCH 3/3] link_map: Inline consider_phdr() into only caller tbaeder
2020-12-06 13:39   ` Mark Wielaard
2020-12-06 13:41 ` link_map: Remove nested functions Mark Wielaard

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=633e97a4293852732af8a9edba9b383a5f9cfeb1.camel@klomp.org \
    --to=mark@klomp.org \
    --cc=elfutils-devel@sourceware.org \
    --cc=tbaeder@redhat.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).