| From: | Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com> | 
|---|---|
| To: | Álvaro Herrera <alvherre(at)kurilemu(dot)de> | 
| Cc: | Michael Paquier <michael(at)paquier(dot)xyz>, Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, Quan Zongliang <quanzongliang(at)yeah(dot)net>, pgsql-hackers(at)lists(dot)postgresql(dot)org | 
| Subject: | Re: Consistently use the XLogRecPtrIsInvalid() macro | 
| Date: | 2025-10-30 09:17:59 | 
| Message-ID: | aQMtR/m4kW4Rkul+@ip-10-97-1-34.eu-west-3.compute.internal | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-hackers | 
Hi,
On Tue, Oct 28, 2025 at 05:57:54PM +0000, Bertrand Drouvot wrote:
> Hi,
> 
> On Tue, Oct 28, 2025 at 04:05:34PM +0200, Álvaro Herrera wrote:
> > 
> > BTW we could use Coccinelle to replace all the XLogRecPtrIsInvalid()
> > calls with !XLogRecPtrIsValid(), as well as all places comparing an LSN
> > to InvalidXLogRecPtr or literal zero.
> 
> I did v1 the old way (shell script) and did not think about using
> Coccinelle for this. That's a good idea and well suited for this purpose: I'll
> work on it. Thanks for the suggestion!
PFA a series of patches to implement what has been discussed above i.e:
- Introduce XLogRecPtrIsValid() and replace XLogRecPtrIsInvalid() calls: this
is done in 0001. The replacement changes have been generated by the Coccinelle
script [1].
- 0002 deprecates XLogRecPtrIsInvalid(): it emits a warning message at compilation
time if XLogRecPtrIsInvalid() is in use in the code base.
- 0003 replaces InvalidXLogRecPtr comparisons with XLogRecPtrIsValid(). The
replacement changes have been generated by the Coccinelle script [2].
- 0004 replaces literal 0 comparisons on XLogRecPtr with XLogRecPtrIsValid(). The
replacement changes have been generated by the Coccinelle script [3].
[1]: https://github.com/bdrouvot/coccinelle_on_pg/blob/main/replace_XLogRecPtrIsInvalid.cocci 
[2]: https://github.com/bdrouvot/coccinelle_on_pg/blob/main/replace_InvalidXLogRecPtr_comparisons.cocci
[3]: https://github.com/bdrouvot/coccinelle_on_pg/blob/main/replace_literal_0_comparisons.cocci
Regards,
-- 
Bertrand Drouvot
PostgreSQL Contributors Team
RDS Open Source Databases
Amazon Web Services: https://aws.amazon.com
| Attachment | Content-Type | Size | 
|---|---|---|
| v2-0001-Introduce-XLogRecPtrIsValid-and-replace-XLogRecPt.patch | text/x-diff | 48.7 KB | 
| v2-0002-Deprecate-XLogRecPtrIsInvalid.patch | text/x-diff | 1.4 KB | 
| v2-0003-Replace-InvalidXLogRecPtr-comparisons-with-XLogRe.patch | text/x-diff | 38.6 KB | 
| v2-0004-Replace-literal-0-comparisons-on-XLogRecPtr-with-.patch | text/x-diff | 1.9 KB | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bertrand Drouvot | 2025-10-30 09:20:02 | Re: Consistently use the XLogRecPtrIsInvalid() macro | 
| Previous Message | Bryan Green | 2025-10-30 09:17:34 | Re: [PATCH] Add Windows support for backtrace_functions (MSVC only) |