lwlocknames.h beautification attempt

From: Gurjeet Singh <gurjeet(at)singh(dot)im>
To: Postgres Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: lwlocknames.h beautification attempt
Date: 2025-03-02 06:09:47
Message-ID: CABwTF4VxfwDtRV-H22_XK4XeDogaV-Vaobu+af5U=8ZAZn9ZZQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Currently the contents of lwlocknames.h look like this:

#define ShmemIndexLock (&MainLWLockArray[1].lock)
#define OidGenLock (&MainLWLockArray[2].lock)
#define XidGenLock (&MainLWLockArray[3].lock)
#define ProcArrayLock (&MainLWLockArray[4].lock)
#define SInvalReadLock (&MainLWLockArray[5].lock)
...

This makes it a bit hard to read, since there is no attempt at vertical
alignment along the opening parentheses. It gets worse if the editor
performs syntax highlighting, and the various colored characters in the
definitions appear haphazardly arranged.

Had this been hand-written, I can imagine the author making an attempt at
aligning the definitions, but since this is a generated file, the lack of
that attempt is understandable.

I propose the following change to the generation script,
generate-lwlocknames.pl

- print $h "#define ${lockname}Lock (&MainLWLockArray[$lockidx].lock)\n";
+ printf $h "#define %-30s %s\n", "${lockname}Lock",
"(&MainLWLockArray[$lockidx].lock)";

which produces the lock names in this format

#define ShmemIndexLock (&MainLWLockArray[1].lock)
#define OidGenLock (&MainLWLockArray[2].lock)
#define XidGenLock (&MainLWLockArray[3].lock)
#define ProcArrayLock (&MainLWLockArray[4].lock)
#define SInvalReadLock (&MainLWLockArray[5].lock)
...

Yet another format, which I prefer, can be achieved by right-aligning the
lock names. In addition to aligning the definitions, it also aligns the
'Lock' suffix in all the names. But as they say beauty is in the eye of the
beholder, so this one may be actively disliked by others.

- print $h "#define ${lockname}Lock (&MainLWLockArray[$lockidx].lock)\n";
+ printf $h "#define %30s %s\n", "${lockname}Lock",
"(&MainLWLockArray[$lockidx].lock)";

#define ShmemIndexLock (&MainLWLockArray[1].lock)
#define OidGenLock (&MainLWLockArray[2].lock)
#define XidGenLock (&MainLWLockArray[3].lock)
#define ProcArrayLock (&MainLWLockArray[4].lock)
#define SInvalReadLock (&MainLWLockArray[5].lock)
...

The lockname column needs to be at least 30 chars wide to accommodate the
longest of the lock names 'DynamicSharedMemoryControlLock'.

Best regards,
Gurjeet
http://Gurje.et

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2025-03-02 06:26:07 Re: lwlocknames.h beautification attempt
Previous Message Junwang Zhao 2025-03-02 05:28:07 Re: Emitting JSON to file using COPY TO