agora inbox for pgsql-hackers@postgresql.org  
help / color / mirror / Atom feed
trivial designated initializers
5+ messages / 4 participants
[nested] [flat]

* trivial designated initializers
@ 2026-01-28 12:20  Álvaro Herrera <alvherre@kurilemu.de>
  0 siblings, 2 replies; 5+ messages in thread

From: Álvaro Herrera @ 2026-01-28 12:20 UTC (permalink / raw)
  To: Pg Hackers <pgsql-hackers@lists.postgresql.org>

Hi

We use C99 designated struct initializers in many places, but for some
reason we don't do it in the tupleLockExtraInfo array in heapam.c nor in
InternalBGWorkers array in bgworker.c.  I've had this trivial patch
rotting in a worktree for a long time.  Any opposition to this change?

Thanks,

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"Postgres is bloatware by design: it was built to house
 PhD theses." (Joey Hellerstein, SIGMOD annual conference 2002)

Attachments:

  [text/x-diff] 0001-use-C99-named-designators.patch (2.8K, ../../202601281204.sdxbr5qvpunk@alvherre.pgsql/2-0001-use-C99-named-designators.patch)
  download | inline diff:
From 9b5827db4b9a2dba0de0f6272d93f54f3f5eff21 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Wed, 23 Aug 2023 12:19:30 +0200
Subject: [PATCH] use C99 named designators

---
 src/backend/access/heap/heapam.c  | 29 +++++++++++++++--------------
 src/backend/postmaster/bgworker.c | 18 ++++++++++++------
 2 files changed, 27 insertions(+), 20 deletions(-)

diff --git a/src/backend/access/heap/heapam.c b/src/backend/access/heap/heapam.c
index f30a56ecf55..75a77052cd4 100644
--- a/src/backend/access/heap/heapam.c
+++ b/src/backend/access/heap/heapam.c
@@ -127,29 +127,30 @@ static const struct
 	LOCKMODE	hwlock;
 	int			lockstatus;
 	int			updstatus;
-}
+}			tupleLockExtraInfo[] =
 
-			tupleLockExtraInfo[MaxLockTupleMode + 1] =
 {
 	{							/* LockTupleKeyShare */
-		AccessShareLock,
-		MultiXactStatusForKeyShare,
-		-1						/* KeyShare does not allow updating tuples */
+		.hwlock = AccessShareLock,
+		.lockstatus = MultiXactStatusForKeyShare,
+		/* KeyShare does not allow updating tuples */
+		.updstatus = -1
 	},
 	{							/* LockTupleShare */
-		RowShareLock,
-		MultiXactStatusForShare,
-		-1						/* Share does not allow updating tuples */
+		.hwlock = RowShareLock,
+		.lockstatus = MultiXactStatusForShare,
+		/* Share does not allow updating tuples */
+		.updstatus = -1
 	},
 	{							/* LockTupleNoKeyExclusive */
-		ExclusiveLock,
-		MultiXactStatusForNoKeyUpdate,
-		MultiXactStatusNoKeyUpdate
+		.hwlock = ExclusiveLock,
+		.lockstatus = MultiXactStatusForNoKeyUpdate,
+		.updstatus = MultiXactStatusNoKeyUpdate
 	},
 	{							/* LockTupleExclusive */
-		AccessExclusiveLock,
-		MultiXactStatusForUpdate,
-		MultiXactStatusUpdate
+		.hwlock = AccessExclusiveLock,
+		.lockstatus = MultiXactStatusForUpdate,
+		.updstatus = MultiXactStatusUpdate
 	}
 };
 
diff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.c
index 65deabe91a7..51874481751 100644
--- a/src/backend/postmaster/bgworker.c
+++ b/src/backend/postmaster/bgworker.c
@@ -120,22 +120,28 @@ static const struct
 
 {
 	{
-		"ParallelWorkerMain", ParallelWorkerMain
+		.fn_name = "ParallelWorkerMain",
+		.fn_addr = ParallelWorkerMain
 	},
 	{
-		"ApplyLauncherMain", ApplyLauncherMain
+		.fn_name = "ApplyLauncherMain",
+		.fn_addr = ApplyLauncherMain
 	},
 	{
-		"ApplyWorkerMain", ApplyWorkerMain
+		.fn_name = "ApplyWorkerMain",
+		.fn_addr = ApplyWorkerMain
 	},
 	{
-		"ParallelApplyWorkerMain", ParallelApplyWorkerMain
+		.fn_name = "ParallelApplyWorkerMain",
+		.fn_addr = ParallelApplyWorkerMain
 	},
 	{
-		"TableSyncWorkerMain", TableSyncWorkerMain
+		.fn_name = "TableSyncWorkerMain",
+		.fn_addr = TableSyncWorkerMain
 	},
 	{
-		"SequenceSyncWorkerMain", SequenceSyncWorkerMain
+		.fn_name = "SequenceSyncWorkerMain",
+		.fn_addr = SequenceSyncWorkerMain
 	}
 };
 
-- 
2.47.3

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: trivial designated initializers
@ 2026-01-28 15:27  Melanie Plageman <melanieplageman@gmail.com>
  parent: Álvaro Herrera <alvherre@kurilemu.de>
  1 sibling, 1 reply; 5+ messages in thread

From: Melanie Plageman @ 2026-01-28 15:27 UTC (permalink / raw)
  To: Álvaro Herrera <alvherre@kurilemu.de>; +Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>

On Wed, Jan 28, 2026 at 7:21 AM Álvaro Herrera <alvherre@kurilemu.de> wrote:
>
> We use C99 designated struct initializers in many places, but for some
> reason we don't do it in the tupleLockExtraInfo array in heapam.c nor in
> InternalBGWorkers array in bgworker.c.  I've had this trivial patch
> rotting in a worktree for a long time.  Any opposition to this change?

I find these much easier to understand with the designated
initializers (and I am a big fan of designated initializers in
general). So +1

- Melanie





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: trivial designated initializers
@ 2026-01-28 22:48  Jelte Fennema-Nio <postgres@jeltef.nl>
  parent: Melanie Plageman <melanieplageman@gmail.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Jelte Fennema-Nio @ 2026-01-28 22:48 UTC (permalink / raw)
  To: Melanie Plageman <melanieplageman@gmail.com>; +Cc: Álvaro Herrera <alvherre@kurilemu.de>; Pg Hackers <pgsql-hackers@lists.postgresql.org>

On Wed, 28 Jan 2026 at 16:28, Melanie Plageman
<melanieplageman@gmail.com> wrote:
> I find these much easier to understand with the designated
> initializers (and I am a big fan of designated initializers in
> general). So +1

yes, +1





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: trivial designated initializers
@ 2026-01-29 00:04  Peter Eisentraut <peter@eisentraut.org>
  parent: Álvaro Herrera <alvherre@kurilemu.de>
  1 sibling, 1 reply; 5+ messages in thread

From: Peter Eisentraut @ 2026-01-29 00:04 UTC (permalink / raw)
  To: Álvaro Herrera <alvherre@kurilemu.de>; Pg Hackers <pgsql-hackers@lists.postgresql.org>

On 28.01.26 13:20, Álvaro Herrera wrote:
>   	{							/* LockTupleKeyShare */
> -		AccessShareLock,
> -		MultiXactStatusForKeyShare,
> -		-1						/* KeyShare does not allow updating tuples */
> +		.hwlock = AccessShareLock,
> +		.lockstatus = MultiXactStatusForKeyShare,
> +		/* KeyShare does not allow updating tuples */
> +		.updstatus = -1
>   	},

You could spruce this up further like

[LockTupleKeyShare] = {
     .hwlock = AccessShareLock,
     ...
},
...

The comments "/* KeyShare does not allow updating tuples */" etc. seem 
repetitive and don't actually explain why -1 is an appropriate value. 
You could instead write a comment by the declaration of the updstatus 
field, like "set to -1 if the tuple lock mode does not allow updating 
tuples (see get_mxact_status_for_lock())".






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: trivial designated initializers
@ 2026-01-30 09:28  Álvaro Herrera <alvherre@kurilemu.de>
  parent: Peter Eisentraut <peter@eisentraut.org>
  0 siblings, 0 replies; 5+ messages in thread

From: Álvaro Herrera @ 2026-01-30 09:28 UTC (permalink / raw)
  To: Peter Eisentraut <peter@eisentraut.org>; +Cc: Pg Hackers <pgsql-hackers@lists.postgresql.org>

On 2026-Jan-29, Peter Eisentraut wrote:

> You could spruce this up further like
> 
> [LockTupleKeyShare] = {
>     .hwlock = AccessShareLock,
>     ...
> },

Oh right, done that way.

> The comments "/* KeyShare does not allow updating tuples */" etc. seem
> repetitive and don't actually explain why -1 is an appropriate value. You
> could instead write a comment by the declaration of the updstatus field,
> like "set to -1 if the tuple lock mode does not allow updating tuples (see
> get_mxact_status_for_lock())".

Good point. I rewrote the comment on top of the declaration and pushed,
thanks for the reviews.

-- 
Álvaro Herrera               48°01'N 7°57'E  —  https://www.EnterpriseDB.com/
"Hay dos momentos en la vida de un hombre en los que no debería
especular: cuando puede permitírselo y cuando no puede" (Mark Twain)





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2026-01-30 09:28 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-01-28 12:20 trivial designated initializers Álvaro Herrera <alvherre@kurilemu.de>
2026-01-28 15:27 ` Melanie Plageman <melanieplageman@gmail.com>
2026-01-28 22:48   ` Jelte Fennema-Nio <postgres@jeltef.nl>
2026-01-29 00:04 ` Peter Eisentraut <peter@eisentraut.org>
2026-01-30 09:28   ` Álvaro Herrera <alvherre@kurilemu.de>

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox