1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-21 00:42:43 +03:00

backend libpq void * argument for binary data

Change some backend libpq functions to take void * for binary data
instead of char *.  This removes the need for numerous casts.

Reviewed-by: Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
Discussion: https://www.postgresql.org/message-id/flat/fd1fcedb-3492-4fc8-9e3e-74b97f2db6c7%40eisentraut.org
This commit is contained in:
Peter Eisentraut
2025-02-23 14:26:39 +01:00
parent ebdccead16
commit 454c182f85
6 changed files with 18 additions and 15 deletions

View File

@@ -144,7 +144,7 @@ static int socket_flush_if_writable(void);
static bool socket_is_send_pending(void);
static int socket_putmessage(char msgtype, const char *s, size_t len);
static void socket_putmessage_noblock(char msgtype, const char *s, size_t len);
static inline int internal_putbytes(const char *s, size_t len);
static inline int internal_putbytes(const void *b, size_t len);
static inline int internal_flush(void);
static pg_noinline int internal_flush_buffer(const char *buf, size_t *start,
size_t *end);
@@ -1060,8 +1060,9 @@ pq_getbyte_if_available(unsigned char *c)
* --------------------------------
*/
int
pq_getbytes(char *s, size_t len)
pq_getbytes(void *b, size_t len)
{
char *s = b;
size_t amount;
Assert(PqCommReadingMsg);
@@ -1209,7 +1210,7 @@ pq_getmessage(StringInfo s, int maxlen)
resetStringInfo(s);
/* Read message length word */
if (pq_getbytes((char *) &len, 4) == EOF)
if (pq_getbytes(&len, 4) == EOF)
{
ereport(COMMERROR,
(errcode(ERRCODE_PROTOCOL_VIOLATION),
@@ -1274,8 +1275,10 @@ pq_getmessage(StringInfo s, int maxlen)
static inline int
internal_putbytes(const char *s, size_t len)
internal_putbytes(const void *b, size_t len)
{
const char *s = b;
while (len > 0)
{
/* If buffer is full, then flush it out */
@@ -1499,7 +1502,7 @@ socket_putmessage(char msgtype, const char *s, size_t len)
goto fail;
n32 = pg_hton32((uint32) (len + 4));
if (internal_putbytes((char *) &n32, 4))
if (internal_putbytes(&n32, 4))
goto fail;
if (internal_putbytes(s, len))

View File

@@ -422,15 +422,15 @@ pq_getmsgint(StringInfo msg, int b)
switch (b)
{
case 1:
pq_copymsgbytes(msg, (char *) &n8, 1);
pq_copymsgbytes(msg, &n8, 1);
result = n8;
break;
case 2:
pq_copymsgbytes(msg, (char *) &n16, 2);
pq_copymsgbytes(msg, &n16, 2);
result = pg_ntoh16(n16);
break;
case 4:
pq_copymsgbytes(msg, (char *) &n32, 4);
pq_copymsgbytes(msg, &n32, 4);
result = pg_ntoh32(n32);
break;
default:
@@ -454,7 +454,7 @@ pq_getmsgint64(StringInfo msg)
{
uint64 n64;
pq_copymsgbytes(msg, (char *) &n64, sizeof(n64));
pq_copymsgbytes(msg, &n64, sizeof(n64));
return pg_ntoh64(n64);
}
@@ -525,7 +525,7 @@ pq_getmsgbytes(StringInfo msg, int datalen)
* --------------------------------
*/
void
pq_copymsgbytes(StringInfo msg, char *buf, int datalen)
pq_copymsgbytes(StringInfo msg, void *buf, int datalen)
{
if (datalen < 0 || datalen > (msg->len - msg->cursor))
ereport(ERROR,