From 1f7ac47f5b6281bd010b5f6451be3f48f8a57151 Mon Sep 17 00:00:00 2001
From: Andres Freund <andres@anarazel.de>
Date: Tue, 14 Jan 2020 12:58:55 -0800
Subject: [PATCH v3 06/10] Use pq_begintypsend_with_size() in a number of send
 functions

If we were to introduce pq_begintypsend_with_size(), we'd probably want to do
this to quite a few more functions.

Author: Andres Freund <andres@anarazel.de>
Discussion: https://postgr.es/m/20200603015559.qc7ry5jqmoxlpu4y@alap3.anarazel.de

<>

Author:
Reviewed-by:
Discussion: https://postgr.es/m/
Backpatch:
---
 src/backend/utils/adt/bool.c    | 2 +-
 src/backend/utils/adt/float.c   | 4 ++--
 src/backend/utils/adt/int.c     | 4 ++--
 src/backend/utils/adt/int8.c    | 2 +-
 src/backend/utils/adt/uuid.c    | 2 +-
 src/backend/utils/adt/varlena.c | 2 +-
 6 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/backend/utils/adt/bool.c b/src/backend/utils/adt/bool.c
index 85e6786563e..fe188f4f03c 100644
--- a/src/backend/utils/adt/bool.c
+++ b/src/backend/utils/adt/bool.c
@@ -189,7 +189,7 @@ boolsend(PG_FUNCTION_ARGS)
 	bool		arg1 = PG_GETARG_BOOL(0);
 	StringInfoData buf;
 
-	pq_begintypsend(&buf);
+	pq_begintypsend_with_size(&buf, 1);
 	pq_sendbyte(&buf, arg1 ? 1 : 0);
 	PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
 }
diff --git a/src/backend/utils/adt/float.c b/src/backend/utils/adt/float.c
index 901edcc8961..4f29c435e2e 100644
--- a/src/backend/utils/adt/float.c
+++ b/src/backend/utils/adt/float.c
@@ -351,7 +351,7 @@ float4send(PG_FUNCTION_ARGS)
 	float4		num = PG_GETARG_FLOAT4(0);
 	StringInfoData buf;
 
-	pq_begintypsend(&buf);
+	pq_begintypsend_with_size(&buf, 4);
 	pq_sendfloat4(&buf, num);
 	PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
 }
@@ -568,7 +568,7 @@ float8send(PG_FUNCTION_ARGS)
 	float8		num = PG_GETARG_FLOAT8(0);
 	StringInfoData buf;
 
-	pq_begintypsend(&buf);
+	pq_begintypsend_with_size(&buf, 8);
 	pq_sendfloat8(&buf, num);
 	PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
 }
diff --git a/src/backend/utils/adt/int.c b/src/backend/utils/adt/int.c
index 234f20796b7..761dc4acce9 100644
--- a/src/backend/utils/adt/int.c
+++ b/src/backend/utils/adt/int.c
@@ -100,7 +100,7 @@ int2send(PG_FUNCTION_ARGS)
 	int16		arg1 = PG_GETARG_INT16(0);
 	StringInfoData buf;
 
-	pq_begintypsend(&buf);
+	pq_begintypsend_with_size(&buf, 2);
 	pq_sendint16(&buf, arg1);
 	PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
 }
@@ -324,7 +324,7 @@ int4send(PG_FUNCTION_ARGS)
 	int32		arg1 = PG_GETARG_INT32(0);
 	StringInfoData buf;
 
-	pq_begintypsend(&buf);
+	pq_begintypsend_with_size(&buf, 4);
 	pq_sendint32(&buf, arg1);
 	PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
 }
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c
index ede14086aee..5423cb2ecde 100644
--- a/src/backend/utils/adt/int8.c
+++ b/src/backend/utils/adt/int8.c
@@ -97,7 +97,7 @@ int8send(PG_FUNCTION_ARGS)
 	int64		arg1 = PG_GETARG_INT64(0);
 	StringInfoData buf;
 
-	pq_begintypsend(&buf);
+	pq_begintypsend_with_size(&buf, 8);
 	pq_sendint64(&buf, arg1);
 	PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
 }
diff --git a/src/backend/utils/adt/uuid.c b/src/backend/utils/adt/uuid.c
index 73dfd711c73..5e04640bce3 100644
--- a/src/backend/utils/adt/uuid.c
+++ b/src/backend/utils/adt/uuid.c
@@ -153,7 +153,7 @@ uuid_send(PG_FUNCTION_ARGS)
 	pg_uuid_t  *uuid = PG_GETARG_UUID_P(0);
 	StringInfoData buffer;
 
-	pq_begintypsend(&buffer);
+	pq_begintypsend_with_size(&buffer, UUID_LEN);
 	pq_sendbytes(&buffer, uuid->data, UUID_LEN);
 	PG_RETURN_BYTEA_P(pq_endtypsend(&buffer));
 }
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 01d5d0dbb63..ea696c1dc71 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -621,7 +621,7 @@ textsend(PG_FUNCTION_ARGS)
 	text	   *t = PG_GETARG_TEXT_PP(0);
 	StringInfoData buf;
 
-	pq_begintypsend(&buf);
+	pq_begintypsend_with_size(&buf, VARSIZE_ANY_EXHDR(t));
 	pq_sendtext(&buf, VARDATA_ANY(t), VARSIZE_ANY_EXHDR(t));
 	PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
 }
-- 
2.38.0

