Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Christian Biesinger via gdb-patches" <gdb-patches@sourceware.org>
To: Tom Tromey <tom@tromey.com>
Cc: Christian Biesinger via gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 3/3] Make relocate_{path,gdb_directory} return std::string
Date: Tue, 10 Sep 2019 19:56:00 -0000	[thread overview]
Message-ID: <CAPTJ0XH8dAKLtPZYKM3Sv83btP-AA3N3mYz-DYZEEoEDr9qg+A@mail.gmail.com> (raw)
In-Reply-To: <87ftl46uke.fsf@tromey.com>

On Tue, Sep 10, 2019 at 10:27 AM Tom Tromey <tom@tromey.com> wrote:
>
> >>>>> "Christian" == Christian Biesinger via gdb-patches <gdb-patches@sourceware.org> writes:
>
> Christian> This simplifies memory management. I've also changed some global variables
> Christian> to std::string accordingly (which store the result of these functions),
> Christian> but not all because some are used with add_setshow_optional_filename_cmd
> Christian> which requires a char*.
>
> Thank you.

Thanks for the review!

> Christian> -  xfree (gdb_datadir);
> Christian> -  gdb_datadir = gdb_realpath (new_datadir).release ();
> Christian> +  gdb_datadir = gdb_realpath (new_datadir).get ();
>
> I wonder if using a unique_xmalloc_ptr would be better.
> I suppose it doesn't matter hugely, but it would eliminate some of these
> double allocations.

Do you mean for the return type of relocate_path and
relocate_gdb_directory? Hm.. I can change it if you want, but I'd
rather not -- not all codepaths go through an xmalloc (when
relocatable=false, or relocate_path returns null in
relocate_gdb_directory). So that would add some xstrdup calls that
would not otherwise be necessary.

> Christian> +      gdb::unique_xmalloc_ptr<char> abs_datadir =
> Christian> +    gdb_abspath (gdb_datadir.c_str ());
>
> "=" on continuation line.

Done.

> Christian> -static char *
> Christian> +static std::string
> Christian>  relocate_path (const char *progname, const char *initial, bool relocatable)
> Christian>  {
> Christian>    if (relocatable)
> Christian> -    return make_relative_prefix (progname, BINDIR, initial);
> Christian> -  return xstrdup (initial);
> Christian> +    {
> Christian> +      char *str = make_relative_prefix (progname, BINDIR, initial);
> Christian> +      if (str != nullptr)
> Christian> +        return str;
>
> This seems to leak "str".

Oh, thanks! Fixed using a unique_xmalloc_ptr.

> Christian> +      char *canon_sysroot = lrealpath (dir.c_str ());
>
> Changing this to a unique_xmalloc_ptr would mean one less call to
> xfree...

Thanks, done.

> Christian> +  debug_file_directory =
>
> "=" on the next line, there is one more of these in this spot.

Done.

I'll send a new version with those comments fixed in a moment.

Christian


  reply	other threads:[~2019-09-10 19:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-09 18:08 [PATCH 0/3] Refactor some path methods in main.c to use std::string Christian Biesinger via gdb-patches
2019-09-09 18:08 ` [PATCH 1/3] Refactor get_init_files " Christian Biesinger via gdb-patches
2019-09-10 15:02   ` Tom Tromey
2019-09-10 19:23     ` [PATCH 1/3 v2] " Christian Biesinger via gdb-patches
2019-09-11 20:16       ` Tom Tromey
2019-09-09 18:08 ` [PATCH 2/3] Factor out the code to do the datadir-relocation for gdbinit Christian Biesinger via gdb-patches
2019-09-10 15:15   ` Tom Tromey
2019-09-10 19:14     ` Christian Biesinger via gdb-patches
2019-09-10 19:14       ` [PATCH 2/3 v2] " Christian Biesinger via gdb-patches
2019-09-11 20:15         ` Tom Tromey
2019-09-09 18:08 ` [PATCH 3/3] Make relocate_{path,gdb_directory} return std::string Christian Biesinger via gdb-patches
2019-09-10 15:27   ` Tom Tromey
2019-09-10 19:56     ` Christian Biesinger via gdb-patches [this message]
2019-09-10 19:58       ` [PATCH v2 " Christian Biesinger via gdb-patches
2019-09-11 20:24         ` Tom Tromey
2019-09-11 20:22       ` [PATCH " Tom Tromey
2019-09-11 21:36 ` [PATCH 0/3] Refactor some path methods in main.c to use std::string Christian Biesinger via gdb-patches

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=CAPTJ0XH8dAKLtPZYKM3Sv83btP-AA3N3mYz-DYZEEoEDr9qg+A@mail.gmail.com \
    --to=gdb-patches@sourceware.org \
    --cc=cbiesinger@google.com \
    --cc=tom@tromey.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