Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
To: Pedro Alves <pedro@palves.net>, gdb-patches@sourceware.org
Cc: Simon Marchi <simon.marchi@efficios.com>
Subject: Re: [PATCH 1/2] gdb: return *this in target_waitstatus setters
Date: Fri, 3 Dec 2021 08:35:13 -0500	[thread overview]
Message-ID: <fc613824-989b-f6a9-2dfd-a1c4eacf5af6@polymtl.ca> (raw)
In-Reply-To: <f6b02773-c3fd-8f62-a2a0-876c2ccc785d@palves.net>

On 2021-12-03 08:10, Pedro Alves wrote:
> On 2021-12-02 01:40, Simon Marchi via Gdb-patches wrote:
>> From: Simon Marchi <simon.marchi@efficios.com>
>>
>> While playing with some code creating target_waitstatus objects, I was
>> mildly annoyed by the fact that we can't just return a new
>> target_waitstatus object.  We have to do:
>>
>>     target_waitstatus ws;
>>     ws.set_exited (123);
>>     return ws;
>>
>> Make the setters return the "this" object as a reference, such that it's
>> possible to do:
>>
>>     return target_waitstatus ().set_exited (123);
>>
>> I initially thought of adding static creation functions, which you would
>> use like:
>>
>>     return target_waitstatus::make_exited (123);
>>
>> However, making the setters return a reference to the object achieves
>> pretty much the same thing, with less new code.
> 
> I think the static methods would be nicer (I'd maybe drop the "make_" to keep
> it short), but I'm fine with this too, it doesn't seem mutually exclusive.

I started with this idea to add static methods and remove the setters,
making target_waitstatus essentially immutable, except through the
assignment operator.  So to change an existing target_waitstatus object,
you would do use static method + assignment operator:

  lp->waitstatus = target_waitstatus::make_stopped (...);

instead of today:

  lp->waitstatus.set_stopped ();

But that would have needed a lot of unnecessary churn again, updating
all existing calls (which I did when introducing the setters).  And
having two ways of setting a target_waitstatus seems redundant, I prefer
if there's just one way.  It makes the code more consistent, easier to
grep for (you can grep for `set_exited`, for example), etc.  So I went
for the solution presented in this patch, but if someone wants to
convert to static methods later, I will be fine with it.

> Series LGTM.

Thanks, pushed.

Simon


      reply	other threads:[~2021-12-03 13:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-02  1:40 Simon Marchi via Gdb-patches
2021-12-02  1:40 ` [PATCH 2/2] gdb: change store_waitstatus to return a target_waitstatus by value Simon Marchi via Gdb-patches
2021-12-02 17:20   ` John Baldwin
2021-12-02 17:21     ` Simon Marchi via Gdb-patches
2021-12-03 13:10 ` [PATCH 1/2] gdb: return *this in target_waitstatus setters Pedro Alves
2021-12-03 13:35   ` Simon Marchi via Gdb-patches [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=fc613824-989b-f6a9-2dfd-a1c4eacf5af6@polymtl.ca \
    --to=gdb-patches@sourceware.org \
    --cc=pedro@palves.net \
    --cc=simon.marchi@efficios.com \
    --cc=simon.marchi@polymtl.ca \
    /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