From fc2c4ca33bdeb78f4fd6d1d7710d0ccd671e69b8 Mon Sep 17 00:00:00 2001 From: Aleksander Alekseev Date: Tue, 16 Jul 2024 16:52:56 +0300 Subject: [PATCH v2 3/3] Rearrange the order of functions in pqformat.{c,h} Place functions that send protocol messages of given PqMsg type closer to each other. This makes no difference for the compiler but makes the code easier to read for humans. Aleksander Alekseev, reviewed by TODO FIXME Discussion: TODO FIXME --- src/backend/libpq/pqformat.c | 76 +++++++++++++++++------------------- src/include/libpq/pqformat.h | 6 +-- 2 files changed, 38 insertions(+), 44 deletions(-) diff --git a/src/backend/libpq/pqformat.c b/src/backend/libpq/pqformat.c index e908144f44..9432749587 100644 --- a/src/backend/libpq/pqformat.c +++ b/src/backend/libpq/pqformat.c @@ -31,6 +31,8 @@ /* * INTERFACE ROUTINES * Message assembly and output: + * pq_puttextmessage - generate a character set-converted message in one step + * pq_putemptymessage - convenience routine for message with empty body * pq_beginmessage - initialize StringInfo buffer * pq_sendbyte - append a raw byte to a StringInfo buffer * pq_sendint - append a binary integer to a StringInfo buffer @@ -51,10 +53,6 @@ * pq_begintypsend - initialize StringInfo buffer * pq_endtypsend - return the completed string as a "bytea*" * - * Special-case message output: - * pq_puttextmessage - generate a character set-converted message in one step - * pq_putemptymessage - convenience routine for message with empty body - * * Message parsing after input: * pq_getmsgbyte - get a raw byte from a message buffer * pq_getmsgint - get a binary integer from a message buffer @@ -79,6 +77,40 @@ #include "port/pg_bswap.h" #include "varatt.h" +/* -------------------------------- + * pq_puttextmessage - generate a character set-converted message in one step + * + * This is the same as the pqcomm.c routine pq_putmessage, except that + * the message body is a null-terminated string to which encoding + * conversion applies. + * -------------------------------- + */ +void +pq_puttextmessage(PqMsg msgtype, const char *str) +{ + int slen = strlen(str); + char *p; + + p = pg_server_to_client(str, slen); + if (p != str) /* actual conversion has been done? */ + { + (void) pq_putmessage(msgtype, p, strlen(p) + 1); + pfree(p); + return; + } + (void) pq_putmessage(msgtype, str, slen + 1); +} + + +/* -------------------------------- + * pq_putemptymessage - convenience routine for message with empty body + * -------------------------------- + */ +void +pq_putemptymessage(PqMsg msgtype) +{ + (void) pq_putmessage(msgtype, NULL, 0); +} /* -------------------------------- * pq_beginmessage - initialize for sending a message @@ -355,42 +387,6 @@ pq_endtypsend(StringInfo buf) } -/* -------------------------------- - * pq_puttextmessage - generate a character set-converted message in one step - * - * This is the same as the pqcomm.c routine pq_putmessage, except that - * the message body is a null-terminated string to which encoding - * conversion applies. - * -------------------------------- - */ -void -pq_puttextmessage(PqMsg msgtype, const char *str) -{ - int slen = strlen(str); - char *p; - - p = pg_server_to_client(str, slen); - if (p != str) /* actual conversion has been done? */ - { - (void) pq_putmessage(msgtype, p, strlen(p) + 1); - pfree(p); - return; - } - (void) pq_putmessage(msgtype, str, slen + 1); -} - - -/* -------------------------------- - * pq_putemptymessage - convenience routine for message with empty body - * -------------------------------- - */ -void -pq_putemptymessage(PqMsg msgtype) -{ - (void) pq_putmessage(msgtype, NULL, 0); -} - - /* -------------------------------- * pq_getmsgbyte - get a raw byte from a message buffer * -------------------------------- diff --git a/src/include/libpq/pqformat.h b/src/include/libpq/pqformat.h index f9e785e6a5..00ef87acb2 100644 --- a/src/include/libpq/pqformat.h +++ b/src/include/libpq/pqformat.h @@ -18,6 +18,8 @@ #include "mb/pg_wchar.h" #include "port/pg_bswap.h" +extern void pq_puttextmessage(PqMsg msgtype, const char *str); +extern void pq_putemptymessage(PqMsg msgtype); extern void pq_beginmessage(StringInfo buf, PqMsg msgtype); extern void pq_beginmessage_reuse(StringInfo buf, PqMsg msgtype); extern void pq_endmessage(StringInfo buf); @@ -191,10 +193,6 @@ pq_sendint(StringInfo buf, uint32 i, int b) extern void pq_begintypsend(StringInfo buf); extern bytea *pq_endtypsend(StringInfo buf); - -extern void pq_puttextmessage(PqMsg msgtype, const char *str); -extern void pq_putemptymessage(PqMsg msgtype); - extern int pq_getmsgbyte(StringInfo msg); extern unsigned int pq_getmsgint(StringInfo msg, int b); extern int64 pq_getmsgint64(StringInfo msg); -- 2.45.2