public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Lancelot SIX <lsix@lancelotsix.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH v2 3/4] gdb: Have setter and getter callbacks for settings
Date: Tue, 10 Aug 2021 23:18:52 +0100	[thread overview]
Message-ID: <20210810221852.bqbb6opnrlaqgob5@Plymouth> (raw)
In-Reply-To: <727ab80a-c72d-960a-6d6e-a731aaa147dd@polymtl.ca>

> > @@ -231,25 +427,50 @@ struct base_setting
> >      gdb_assert (var_type_uses<T> (this->m_var_type));
> >      gdb_assert (!this->empty ());
> 
> I think this needs to call operator bool, like so:
> 
>   gdb_assert (*this);
> 
> Otherwise, the assert fails when using a getter/setter (empty only
> checks for m_var to be non-NULL, which is false when using
> getter/setter).
> 

Thanks for spotting this.  The second assertion should only be on the
branch that does not use the setter callback.

I also realized that the 'set' method should use 'get_p<T> () = v', which
includes this assertion making the one you ran into redundant.


> I don't find this notation super clear, it might be clearer if we could
> call a named method instead of operator bool.  Maybe "empty" could mean
> "does not have a buffer nor getter/setter"?

I think I got confused about what empty means when I rebased the patch
and handled the conflicts from the previous iteration. This is a good
indication that the naming is not as good as it could be.

'empty' refers to the fact that there is an underlying buffer register.
I could just check 'm_var != nullptr' in 'get_p' and 'operator bool()'.
This is a protected method not meant to be used outside of the class
anyway.

The 'bool()' operator is intended to check if a setting is
valid, i.e. 'get' and 'set' can be called without a guarantied error.
We could use something like 'valid ()' instead (or 'good ()' if we want
to mimic iostream).  Not that 'empty' would not work, I think I would
prefer to read

	if (foo.valid ())
		use (foo);

over

	if (!foo.empty ())
		use (foo);

I tend to prefer the affirmative version over the double negation.

I’ll change that for the next iteration.

Lancelot.

> 
> Simon


  reply	other threads:[~2021-08-10 22:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-08 19:22 [PATCH v2 0/4] gdb: Refactor cmd_list_element.var Lancelot SIX
2021-08-08 19:22 ` [PATCH v2 1/4] gdb: Add typesafe getter/setter for cmd_list_element.var Lancelot SIX
2021-08-10  1:29   ` Simon Marchi
2021-08-10 12:22   ` Simon Marchi
2021-08-10 21:58     ` Lancelot SIX
2021-08-11  0:56       ` Simon Marchi
2021-08-08 19:23 ` [PATCH v2 2/4] gdb: make string-like set show commands use std::string variable Lancelot SIX
2021-08-08 19:23 ` [PATCH v2 3/4] gdb: Have setter and getter callbacks for settings Lancelot SIX
2021-08-10  3:01   ` Simon Marchi
2021-08-10 22:18     ` Lancelot SIX [this message]
2021-08-11  1:01       ` Simon Marchi
2021-08-11 20:00         ` Lancelot SIX
2021-08-19 21:03           ` Simon Marchi
2021-08-20  7:04             ` Lancelot SIX
2021-08-08 19:23 ` [PATCH v2 4/4] gdb: Setting setter return a bool to tell if the value changed Lancelot SIX

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=20210810221852.bqbb6opnrlaqgob5@Plymouth \
    --to=lsix@lancelotsix.com \
    --cc=gdb-patches@sourceware.org \
    --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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).