Re: lwlocknames.h beautification attempt

From: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: Gurjeet Singh <gurjeet(at)singh(dot)im>
Cc: Postgres Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: lwlocknames.h beautification attempt
Date: 2025-03-03 17:14:45
Message-ID: 202503031714.c3qsffucwcqh@alvherre.pgsql
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2025-Mar-01, Gurjeet Singh wrote:

> 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)

This format seems more than acceptable. It'd be nice to avoid printf
for such a small thing; but at least we can use the %-specifiers only
where necessary, so I'd do this instead:

diff --git a/src/backend/storage/lmgr/generate-lwlocknames.pl b/src/backend/storage/lmgr/generate-lwlocknames.pl
index 084da2ea6e0..2927f144905 100644
--- a/src/backend/storage/lmgr/generate-lwlocknames.pl
+++ b/src/backend/storage/lmgr/generate-lwlocknames.pl
@@ -108,7 +108,8 @@ while (<$lwlocklist>)
$continue = ",\n";

# Add a "Lock" suffix to each lock name, as the C code depends on that
- print $h "#define ${lockname}Lock (&MainLWLockArray[$lockidx].lock)\n";
+ printf $h "#define %-32s (&MainLWLockArray[$lockidx].lock)\n",
+ "${lockname}Lock";
}

die

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Melanie Plageman 2025-03-03 17:18:37 Re: Trigger more frequent autovacuums of heavy insert tables
Previous Message Isaac Morland 2025-03-03 17:11:55 Re: PATCH: warn about, and deprecate, clear text passwords