Re: lwlocknames.h beautification attempt

Alvaro Herrera <alvherre@alvh.no-ip.org>

From: Álvaro Herrera <alvherre@alvh.no-ip.org>
To: Gurjeet Singh <gurjeet@singh.im>
Cc: Postgres Hackers <pgsql-hackers@postgresql.org>
Date: 2025-03-03T17:14:45Z
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/



Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Make lwlocknames.h generated file less ugly