>>>>> "Petr" == Petr Jelinek <[email protected]> writes:
>> So wouldn't it make more sense to move these definitions into c.h and
>> standardize their usage?
Petr> I was thinking the same when I've seen Peter's version of Numeric
Petr> abbreviations patch. So +1 for that.
Suggested patch attached.
--
Andrew (irc:RhodiumToad)
diff --git a/contrib/btree_gist/btree_ts.c b/contrib/btree_gist/btree_ts.c
index b9c2b49..d472d49 100644
--- a/contrib/btree_gist/btree_ts.c
+++ b/contrib/btree_gist/btree_ts.c
@@ -153,7 +153,7 @@ ts_dist(PG_FUNCTION_ARGS)
p->day = INT_MAX;
p->month = INT_MAX;
#ifdef HAVE_INT64_TIMESTAMP
- p->time = INT64CONST(0x7FFFFFFFFFFFFFFF);
+ p->time = INT64_MAX;
#else
p->time = DBL_MAX;
#endif
@@ -181,7 +181,7 @@ tstz_dist(PG_FUNCTION_ARGS)
p->day = INT_MAX;
p->month = INT_MAX;
#ifdef HAVE_INT64_TIMESTAMP
- p->time = INT64CONST(0x7FFFFFFFFFFFFFFF);
+ p->time = INT64_MAX;
#else
p->time = DBL_MAX;
#endif
diff --git a/contrib/pgbench/pgbench.c b/contrib/pgbench/pgbench.c
index 706fdf5..822adfd 100644
--- a/contrib/pgbench/pgbench.c
+++ b/contrib/pgbench/pgbench.c
@@ -49,10 +49,6 @@
#include <sys/resource.h> /* for getrlimit */
#endif
-#ifndef INT64_MAX
-#define INT64_MAX INT64CONST(0x7FFFFFFFFFFFFFFF)
-#endif
-
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
@@ -453,7 +449,7 @@ strtoint64(const char *str)
*/
if (strncmp(ptr, "9223372036854775808", 19) == 0)
{
- result = -INT64CONST(0x7fffffffffffffff) - 1;
+ result = INT64_MIN;
ptr += 19;
goto gotdigits;
}
diff --git a/src/backend/access/transam/xlog.c b/src/backend/access/transam/xlog.c
index e2d187f..656d55b 100644
--- a/src/backend/access/transam/xlog.c
+++ b/src/backend/access/transam/xlog.c
@@ -1408,7 +1408,7 @@ WALInsertLockAcquireExclusive(void)
{
LWLockAcquireWithVar(&WALInsertLocks[i].l.lock,
&WALInsertLocks[i].l.insertingAt,
- UINT64CONST(0xFFFFFFFFFFFFFFFF));
+ UINT64_MAX);
}
LWLockAcquireWithVar(&WALInsertLocks[i].l.lock,
&WALInsertLocks[i].l.insertingAt,
diff --git a/src/backend/utils/adt/int8.c b/src/backend/utils/adt/int8.c
index 56d909a..b3a1191 100644
--- a/src/backend/utils/adt/int8.c
+++ b/src/backend/utils/adt/int8.c
@@ -78,7 +78,7 @@ scanint8(const char *str, bool errorOK, int64 *result)
*/
if (strncmp(ptr, "9223372036854775808", 19) == 0)
{
- tmp = -INT64CONST(0x7fffffffffffffff) - 1;
+ tmp = INT64_MIN;
ptr += 19;
goto gotdigits;
}
diff --git a/src/backend/utils/adt/numutils.c b/src/backend/utils/adt/numutils.c
index d77799a..585da1e 100644
--- a/src/backend/utils/adt/numutils.c
+++ b/src/backend/utils/adt/numutils.c
@@ -190,7 +190,7 @@ pg_lltoa(int64 value, char *a)
* Avoid problems with the most negative integer not being representable
* as a positive integer.
*/
- if (value == (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1))
+ if (value == INT64_MIN)
{
memcpy(a, "-9223372036854775808", 21);
return;
diff --git a/src/backend/utils/adt/timestamp.c b/src/backend/utils/adt/timestamp.c
index 723c670..33e859d 100644
--- a/src/backend/utils/adt/timestamp.c
+++ b/src/backend/utils/adt/timestamp.c
@@ -44,14 +44,6 @@
#define SAMESIGN(a,b) (((a) < 0) == ((b) < 0))
-#ifndef INT64_MAX
-#define INT64_MAX INT64CONST(0x7FFFFFFFFFFFFFFF)
-#endif
-
-#ifndef INT64_MIN
-#define INT64_MIN (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
-#endif
-
/* Set at postmaster start */
TimestampTz PgStartTime;
diff --git a/src/backend/utils/adt/txid.c b/src/backend/utils/adt/txid.c
index f973ef9..31f8033 100644
--- a/src/backend/utils/adt/txid.c
+++ b/src/backend/utils/adt/txid.c
@@ -34,7 +34,7 @@
/* txid will be signed int8 in database, so must limit to 63 bits */
-#define MAX_TXID UINT64CONST(0x7FFFFFFFFFFFFFFF)
+#define MAX_TXID ((uint64) INT64_MAX)
/* Use unsigned variant internally */
typedef uint64 txid;
diff --git a/src/include/c.h b/src/include/c.h
index 7447218..e3ed527 100644
--- a/src/include/c.h
+++ b/src/include/c.h
@@ -284,6 +284,17 @@ typedef unsigned long long int uint64;
#define UINT64CONST(x) ((uint64) x)
#endif
+/* should be defined in stdint.h */
+#ifndef INT64_MIN
+#define INT64_MIN (-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
+#endif
+#ifndef INT64_MAX
+#define INT64_MAX INT64CONST(0x7FFFFFFFFFFFFFFF)
+#endif
+#ifndef UINT64_MAX
+#define UINT64_MAX UINT64CONST(0xFFFFFFFFFFFFFFFF)
+#endif
+
/* snprintf format strings to use for 64-bit integers */
#define INT64_FORMAT "%" INT64_MODIFIER "d"
#define UINT64_FORMAT "%" INT64_MODIFIER "u"
diff --git a/src/include/datatype/timestamp.h b/src/include/datatype/timestamp.h
index 6dfaf23..d3450d6 100644
--- a/src/include/datatype/timestamp.h
+++ b/src/include/datatype/timestamp.h
@@ -119,8 +119,8 @@ typedef struct
* DT_NOBEGIN represents timestamp -infinity; DT_NOEND represents +infinity
*/
#ifdef HAVE_INT64_TIMESTAMP
-#define DT_NOBEGIN (-INT64CONST(0x7fffffffffffffff) - 1)
-#define DT_NOEND (INT64CONST(0x7fffffffffffffff))
+#define DT_NOBEGIN INT64_MIN
+#define DT_NOEND INT64_MAX
#else /* !HAVE_INT64_TIMESTAMP */
#ifdef HUGE_VAL
#define DT_NOBEGIN (-HUGE_VAL)
diff --git a/src/include/pg_config_manual.h b/src/include/pg_config_manual.h
index 5cfc0ae..a207aeb 100644
--- a/src/include/pg_config_manual.h
+++ b/src/include/pg_config_manual.h
@@ -48,7 +48,7 @@
/*
* Set the upper and lower bounds of sequence values.
*/
-#define SEQ_MAXVALUE INT64CONST(0x7FFFFFFFFFFFFFFF)
+#define SEQ_MAXVALUE INT64_MAX
#define SEQ_MINVALUE (-SEQ_MAXVALUE)
/*
diff --git a/src/include/port/atomics.h b/src/include/port/atomics.h
index 89868b5..9917364 100644
--- a/src/include/port/atomics.h
+++ b/src/include/port/atomics.h
@@ -489,7 +489,7 @@ STATIC_IF_INLINE uint64
pg_atomic_fetch_sub_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
{
AssertPointerAlignment(ptr, 8);
- Assert(sub_ != -INT64CONST(0x7FFFFFFFFFFFFFFF) - 1);
+ Assert(sub_ != INT64_MIN);
return pg_atomic_fetch_sub_u64_impl(ptr, sub_);
}
@@ -518,7 +518,7 @@ STATIC_IF_INLINE uint64
pg_atomic_sub_fetch_u64(volatile pg_atomic_uint64 *ptr, int64 sub_)
{
AssertPointerAlignment(ptr, 8);
- Assert(sub_ != -INT64CONST(0x7FFFFFFFFFFFFFFF) - 1);
+ Assert(sub_ != INT64_MIN);
return pg_atomic_sub_fetch_u64_impl(ptr, sub_);
}
diff --git a/src/include/storage/predicate_internals.h b/src/include/storage/predicate_internals.h
index 2aaf580..8ecf923 100644
--- a/src/include/storage/predicate_internals.h
+++ b/src/include/storage/predicate_internals.h
@@ -33,7 +33,7 @@ typedef uint64 SerCommitSeqNo;
* at that point. It's earlier than all normal sequence numbers,
* and is only used by recovered prepared transactions
*/
-#define InvalidSerCommitSeqNo ((SerCommitSeqNo) UINT64CONST(0xFFFFFFFFFFFFFFFF))
+#define InvalidSerCommitSeqNo ((SerCommitSeqNo) UINT64_MAX)
#define RecoverySerCommitSeqNo ((SerCommitSeqNo) 1)
#define FirstNormalSerCommitSeqNo ((SerCommitSeqNo) 2)
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers