Remove MsgType type

Started by Peter Eisentraut22 days ago3 messages
#1Peter Eisentraut
peter@eisentraut.org
1 attachment(s)

Presumably, the C type MsgType was meant to hold the protocol message
type in the pre-version-3 era, but this was never fully developed even
then, and the name is pretty confusing nowadays. It has only one
vestigial use for cancel requests that we can get rid of. Since a
cancel request is indicated by a special protocol version number, we can
use the ProtocolVersion type, which MsgType was based on. (If this is
also found confusing, we could also use uint32 directly.)

Attachments:

0001-Remove-MsgType-type.patchtext/plain; charset=UTF-8; name=0001-Remove-MsgType-type.patchDownload
From b74e5ff37ce648639d662600a392e12a8c9b44f4 Mon Sep 17 00:00:00 2001
From: Peter Eisentraut <peter@eisentraut.org>
Date: Thu, 3 Jul 2025 14:46:17 +0200
Subject: [PATCH] Remove MsgType type

Presumably, this type was meant to hold the protocol message type in
the pre-version-3 era, but this was never even fully developed then,
and the name is pretty confusing nowadays.  It has only one vestigial
use that we can get rid of.  Since a cancel request is indicated by a
special protocol version number, we can use the ProtocolVersion type,
which MsgType was based on.  (If this is also found confusing, we
could also use uint32 directly.)
---
 src/include/libpq/pqcomm.h       | 3 +--
 src/interfaces/libpq/fe-cancel.c | 4 ++--
 src/tools/pgindent/typedefs.list | 1 -
 3 files changed, 3 insertions(+), 5 deletions(-)

diff --git a/src/include/libpq/pqcomm.h b/src/include/libpq/pqcomm.h
index 625f4b43879..235f6ed7d0d 100644
--- a/src/include/libpq/pqcomm.h
+++ b/src/include/libpq/pqcomm.h
@@ -114,7 +114,6 @@ is_unixsock_path(const char *path)
 
 
 typedef uint32 ProtocolVersion; /* FE/BE protocol version number */
-typedef ProtocolVersion MsgType;
 
 
 /*
@@ -146,7 +145,7 @@ typedef uint32 AuthRequest;		/* an AUTH_REQ_* code */
 typedef struct CancelRequestPacket
 {
 	/* Note that each field is stored in network byte order! */
-	MsgType		cancelRequestCode;	/* code to identify a cancel request */
+	ProtocolVersion cancelRequestCode;	/* code to identify a cancel request */
 	uint32		backendPID;		/* PID of client's backend */
 	uint8		cancelAuthCode[FLEXIBLE_ARRAY_MEMBER];	/* secret key to
 														 * authorize cancel */
diff --git a/src/interfaces/libpq/fe-cancel.c b/src/interfaces/libpq/fe-cancel.c
index c872a0267f0..f23caf8349d 100644
--- a/src/interfaces/libpq/fe-cancel.c
+++ b/src/interfaces/libpq/fe-cancel.c
@@ -448,7 +448,7 @@ PQgetCancel(PGconn *conn)
 	}
 
 	req = (CancelRequestPacket *) &cancel->cancel_req;
-	req->cancelRequestCode = (MsgType) pg_hton32(CANCEL_REQUEST_CODE);
+	req->cancelRequestCode = pg_hton32(CANCEL_REQUEST_CODE);
 	req->backendPID = pg_hton32(conn->be_pid);
 	memcpy(req->cancelAuthCode, conn->be_cancel_key, conn->be_cancel_key_len);
 	/* include the length field itself in the length */
@@ -479,7 +479,7 @@ PQsendCancelRequest(PGconn *cancelConn)
 
 	/* Send the message body. */
 	memset(&req, 0, offsetof(CancelRequestPacket, cancelAuthCode));
-	req.cancelRequestCode = (MsgType) pg_hton32(CANCEL_REQUEST_CODE);
+	req.cancelRequestCode = pg_hton32(CANCEL_REQUEST_CODE);
 	req.backendPID = pg_hton32(cancelConn->be_pid);
 	if (pqPutnchar(&req, offsetof(CancelRequestPacket, cancelAuthCode), cancelConn))
 		return STATUS_ERROR;
diff --git a/src/tools/pgindent/typedefs.list b/src/tools/pgindent/typedefs.list
index 9dd65b10254..792042e4961 100644
--- a/src/tools/pgindent/typedefs.list
+++ b/src/tools/pgindent/typedefs.list
@@ -1722,7 +1722,6 @@ ModifyTablePath
 ModifyTableState
 MonotonicFunction
 MorphOpaque
-MsgType
 MultiAssignRef
 MultiSortSupport
 MultiSortSupportData
-- 
2.52.0

#2Chao Li
li.evan.chao@gmail.com
In reply to: Peter Eisentraut (#1)
Re: Remove MsgType type

On Dec 22, 2025, at 16:46, Peter Eisentraut <peter@eisentraut.org> wrote:

Presumably, the C type MsgType was meant to hold the protocol message type in the pre-version-3 era, but this was never fully developed even then, and the name is pretty confusing nowadays. It has only one vestigial use for cancel requests that we can get rid of. Since a cancel request is indicated by a special protocol version number, we can use the ProtocolVersion type, which MsgType was based on. (If this is also found confusing, we could also use uint32 directly.)
<0001-Remove-MsgType-type.patch>

LGTM. I searched over the source tree, MsgType had only a single usage before the patch, so it makes sense to remove it.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

#3Peter Eisentraut
peter@eisentraut.org
In reply to: Chao Li (#2)
Re: Remove MsgType type

On 22.12.25 10:06, Chao Li wrote:

On Dec 22, 2025, at 16:46, Peter Eisentraut <peter@eisentraut.org> wrote:

Presumably, the C type MsgType was meant to hold the protocol message type in the pre-version-3 era, but this was never fully developed even then, and the name is pretty confusing nowadays. It has only one vestigial use for cancel requests that we can get rid of. Since a cancel request is indicated by a special protocol version number, we can use the ProtocolVersion type, which MsgType was based on. (If this is also found confusing, we could also use uint32 directly.)
<0001-Remove-MsgType-type.patch>

LGTM. I searched over the source tree, MsgType had only a single usage before the patch, so it makes sense to remove it.

committed, thanks