Use inttypes.h definitions

This commit is contained in:
Daniele Varrazzo 2016-08-14 19:48:31 +01:00
parent 12ecb4b2ce
commit e5390fed98
4 changed files with 17 additions and 18 deletions

View File

@ -46,15 +46,15 @@
* backend code. The protocol always uses integer timestamps, regardless of * backend code. The protocol always uses integer timestamps, regardless of
* server setting. * server setting.
*/ */
pg_int64 int64_t
feGetCurrentTimestamp(void) feGetCurrentTimestamp(void)
{ {
pg_int64 result; int64_t result;
struct timeval tp; struct timeval tp;
gettimeofday(&tp, NULL); gettimeofday(&tp, NULL);
result = (pg_int64) tp.tv_sec - result = (int64_t) tp.tv_sec -
((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY); ((POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * SECS_PER_DAY);
result = (result * USECS_PER_SEC) + tp.tv_usec; result = (result * USECS_PER_SEC) + tp.tv_usec;
@ -66,17 +66,17 @@ feGetCurrentTimestamp(void)
* Converts an int64 to network byte order. * Converts an int64 to network byte order.
*/ */
void void
fe_sendint64(pg_int64 i, char *buf) fe_sendint64(int64_t i, char *buf)
{ {
uint32 n32; uint32_t n32;
/* High order half first, since we're doing MSB-first */ /* High order half first, since we're doing MSB-first */
n32 = (uint32) (i >> 32); n32 = (uint32_t) (i >> 32);
n32 = htonl(n32); n32 = htonl(n32);
memcpy(&buf[0], &n32, 4); memcpy(&buf[0], &n32, 4);
/* Now the low order half */ /* Now the low order half */
n32 = (uint32) i; n32 = (uint32_t) i;
n32 = htonl(n32); n32 = htonl(n32);
memcpy(&buf[4], &n32, 4); memcpy(&buf[4], &n32, 4);
} }
@ -84,12 +84,12 @@ fe_sendint64(pg_int64 i, char *buf)
/* /*
* Converts an int64 from network byte order to native format. * Converts an int64 from network byte order to native format.
*/ */
pg_int64 int64_t
fe_recvint64(char *buf) fe_recvint64(char *buf)
{ {
pg_int64 result; int64_t result;
uint32 h32; uint32_t h32;
uint32 l32; uint32_t l32;
memcpy(&h32, buf, 4); memcpy(&h32, buf, 4);
memcpy(&l32, buf + 4, 4); memcpy(&l32, buf + 4, 4);

View File

@ -29,11 +29,10 @@
/* type and constant definitions from internal postgres include */ /* type and constant definitions from internal postgres include */
typedef unsigned PG_INT64_TYPE XLogRecPtr; typedef unsigned PG_INT64_TYPE XLogRecPtr;
typedef uint32_t uint32;
/* have to use lowercase %x, as PyString_FromFormat can't do %X */ /* have to use lowercase %x, as PyString_FromFormat can't do %X */
#define XLOGFMTSTR "%x/%x" #define XLOGFMTSTR "%x/%x"
#define XLOGFMTARGS(x) ((uint32)((x) >> 32)), ((uint32)((x) & 0xFFFFFFFF)) #define XLOGFMTARGS(x) ((uint32_t)((x) >> 32)), ((uint32_t)((x) & 0xFFFFFFFF))
/* Julian-date equivalents of Day 0 in Unix and Postgres reckoning */ /* Julian-date equivalents of Day 0 in Unix and Postgres reckoning */
#define UNIX_EPOCH_JDATE 2440588 /* == date2j(1970, 1, 1) */ #define UNIX_EPOCH_JDATE 2440588 /* == date2j(1970, 1, 1) */
@ -42,8 +41,8 @@ typedef uint32_t uint32;
#define SECS_PER_DAY 86400 #define SECS_PER_DAY 86400
#define USECS_PER_SEC 1000000LL #define USECS_PER_SEC 1000000LL
HIDDEN pg_int64 feGetCurrentTimestamp(void); HIDDEN int64_t feGetCurrentTimestamp(void);
HIDDEN void fe_sendint64(pg_int64 i, char *buf); HIDDEN void fe_sendint64(int64_t i, char *buf);
HIDDEN pg_int64 fe_recvint64(char *buf); HIDDEN int64_t fe_recvint64(char *buf);
#endif /* !defined(PSYCOPG_LIBPQ_SUPPORT_H) */ #endif /* !defined(PSYCOPG_LIBPQ_SUPPORT_H) */

View File

@ -1555,7 +1555,7 @@ pq_read_replication_message(replicationCursorObject *repl, replicationMessageObj
char *buffer = NULL; char *buffer = NULL;
int len, data_size, consumed, hdr, reply; int len, data_size, consumed, hdr, reply;
XLogRecPtr data_start, wal_end; XLogRecPtr data_start, wal_end;
pg_int64 send_time; int64_t send_time;
PyObject *str = NULL, *result = NULL; PyObject *str = NULL, *result = NULL;
int ret = -1; int ret = -1;

View File

@ -45,7 +45,7 @@ struct replicationMessageObject {
int data_size; int data_size;
XLogRecPtr data_start; XLogRecPtr data_start;
XLogRecPtr wal_end; XLogRecPtr wal_end;
pg_int64 send_time; int64_t send_time;
}; };
RAISES_NEG int psyco_replmsg_datetime_init(void); RAISES_NEG int psyco_replmsg_datetime_init(void);