public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: John Baldwin <jhb@FreeBSD.org>
To: Tom Tromey <tromey@adacore.com>, gdb-patches@sourceware.org
Subject: Re: [PATCH 0/4] Unify getpkt methods in remote.c
Date: Mon, 28 Aug 2023 10:51:53 -0700	[thread overview]
Message-ID: <0451edf2-c709-9e97-5145-1b07653cda9b@FreeBSD.org> (raw)
In-Reply-To: <20230828-getpkt-cleanup-v1-0-0f3da220530c@adacore.com>

On 8/28/23 10:14 AM, Tom Tromey via Gdb-patches wrote:
> This series unifies the various getpkt methods in remote.c, and
> applies a little bit of bool-ification as well.
> 
> ---
> Tom Tromey (4):
>        Remove getpkt_sane
>        Remove expecting_notif parameter from getpkt_or_notif_sane_1
>        Use bool in getpkt
>        Unify getpkt and getpkt_or_notif_sane
> 
>   gdb/remote.c | 242 +++++++++++++++++++++++++----------------------------------
>   1 file changed, 103 insertions(+), 139 deletions(-)
> ---
> base-commit: b8a175b415454df6a039ba0b5d2ff13c3c180275
> change-id: 20230828-getpkt-cleanup-126c625821bf
> 
> Best regards,

These all look fine to me.  My only thought was if you wanted to
make use of a default value for the 'forever' argument, or perhaps
have a 'getpkt_wait' wrapper.  My one worry about bool arguments
to functions (in general) is that true/false often do not convey
obvious meaning in context.  One way to deal with this can be to
use dedicated enums, e.g.:

enum getpkt_forever {
     NON_BLOCKING,
     BLOCKING
}

so that the invocations have more obvious intent.  However, reading
the patch 3 in particular, it seems like the vast majority of getpkt
calls end up passing false, so I wonder if you might not like to
end up with something like this at the end:

    int getpkt_1 (gdb::char_vector *buf, bool forever, bool *is_notif);
    int getpkt (gdb::char_vector *buf, bool *is_notif = nullptr)
    { return getpkt_1 (buf, false, is_notif); }
    int getpkt_wait (gdb::char_vector *buf, bool *is_notif = nullptr)
    { return getpkt_1 (buf, true, is_notif); }

Maybe you could get by with defaulting both arguments to getpkt and
not needing getpkt_1 at all, just having getpkt_wait() as wrapper?
I think that might end up being more readable as in many cases in
the resulting code you'd end up with:

    putpkt ("<mumble>");
    getpkt (&rs->buf);

(You could also call the wrapper `getpkt_forever` if that seems like
a better name.)

-- 
John Baldwin


  parent reply	other threads:[~2023-08-28 17:51 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-28 17:14 Tom Tromey
2023-08-28 17:14 ` [PATCH 1/4] Remove getpkt_sane Tom Tromey
2023-08-28 17:14 ` [PATCH 2/4] Remove expecting_notif parameter from getpkt_or_notif_sane_1 Tom Tromey
2023-08-28 17:14 ` [PATCH 3/4] Use bool in getpkt Tom Tromey
2023-08-28 17:14 ` [PATCH 4/4] Unify getpkt and getpkt_or_notif_sane Tom Tromey
2023-08-28 17:51 ` John Baldwin [this message]
2023-08-28 19:06   ` [PATCH 0/4] Unify getpkt methods in remote.c Tom Tromey

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=0451edf2-c709-9e97-5145-1b07653cda9b@FreeBSD.org \
    --to=jhb@freebsd.org \
    --cc=gdb-patches@sourceware.org \
    --cc=tromey@adacore.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).