Thread: defGetBoolean - Fix comment

defGetBoolean - Fix comment

From
Peter Smith
Date:
Hi.

IMO the comment ("If no parameter given, ...") is a bit misleading:

====

(gdb) list
108 defGetBoolean(DefElem *def)
109 {
110 /*
111 * If no parameter given, assume "true" is meant.
112 */
113 if (def->arg == NULL)
114 return true;
115
116 /*
117 * Allow 0, 1, "true", "false", "on", "off"
(gdb) p *def
$9 = {type = T_DefElem, defnamespace = 0x0, defname = 0x1c177a8
"copy_data", arg = 0x0,
  defaction = DEFELEM_UNSPEC, location = 93}
(gdb)


====

Really this code is for the case when there *was* a parameter given
(e.g. "copy_data" in my example above) but when there is no parameter
*value* given.

Suggested comment fix:
BEFORE
If no parameter given, assume "true" is meant.
AFTER
If no parameter value given, assume "true" is meant.

~~

Although it seems a trivial point, the motivation is that the above
code has been adapted (cut/paste) by multiple other WIP patches [1][2]
that I'm aware of, and so this original (misleading) comment is now
spreading to other places.

PSA patch to tweak both the original comment and another place it
already spread to.

------
[1] https://www.postgresql.org/message-id/flat/CALDaNm0gwjY_4HFxvvty01BOT01q_fJLKQ3pWP9%3D9orqubhjcQ%40mail.gmail.com
+static char
+defGetStreamingMode(DefElem *def)

[2]
https://www.postgresql.org/message-id/flat/CAHut%2BPs%2B4iLzJGkPFEatv%3D%2Baa6NUB38-WT050RFKeJqhdcLaGA%40mail.gmail.com#6d43277cbb074071b8e9602ff8be7e41
+static CopyData
+DefGetCopyData(DefElem *def)

Kind Regards,
Peter Smith.
Fujitsu Australia

Attachment

Re: defGetBoolean - Fix comment

From
Michael Paquier
Date:
On Thu, Jul 07, 2022 at 09:53:01AM +1000, Peter Smith wrote:
> Really this code is for the case when there *was* a parameter given
> (e.g. "copy_data" in my example above) but when there is no parameter
> *value* given.
>
> Suggested comment fix:
> BEFORE
> If no parameter given, assume "true" is meant.
> AFTER
> If no parameter value given, assume "true" is meant.

Still, I think that your adjustment is right, as the check is, indeed,
on the DefElem's value*.  Or you could just say "If no value given".
--
Michael

Attachment

Re: defGetBoolean - Fix comment

From
Michael Paquier
Date:
On Thu, Jul 07, 2022 at 09:54:24AM +0900, Michael Paquier wrote:
> Still, I think that your adjustment is right, as the check is, indeed,
> on the DefElem's value*.  Or you could just say "If no value given".

Peter, I have applied something using your original wording.  This is
a minor issue, but I did not see my suggestion as being better than
yours.
--
Michael

Attachment

Re: defGetBoolean - Fix comment

From
Peter Smith
Date:
On Mon, Jul 11, 2022 at 12:09 PM Michael Paquier <michael@paquier.xyz> wrote:
>
> On Thu, Jul 07, 2022 at 09:54:24AM +0900, Michael Paquier wrote:
> > Still, I think that your adjustment is right, as the check is, indeed,
> > on the DefElem's value*.  Or you could just say "If no value given".
>
> Peter, I have applied something using your original wording.  This is
> a minor issue, but I did not see my suggestion as being better than
> yours.

Thanks for pushing it.

------
Kind Regards,
Peter Smith.
Fujitsu Australia