Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 454c182

Browse files
committed
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
1 parent ebdccea commit 454c182

File tree

6 files changed

+18
-15
lines changed

6 files changed

+18
-15
lines changed

src/backend/libpq/pqcomm.c

+8-5
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ static int socket_flush_if_writable(void);
144144
static bool socket_is_send_pending(void);
145145
static int socket_putmessage(char msgtype, const char *s, size_t len);
146146
static void socket_putmessage_noblock(char msgtype, const char *s, size_t len);
147-
static inline int internal_putbytes(const char *s, size_t len);
147+
static inline int internal_putbytes(const void *b, size_t len);
148148
static inline int internal_flush(void);
149149
static pg_noinline int internal_flush_buffer(const char *buf, size_t *start,
150150
size_t *end);
@@ -1060,8 +1060,9 @@ pq_getbyte_if_available(unsigned char *c)
10601060
* --------------------------------
10611061
*/
10621062
int
1063-
pq_getbytes(char *s, size_t len)
1063+
pq_getbytes(void *b, size_t len)
10641064
{
1065+
char *s = b;
10651066
size_t amount;
10661067

10671068
Assert(PqCommReadingMsg);
@@ -1209,7 +1210,7 @@ pq_getmessage(StringInfo s, int maxlen)
12091210
resetStringInfo(s);
12101211

12111212
/* Read message length word */
1212-
if (pq_getbytes((char *) &len, 4) == EOF)
1213+
if (pq_getbytes(&len, 4) == EOF)
12131214
{
12141215
ereport(COMMERROR,
12151216
(errcode(ERRCODE_PROTOCOL_VIOLATION),
@@ -1274,8 +1275,10 @@ pq_getmessage(StringInfo s, int maxlen)
12741275

12751276

12761277
static inline int
1277-
internal_putbytes(const char *s, size_t len)
1278+
internal_putbytes(const void *b, size_t len)
12781279
{
1280+
const char *s = b;
1281+
12791282
while (len > 0)
12801283
{
12811284
/* If buffer is full, then flush it out */
@@ -1499,7 +1502,7 @@ socket_putmessage(char msgtype, const char *s, size_t len)
14991502
goto fail;
15001503

15011504
n32 = pg_hton32((uint32) (len + 4));
1502-
if (internal_putbytes((char *) &n32, 4))
1505+
if (internal_putbytes(&n32, 4))
15031506
goto fail;
15041507

15051508
if (internal_putbytes(s, len))

src/backend/libpq/pqformat.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -422,15 +422,15 @@ pq_getmsgint(StringInfo msg, int b)
422422
switch (b)
423423
{
424424
case 1:
425-
pq_copymsgbytes(msg, (char *) &n8, 1);
425+
pq_copymsgbytes(msg, &n8, 1);
426426
result = n8;
427427
break;
428428
case 2:
429-
pq_copymsgbytes(msg, (char *) &n16, 2);
429+
pq_copymsgbytes(msg, &n16, 2);
430430
result = pg_ntoh16(n16);
431431
break;
432432
case 4:
433-
pq_copymsgbytes(msg, (char *) &n32, 4);
433+
pq_copymsgbytes(msg, &n32, 4);
434434
result = pg_ntoh32(n32);
435435
break;
436436
default:
@@ -454,7 +454,7 @@ pq_getmsgint64(StringInfo msg)
454454
{
455455
uint64 n64;
456456

457-
pq_copymsgbytes(msg, (char *) &n64, sizeof(n64));
457+
pq_copymsgbytes(msg, &n64, sizeof(n64));
458458

459459
return pg_ntoh64(n64);
460460
}
@@ -525,7 +525,7 @@ pq_getmsgbytes(StringInfo msg, int datalen)
525525
* --------------------------------
526526
*/
527527
void
528-
pq_copymsgbytes(StringInfo msg, char *buf, int datalen)
528+
pq_copymsgbytes(StringInfo msg, void *buf, int datalen)
529529
{
530530
if (datalen < 0 || datalen > (msg->len - msg->cursor))
531531
ereport(ERROR,

src/backend/tcop/backend_startup.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done)
480480
* sound inefficient, but it's not really, because of buffering in
481481
* pqcomm.c.)
482482
*/
483-
if (pq_getbytes((char *) &len, 1) == EOF)
483+
if (pq_getbytes(&len, 1) == EOF)
484484
{
485485
/*
486486
* If we get no data at all, don't clutter the log with a complaint;

src/backend/utils/adt/varbit.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ bit_recv(PG_FUNCTION_ARGS)
361361
SET_VARSIZE(result, len);
362362
VARBITLEN(result) = bitlen;
363363

364-
pq_copymsgbytes(buf, (char *) VARBITS(result), VARBITBYTES(result));
364+
pq_copymsgbytes(buf, VARBITS(result), VARBITBYTES(result));
365365

366366
/* Make sure last byte is correctly zero-padded */
367367
VARBIT_PAD(result);
@@ -666,7 +666,7 @@ varbit_recv(PG_FUNCTION_ARGS)
666666
SET_VARSIZE(result, len);
667667
VARBITLEN(result) = bitlen;
668668

669-
pq_copymsgbytes(buf, (char *) VARBITS(result), VARBITBYTES(result));
669+
pq_copymsgbytes(buf, VARBITS(result), VARBITBYTES(result));
670670

671671
/* Make sure last byte is correctly zero-padded */
672672
VARBIT_PAD(result);

src/include/libpq/libpq.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ extern int AcceptConnection(pgsocket server_fd, ClientSocket *client_sock);
7171
extern void TouchSocketFiles(void);
7272
extern void RemoveSocketFiles(void);
7373
extern Port *pq_init(ClientSocket *client_sock);
74-
extern int pq_getbytes(char *s, size_t len);
74+
extern int pq_getbytes(void *b, size_t len);
7575
extern void pq_startmsgread(void);
7676
extern void pq_endmsgread(void);
7777
extern bool pq_is_reading_msg(void);

src/include/libpq/pqformat.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ extern int64 pq_getmsgint64(StringInfo msg);
200200
extern float4 pq_getmsgfloat4(StringInfo msg);
201201
extern float8 pq_getmsgfloat8(StringInfo msg);
202202
extern const char *pq_getmsgbytes(StringInfo msg, int datalen);
203-
extern void pq_copymsgbytes(StringInfo msg, char *buf, int datalen);
203+
extern void pq_copymsgbytes(StringInfo msg, void *buf, int datalen);
204204
extern char *pq_getmsgtext(StringInfo msg, int rawbytes, int *nbytes);
205205
extern const char *pq_getmsgstring(StringInfo msg);
206206
extern const char *pq_getmsgrawstring(StringInfo msg);

0 commit comments

Comments
 (0)