Re: lwlocknames.h beautification attempt

Поиск
Список
Период
Сортировка
От Álvaro Herrera
Тема Re: lwlocknames.h beautification attempt
Дата
Msg-id 202503031714.c3qsffucwcqh@alvherre.pgsql
обсуждение исходный текст
Ответ на lwlocknames.h beautification attempt  (Gurjeet Singh <gurjeet@singh.im>)
Список 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 по дате отправления: