Re: Use XLogRecPtrIsValid() instead of negated XLogRecPtrIsInvalid - Mailing list pgsql-hackers

From Fujii Masao
Subject Re: Use XLogRecPtrIsValid() instead of negated XLogRecPtrIsInvalid
Date
Msg-id CAHGQGwEuEd2StEYuP9vj+jCFT=hQbX8xcQeq8=Kj8r9xT3vmyg@mail.gmail.com
Whole thread
In response to Use XLogRecPtrIsValid() instead of negated XLogRecPtrIsInvalid  (vignesh C <vignesh21@gmail.com>)
Responses Re: Use XLogRecPtrIsValid() instead of negated XLogRecPtrIsInvalid
List pgsql-hackers
On Fri, Apr 10, 2026 at 3:11 PM vignesh C <vignesh21@gmail.com> wrote:
>
> Hi,
>
> This small cleanup patch updates src/bin/pg_waldump/archive_waldump.c
> to use the recently introduced XLogRecPtrIsValid() helper instead of
> negating XLogRecPtrIsInvalid(). The current code uses double-negative
> checks such as:
> Assert(!XLogRecPtrIsInvalid(privateInfo->startptr));
> if (!XLogRecPtrIsInvalid(privateInfo->endptr))
>
> This patch changes them to:
> Assert(XLogRecPtrIsValid(privateInfo->startptr));
> if (XLogRecPtrIsValid(privateInfo->endptr))
>
> This improves readability without changing behavior. The attached
> patch has the changes for the same.

Commit a2b02293bc6 switched various places to use XLogRecPtrIsValid(),
but it looks like later commits accidentally introduced uses of
XLogRecPtrIsInvalid() again. So +1 for this change.

Also, that commit replaced direct comparisons with InvalidXLogRecPtr with
XLogRecPtrIsValid(). I noticed two such comparisons [1]. Should these be
updated as well?

Regards,

[1]
$ git grep -E "[=\!]= InvalidXLogRecPtr"
src/backend/commands/repack_worker.c:   Assert(ctx->reader->EndRecPtr
!= InvalidXLogRecPtr);
src/backend/replication/walreceiver.c:  applyPtr = (latestApplyPtr ==
InvalidXLogRecPtr) ?

--
Fujii Masao



pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Documenting coding style
Next
From: Nathan Bossart
Date:
Subject: Re: Documenting coding style