Subject: [PATCH v3 3/3] add helper functions for fast-path arg setup

From: Reviewer <[email-masked]>
Date: Tue, 2 Jun 2026 18:24:30 +0000

---
 src/interfaces/libpq/fe-lobj.c | 104 ++++++++++++---------------------
 1 file changed, 38 insertions(+), 66 deletions(-)

diff --git a/src/interfaces/libpq/fe-lobj.c b/src/interfaces/libpq/fe-lobj.c
index 42b2a36bda9..8802c6f8098 100644
--- a/src/interfaces/libpq/fe-lobj.c
+++ b/src/interfaces/libpq/fe-lobj.c
@@ -44,6 +44,22 @@
 static int	lo_initialize(PGconn *conn);
 static Oid	lo_import_internal(PGconn *conn, const char *filename, Oid oid);
 
+static inline void
+lo_set_int_arg(PQArgBlock *arg, int value)
+{
+	arg->isint = 1;
+	arg->len = 4;
+	arg->u.integer = value;
+}
+
+static inline void
+lo_set_ptr_arg(PQArgBlock *arg, const void *ptr, int len)
+{
+	arg->isint = 0;
+	arg->len = len;
+	arg->u.ptr = (int *) unconstify(void *, ptr);
+}
+
 /*
  * lo_open
  *	  opens an existing large object
@@ -62,13 +78,9 @@ lo_open(PGconn *conn, Oid lobjId, int mode)
 	if (lo_initialize(conn) < 0)
 		return -1;
 
-	argv[0].isint = 1;
-	argv[0].len = 4;
-	argv[0].u.integer = lobjId;
+	lo_set_int_arg(&argv[0], lobjId);
 
-	argv[1].isint = 1;
-	argv[1].len = 4;
-	argv[1].u.integer = mode;
+	lo_set_int_arg(&argv[1], mode);
 
 	res = PQnfn(conn, conn->lobjfuncs->fn_lo_open, &fd, -1, &result_len, 1, argv, 2);
 	if (PQresultStatus(res) == PGRES_COMMAND_OK)
@@ -101,9 +113,7 @@ lo_close(PGconn *conn, int fd)
 	if (lo_initialize(conn) < 0)
 		return -1;
 
-	argv[0].isint = 1;
-	argv[0].len = 4;
-	argv[0].u.integer = fd;
+	lo_set_int_arg(&argv[0], fd);
 	res = PQnfn(conn, conn->lobjfuncs->fn_lo_close,
 				&retval, -1, &result_len, 1, argv, 1);
 	if (PQresultStatus(res) == PGRES_COMMAND_OK)
@@ -159,13 +169,9 @@ lo_truncate(PGconn *conn, int fd, size_t len)
 		return -1;
 	}
 
-	argv[0].isint = 1;
-	argv[0].len = 4;
-	argv[0].u.integer = fd;
+	lo_set_int_arg(&argv[0], fd);
 
-	argv[1].isint = 1;
-	argv[1].len = 4;
-	argv[1].u.integer = (int) len;
+	lo_set_int_arg(&argv[1], (int) len);
 
 	res = PQnfn(conn, conn->lobjfuncs->fn_lo_truncate,
 				&retval, -1, &result_len, 1, argv, 2);
@@ -207,14 +213,10 @@ lo_truncate64(PGconn *conn, int fd, int64_t len)
 		return -1;
 	}
 
-	argv[0].isint = 1;
-	argv[0].len = 4;
-	argv[0].u.integer = fd;
+	lo_set_int_arg(&argv[0], fd);
 
 	len = pg_hton64(len);
-	argv[1].isint = 0;
-	argv[1].len = 8;
-	argv[1].u.ptr = (int *) &len;
+	lo_set_ptr_arg(&argv[1], &len, 8);
 
 	res = PQnfn(conn, conn->lobjfuncs->fn_lo_truncate64,
 				&retval, -1, &result_len, 1, argv, 2);
@@ -261,13 +263,9 @@ lo_read(PGconn *conn, int fd, char *buf, size_t len)
 		return -1;
 	}
 
-	argv[0].isint = 1;
-	argv[0].len = 4;
-	argv[0].u.integer = fd;
+	lo_set_int_arg(&argv[0], fd);
 
-	argv[1].isint = 1;
-	argv[1].len = 4;
-	argv[1].u.integer = (int) len;
+	lo_set_int_arg(&argv[1], (int) len);
 
 	res = PQnfn(conn, conn->lobjfuncs->fn_lo_read,
 				(void *) buf, len, &result_len, 0, argv, 2);
@@ -312,13 +310,9 @@ lo_write(PGconn *conn, int fd, const char *buf, size_t len)
 		return -1;
 	}
 
-	argv[0].isint = 1;
-	argv[0].len = 4;
-	argv[0].u.integer = fd;
+	lo_set_int_arg(&argv[0], fd);
 
-	argv[1].isint = 0;
-	argv[1].len = (int) len;
-	argv[1].u.ptr = (int *) unconstify(char *, buf);
+	lo_set_ptr_arg(&argv[1], buf, (int) len);
 
 	res = PQnfn(conn, conn->lobjfuncs->fn_lo_write,
 				&retval, -1, &result_len, 1, argv, 2);
@@ -349,17 +343,11 @@ lo_lseek(PGconn *conn, int fd, int offset, int whence)
 	if (lo_initialize(conn) < 0)
 		return -1;
 
-	argv[0].isint = 1;
-	argv[0].len = 4;
-	argv[0].u.integer = fd;
+	lo_set_int_arg(&argv[0], fd);
 
-	argv[1].isint = 1;
-	argv[1].len = 4;
-	argv[1].u.integer = offset;
+	lo_set_int_arg(&argv[1], offset);
 
-	argv[2].isint = 1;
-	argv[2].len = 4;
-	argv[2].u.integer = whence;
+	lo_set_int_arg(&argv[2], whence);
 
 	res = PQnfn(conn, conn->lobjfuncs->fn_lo_lseek,
 				&retval, -1, &result_len, 1, argv, 3);
@@ -397,18 +385,12 @@ lo_lseek64(PGconn *conn, int fd, int64_t offset, int whence)
 		return -1;
 	}
 
-	argv[0].isint = 1;
-	argv[0].len = 4;
-	argv[0].u.integer = fd;
+	lo_set_int_arg(&argv[0], fd);
 
 	offset = pg_hton64(offset);
-	argv[1].isint = 0;
-	argv[1].len = 8;
-	argv[1].u.ptr = (int *) &offset;
+	lo_set_ptr_arg(&argv[1], &offset, 8);
 
-	argv[2].isint = 1;
-	argv[2].len = 4;
-	argv[2].u.integer = whence;
+	lo_set_int_arg(&argv[2], whence);
 
 	res = PQnfn(conn, conn->lobjfuncs->fn_lo_lseek64,
 				(void *) &retval, sizeof(retval), &result_len, 0, argv, 3);
@@ -443,9 +425,7 @@ lo_creat(PGconn *conn, int mode)
 	if (lo_initialize(conn) < 0)
 		return InvalidOid;
 
-	argv[0].isint = 1;
-	argv[0].len = 4;
-	argv[0].u.integer = mode;
+	lo_set_int_arg(&argv[0], mode);
 	res = PQnfn(conn, conn->lobjfuncs->fn_lo_creat,
 				&retval, -1, &result_len, 1, argv, 1);
 	if (PQresultStatus(res) == PGRES_COMMAND_OK)
@@ -487,9 +467,7 @@ lo_create(PGconn *conn, Oid lobjId)
 		return InvalidOid;
 	}
 
-	argv[0].isint = 1;
-	argv[0].len = 4;
-	argv[0].u.integer = lobjId;
+	lo_set_int_arg(&argv[0], lobjId);
 	res = PQnfn(conn, conn->lobjfuncs->fn_lo_create,
 				&retval, -1, &result_len, 1, argv, 1);
 	if (PQresultStatus(res) == PGRES_COMMAND_OK)
@@ -520,9 +498,7 @@ lo_tell(PGconn *conn, int fd)
 	if (lo_initialize(conn) < 0)
 		return -1;
 
-	argv[0].isint = 1;
-	argv[0].len = 4;
-	argv[0].u.integer = fd;
+	lo_set_int_arg(&argv[0], fd);
 
 	res = PQnfn(conn, conn->lobjfuncs->fn_lo_tell,
 				&retval, -1, &result_len, 1, argv, 1);
@@ -560,9 +536,7 @@ lo_tell64(PGconn *conn, int fd)
 		return -1;
 	}
 
-	argv[0].isint = 1;
-	argv[0].len = 4;
-	argv[0].u.integer = fd;
+	lo_set_int_arg(&argv[0], fd);
 
 	res = PQnfn(conn, conn->lobjfuncs->fn_lo_tell64,
 				(void *) &retval, sizeof(retval), &result_len, 0, argv, 1);
@@ -594,9 +568,7 @@ lo_unlink(PGconn *conn, Oid lobjId)
 	if (lo_initialize(conn) < 0)
 		return -1;
 
-	argv[0].isint = 1;
-	argv[0].len = 4;
-	argv[0].u.integer = lobjId;
+	lo_set_int_arg(&argv[0], lobjId);
 
 	res = PQnfn(conn, conn->lobjfuncs->fn_lo_unlink,
 				&retval, -1, &result_len, 1, argv, 1);
-- 
2.50.1 (Apple Git-155)

--6CoALBM/+cswbGQ8--