Skip to content

Commit 3c86223

Browse files
committed
libpq: Deprecate pg_int64.
Previously we used pg_int64 in three function prototypes in libpq. It was added by commit 461ef73 to expose the platform-dependent type used for int64 in the C89 era. As of commit 962da90 it is defined as standard int64_t, and the dust seems to have settled. Let's just use int64_t directly in these three client-facing functions instead of (yet) another name. We've required C99 and thus <stdint.h> since PostgreSQL 12, C89 and C++98 compilers are long gone, and client applications very likely use standard types for their own 64-bit needs. This also cleans up the obscure placement of a new #include <stdint.h> directive in postgres_ext.h, required for the new definition. The typedef was hiding in there for historical reasons, but it doesn't fit postgres_ext.h's own description of its purpose and there is no evidence of client applications including postgres_ext.h directly to see it. Keep a typedef marked deprecated for backward compatibility, but move it into libpq-fe.h where it was used. Reviewed-by: Peter Eisentraut <peter@eisentraut.org> Discussion: https://postgr.es/m/CA%2BhUKGKn_EkNNGMY5RzMcKP%2Ba6urT4JF%3DCPhw_zHtQwjvX6P2g%40mail.gmail.com
1 parent be1cc9a commit 3c86223

File tree

6 files changed

+31
-31
lines changed

6 files changed

+31
-31
lines changed

doc/src/sgml/libpq.sgml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ switch(PQstatus(conn))
522522
sequence described in the documentation of
523523
<xref linkend="libpq-PQconnectStartParams"/>.
524524
<synopsis>
525-
typedef pg_int64 pg_usec_time_t;
525+
typedef int64_t pg_usec_time_t;
526526

527527
int PQsocketPoll(int sock, int forRead, int forWrite,
528528
pg_usec_time_t end_time);

doc/src/sgml/lobj.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ int lo_lseek(PGconn *conn, int fd, int offset, int whence);
398398
When dealing with large objects that might exceed 2GB in size,
399399
instead use
400400
<synopsis>
401-
pg_int64 lo_lseek64(PGconn *conn, int fd, pg_int64 offset, int whence);
401+
int64_t lo_lseek64(PGconn *conn, int fd, int64_t offset, int whence);
402402
</synopsis>
403403
This function has the same behavior
404404
as <function>lo_lseek</function>, but it can accept an
@@ -434,7 +434,7 @@ int lo_tell(PGconn *conn, int fd);
434434
When dealing with large objects that might exceed 2GB in size,
435435
instead use
436436
<synopsis>
437-
pg_int64 lo_tell64(PGconn *conn, int fd);
437+
int64_t lo_tell64(PGconn *conn, int fd);
438438
</synopsis>
439439
This function has the same behavior
440440
as <function>lo_tell</function>, but it can deliver a result larger
@@ -485,7 +485,7 @@ int lo_truncate(PGconn *conn, int fd, size_t len);
485485
When dealing with large objects that might exceed 2GB in size,
486486
instead use
487487
<synopsis>
488-
int lo_truncate64(PGconn *conn, int fd, pg_int64 len);
488+
int lo_truncate64(PGconn *conn, int fd, int64_t len);
489489
</synopsis>
490490
This function has the same
491491
behavior as <function>lo_truncate</function>, but it can accept a

src/include/postgres_ext.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
#ifndef POSTGRES_EXT_H
2525
#define POSTGRES_EXT_H
2626

27-
#include <stdint.h>
28-
2927
/*
3028
* Object ID is a fundamental type in Postgres.
3129
*/
@@ -44,9 +42,6 @@ typedef unsigned int Oid;
4442
/* the above needs <stdlib.h> */
4543

4644

47-
/* Define a signed 64-bit integer type for use in client API declarations. */
48-
typedef int64_t pg_int64;
49-
5045
/*
5146
* Identifiers of error message fields. Kept here to keep common
5247
* between frontend and backend, and also to export them to libpq

src/interfaces/libpq/fe-lobj.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343

4444
static int lo_initialize(PGconn *conn);
4545
static Oid lo_import_internal(PGconn *conn, const char *filename, Oid oid);
46-
static pg_int64 lo_hton64(pg_int64 host64);
47-
static pg_int64 lo_ntoh64(pg_int64 net64);
46+
static int64_t lo_hton64(int64_t host64);
47+
static int64_t lo_ntoh64(int64_t net64);
4848

4949
/*
5050
* lo_open
@@ -192,7 +192,7 @@ lo_truncate(PGconn *conn, int fd, size_t len)
192192
* returns -1 upon failure
193193
*/
194194
int
195-
lo_truncate64(PGconn *conn, int fd, pg_int64 len)
195+
lo_truncate64(PGconn *conn, int fd, int64_t len)
196196
{
197197
PQArgBlock argv[2];
198198
PGresult *res;
@@ -381,12 +381,12 @@ lo_lseek(PGconn *conn, int fd, int offset, int whence)
381381
* lo_lseek64
382382
* change the current read or write location on a large object
383383
*/
384-
pg_int64
385-
lo_lseek64(PGconn *conn, int fd, pg_int64 offset, int whence)
384+
int64_t
385+
lo_lseek64(PGconn *conn, int fd, int64_t offset, int whence)
386386
{
387387
PQArgBlock argv[3];
388388
PGresult *res;
389-
pg_int64 retval;
389+
int64 retval;
390390
int result_len;
391391

392392
if (lo_initialize(conn) < 0)
@@ -544,10 +544,10 @@ lo_tell(PGconn *conn, int fd)
544544
* lo_tell64
545545
* returns the current seek location of the large object
546546
*/
547-
pg_int64
547+
int64_t
548548
lo_tell64(PGconn *conn, int fd)
549549
{
550-
pg_int64 retval;
550+
int64 retval;
551551
PQArgBlock argv[1];
552552
PGresult *res;
553553
int result_len;
@@ -1019,12 +1019,12 @@ lo_initialize(PGconn *conn)
10191019
* lo_hton64
10201020
* converts a 64-bit integer from host byte order to network byte order
10211021
*/
1022-
static pg_int64
1023-
lo_hton64(pg_int64 host64)
1022+
static int64_t
1023+
lo_hton64(int64_t host64)
10241024
{
10251025
union
10261026
{
1027-
pg_int64 i64;
1027+
int64 i64;
10281028
uint32 i32[2];
10291029
} swap;
10301030
uint32 t;
@@ -1044,15 +1044,15 @@ lo_hton64(pg_int64 host64)
10441044
* lo_ntoh64
10451045
* converts a 64-bit integer from network byte order to host byte order
10461046
*/
1047-
static pg_int64
1048-
lo_ntoh64(pg_int64 net64)
1047+
static int64_t
1048+
lo_ntoh64(int64_t net64)
10491049
{
10501050
union
10511051
{
1052-
pg_int64 i64;
1052+
int64 i64;
10531053
uint32 i32[2];
10541054
} swap;
1055-
pg_int64 result;
1055+
int64 result;
10561056

10571057
swap.i64 = net64;
10581058

src/interfaces/libpq/libpq-fe.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ extern "C"
2020
{
2121
#endif
2222

23+
#include <stdint.h>
2324
#include <stdio.h>
2425

2526
/*
@@ -233,8 +234,11 @@ typedef struct pgNotify
233234
struct pgNotify *next; /* list link */
234235
} PGnotify;
235236

237+
/* deprecated name for int64_t */
238+
typedef int64_t pg_int64;
239+
236240
/* pg_usec_time_t is like time_t, but with microsecond resolution */
237-
typedef pg_int64 pg_usec_time_t;
241+
typedef int64_t pg_usec_time_t;
238242

239243
/* Function types for notice-handling callbacks */
240244
typedef void (*PQnoticeReceiver) (void *arg, const PGresult *res);
@@ -691,13 +695,13 @@ extern int lo_close(PGconn *conn, int fd);
691695
extern int lo_read(PGconn *conn, int fd, char *buf, size_t len);
692696
extern int lo_write(PGconn *conn, int fd, const char *buf, size_t len);
693697
extern int lo_lseek(PGconn *conn, int fd, int offset, int whence);
694-
extern pg_int64 lo_lseek64(PGconn *conn, int fd, pg_int64 offset, int whence);
698+
extern int64_t lo_lseek64(PGconn *conn, int fd, int64_t offset, int whence);
695699
extern Oid lo_creat(PGconn *conn, int mode);
696700
extern Oid lo_create(PGconn *conn, Oid lobjId);
697701
extern int lo_tell(PGconn *conn, int fd);
698-
extern pg_int64 lo_tell64(PGconn *conn, int fd);
702+
extern int64_t lo_tell64(PGconn *conn, int fd);
699703
extern int lo_truncate(PGconn *conn, int fd, size_t len);
700-
extern int lo_truncate64(PGconn *conn, int fd, pg_int64 len);
704+
extern int lo_truncate64(PGconn *conn, int fd, int64_t len);
701705
extern int lo_unlink(PGconn *conn, Oid lobjId);
702706
extern Oid lo_import(PGconn *conn, const char *filename);
703707
extern Oid lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId);

src/test/examples/testlo64.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
15+
#include <stdint.h>
1516
#include <stdio.h>
1617
#include <stdlib.h>
1718

@@ -75,7 +76,7 @@ importFile(PGconn *conn, char *filename)
7576
}
7677

7778
static void
78-
pickout(PGconn *conn, Oid lobjId, pg_int64 start, int len)
79+
pickout(PGconn *conn, Oid lobjId, int64_t start, int len)
7980
{
8081
int lobj_fd;
8182
char *buf;
@@ -110,7 +111,7 @@ pickout(PGconn *conn, Oid lobjId, pg_int64 start, int len)
110111
}
111112

112113
static void
113-
overwrite(PGconn *conn, Oid lobjId, pg_int64 start, int len)
114+
overwrite(PGconn *conn, Oid lobjId, int64_t start, int len)
114115
{
115116
int lobj_fd;
116117
char *buf;
@@ -148,7 +149,7 @@ overwrite(PGconn *conn, Oid lobjId, pg_int64 start, int len)
148149
}
149150

150151
static void
151-
my_truncate(PGconn *conn, Oid lobjId, pg_int64 len)
152+
my_truncate(PGconn *conn, Oid lobjId, int64_t len)
152153
{
153154
int lobj_fd;
154155

0 commit comments

Comments
 (0)