Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Aaron Merey <amerey@redhat.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH] debuginfod-support.c: Replace globals with user_data
Date: Sat, 1 Aug 2020 10:44:56 -0400	[thread overview]
Message-ID: <ceba3ac1-708a-83ad-7d46-75b5a04f1d2d@simark.ca> (raw)
In-Reply-To: <CAJDtP-QeNpAvKwhnqBj0xYBpkPvP_4fvUBeFWWp_kFcFvZPXxQ@mail.gmail.com>

> From 1913317cb95d02c3244e5d91b7b59e33cfe991c5 Mon Sep 17 00:00:00 2001
> From: Aaron Merey <amerey@redhat.com>
> Date: Fri, 31 Jul 2020 18:25:48 -0400
> Subject: [PATCH] debuginfod-support.c: Replace globals with user_data
>
> Store query information in user_data struct instead of global
> variables. Also include DEBUGINFOD_CFLAGS in INTERNAL_CFLAG_BASE.

The DEBUGINFOD_CFLAGS change looks good, but it's unrelated to the topic of this patch,
please make it its own patch, with its own justification.

> diff --git a/gdb/debuginfod-support.c b/gdb/debuginfod-support.c
> index f4a227b040..9325bf8651 100644
> --- a/gdb/debuginfod-support.c
> +++ b/gdb/debuginfod-support.c
> @@ -43,29 +43,39 @@ debuginfod_debuginfo_query (const unsigned char *build_id,
>  #else
>  #include <elfutils/debuginfod.h>
>
> -/* TODO: Use debuginfod API extensions instead of these globals.  */
> -static std::string desc;
> -static std::string fname;
> -static bool has_printed;
> +struct user_data
> +{
> +  std::string desc;
> +  std::string fname;
> +  bool has_printed;
> +
> +  user_data (std::string desc, std::string fname, bool has_printed)
> +    : desc (desc), fname (fname), has_printed (has_printed)
> +  { }

Put the constructor before the fields.  Make the fields const if they are not intended
to be changed once the object has been created.

Using `std::string` causes unnecessary copying to happen.  Just use `const char *`
(`const char * const` for the fields) or gdb::string_view, if you want to be more
generic (but all callers are `const char *`, so it's not really necessary).  That's
assuming that the lifetime of those strings will always be longer than the lifetime
of the debuginfo client.  I think that's the case, since the debug info client is
always created and destroyed in the same function.

> +};
>
>  static int
>  progressfn (debuginfod_client *c, long cur, long total)
>  {
> +  struct user_data *data = static_cast<user_data*> (debuginfod_get_user_data (c));

This line is too long, just skip the `struct` keyword and you'll be fine.  Also, space
before `*`.

> +
>    if (check_quit_flag ())
>      {
>        printf_filtered ("Cancelling download of %s %ps...\n",
> -		       desc.c_str (),
> -		       styled_string (file_name_style.style (), fname.c_str ()));
> +		       data->desc.c_str (),
> +		       styled_string (file_name_style.style (),
> +				      data->fname.c_str ()));
>        return 1;
>      }
>
> -  if (!has_printed && total != 0)
> +  if (! data->has_printed && total != 0)

Remove space after `!`.

Simon


  reply	other threads:[~2020-08-01 14:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-31 22:44 Aaron Merey
2020-08-01 14:44 ` Simon Marchi [this message]
2020-08-12 21:39   ` Aaron Merey
2020-08-12 21:45     ` Simon Marchi
2020-08-13 21:54       ` Aaron Merey

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=ceba3ac1-708a-83ad-7d46-75b5a04f1d2d@simark.ca \
    --to=simark@simark.ca \
    --cc=amerey@redhat.com \
    --cc=gdb-patches@sourceware.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