use PqMsg macros in fe-protocol3.c

Started by Nathan Bossart5 months ago7 messages
#1Nathan Bossart
nathandbossart@gmail.com
1 attachment(s)

I noticed a couple more opportunities to use the PqMsg_* macros.

--
nathan

Attachments:

v1-0001-Use-PqMsg_-macros-in-fe-protocol3.c.patchtext/plain; charset=us-asciiDownload
From 7cdd91579734de76fcd52cabdb49671ee309ddf6 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nathan@postgresql.org>
Date: Mon, 25 Aug 2025 09:53:48 -0500
Subject: [PATCH v1 1/1] Use PqMsg_* macros in fe-protocol3.c.

---
 src/include/libpq/protocol.h        |  1 +
 src/interfaces/libpq/fe-protocol3.c | 12 ++++++------
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/include/libpq/protocol.h b/src/include/libpq/protocol.h
index c64e628628d..7bf90053bcb 100644
--- a/src/include/libpq/protocol.h
+++ b/src/include/libpq/protocol.h
@@ -66,6 +66,7 @@
 
 
 /* These are the codes sent by parallel workers to leader processes. */
+
 #define PqMsg_Progress              'P'
 
 
diff --git a/src/interfaces/libpq/fe-protocol3.c b/src/interfaces/libpq/fe-protocol3.c
index 43ad672abce..da7a8db68c8 100644
--- a/src/interfaces/libpq/fe-protocol3.c
+++ b/src/interfaces/libpq/fe-protocol3.c
@@ -2262,7 +2262,7 @@ pqFunctionCall3(PGconn *conn, Oid fnid,
 		 */
 		switch (id)
 		{
-			case 'V':			/* function result */
+			case PqMsg_FunctionCallResponse:
 				if (pqGetInt(actual_result_len, 4, conn))
 					continue;
 				if (*actual_result_len != -1)
@@ -2283,22 +2283,22 @@ pqFunctionCall3(PGconn *conn, Oid fnid,
 				/* correctly finished function result message */
 				status = PGRES_COMMAND_OK;
 				break;
-			case 'E':			/* error return */
+			case PqMsg_ErrorResponse:
 				if (pqGetErrorNotice3(conn, true))
 					continue;
 				status = PGRES_FATAL_ERROR;
 				break;
-			case 'A':			/* notify message */
+			case PqMsg_NotificationResponse:
 				/* handle notify and go back to processing return values */
 				if (getNotify(conn))
 					continue;
 				break;
-			case 'N':			/* notice */
+			case PqMsg_NoticeResponse:
 				/* handle notice and go back to processing return values */
 				if (pqGetErrorNotice3(conn, false))
 					continue;
 				break;
-			case 'Z':			/* backend is ready for new query */
+			case PqMsg_ReadyForQuery:
 				if (getReadyForQuery(conn))
 					continue;
 
@@ -2330,7 +2330,7 @@ pqFunctionCall3(PGconn *conn, Oid fnid,
 				}
 				/* and we're out */
 				return pqPrepareAsyncResult(conn);
-			case 'S':			/* parameter status */
+			case PqMsg_ParameterStatus:
 				if (getParameterStatus(conn))
 					continue;
 				break;
-- 
2.39.5 (Apple Git-154)

#2Jacob Champion
jacob.champion@enterprisedb.com
In reply to: Nathan Bossart (#1)
Re: use PqMsg macros in fe-protocol3.c

On Mon, Aug 25, 2025 at 7:57 AM Nathan Bossart <nathandbossart@gmail.com> wrote:

I noticed a couple more opportunities to use the PqMsg_* macros.

LGTM!

--Jacob

#3Fabrízio de Royes Mello
fabriziomello@gmail.com
In reply to: Nathan Bossart (#1)
Re: use PqMsg macros in fe-protocol3.c

On Mon, Aug 25, 2025 at 11:57 AM Nathan Bossart <nathandbossart@gmail.com>
wrote:

I noticed a couple more opportunities to use the PqMsg_* macros.

Nice. LGTM!

--
Fabrízio de Royes Mello

#4Nathan Bossart
nathandbossart@gmail.com
In reply to: Fabrízio de Royes Mello (#3)
Re: use PqMsg macros in fe-protocol3.c

On Mon, Aug 25, 2025 at 12:13:27PM -0300, Fabrízio de Royes Mello wrote:

On Mon, Aug 25, 2025 at 11:57 AM Nathan Bossart <nathandbossart@gmail.com> wrote:

I noticed a couple more opportunities to use the PqMsg_* macros.

Nice. LGTM!

Thanks, committed.

--
nathan

#5Ranier Vilela
ranier.vf@gmail.com
In reply to: Nathan Bossart (#4)
1 attachment(s)
Re: use PqMsg macros in fe-protocol3.c

Em seg., 25 de ago. de 2025 às 13:10, Nathan Bossart <
nathandbossart@gmail.com> escreveu:

On Mon, Aug 25, 2025 at 12:13:27PM -0300, Fabrízio de Royes Mello wrote:

On Mon, Aug 25, 2025 at 11:57 AM Nathan Bossart <

nathandbossart@gmail.com> wrote:

I noticed a couple more opportunities to use the PqMsg_* macros.

Nice. LGTM!

Thanks, committed.

If you don't mind I think that have one more source.

patch attached.

best regards,
Ranier Vilela

Attachments:

0001-Use-PqMsg-macros-in-applyparallelworker.patchapplication/octet-stream; name=0001-Use-PqMsg-macros-in-applyparallelworker.patchDownload
diff --git a/src/backend/replication/logical/applyparallelworker.c b/src/backend/replication/logical/applyparallelworker.c
index cd0e19176f..8e849af958 100644
--- a/src/backend/replication/logical/applyparallelworker.c
+++ b/src/backend/replication/logical/applyparallelworker.c
@@ -1007,7 +1007,7 @@ ProcessParallelApplyMessage(StringInfo msg)
 
 	switch (msgtype)
 	{
-		case 'E':				/* ErrorResponse */
+		case PqMsg_ErrorResponse:				/* ErrorResponse */
 			{
 				ErrorData	edata;
 
@@ -1047,8 +1047,8 @@ ProcessParallelApplyMessage(StringInfo msg)
 			 * NotifyResponse as the logical replication worker doesn't need
 			 * to send messages to the client.
 			 */
-		case 'N':
-		case 'A':
+		case PqMsg_NoticeResponse:
+		case PqMsg_NotificationResponse:
 			break;
 
 		default:
#6Nathan Bossart
nathandbossart@gmail.com
In reply to: Ranier Vilela (#5)
Re: use PqMsg macros in fe-protocol3.c

On Mon, Aug 25, 2025 at 02:03:11PM -0300, Ranier Vilela wrote:

If you don't mind I think that have one more source.

Good catch. Committed.

--
nathan

#7Ranier Vilela
ranier.vf@gmail.com
In reply to: Nathan Bossart (#6)
Re: use PqMsg macros in fe-protocol3.c

Em seg., 25 de ago. de 2025 às 16:11, Nathan Bossart <
nathandbossart@gmail.com> escreveu:

On Mon, Aug 25, 2025 at 02:03:11PM -0300, Ranier Vilela wrote:

If you don't mind I think that have one more source.

Good catch. Committed.

Thanks.

best regards,
Ranier Vilela