Re: lwlocknames.h beautification attempt - Mailing list pgsql-hackers

From Álvaro Herrera
Subject Re: lwlocknames.h beautification attempt
Date
Msg-id 202503031714.c3qsffucwcqh@alvherre.pgsql
Whole thread Raw
In response to lwlocknames.h beautification attempt  (Gurjeet Singh <gurjeet@singh.im>)
List 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/



pgsql-hackers by date:

Previous
From: Isaac Morland
Date:
Subject: Re: PATCH: warn about, and deprecate, clear text passwords
Next
From: Melanie Plageman
Date:
Subject: Re: Trigger more frequent autovacuums of heavy insert tables